Skip to content

Commit

Permalink
Uploading csvMentingToBin.py used to produce binary magnetic field table
Browse files Browse the repository at this point in the history
  • Loading branch information
jgalan committed Feb 12, 2024
1 parent 4c74ea9 commit 3951cb4
Showing 1 changed file with 39 additions and 50 deletions.
89 changes: 39 additions & 50 deletions scripts/csvMentinkToBin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,34 @@
import matplotlib.pyplot as plt
import pandas as pd

# We insert a cut-off on the field z-axis (in meters)
zCutOffLow = -6
zCutOffHigh = 6

# Field map is provided only for the top magnetic bore. We will recenter the field map.
# Since this is a condition for TRestAxionMagneticField.
xCenter = 0
yCenter = 0
zCenter = 0.7975
yCenter = 0.8
zCenter = 0

print("Starting to read")
# loading the data into a matrix (xyzBdata)
file = r"../../../data/magneticField/Mentink_202401.xlsx"
df = pd.read_excel(file)
file = r"../data/magneticField/Mentink_20240124.txt"
df = pd.read_csv(file, comment="%", sep='\t',header=None)
print( df.head() )

print(df[1:5])
print( "---" )
print(df[0:5])
print( "---" )

print("Translating to matrix")
xyzBdata = df.as_matrix(columns=df.columns[0:])
xyzBdata = df.values

print( "#####" )
print(xyzBdata[0][0:6])
print(xyzBdata[1][0:6])
print(xyzBdata[2][0:6])
print( "#####" )

print(len(xyzBdata))

Expand All @@ -52,20 +63,7 @@
f = open("output.txt", "wt")

for x in xyzBdata:
f.write(
str(x[0])
+ "\t"
+ str(x[1])
+ "\t"
+ str(x[2])
+ "\t"
+ str(x[3])
+ "\t"
+ str(x[4])
+ "\t"
+ str(x[5])
+ "\n"
)
f.write( str(x[0]) + "\t" + str(x[1]) + "\t" + str(x[2]) + "\t" + str(x[3]) + "\t" + str(x[4]) + "\t" + str(x[5]) + "\n")
if xMax < x[0]:
xMax = x[0]
if yMax < x[1]:
Expand Down Expand Up @@ -118,35 +116,26 @@
for x in xyzBdata:
# We recenter the volume and redefine axis (x becomes z, y becomes x and z becomes y)
# XLS file distances are expressed in m. We translate to mm.
y = [
1000 * (x[1] - yCenter),
1000 * (x[2] - zCenter),
1000 * (x[0] - xCenter),
x[4],
x[5],
x[3],
]

# Baby-IAXO is symmetric respect to z (direction along axis) and x (direction parallel to the ground).
# I.e. x and y in the previous axis definition.
# The y-axis symmetry (in the new axis definition) affects the second bore that is not described in this map.
# We apply the corresponding symmetries to define the full map of one magnetic bore in the output binary file.

count = count + 1
fbin.write(struct.pack("<%df" % len(y), *y))
if count < 6:
print(len(y))
print(x[0:6])
print(y[0:6])
# The original file was only missing the z-axis, when we change the sign of z-axis we must change the sign of Bz.
if y[2] > 0:
y[2] = -y[2]
y[5] = -y[5]
count = count + 1
fbin.write(struct.pack("<%df" % len(y), *y))
if count < 6:
print(len(y))
print(x[0:6])
print(y[0:6])

if( x[2] <= zCutOffHigh and x[2] > zCutOffLow):
y = [
1000 * (x[0] - xCenter),
1000 * (x[1] - yCenter),
1000 * (x[2] - zCenter),
x[3],
x[4],
x[5],
]

# Baby-IAXO is symmetric respect to z (direction along axis) and x (direction parallel to the ground).
# I.e. x and y in the previous axis definition.
# The y-axis symmetry (in the new axis definition) affects the second bore that is not described in this map.
# We apply the corresponding symmetries to define the full map of one magnetic bore in the output binary file.
count = count + 1
fbin.write(struct.pack("<%df" % len(y), *y))
if count < 6:
print(len(y))
print(x[0:6])
print(y[0:6])
fbin.close()
print("Lines writen : " + str(count))

0 comments on commit 3951cb4

Please sign in to comment.