Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

massoft-export

Read Hiden Analytical MASsoft QMS experiment files directly and export to csv.

MASsoft stores an experiment as a group of files sharing one stem: .scn (scan definitions), .exp (an index), .dat (the data), .env (the instrument and its settings), plus .ann. This package decodes them and hands back the readings, with a massoft2csv command for the common case.

By default the CSV it writes is byte-for-byte what MASsoft itself would export — same header, same fixed-width columns, same CRLF endings. This is tested by comparison of exports of the same data by MASsoft and this package. An example experiment is in tests/data.

Install

uv sync

Or add it to another project:

uv add git+https://github.com/blongworth/massoft-export

The package itself has no dependencies. The polars and pandas extras only matter if you want to_polars() / to_pandas().

Command line

massoft2csv path/to/run.exp

Writes run.csv beside the experiment. Pass any member file or the bare stem; pass several at once; use -o for a specific destination or -o - for stdout.

massoft2csv data/*.exp

A MID experiment — every scan parked on one mass — comes out in MASsoft's own layout: a 24-line header describing the instrument, the scans and the environment, then one fixed-width row per cycle.

0000000437,scans,0000000092,DataLength
"header",0000000024,"lines"
"Date",8/14/2026,"Time",21:20:59
"ID","HAL RC HALO 201 #15876","Version",3
...
"Time","ms","14 amu","32 amu","40 amu","18 amu","44 amu",
00:00:01,      1521,  5.55624e-09,  1.46572e-08,  5.89014e-10, ...

The tidy style

--style tidy drops the header and gives every reading an absolute timestamp instead of time-since-start:

massoft2csv --style tidy path/to/run.exp
datetime,elapsed_ms,14 amu,32 amu,40 amu,18 amu,44 amu
2026-08-14 21:20:59,1521,5.55624e-09,1.46572e-08,5.89014e-10,2.27233e-10,3.91716e-11

An experiment containing a mass sweep is always written this way — long, one row per measured point, with the mass axis reconstructed from the scan definition — because MASsoft's wide layout has no column for a mass axis:

cycle,datetime,elapsed_ms,scan,detector,mass,value
1,2026-08-12 21:30:34,391,1,Faraday,2,2.14999e-10

As a module

import massoft_export

run = massoft_export.read_experiment("data/20260814hrs2609f2")

run.columns          # ['14 amu', '32 amu', '40 amu', '18 amu', '44 amu']
len(run)             # 437 cycles
run.start_time       # datetime.datetime(2026, 8, 14, 21, 20, 59)
run.is_mid           # True

for time, elapsed_ms, *values in run.rows():
    ...

df = run.to_polars()
run.write_csv("run.csv")               # MASsoft's format
run.write_csv("run.csv", "tidy")       # or the plain table

run.environment holds the instrument identity and its setting modes, which is where the export header's "ID" line and "Environment" block come from:

run.environment.instrument                       # 'HAL RC HALO 201 #15876'
run.environment.active_mode.name                 # 'RGA'
run.environment.active_mode["emission"].value    # 50.0

run.scans holds the Scan definitions (start, stop, increment, dwell, settle, detector). run.cycles holds one Cycle per pass, each with a Reading per scan carrying its own timestamp — the masses in a cycle are measured seconds apart, and each is stamped when it was taken. For sweeps, or for anything you would rather have long than wide, run.points() yields every measured point as a dict.

Timestamps

MASsoft's export gives only time since the start of the run, and the massoft style reproduces that. The absolute time of every reading is reconstructed too, and the tidy style writes it — useful for merging against underway or CTD data. Two things to know:

  • Elapsed time and wall-clock time drift apart. The millisecond counter stops while acquisition is paused; the clock does not. One 17-hour run in the test set accumulates 153 seconds of drift across four pause/resume events. Both are reported: elapsed_ms and datetime.
  • The instrument clock can be reset mid-run, which on a ship means timestamps step backwards when the vessel changes time zone. That is left as recorded rather than smoothed over. Only a near-full-day step backwards is corrected, since that one is a MASsoft artifact: the seconds counter and the Julian day number roll over midnight one reading apart.

The file format

massoft_export/format.py documents the .scn/.exp/.dat layout — block structure, field offsets, and the quirks worth knowing — and massoft_export/environment.py documents the .env. Both were worked out by inspection and checked against MASsoft exports; neither is from a vendor specification, so treat anything they call "in practice" as an observation rather than a guarantee.

Two details of the export format are inferred rather than confirmed, because the available exports do not distinguish the alternatives. Increment is written with %g, which reproduces every observed value without losing precision on a finer step. And MASsoft writes the first character of the scan count as a on some exports and 0 on others, with nothing else in the file explaining which; this always writes 0, so the field parses as a number.

Tests

uv run pytest

tests/data holds two small real experiments — a five-mass MID run and a 2–50 amu Faraday background sweep — with MASsoft's own export of the first as the regression baseline.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages