Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove special treatment of DC in tfCorrection + fix load_TF_fromVNA #100

Merged
merged 12 commits into from
Dec 6, 2024
14 changes: 3 additions & 11 deletions src/MDF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,9 @@ function rxTransferFunction(f::MDFFile)
return nothing
end
end
function rxTransferFunctionFileName(f::MDFFile)
parameter = "/acquisition/receiver/transferFunctionFileName"
if haskey(f.file, parameter)
return f[parameter]
else
return nothing
end
end
function rxHasTransferFunction(f::MDFFile)
haskey(f.file, "/acquisition/receiver/transferFunction")
end
rxTransferFunctionFileName(f::MDFFile) = @keyoptional f["/acquisition/receiver/transferFunctionFileName"]
rxHasTransferFunction(f::MDFFile) = haskey(f.file, "/acquisition/receiver/transferFunction")

rxInductionFactor(f::MDFFileV1) = nothing
rxInductionFactor(f::MDFFileV2) = @keyoptional f["/acquisition/receiver/inductionFactor"]

Expand Down
13 changes: 3 additions & 10 deletions src/Measurements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,8 @@ function getMeasurements(f::MPIFile, neglectBGFrames=true;

J = size(data,1)
dataF = rfft(data, 1)
dataF[2:end,:,:,:] ./= tf[2:end,:,:,:]

if all(tf[1,:,:,:] .!= 0) && !any(isnan.(tf[1,:,:,:]))
dataF[1,:,:,:] ./= tf[1,:,:,:]
end
dataF ./= tf
dataF[isnan.(dataF)] .= zero(eltype(dataF))
jusack marked this conversation as resolved.
Show resolved Hide resolved

@warn "This measurement has been corrected with a Transfer Function. Name of TF: $(rxTransferFunctionFileName(f))"
if !isnothing(inductionFactor)
Expand Down Expand Up @@ -335,11 +332,7 @@ function getMeasurementsFD(f::MPIFile, args...;
inductionFactor = ones(Float64, rxNumChannels(f))
end

data[2:end,:,:,:] ./= tf[2:end,:,:,:]

if all(tf[1,:,:,:] .!= 0) && !any(isnan.(tf[1,:,:,:]))
data[1,:,:,:] ./= tf[1,:,:,:]
end
data ./= tf
jonschumacher marked this conversation as resolved.
Show resolved Hide resolved

@warn "This measurement has been corrected with a Transfer Function. Name of TF: $(rxTransferFunctionFileName(f))"
if !isnothing(inductionFactor)
Expand Down
10 changes: 7 additions & 3 deletions src/TransferFunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@
return
end

setTF(f::MDFFile, filenameTF::AbstractString) = setTF(f, TransferFunction(filenameTF), filenameTF)

Check warning on line 293 in src/TransferFunction.jl

View check run for this annotation

Codecov / codecov/patch

src/TransferFunction.jl#L293

Added line #L293 was not covered by tests

function setTF(f::MDFFile, filenameTF::AbstractString)
tmf = TransferFunction(filenameTF)
function setTF(f::MDFFile, tmf::TransferFunction, filenameTF::Union{AbstractString,Nothing}=nothing)

Check warning on line 295 in src/TransferFunction.jl

View check run for this annotation

Codecov / codecov/patch

src/TransferFunction.jl#L295

Added line #L295 was not covered by tests
jusack marked this conversation as resolved.
Show resolved Hide resolved
tf = sampleTF(tmf, f)

# We need to close the HDF5 file handle before we can write to it
Expand All @@ -302,7 +302,9 @@
if haskey(file, "/acquisition/receiver/transferFunctionFileName")
delete_object(file, "/acquisition/receiver/transferFunctionFileName")
end
write(file, "/acquisition/receiver/transferFunctionFileName", filenameTF)
if !isnothing(filenameTF)
write(file, "/acquisition/receiver/transferFunctionFileName", filenameTF)

Check warning on line 306 in src/TransferFunction.jl

View check run for this annotation

Codecov / codecov/patch

src/TransferFunction.jl#L305-L306

Added lines #L305 - L306 were not covered by tests
end
if haskey(file, "/acquisition/receiver/transferFunction")
delete_object(file, "/acquisition/receiver/transferFunction")
end
Expand All @@ -312,6 +314,8 @@
end
write(file, "/acquisition/receiver/inductionFactor", tmf.inductionFactor)
end
# reopen filehandler so f stays usable
f.file = h5open(filepath(f), "r")

Check warning on line 318 in src/TransferFunction.jl

View check run for this annotation

Codecov / codecov/patch

src/TransferFunction.jl#L318

Added line #L318 was not covered by tests
return
end

Expand Down
Loading