rainbow.agilent.chemstation
Methods for parsing Agilent Chemstation files.
Functions
|
|
|
|
|
Decode the absorbances of an Agilent .uv file stored as raw doubles. |
|
Decode the delta-encoded absorbances of an Agilent .uv file. |
|
Returns the string at the next index in |
|
Returns the VialNumber from an XML document, if it exists. |
|
Finds and parses Agilent Chemstation data files with a .ch, .uv, or .ms extension from a .D directory. |
|
Parses an Agilent .ch file. |
|
Parses an Agilent .ch file in the 179/181 container. |
|
Parses an Agilent .ch file with CAD, ELSD, or UV channel data. |
|
Parses an Agilent Chemstation data file. |
|
Parses Agilent metadata at the directory level. |
|
Parses an Agilent .ms file. |
|
Parses a partial Agilent .ms file. |
|
Extracts wavelength settings from a signal description, if present. |
|
Parses an Agilent .uv file. |
|
Parses a partial Agilent .uv file. |
|
Extracts metadata from the header of an Agilent data file. |
|
Reads the sample name and operator from a .D directory's metadata files. |
|
Extracts a string from the specified offset. |
- parse_optics(description)[source]
Extracts wavelength settings from a signal description, if present.
Returns a dict with any of
wavelength,bandwidth,reference_wavelength, andreference_bandwidth(in nm), parsed from theSig=/Ref=clause of a single-wavelength channel.Ref=offgives areference_wavelengthof None: the channel states that it has no reference, which is not the same as stating nothing about one, and two channels at one wavelength differ by it. A fluorescence channel’sEx=/Em=clause givesexcitation_wavelengthandemission_wavelengthinstead. Descriptions without such a clause (spectra, FID, telemetry) yield an empty dict.
- parse_allfiles(path, display_precision='auto', bin_width=None, requested_files=None, labels_only=False)[source]
Finds and parses Agilent Chemstation data files with a .ch, .uv, or .ms extension from a .D directory.
- Parameters:
path (str) – Path to the .D directory.
display_precision (int, optional) – Decimals for the displayed m/z labels.
bin_width (float, optional) – m/z bin width for .ms binning.
requested_files (list, optional) – List of filenames to parse.
- Returns:
List with a DataFile for each parsed data file.
- parse_file(path, display_precision=0, bin_width=1.0, labels_only=False)[source]
Parses an Agilent Chemstation data file.
Supported extensions are .ch, .uv, and .ms.
- Parameters:
path (str) – Path to the data file.
display_precision (int, optional) – Decimals for displayed m/z labels.
bin_width (float, optional) – m/z bin width for .ms binning.
- Returns:
DataFile representing the file, if it can be parsed. Otherwise, None.
- parse_ch(path)[source]
Parses an Agilent .ch file.
These files contain data from a FID, CAD, ELSD, or UV channel. The version at the head of the file says how the data is encoded, not what measured it: Chemstation writes a diode-array channel and a flame ionization channel into the same 179/181 container, and the channel’s own signal string is what tells them apart.
This method calls the appropriate subroutine by file format.
- Parameters:
path (str) – Path to the .ch file.
- Returns:
DataFile with data from a channel, if the file can be parsed. Otherwise, None.
- parse_ch_fid(path, head)[source]
Parses an Agilent .ch file in the 179/181 container.
Flame ionization data is the usual occupant, and the default for a channel whose signal string names no detector rainbow knows, but a diode-array channel is written into the same container: the detector comes from the signal string, not from the version. Note that the 181 layout has no signal offset, so a 181 file is always read as FID.
This method should not be called directly. Use
parse_chinstead.Learn more about this file format here.
- Parameters:
path (str) – Path to the .ch file.
- Returns:
DataFile for the channel, if the file can be parsed. Otherwise, None.
- parse_ch_other(path, head)[source]
Parses an Agilent .ch file with CAD, ELSD, or UV channel data.
This method should not be called directly. Use
parse_chinstead.IMPORTANT: ELSD data may be mistakenly labeled as CAD on rare occasions. Users may need to make this distinction on their own when decoding Agilent CAD or ELSD data.
Learn more about this file format here.
- Parameters:
path (str) – Path to the .ch file with UV, CAD, or ELSD data.
- Returns:
DataFile with CAD, ELSD, or UV data, if parsable. Otherwise, None.
- decode_uv_delta(f, data_offsets, num_times, num_wavelengths)[source]
Decode the delta-encoded absorbances of an Agilent .uv file.
Each retention time holds
num_wavelengthsabsorbances stored as 16-bit deltas against a running accumulator. The sentinel value-0x8000instead signals that the next 32-bit integer is a new absolute value.If the compiled accelerator (
rainbow.agilent._uvdelta) was built it is used for the inner loop; otherwise this falls back to the pure-Python loop below, which produces identical output. Seeparse_uv.- Parameters:
f (_io.BufferedReader) – File opened in ‘rb’ mode.
data_offsets (dict) – Offsets for this file format.
num_times (int) – Number of retention times.
num_wavelengths (int) – Number of wavelengths per time.
- Returns:
a uint32 array of raw times and an
(num_times, num_wavelengths)int64 array of absorbances.- Return type:
Tuple of
(times, data)
- decode_uv_array(f, data_offsets, num_times, num_wavelengths)[source]
Decode the absorbances of an Agilent .uv file stored as raw doubles.
Used by the
OLformat variant, where each absorbance is a little-endian float64 rather than a delta. Seeparse_uv.- Parameters:
f (_io.BufferedReader) – File opened in ‘rb’ mode.
data_offsets (dict) – Offsets for this file format.
num_times (int) – Number of retention times.
num_wavelengths (int) – Number of wavelengths per time.
- Returns:
a uint32 array of raw times and an
(num_times, num_wavelengths)float64 array of absorbances.- Return type:
Tuple of
(times, data)
- parse_uv(path)[source]
Parses an Agilent .uv file.
These files contain UV spectra.
Learn more about this file format here.
- Parameters:
path (str) – Path to the Agilent .uv file.
- Returns:
DataFile with UV data, if the file can be parsed. Otherwise, None.
- parse_uv_partial(path)[source]
Parses a partial Agilent .uv file.
Learn more about this file format here.
- Parameters:
path (str) – Path to the partial .uv file.
- Returns:
DataFile with UV data, if the file can be parsed. Otherwise, None.
- parse_ms(path, display_precision=0, bin_width=1.0, labels_only=False)[source]
Parses an Agilent .ms file.
These files contain MS spectra and SIM.
Learn more about this file format here.
- Parameters:
path (str) – Path to Agilent .ms file.
display_precision (int, optional) – Decimals for the displayed m/z labels.
bin_width (float, optional) – Width in daltons of each m/z bin. The lossy control: pairs within one bin are summed. Defaults to 1 (nominal mass). Agilent quadrupole .ms records m/z on a 0.05 Da grid.
labels_only (bool, optional) – Return the m/z labels against an empty grid, for a caller that reads nothing but the axis; see
rainbow._binning.bin_datapairs. Passed on toparse_ms_partialwhen the file turns out to be a partial.
- Returns:
DataFile with MS data, if the file can be parsed. Otherwise, None.
- parse_ms_partial(path, display_precision=0, bin_width=1.0, labels_only=False)[source]
Parses a partial Agilent .ms file.
IMPORTANT: This method only supports LC .ms partials.
Learn more about this file format here.
- Parameters:
path (str) – Path to the partial .ms file.
display_precision (int, optional) – Decimals for the displayed m/z labels.
bin_width (float, optional) – Width in daltons of each m/z bin.
labels_only (bool, optional) – Return the m/z labels against an empty grid, for a caller that reads nothing but the axis; see
rainbow._binning.bin_datapairs.
- Returns:
DataFile with MS data, if the file can be parsed. Otherwise, None.
- read_header(f, offsets, gap=2)[source]
Extracts metadata from the header of an Agilent data file.
- Parameters:
f (_io.BufferedReader) – File opened in ‘rb’ mode.
offsets (dict) – Dictionary mapping properties to file offsets.
gap (int) – Distance between two adjacent characters.
- Returns:
Dictionary containing metadata as string key-value pairs.
- read_string(f, offset, gap=2)[source]
Extracts a string from the specified offset.
This method is primarily useful for retrieving metadata.
- Parameters:
f (_io.BufferedReader) – File opened in ‘rb’ mode.
offset (int) – Offset to begin reading from.
gap (int) – Distance between two adjacent characters.
- Returns:
String at the specified offset in the file header.
- parse_metadata(path, datafiles)[source]
Parses Agilent metadata at the directory level.
First, the DataFiles are checked for date and vial position metadata.
Then, several files are scanned for the vial position. This method can look inside the AcqData directory, which may be misleading because this method resides in the Chemstation module.
- Parameters:
path (str) – Path to the directory.
datafiles (list) – List of DataFile objects.
- Returns:
Dictionary containing directory metadata.
- read_sample_metadata(path, dircontents)[source]
Reads the sample name and operator from a .D directory’s metadata files.
Classic Chemstation runs store these in
SAMPLE.XML(UTF-16); MassHunter runs store them asFieldentries inAcqData/sample_info.xml. Both are optional and best-effort: a missing file, an empty value, or a parse error simply yields nothing.- Parameters:
path (str) – Path to the .D directory.
dircontents (set) – Names in the directory (from
os.listdir).
- Returns:
Dictionary with any of
sampleandoperator.