yadg.parsers.masstrace package

List of supported file formats:

Submodules

yadg.parsers.masstrace.main module

yadg.parsers.masstrace.main.process(fn, encoding='utf-8', timezone='localtime', tracetype='quadstar.sac')

Unified mass spectrometry data parser.

This parser processes mass spectrometry scans in signal(mass) format.

Parameters
  • fn (str) – The file containing the trace(s) to parse.

  • encoding (str) – Encoding of fn, by default “utf-8”.

  • timezone (str) – A string description of the timezone. Default is “localtime”.

  • tracetype (str) –

    Determines the output file format. Currently supported formats can be found here.

    The default is "quadstar.sac".

Returns

(data, metadata, fulldate) – Tuple containing the timesteps, metadata, and full date tag.

Return type

tuple[list, dict, bool]

yadg.parsers.masstrace.quadstarsac module

Processing of Quadstar 32-bit scan analog data.

The [sac2dat.c code from Dr. Moritz Bubek](https://www.bubek.org/sac2dat.php) was a really useful stepping stone for this Python adaptation.

Pretty much the entire file format has been reverse engineered. There are still one or two unknown fields.

File Structure of .sac Files

0x00 "data_index"
0x02 "software_id"
0x06 "version_major"
0x07 "version_minor"
0x08 "second"
0x09 "minute"
0x0a "hour"
0x0b "day"
0x0c "month"
0x0d "year"
0x0f "author"
0x64 "n_timesteps"
0x68 "n_traces"
0x6a "timestep_length"
...
# Not sure what sits from 0x6e to 0xc2.
...
0xc2 "uts_base_s"
0xc6 "uts_base_ms"
# Trace header. Read these 9 bytes for every trace (n_traces).
0xc8 + (n * 0x09) "type"
0xc9 + (n * 0x09) "info_position"
0xcd + (n * 0x09) "data_position"
...
# Trace info. Read these 137 bytes for every trace where type != 0x11.
info_position + 0x00 "data_format"
info_position + 0x02 "y_title"
info_position + 0x0f "y_unit"
info_position + 0x1d "x_title"
info_position + 0x2a "x_unit"
info_position + 0x38 "comment"
info_position + 0x7a "first_mass"
info_position + 0x7e "scan_width"
info_position + 0x80 "values_per_mass"
info_position + 0x81 "zoom_start"
info_position + 0x85 "zoom_end"
...
# UTS offset. Read these 6 bytes for every timestep (n_timesteps).
0xc2 + (n * timestep_length) "uts_offset_s"
0xc6 + (n * timestep_length) "uts_offset_ms"
# Read everything remaining below for every timestep and every trace
# where type != 0x11.
data_position + (n * timestep_length) + 0x00 "n_datapoints"
data_position + (n * timestep_length) + 0x04 "data_range"
# Datapoints. Read these 4 bytes (scan_width * values_per_mass)
# times.
data_position + (n * timestep_length) + 0x06 "datapoints"
...

Structure of Parsed Timesteps

- fn:  !!str
- uts: !!float
- raw:
    traces:
      "{{ trace_number }}":  # number of the trace
        y_title:  !!str      # y-axis label from file
        comment:  !!str      # comment
        fsr:      !!str      # full scale range of detector
        m/z:                 # masses are always in amu
          {n: [!!float, ...], s: [!!float, ...], u: "amu"}
        y:                   # y-axis units from file
          {n: [!!float, ...], s: [!!float, ...], u: !!str}
yadg.parsers.masstrace.quadstarsac.process(fn, encoding='utf-8', timezone='localtime')

Processes a Quadstar 32-bit analog data .sac file.

Parameters
  • fn (str) – The file containing the trace(s) to parse.

  • encoding (str) – Encoding of fn, by default “utf-8”.

  • timezone (str) – A string description of the timezone. Default is “localtime”.

Returns

(data, metadata, common) – Tuple containing the timesteps, metadata, and common data.

Return type

tuple[list, dict, None]