Skip to content

Commit

Permalink
load positions from t-design measurement files
Browse files Browse the repository at this point in the history
  • Loading branch information
mboberg committed Aug 20, 2024
1 parent f402bf8 commit 836cac8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/MagneticFieldCoefficients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,17 @@ end
# TODO: This should be merged with and moved to MPIFiles
function calcTDesignCoefficients(filename::String)
# load the measurement data
field, radius, N, t, center, correction = loadMagneticFieldMeasurementData(filename)
field, tDes, correction = loadMagneticFieldMeasurementData(filename)

# calculate the coefficients
tDes = MPIFiles.loadTDesign(Int(t), N, radius * u"m", center .* u"m")
coeffs = magneticField(tDes, field)

# apply the correction of the sensors
for c = 1:size(coeffs, 2), j = 1:3
coeffs[j, c] = SphericalHarmonicExpansions.translation(coeffs[j, c], correction[:, j])
end

coeffs_MF = MagneticFieldCoefficients(coeffs, radius, zeros(size(coeffs)))
coeffs_MF = MagneticFieldCoefficients(coeffs, ustrip(tDes.radius), zeros(size(coeffs)))

return coeffs_MF
end
Expand Down
13 changes: 12 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ function loadMagneticFieldMeasurementData(filename::String)
t = tDes["t"]
center = tDes["center"]

# load spherical t-design
tDes = MPIFiles.loadTDesign(Int(t), N, radius * u"m", center .* u"m")
# if measurementData contains positions, use them as t-design positions
if haskey(measurementData["positions"]["tDesign"], "positions")
tDes.positions = measurementData["positions"]["tDesign"]["positions"]
end

# get optional data
if haskey(measurementData, "sensor")
correction = measurementData["sensor"]["correctionTranslation"]
else
correction = zeros(3,3)
@warn "No correction of the sensor translations found."
end

return field, radius, N, t, center, correction
return field, tDes, correction
end

"""
Expand All @@ -57,6 +65,9 @@ function loadMagneticFieldMeasurementDataV2(filename::String)
tDes["N"] = read(file, "/positions/tDesign/N") # number of points of the t-design
tDes["t"] = Int(read(file, "/positions/tDesign/t")) # t of the t-design
tDes["center"] = read(file, "/positions/tDesign/center") # center of the measured ball
if haskey(file,"positions/tDesign/positions") # optional data
tDes["positions"] = read(file, "/positions/tDesign/positions") # measured positions (shifted and scaled t-design)
end

# sensor
measurementData["sensor"] = Dict{String, Any}()
Expand Down
1 change: 1 addition & 0 deletions test/testWriteLoad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# write data (v2)
h5open(filename, "w") do file
write(file,"/fields", fieldValues) # measured field (size: 3 x #points x #patches)
write(file,"/positions/tDesign/positions", tDes.positions) # measured positions (on the unit-sphere)
write(file,"/positions/tDesign/radius", ustrip(u"m", tDes.radius)) # radius of the measured ball
write(file,"/positions/tDesign/N", size(tDes.positions,2)) # number of points of the t-design
write(file,"/positions/tDesign/t", tDes.T) # t of the t-design
Expand Down

0 comments on commit 836cac8

Please sign in to comment.