rainbow.datadirectory.DataDirectory

class DataDirectory(path, datafiles, metadata)[source]

Bases: object

Class representing a chromatogram data directory.

Parameters:
  • path (str) – Path of the directory.

  • datafiles (list) – All DataFile objects for the directory.

  • metadata (dict) – Metadata for the directory.

Attributes:
  • name (str) – Name of the DataDirectory.

  • datafiles (list) – DataFile objects with a detector. This does not include miscellaneous analog data.

  • detectors (set) – String detector names in the DataDirectory. Options: UV, MS, FID, CAD, ELSD, RID, FLD.

  • by_name (dict) – Maps filenames to DataFile objects.

  • by_detector (dict) – Maps detector names to lists of DataFile objects.

  • analog (list) – DataFile objects with miscellaneous analog data.

  • metadata (dict) – Depends on the vendor.

  • path (str) – Path the directory was read from.

  • name (str) – Name of the directory.

get_info()[source]

Returns a string summary of the DataDirectory.

get_file(filename)[source]

Returns a DataFile object by filename.

Raises an exception if the filename is not in the DataDirectory.

Parameters:

filename (str) – DataFile name.

get_detector(detector)[source]

Returns a list of DataFile objects by detector.

Raises an exception if the detector is invalid.

Parameters:

detector (str) – Detector name.

list_analog()[source]

Prints a summary of the miscellaneous analog data.

extract_traces(filename, labels=None)[source]

Extracts data corresponding to the specified DataFile and labels.

Parameters:
  • filename (str) – DataFile name.

  • labels (int/float/list, optional) – Ylabel(s) to extract.

Returns:

2D numpy array containing data for the specified ylabel(s). The rows correspond to the ylabels and the columns corrrespond to the retention times.

export_csv(in_filename, out_filename, labels=None, delim=',')[source]

Outputs a CSV with data for the specified DataFile and labels.

Parameters:
  • in_filename (str) – DataFile name.

  • out_filename (str) – Filename for the output CSV.

  • labels (int/float/list, optional) – Ylabel(s) to export.

  • delim (str, optional) – Delimiter used in the output CSV.

plot(filename, label, **kwargs)[source]

Shows a basic matplotlib plot for the specified DataFile and label.

Parameters:
  • filename (str) – DataFile name.

  • label (int/float) – Ylabel to be plotted.

  • **kwargs (optional) – Keyword arguments for matplotlib.

to_asm(*, export_dad_cube=True, wavelengths=None, ions=None, decimal_places=None, technique=None, utc_offset=None)[source]

Returns an Allotrope Simple Model (ASM) document for this directory.

ASM is an open, JSON-based standard for analytical data. See rainbow.asm for the scope of the current mapping.

Parameters:
  • export_dad_cube (bool, optional) – Include multi-wavelength DAD spectra as 3D UV spectrum cubes. On by default; the DAD cube is by far the largest part of a document, so turning it off (single-wavelength channels still export) shrinks the output.

  • wavelengths (float/list, optional) – Restrict the DAD spectrum cube to these wavelengths (nearest available, in nm); the default keeps every wavelength.

  • ions (float/list, optional) – m/z value(s) to extract from full-scan MS data, each exported as its own mass chromatogram. Single-ion (SIM) MS is always exported regardless of this argument.

  • decimal_places (int, optional) – Round emitted numeric values to this many decimal places. The default keeps full precision.

  • technique (str, optional) – Force the export technique, "GC" or "LC", overriding the method’s declaration and the FID-presence fallback.

  • utc_offset (str, optional) – UTC offset such as "-05:00" or "Z", stamped on timestamps the instrument recorded without one. An offset the source did record is never overridden.

Returns:

The ASM document.

Return type:

dict

export_asm(filename, *, export_dad_cube=True, wavelengths=None, ions=None, decimal_places=None, technique=None, utc_offset=None, indent=2)[source]

Writes an Allotrope Simple Model (ASM) JSON document for this directory.

The document is streamed to disk, so even a large spectrum cube never needs to fit in memory as one string.

Parameters:
  • filename (str) – Filename for the output JSON.

  • export_dad_cube (bool, optional) – Include multi-wavelength DAD spectra as 3D UV spectrum cubes. On by default; turning it off shrinks the output sharply.

  • wavelengths (float/list, optional) – Restrict the DAD spectrum cube to these wavelengths (nearest available, in nm); the default keeps every wavelength.

  • ions (float/list, optional) – m/z value(s) to extract from full-scan MS data, each exported as its own mass chromatogram. Single-ion (SIM) MS is always exported regardless of this argument.

  • decimal_places (int, optional) – Round emitted numeric values to this many decimal places. The default keeps full precision.

  • technique (str, optional) – Force the export technique, "GC" or "LC", overriding the method’s declaration and the FID-presence fallback.

  • utc_offset (str, optional) – UTC offset such as "-05:00" or "Z", stamped on timestamps the instrument recorded without one. An offset the source did record is never overridden.

  • indent (int, optional) – Indentation for the output JSON.