Exporting To HDF5¶
ChromStream can save an Experiment object to HDF5 and load it back again. This format is useful when you want a compact binary file, faster repeated loading than reparsing vendor exports, and a portable experiment snapshot for later analysis. It also allows to share a full experiment in one consistent file in an open format, without relying on exporting every injection per channel to seperate files (e.g. csv)
In [3]:
Copied!
from pathlib import Path
from tempfile import TemporaryDirectory
import chromstream as cs
from pathlib import Path
from tempfile import TemporaryDirectory
import chromstream as cs
In [4]:
Copied!
chrompaths = Path("../..") / "tests" / "testdata" / "chroms"
source_path = chrompaths / "test_dx.dx"
experiment = cs.Experiment(name="Agilent DX Export Example")
experiment.add_mult_chromatograms(source_path)
output_path = "example_export.h5"
experiment.to_hdf5(output_path,overwrite=False,compression="gzip") # compression is enabled by default.
loaded = cs.parse_experiment_hdf5(output_path)
chrompaths = Path("../..") / "tests" / "testdata" / "chroms"
source_path = chrompaths / "test_dx.dx"
experiment = cs.Experiment(name="Agilent DX Export Example")
experiment.add_mult_chromatograms(source_path)
output_path = "example_export.h5"
experiment.to_hdf5(output_path,overwrite=False,compression="gzip") # compression is enabled by default.
loaded = cs.parse_experiment_hdf5(output_path)
Exporting single channels and chromatograms¶
Individual ChannelChromatograms and Chromatogram objects can also be written to their own HDF5 files with to_hdf5(), using the same schema-tagged format.
In [ ]:
Copied!
# A single channel...
channel = experiment.channels[experiment.channel_names[0]]
channel.to_hdf5("example_channel.h5", overwrite=True)
# ...or a single chromatogram. Storing its injection_index lets it be
# reassembled into an Experiment later (see the parsing notebook).
injection_num, chromatogram = next(iter(channel.chromatograms.items()))
chromatogram.to_hdf5("example_chromatogram.h5", injection_index=injection_num, overwrite=True)
# A single channel...
channel = experiment.channels[experiment.channel_names[0]]
channel.to_hdf5("example_channel.h5", overwrite=True)
# ...or a single chromatogram. Storing its injection_index lets it be
# reassembled into an Experiment later (see the parsing notebook).
injection_num, chromatogram = next(iter(channel.chromatograms.items()))
chromatogram.to_hdf5("example_chromatogram.h5", injection_index=injection_num, overwrite=True)