8import matplotlib.pylab
as plt
11from scipy.ndimage
import gaussian_filter
15 plotData = datum[datum[
"y"] == 0]
16 H, _xedges, _yedges = np.histogram2d(plotData[
"x"], plotData[
"z"], bins=[50, 500], weights=plotData[
"by"])
17 plt.figure(figsize=[20, 10])
18 plt.imshow(H, interpolation=
"nearest", origin=
"low")
23def generate_file(input_fileName, output, xSpace=73, ySpace=128, zSpace=1214, step=2.5, args=None) -> None:
25 field = pd.read_csv(input_fileName, skiprows=1, sep=
r"\s+", names=[
"x",
"y",
"z",
"bx",
"by",
"bz"])
27 field_mask = field.copy()
28 field_mask[[
"bx",
"by",
"bz"]] = field_mask[[
"bx",
"by",
"bz"]] != 0
30 field_new = field.copy()
33 temp_by = np.array(field_new[
"by"]).reshape([xSpace, ySpace, zSpace])
34 temp_by = gaussian_filter(temp_by, sigma=args.sigma)
35 field_new[
"by"] = temp_by.reshape(-1)
36 field_new[
"by"] = field_new[
"by"] * field_mask[
"by"]
39 field_new[[
"bx",
"by",
"bz"]] = 0
40 index_range = np.random.choice(field_new.index, size=args.nCores)
41 field_new.loc[index_range,
"by"] = random.uniform(-args.peak, args.peak)
42 temp_by = np.array(field_new[
"by"]).reshape([xSpace, ySpace, zSpace])
43 temp_by = gaussian_filter(temp_by, sigma=args.sigma)
44 field_new[
"by"] = temp_by.reshape(-1)
45 field_new[
"by"] = field_new[
"by"] / (field_new[
"by"].abs().max())
46 field_new[
"by"] = field_new[
"by"] * field_mask[
"by"]
48 rezult[
"by"] = rezult[
"by"] + rezult[
"by"] * field_new[
"by"] * args.fraction
54 rezult.to_csv(output, sep=
"\t", header=
None, index=
None)
57if __name__ ==
"__main__":
58 parser = argparse.ArgumentParser(description=
"Process field.")
59 parser.add_argument(
"--input", default=os.path.expandvars(
"$FAIRSHIP/files/fieldMap.csv"), type=str, action=
"store")
61 "--output", default=os.path.expandvars(
"$FAIRSHIP/files/noisy_fieldMap.csv"), type=str, action=
"store"
63 parser.add_argument(
"--sidesOnly", default=
False, action=
"store_true")
64 parser.add_argument(
"--sigma", default=30, type=float, action=
"store")
65 parser.add_argument(
"--nCores", default=1000, type=int, action=
"store")
66 parser.add_argument(
"--peak", default=500, type=float, action=
"store")
67 parser.add_argument(
"--fraction", default=0.4, type=float, action=
"store")
68 args = parser.parse_args()
70 with open(args.input)
as f:
71 first_line = f.readline().strip().split()
76 xSpace=
int(first_line[0]),
77 ySpace=
int(first_line[1]),
78 zSpace=
int(first_line[2]),
None generate_file(input_fileName, output, xSpace=73, ySpace=128, zSpace=1214, step=2.5, args=None)
int open(const char *, int)
Opens a file descriptor.