objects
ChannelChromatograms
dataclass
¶
ChannelChromatograms(
channel: str,
chromatograms: dict[int, Chromatogram] = dict(),
integrals: DataFrame | None = None,
)
Contains data of a single channel with multiple chromatograms
Parameters:
-
channel(str) –Name of the channel (e.g., 'FID', 'TCD')
-
chromatograms(dict[int, Chromatogram], default:dict()) –Dictionary mapping chromatogram number to Chromatogram objects
-
integrals(DataFrame | None, default:None) –DataFrame containing integrated peak areas for each chromatogram (optional)
Methods:
-
add_chromatogram–Add a chromatogram to the channel
-
plot–Plot all chromatograms in the channel
-
integrate_peaks–Integrate peaks for all chromatograms in the channel, requieres dict of peak limits
chromatograms
class-attribute
instance-attribute
¶
chromatograms: dict[int, Chromatogram] = field(
default_factory=dict
)
add_chromatogram ¶
add_chromatogram(
injection_num: int, chromatogram: Chromatogram
)
apply_baseline ¶
Apply baseline correction to all chromatograms in the channel
Parameters:
-
correction_func–Function that takes a pandas DataFrame and returns corrected Series
-
inplace(bool, default:False) –If True, modify the original data. If False, add new column
-
suffix(str, default:'_BLcorr') –Suffix to add to the new column name when inplace=False
-
**kwargs–Additional arguments to pass to the correction function
Returns:
-
None–Modifies chromatograms in place
Source code in src/chromstream/objects.py
integrate_peaks ¶
Integrate peaks for all chromatograms in the channel
Parameters:
-
peaklist(dict) –Dictionary defining the peaks to integrate. Example:
-
Peaks_TCD = {"N2"–[20, 26], "H2": [16, 19]}
-
column(None | str, default:None) –Optional column name to use for integration. If None, uses second column.
Returns:
-
DataFrame–DataFrame with integrated peak areas for each injection
Source code in src/chromstream/objects.py
plot ¶
Plotting all chromatograms of a channel channel
Source code in src/chromstream/objects.py
to_hdf5 ¶
Write this channel to a standalone HDF5 file.
Parameters:
-
path(Path | str) –The path to the HDF5 file to write.
-
overwrite(bool, default:False) –If True, overwrite the file if it exists.
-
compression(str | None, default:'gzip') –Dataset compression ("gzip", "lzf", or None).
Source code in src/chromstream/objects.py
Chromatogram
dataclass
¶
Chromatogram(
data: DataFrame,
injection_time: Timestamp,
metadata: dict,
channel: str,
path: Path | str | None,
)
Single chromatogram data for one injection on one channel
apply_baseline ¶
Apply baseline correction to the chromatogram data
Parameters:
-
correction_func–Function that takes a pandas DataFrame and returns corrected Series
-
inplace(bool, default:False) –If True, modify the original data. If False, add new column
-
suffix(str, default:'_BLcorr') –Suffix to add to the new column name when inplace=False
Returns:
-
–
pd.DataFrame: The corrected data (same as self.data if inplace=True)
Source code in src/chromstream/objects.py
integrate_peaks ¶
Integrate peaks for this chromatogram
Parameters:
-
peaklist(dict) –Dictionary defining the peaks to integrate. Example:
-
Peaks_TCD = {"N2"–[20, 26], "H2": [16, 19]}
-
column(None | str, default:None) –Optional column name to use for integration. If None, uses second column.
Returns:
-
dict–Dictionary with integrated peak areas and timestamp
Source code in src/chromstream/objects.py
plot ¶
Plot the chromatogram data
Source code in src/chromstream/objects.py
to_hdf5 ¶
to_hdf5(
path: Path | str,
*,
injection_index: int | None = None,
overwrite: bool = False,
compression: str | None = "gzip",
) -> Path
Write this chromatogram to a standalone HDF5 file.
Parameters:
-
path(Path | str) –The path to the HDF5 file to write.
-
injection_index(int | None, default:None) –Optional channel-level injection index to persist so the chromatogram can be reassembled into an Experiment losslessly.
-
overwrite(bool, default:False) –If True, overwrite the file if it exists.
-
compression(str | None, default:'gzip') –Dataset compression ("gzip", "lzf", or None).
Source code in src/chromstream/objects.py
Experiment
dataclass
¶
Experiment(
name: str,
schema: str = SCHEMA_EXPERIMENT,
author: str | None = None,
creation_date: Timestamp | None = None,
metadata: dict[str, object] = dict(),
channels: dict[str, ChannelChromatograms] = dict(),
experiment_starttime: Timestamp | None = None,
experiment_endtime: Timestamp | None = None,
log: DataFrame | None = None,
)
Data for a single experiment containing multiple on-line GC channels
channels
class-attribute
instance-attribute
¶
channels: dict[str, ChannelChromatograms] = field(
default_factory=dict
)
experiment_starttime
class-attribute
instance-attribute
¶
metadata
class-attribute
instance-attribute
¶
add_channel ¶
add_channel(
channel_name: str, channel_data: ChannelChromatograms
)
add_chromatogram ¶
add_chromatogram(
chromatogram: Path | str | Chromatogram,
channel_name: str | None = None,
)
Add a chromatogram to the experiment, automatically creating the channel if it does not exist
Parameters:
-
chromatogram(Path | str | Chromatogram) –Path to the chromatogram file or a Chromatogram object
-
channel_name(Optional[str], default:None) –Optional channel name to override
Source code in src/chromstream/objects.py
add_chromatogram_hdf5 ¶
Add a chromatogram from a standalone HDF5 file into this experiment.
Note on injection index: a standalone chromatogram file may
store the injection_index it had within its channel. When that attr
is present we restore the chromatogram under that exact key, so writing
each chromatogram of an experiment to its own file and reassembling them
round-trips the original (possibly non-contiguous) injection numbering
regardless of the order the files are loaded in. When the attr is absent
(e.g. a hand-made file) we fall back to sequential numbering,
len(existing), matching add_chromatogram's behavior.
Parameters:
-
path(Path | str) –Path to a chromatogram HDF5 file written by ChromStream.
-
channel_name(str | None, default:None) –Optional channel name override; defaults to the channel stored on the chromatogram.
Source code in src/chromstream/objects.py
add_log ¶
Adds a log dataframe to the experiment, either from a dataframe or from a path to the log file.
Parameters:
Source code in src/chromstream/objects.py
add_mult_chromatograms ¶
add_mult_chromatograms(
chromatograms: list[Path | str | Chromatogram]
| Path
| str,
channel_name: str | None = None,
)
Add multiple chromatograms to the experiment
Parameters:
-
chromatograms(list[Path | str | Chromatogram] | Path | str) –Either: - A list of Chromatogram objects - A list of paths to chromatogram files - A path to a .d directory containing .ch files - A path to a .dx archive containing .ch files
-
channel_name(str | None, default:None) –Optional channel name to override for all chromatograms
Source code in src/chromstream/objects.py
plot_chromatograms ¶
Source code in src/chromstream/objects.py
plot_log ¶
Plots specified colums of the experiment log. If use_exp_time is True, the x-axis will be the time since the start of the experiment in minutes. Args: columns (str | list): Column name or list of column names to plot ax (matplotlib.axes.Axes, optional): Axes to plot on. If None, a new figure and axes will be created. use_exp_time (bool, optional): Whether to use time since start of experiment as x-axis. Defaults to False.
Source code in src/chromstream/objects.py
to_hdf5 ¶
Write this experiment to a single HDF5 file. Args: path: The path to the HDF5 file to write. overwrite: If True, overwrite the file if it exists. compression: The compression algorithm to use for datasets. Available options include "gzip", "lzf", or None for no compression. Compression can reduce file size but may increase read/write time. Turned on by default with "gzip". Set to None to disable compression.