Skip to content

Commit

Permalink
Remove explicit HDF5 dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
fhagemann committed Nov 5, 2024
1 parent 068fae0 commit f1f1c5a
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 37 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
ElasticArrays = "fdbdab4c-e67f-52f5-8c3f-e7b388dad3d4"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LegendDataManagement = "9feedd95-f0e0-423f-a8dc-de0970eae6b3"
Expand Down Expand Up @@ -48,7 +47,6 @@ DSP = "0.7"
DelimitedFiles = "1"
Distributions = "0.23, 0.24, 0.25"
ElasticArrays = "1"
HDF5 = "0.15, 0.16, 0.17"
IntervalSets = "0.5, 0.6, 0.7"
JSON = "0.21"
LegendDataManagement = "0.2.1, 0.3, 0.4"
Expand Down
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
LegendHDF5IO = "c9265ca6-b027-5446-b1a4-febfa8dd10b0"
LegendTestData = "33d6da08-6349-5f7c-b5a4-6ff4d8795aaf"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Expand Down
7 changes: 3 additions & 4 deletions docs/src/tutorials/simulate_ideal_pulses_lit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ plot(pss_table.waveform[1:5], legend=false, title="only p+ contact pulses")

# You can save simulated pulses in a file that can be used later.

using HDF5
using LegendHDF5IO

#

pss_name = "cache/test_100wfs_pss.hdf5"
h5open(pss_name, "w") do f
LegendHDF5IO.writedata(f, "pss/pss", pss_table[1:5])
LegendHDF5IO.writedata(f, "pss/truth", pss_truth[1:5])
lh5open(pss_name, "w") do f
LegendHDF5IO.writedata(f.data_store, "pss/pss", pss_table[1:5])
LegendHDF5IO.writedata(f.data_store, "pss/truth", pss_truth[1:5])
end

12 changes: 5 additions & 7 deletions docs/src/tutorials/simulate_realistic_waveforms_lit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ plot(raw_table.waveform[1:10], legend=false, title="only p+ contact waveforms")

# You can save simulated waveforms in a file that can be used later

using HDF5
using LegendHDF5IO

#

raw_name = "cache/test_100wfs_raw.hdf5"
h5open(raw_name, "w") do f
LegendHDF5IO.writedata(f, "raw", raw_table[1:10])
lh5open(raw_name, "w") do f
LegendHDF5IO.writedata(f.data_store, "raw", raw_table[1:10])
end

