From 060430f3951d48dbe297e806adeae9c28da39e3f Mon Sep 17 00:00:00 2001 From: Jonas Krimmer <jonas.krimmer@kit.edu> Date: Mon, 24 Mar 2025 17:16:50 +0000 Subject: [PATCH] refactor --- examples/from_dump.jl | 50 ++++++++++++++++++++++++++++++++++++++++ examples/plot_results.jl | 37 ----------------------------- 2 files changed, 50 insertions(+), 37 deletions(-) create mode 100644 examples/from_dump.jl diff --git a/examples/from_dump.jl b/examples/from_dump.jl new file mode 100644 index 0000000..27eff50 --- /dev/null +++ b/examples/from_dump.jl @@ -0,0 +1,50 @@ +function plot_from_dump(fn; iter=1, mode=1, collimate=false) + z0, meta = h5open(fn, "r") do fid + rx = fid["RXFields"] + _colons = ntuple(_ -> Colon(), ndims(rx) - 1) + + getindex(rx, _colons..., iter), Dict(attrs(fid)) + end + + # third dimension can contain fields for different TX modes + z = z0[:, :, mode] + + Dx = meta["Dx"] + Dy = meta["Dy"] + Nx = meta["Nx"] + Ny = meta["Ny"] + + x, y = fftfreq(Nx, Dx[end]), fftfreq(Ny, Dy[end]) + + if collimate + λ = meta["lambda"] + Dz = meta["Dz"] + yt = transpose(y) + r² = @. x^2 + yt^2 + @. z *= cis(π / (λ * Dz) * r²) + end + + tr = complex_plot(; x, y, z=fftshift(z)) + lt = Config(; xaxis=Config(title="x"), yaxis=Config(title="y", scaleanchor="x", autorange=true)) + Plot(tr, lt) +end + +function attributes_from_dump(fn) + h5open(fn, "r") do fid + OrderedDict(attrs(fid)) + end +end + +function post_dump_sampling_check(fn; kwargs...) + + meta = attributes_from_dump(fn) + N = meta["Nx"] + dx1, dxn = extrema(meta["dx"]) + D1, Dn = extrema(meta["Dx"]) + λ = meta["lambda"] + r0 = meta["r0eff"] + + z = range(0, meta["Dz"], meta["Nz"]) + + check_sampling(z, N, dx1, D1, dxn, Dn; λ, r0, kwargs...) +end \ No newline at end of file diff --git a/examples/plot_results.jl b/examples/plot_results.jl index 8ebf09c..5949040 100644 --- a/examples/plot_results.jl +++ b/examples/plot_results.jl @@ -148,40 +148,3 @@ function plot_fields(T::DataType=Float64; domain::Domain=Domain{T}(), beam::Beam η end - -function plot_from_dump(fn; iter=1, mode=1, collimate=false) - z0, meta = h5open(fn, "r") do fid - rx = fid["RXFields"] - _colons = ntuple(_ -> Colon(), ndims(rx) - 1) - - getindex(rx, _colons..., iter), Dict(attrs(fid)) - end - - # third dimension can contain fields for different TX modes - z = z0[:, :, mode] - - Dx = meta["Dx"] - Dy = meta["Dy"] - Nx = meta["Nx"] - Ny = meta["Ny"] - - x, y = fftfreq(Nx, Dx[end]), fftfreq(Ny, Dy[end]) - - if collimate - λ = meta["lambda"] - Dz = meta["Dz"] - yt = transpose(y) - r² = @. x^2 + yt^2 - @. z *= cis(π / (λ * Dz) * r²) - end - - tr = complex_plot(; x, y, z=fftshift(z)) - lt = Config(; xaxis=Config(title="x"), yaxis=Config(title="y", scaleanchor="x", autorange=true)) - Plot(tr, lt) -end - -function attributes_from_dump(fn) - h5open(fn, "r") do fid - OrderedDict(attrs(fid)) - end -end \ No newline at end of file -- GitLab