# ## Simulate from `pss` table in code
Expand Down Expand Up @@ -131,14 +130,13 @@ plot(
# Save the pss file for the next section

using LegendHDF5IO
using HDF5

#

pss_name = "cache/test_100wfs_pss.hdf5"
h5open(pss_name, "w") do f
LegendHDF5IO.writedata(f, "pss/pss", pss_table[1:10])
LegendHDF5IO.writedata(f, "pss/truth", pss_truth[1:10])
lh5open(pss_name, "w") do f
LegendHDF5IO.writedata(f.data_store, "pss/pss", pss_table[1:10])
LegendHDF5IO.writedata(f.data_store, "pss/truth", pss_truth[1:10])
end

# ## Simulate from pre-saved `pss` hdf5 file
Expand Down
1 change: 0 additions & 1 deletion src/LegendGeSim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ using DelimitedFiles
using Distributions
using DSP
using ElasticArrays
using HDF5
using IntervalSets
using JSON
using LegendDataManagement
Expand Down
10 changes: 6 additions & 4 deletions src/baselines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ function baseline_catalog(raw_filename::AbstractString)

if isfile(base_filename)
@info "Selecting baseline samples from $base_filename"
baseline_table = h5open(base_filename) do input Table(waveform = LegendDataTypes.readdata(input, "raw/waveform")) end
baseline_table = LegendHDF5IO.lh5open(base_filename) do input
Table(waveform = LegendDataTypes.readdata(input.data_store, "raw/waveform"))
end
else
@info "Extracting baseline samples from $raw_filename"
raw_table = HDF5.h5open(raw_filename, "r") do input
LegendHDF5IO.readdata(input, "raw")
raw_table = LegendHDF5IO.lh5open(raw_filename, "r") do input
LegendHDF5IO.readdata(input.data_store, "raw")
end
baseline_table = baseline_catalog(raw_table)
# cache for later
if !ispath(dirname(base_filename)) mkpath(dirname(base_filename)) end
h5open(base_filename, "w") do f LegendHDF5IO.writedata(f, "raw", baseline_table) end
LegendHDF5IO.lh5open(base_filename, "w") do f LegendHDF5IO.writedata(f.data_store, "raw", baseline_table) end
@info "Baselines saved to $base_filename"
end

Expand Down
18 changes: 9 additions & 9 deletions src/detector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ function simulate_detector(det_meta::PropDict, env::Environment, simulator::SSDS
if !ispath(dirname(h5fn))
mkpath(dirname(h5fn))
end
HDF5.h5open(h5fn, "w") do h5f
LegendHDF5IO.writedata(h5f, "SSD_electric_potential", NamedTuple(sim.electric_potential))
LegendHDF5IO.writedata(h5f, "SSD_point_types", NamedTuple(sim.point_types))
LegendHDF5IO.writedata(h5f, "SSD_q_eff_fix", NamedTuple(sim.q_eff_fix))
LegendHDF5IO.writedata(h5f, "SSD_q_eff_imp", NamedTuple(sim.q_eff_imp))
LegendHDF5IO.writedata(h5f, "SSD_dielectric_distribution", NamedTuple(sim.ϵ_r))
LegendHDF5IO.writedata(h5f, "SSD_electric_field", NamedTuple(sim.electric_field))
LegendHDF5IO.lh5open(h5fn, "w") do h5f
LegendHDF5IO.writedata(h5f.data_store, "SSD_electric_potential", NamedTuple(sim.electric_potential))
LegendHDF5IO.writedata(h5f.data_store, "SSD_point_types", NamedTuple(sim.point_types))
LegendHDF5IO.writedata(h5f.data_store, "SSD_q_eff_fix", NamedTuple(sim.q_eff_fix))
LegendHDF5IO.writedata(h5f.data_store, "SSD_q_eff_imp", NamedTuple(sim.q_eff_imp))
LegendHDF5IO.writedata(h5f.data_store, "SSD_dielectric_distribution", NamedTuple(sim.ϵ_r))
LegendHDF5IO.writedata(h5f.data_store, "SSD_electric_field", NamedTuple(sim.electric_field))
for i in eachindex(sim.weighting_potentials)
LegendHDF5IO.writedata(h5f, "SSD_weighting_potential_$(i)", NamedTuple(sim.weighting_potentials[i]))
LegendHDF5IO.writedata(h5f.data_store, "SSD_weighting_potential_$(i)", NamedTuple(sim.weighting_potentials[i]))
end
end
@info("-> Saved cached simulation to $h5fn")
Expand All @@ -125,7 +125,7 @@ function simulate_detector(det_meta::PropDict, env::Environment, simulator::SSDS
# read from previously cached
sim = construct_ssd_simulation(det_meta, env, simulator)
@info("Reading SSD simulation from cached file $h5fn")
HDF5.h5open(h5fn, "r") do h5f
LegendHDF5IO.lh5open(h5fn, "r") do h5f
sim.electric_potential = ElectricPotential(LegendHDF5IO.readdata(h5f, "SSD_electric_potential"))
sim.point_types = PointTypes(LegendHDF5IO.readdata(h5f, "SSD_point_types"))
sim.q_eff_fix = EffectiveChargeDensity(LegendHDF5IO.readdata(h5f, "SSD_q_eff_fix"))
Expand Down
6 changes: 3 additions & 3 deletions src/pss_to_raw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ end

# wrapper for user reading from pre-saved pss file
function pss_to_raw(pss_file::AbstractString, setup_settings::Dict, noise_settings::Dict=Dict("type"=>"none"); n_waveforms::Int=0)
pss_h5 = h5open(pss_file, "r")
pss_table = LegendHDF5IO.readdata(pss_h5, "pss/pss")
pss_truth = LegendHDF5IO.readdata(pss_h5, "pss/truth")
pss_h5 = LegendHDF5IO.lh5open(pss_file, "r")
pss_table = LegendHDF5IO.readdata(pss_h5.data_store, "pss/pss")
pss_truth = LegendHDF5IO.readdata(pss_h5.data_store, "pss/truth")
close(pss_h5)

pss_to_raw(pss_table, pss_truth, setup_settings, noise_settings; n_waveforms)
Expand Down
4 changes: 2 additions & 2 deletions src/stp_to_pss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ end


# function stp_to_pss(stp_filepath::AbstractString, det_meta_fullpath::AbstractString, sim_config_filename::AbstractString)
# stp_table = h5open(stp_filepath, "r") do input
# LegendHDF5IO.readdata(input, "stp")
# stp_table = LegendHDF5IO.lh5open(stp_filepath, "r") do input
# LegendHDF5IO.readdata(input.data_store, "stp")
# end

# stp_to_pss(stp_table, det_meta_fullpath, sim_config_filename)
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Test

using LegendGeSim
using LegendHDF5IO, HDF5
using LegendHDF5IO
using LegendTestData
using Unitful

Expand Down Expand Up @@ -62,9 +62,9 @@ end
end

pss_name = "cache/" * LegendGeSim.filename(path_to_pet_file) * "_pss.hdf5"
h5open(pss_name, "w") do f
LegendHDF5IO.writedata(f, "pss/pss", pss_table)
LegendHDF5IO.writedata(f, "pss/truth", pss_truth)
LegendHDF5IO.lh5open(pss_name, "w") do f
LegendHDF5IO.writedata(f.data_store, "pss/pss", pss_table)
LegendHDF5IO.writedata(f.data_store, "pss/truth", pss_truth)
end

@testset "pss I/O using LegendHDF5IO" begin
Expand Down

0 comments on commit f1f1c5a

Please sign in to comment.