Skip to content

API reference

Generated directly from the docstrings of the invisensing package (version always matches the wheel you're reading these docs from).

The stable public symbols (those listed in invisensing.__all__) are documented below. Anything not listed there is internal and may change without notice.


File

The unified reader. Auto-detects the on-disk format from the path suffix and exposes the channels each file actually contains.

File

File(
    path,
    *,
    format=None,
    phase_unit="rad",
    fiber_group_index=None
)

Unified reader for Audace DAS acquisition files.

Detects the on-disk format from the path's suffix (.dat, .h5/.hdf5, .tdms, .sgy/.segy) and delegates the bytes-to-numpy work to a format-specific backend. The public API is identical across formats: same properties, same channel extractors, same numpy output shape.

Use it as a context manager. It is the only usage whose file descriptor is released at a point you control rather than whenever the garbage collector gets to the object::

with File("acquisition.dat") as f:
    ...

Outside a with block, call :meth:close yourself; it is idempotent. A :class:File that is neither closed nor used as a context manager emits a :class:ResourceWarning when it is collected — silent by default, shown under python -W default, python -X dev and pytest. This matters on a long-running process walking a data tree: one leaked descriptor per file ends in EMFILE, and on an NFS/CIFS mount an open handle also blocks the file from being deleted or replaced.

Closing releases the descriptor, and nothing else. The header was read at open and is kept, so a closed :class:File still describes the recording — :attr:header, :attr:mode, :attr:num_lines, :attr:sample_rate, :attr:dtype, :attr:duration, the is_* predicates and the rest all keep answering, and asking them is not an error::

with File("acquisition.dat") as f:
    data = f.read_all()
dt = 1.0 / f.trig_frequency_real_hz  # fine: metadata, not I/O

numpy arrays already returned by :meth:read_lines or the channel extractors own their memory and remain valid and readable too. Only an operation that would have to touch the file again — :meth:read_lines, :meth:read_all, :meth:rewind, :meth:seek_lines, iterating the file, and :attr:lines_left, which is the cursor of a handle that no longer exists — raises :class:ValueError.

Parameters

path Path to the file. Suffix is used to pick the backend unless format is supplied explicitly. format Optional override ("dat", "hdf5", "tdms", "segy"). Use when the file has no recognised suffix. phase_unit "rad" (the default): every sample is read as stored — a phase in radians. "nanostrain": the phase is read as strain in nm/m, converted while it is read::

    strain_nm_per_m = phase_rad / gauge_length_m * NANOSTRAIN_PER_RAD_METRE

with the gauge length the file records (:attr:`gauge_length_m`) and
``NANOSTRAIN_PER_RAD_METRE`` (110.37 nm/m per rad/m, at
λ = 1550.12 nm and n = 1.46). The factor
``NANOSTRAIN_PER_RAD_METRE / gauge_length_m`` is computed once
(:attr:`nanostrain_per_rad`) and every phase sample takes one
multiply by it, in the native core: the dtype stays ``float32``.
Everything that returns samples honours it (:meth:`read_lines`,
:meth:`read_all`, iteration, :meth:`get_phase`, :meth:`channels`,
the legacy ``get_lines``); on a file of phase/amplitude pairs only
the phase lanes are converted, the amplitude is left as stored.
:attr:`unit` then says ``"nm/m"`` and :attr:`quantity` ``"strain"``;
:attr:`mode` stays :attr:`Mode.PHASE`. :meth:`export_dat` still
writes the file's own samples (radians).

``"strain_rate"``: the phase is read as **strain rate in nm/m/s**,
the strain increment from the previous line times the line rate::

    strain_rate[n] = (strain[n] - strain[n-1]) * trig_frequency_real_hz
                   = (phase[n] - phase[n-1]) * NANOSTRAIN_PER_RAD_METRE
                     / gauge_length_m * trig_frequency_real_hz

``strain`` being the ``"nanostrain"`` reading and the line rate the
rate the card really fired at (:attr:`trig_frequency_real_hz`: the
requested :attr:`trig_frequency` on a file that does not carry the
exact clock). The factor is computed once
(:attr:`strain_rate_per_rad`); every phase sample takes one
subtraction of the previous line's stored phase, then one multiply
by it, in the native core (see :func:`_phase_to_strain_rate`, the one
place this definition lives). Every read path honours it, as above,
and carries the previous line across reads: reading the file in
blocks of any size gives the bits of :meth:`read_all`, and a read
after :meth:`seek_lines` to line ``k > 0`` reads line ``k − 1`` first.
Two lines have no increment at the line rate, and read **NaN** in
their phase lanes (the amplitude of pairs stays as stored): line 0
of the file (nothing precedes it: the previous file of a recording is
never opened), and every line that follows a gap of the file's time
axis (:attr:`time_gaps`: lost shots), whose increment spans more than
one line period and is never divided by one. :attr:`unit` then says
``"nm/m/s"`` and :attr:`quantity` ``"strain rate"``.

fiber_group_index None (the default): every metre is labelled at the speed of light the file was acquired at (:attr:light_speed_in_fiber_m_s; the legacy 2·10⁸ m/s for a file recorded before the acquisition wrote it). A number: label the recording at this fibre group index instead — typically an old recording whose fibre is known, e.g. File(path, fiber_group_index=1.4682) for an SMF-28 fibre at 1550 nm. Only the labels change, never the samples (the card samples time; the speed only says how many metres a sample is): the speed becomes round(c / n) (:func:light_speed_of_group_index), and :attr:distance, :attr:spatial_step_m, :attr:gauge_length_m and :attr:trigger_delay follow it (see Header.with_fiber_group_index), and with the gauge the strain factors (:attr:nanostrain_per_rad). :attr:header is the relabelled header (an export carries the new index); :attr:recorded_fiber_group_index keeps the file's own. Any number from 1 to 100 is accepted.

Raises

FileNotFoundError If the path doesn't exist. ValueError If the format can't be auto-detected (and no override was given) or if the file isn't a valid Audace acquisition (zero line_size / sample_size). With phase_unit="nanostrain" or "strain_rate": if the file does not hold a phase (raw samples, I/Q, arctan, amplitude, variances…), or holds one without recording its gauge length (no gauge is ever assumed). With "strain_rate": if its trigger frequency is unknown (0). If fiber_group_index is below 1, above 100 or not finite. TypeError If fiber_group_index is not a real number. ImportError If the chosen backend needs an optional third-party library (h5py / npTDMS / segyio) that isn't installed. The message names the right pip install invisensing[<extra>].

closed property

closed

True once :meth:close has run. Never resets.

path property

path

Path to the source file.

header property

header

Parsed :class:Header (line_size, flags, rates, timestamp…) — as relabelled at File(path, fiber_group_index=…) when one was given (its speed, index and metres; every other field as stored).

mode property

mode

What the file holds — see :class:Mode: from the content type, or from the flags on a file written before it existed.

line_size property

line_size

Wire-side samples per pulse (doubled when is_interleaved).

positions_per_line property

positions_per_line

Spatial fibre positions per pulse — line_size / 2 for a file of pairs (:attr:is_interleaved), line_size otherwise.

sample_size property

sample_size

Bytes per sample (2 for i16, 4 for i32/f32).

sample_rate property

sample_rate

Wire-side sample rate in Hz.

trig_frequency property

trig_frequency

Requested trigger pulse repetition rate in Hz (an integer).

The card fires at exactly this rate only when it divides the card's clock; otherwise it fires slightly faster — see :attr:trig_frequency_real_hz, which is the rate to compute times and durations with. This integer stays the configured value: use it to size blocks or to label the acquisition.

trig_clock_hz property

trig_clock_hz

Clock the card counts its trigger period in, Hz — or None.

With :attr:trig_period_ticks, the exact rate the card fires at: trig_clock_hz / trig_period_ticks. None when the file does not carry it (recordings made before it existed, an external trigger, TDMS and SEG-Y files) or carries one that does not describe this file's :attr:trig_frequency (further from it than a card's own quantization puts it — one tick of trig_clock_hz at 10 MHz, plus 1 Hz: left behind by a header whose frequency was rewritten — it is ignored). The raw stored values are in header.trig_clock_hz / header.trig_period_ticks.

trig_period_ticks property

trig_period_ticks

Trigger period in ticks of :attr:trig_clock_hz — or None (same rule as :attr:trig_clock_hz; both are None together).

trig_frequency_real_hz property

trig_frequency_real_hz

The trigger rate the card really fired at, in Hz.

  • trig_clock_hz / trig_period_ticks when the file carries the card's rational (75_000 requested on a 250 MHz clock → 250e6 / 3333 = 75007.5008 Hz);
  • else HDF5's trig_frequency_real_hz attribute, when the file carries it alone;
  • else float(trig_frequency) — older recordings and external triggers, where the requested rate is the only one known.

Use it for anything derived from the line cadence: time axes, durations, the sampling rate of a spectrum along time.

trig_frequency_is_exact property

trig_frequency_is_exact

True when the card fired exactly at :attr:trig_frequency, and when the real rate is unknown (then nothing says otherwise).

time_correction property

time_correction

How the file's times were stamped, or None when it does not say (files written before the card's time map, a DAT without the flag, and every TDMS and SEG-Y: neither format carries an absolute time or the time flags).

  • "cardclock-v1": from the card's time map — timestamp_ns and :meth:line_time_ns are the corrected times (the card's oscillator drift and lost shots taken out); the count is line_time_ns(i, nominal=True). A DAT says so with :attr:Header.time_corrected (its start time only).
  • "none": timed by the count (no time map for that run).

time_correction_state property

time_correction_state

The least favourable state of the correction over the file ("tracking", "prior", "slewing", "suspect", "provisional"…), or None when the file does not say.

time_uncertainty_ns property

time_uncertainty_ns

Largest estimated uncertainty (1 σ) of the corrected time over the file, ns — the precision of the TIME, not of the cadence — or None.

trig_frequency_measured_hz property

trig_frequency_measured_hz

The card's cadence as the acquisition measured it against the host clock (true seconds), Hz, or None when the file does not carry it.

Not the rate to compute a spectrum with: :attr:trig_frequency_real_hz (the programmed cadence) stays the sampling rate of the data along time; this one says how far the card's oscillator was off it.

num_lines property

num_lines

Total trigger pulses recorded in the file (whole lines only, see :attr:trailing_bytes).

trailing_bytes property

trailing_bytes

Bytes after the last whole line of a .dat — 0 for a complete file. Non-zero means the file was cut short in the middle of a line (a recording stopped mid-write, a partial copy): those bytes are not read, and opening the file emits a warning. Always 0 for HDF5, TDMS and SEG-Y, which store whole lines.

lines_left property

lines_left

Pulses remaining behind the current read cursor.

This one does need the file open: it describes the position of a live read cursor, not a property of the recording. On a closed file it raises :class:ValueError — use :attr:num_lines, which keeps answering, to describe what the file contains.

timestamp property

timestamp

Acquisition start time as the file spells it — a string whose form depends on the format:

  • DAT: the header's anchor in nanoseconds since the Unix epoch (UTC), as a decimal string ("1790000000000000000"); a capture written before the binary anchor carries its free-form ASCII string instead.
  • HDF5: the timestamp attribute, the node's local time with its UTC offset, to the millisecond ("2026-09-23 14:03:12.123+02:00") or the legacy string.
  • TDMS: the timestamp property, same form as HDF5.
  • SEG-Y: the TIMESTAMP line of the textual header, same form.

To compute with, use header.acquisition_ns (the exact anchor, ns, UTC; 0 when the file has none — always for TDMS and SEG-Y, which carry only this display string) and :meth:line_time_ns.

content_type property

content_type

What the samples are: the header's content_type byte (0 on a capture written before the byte existed). See :attr:content_type_name.

content_type_name property

content_type_name

The lowercase tag of :attr:content_type ("hw_phase", "sw_mozart", "hw_amplitude"…): "undefined" for a capture written before the byte existed (0). A value this SDK does not know (a newer producer) is named by the file's own tag when it carries one (HDF5 / TDMS content_type_name), else "unknown(<n>)".

card property

card

The code of the acquisition card that recorded the file — "p18", "p21", "s125" or "s500" — or None when the file does not say. Every file of data format v1 carries it (DAT header, HDF5 / TDMS card, SEG-Y CARD: line); before v1 only DAT headers did, as a tag read as the same code: every run's from 2026-07-15 to 2026-10-13, then a two-card run's.

format_version property

format_version

The data format version the file was written in: 1 for data format v1 (content type authoritative, steps and duration in the header), 0 for a file written before it.

duration_s property

duration_s

The duration the writer recorded when it closed the file, in whole seconds rounded down — or None when the file does not say (a file written before data format v1, one cut short by a crash, one under a second). :attr:duration is the duration measured from the lines, to the nanosecond.

A file shorter than one second — the sub-second file durations (0.1 s), analog-trigger files — always reads None here: use :attr:duration (or, on HDF5, :attr:duration_exact_s).

duration_exact_s property

duration_exact_s

The exact duration of the file's lines in seconds (lines × the real line period), as the writer recorded it: HDF5 files of a sub-second file duration and of the analog-trigger mode only; None for every other file (:attr:duration measures it from the lines on any file).

first_line property

first_line

The card-line index of the file's first line (HDF5 files of a sub-second file duration and of the analog-trigger mode), or None when the file does not record it.

analog_trigger property

analog_trigger

What triggered an analog-trigger recording (:class:~invisensing.AnalogTrigger: option, threshold, offset, hold, trigger line, sample and time, event and part, how the event ended on its last file), or None for a file of any other mode. HDF5 only: the mode writes nothing else. CH2, the trigger input, is never in the file.

host_clock_synchronized property

host_clock_synchronized

Whether the node's clock was synchronised when the console sent the START of the run this file belongs to (:class:~invisensing.HostClockSync: SYNCHRONIZED, NOT_SYNCHRONIZED or UNKNOWN; .synchronized gives it as a bool). None when the file does not record it: a DAT, SEG-Y or TDMS file (the manifest beside it does) and every HDF5 file written before 2026-11-22. A value this SDK does not know reads UNKNOWN, never synchronised.

start_time_guard property

start_time_guard

How the START of the run this file belongs to passed the console's time guard (:class:~invisensing.StartTimeGuard: OPEN, WAIVED, LIFTED, LIFTED_PERMANENT or UNKNOWN); .forced is True for a START forced past a lifted guard — its times come from a clock nobody proved. None when the file does not record it (see :attr:host_clock_synchronized).

analog_trigger_index property

analog_trigger_index

The index of the trigger line in this file (analog_trigger.line − first_line), or None when the file does not say. It may lie outside [0, num_lines): a negative index is a trigger before this file (a later part of a long event, a positive offset), one past the end a file of pre-trigger only.

spatial_step_m property

spatial_step_m

Metres of fibre between two adjacent positions (columns).

The file's own value when it carries one (data format v1; the zone spacing of an archive export); else derived from the sample rate, v / (2 · sample_rate) with v the speed of light in the fibre (:attr:light_speed_in_fiber_m_s; halved for the round trip: 1e8 / sample_rate at the legacy 2·10⁸ m/s), for samples that are the acquisition's own; else None (a script's output, an archive export of an older file). 0.408381 m at 250 MS/s on an SMF-28 fibre (index 1.4682), 0.4 m on a recording made before the index existed.

light_speed_in_fiber_m_s property

light_speed_in_fiber_m_s

The speed of light in the fibre every metre of this file is labelled with, whole m/s: round(c / n) of the fibre group index the acquisition was configured with (header bytes 124..128, HDF5 / TDMS light_speed_in_fiber_m_s, SEG-Y FIBER GROUP INDEX line) — or of File(path, fiber_group_index=…) when one was given. A file recorded before the acquisition wrote it reads as the legacy 200 000 000 m/s it was acquired at (:data:LEGACY_LIGHT_SPEED_IN_FIBER_M_S).

fiber_group_index property

fiber_group_index

The fibre group index the file's metres are labelled at: the index exactly as configured when the file stores it (HDF5, TDMS, SEG-Y: 1.4682, not c / v round-tripped), else the index of :attr:light_speed_in_fiber_m_s — the legacy 1.49896229 for 2·10⁸ m/s (every recording made before the index existed), 1.4682 for 204 190 477 m/s, c / v otherwise (:func:group_index_of_light_speed). The value given to File(path, fiber_group_index=…) when one was given.

recorded_fiber_group_index property

recorded_fiber_group_index

The fibre group index the file itself states (as :attr:fiber_group_index reads it without fiber_group_index=): what the recording was acquired at, whatever it is relabelled at.

recorded_light_speed_in_fiber_m_s property

recorded_light_speed_in_fiber_m_s

The speed of light in the fibre the file itself states (as :attr:light_speed_in_fiber_m_s reads it without fiber_group_index=), m/s.

temporal_step_s property

temporal_step_s

Seconds between two lines: the file's own value when it carries one (data format v1), else the line period of the header's cadence (Header.derived_temporal_step_s: trig_period_ticks / trig_clock_hz on the card's rational when the header carries a consistent one, else 1 / trig_frequency), else None. Informative — times come from :meth:line_time_ns.

quantity property

quantity

What the samples are, from the content type: "raw", "phase", "arctan", "amplitude", "i", "q", "custom", "variance", "log_variance" — or both members of a file of pairs ("phase+amplitude"). None when the content type does not say and :attr:mode comes from the flags (Header.mode_from_flags): content type 0, a value this SDK does not know, a file written before data format v1 whose content type does not describe it. A phase read with phase_unit="nanostrain" is "strain" ("strain+amplitude" for pairs), with phase_unit="strain_rate" "strain rate".

unit property

unit

The unit of the samples, from the content type: "rad", "count" (the card's integer scale), "adc_count", "front_end_count", "source_unit_squared", "dimensionless", "script" — or "rad+count" for a file of pairs; None when the content type does not say (see :attr:quantity). A phase read with phase_unit="nanostrain" is in "nm/m" ("nm/m+count" for pairs), with phase_unit="strain_rate" in "nm/m/s".

phase_unit property

phase_unit

How the phase is read: "rad" (as stored, the default), "nanostrain" (strain in nm/m) or "strain_rate" (strain rate in nm/m/s) — the phase_unit the file was opened with.

gauge_length_m property

gauge_length_m

The gauge length the producer applied to this phase, in metres of fibre — the distance between the two ends of the differential gauge as it was realised (a whole number of positions), not the length the configuration asked for — or None when the file does not record one.

Audace writes it on a phase only (DAT header bytes 120..124, HDF5 attribute and TDMS property gauge_length_m, SEG-Y line GAUGE LENGTH), and only from the release that adds it. None for every recording made before that release, for a MOZART / MOZART_PLUS phase (its gauge is set by the optics, not by software), for every non-phase file (raw, I/Q, arctan, amplitude, variances: no gauge, whatever the header bytes hold) and for a file whose mode comes from its flags (Header.mode_from_flags). The value as stored is header.gauge_length_m.

nanostrain_per_rad property

nanostrain_per_rad

The factor a phase sample of this file is multiplied by to read in nm/m: NANOSTRAIN_PER_RAD_METRE / gauge_length_m, computed once in float64 and rounded once to float32 (the factor of the float32 samples), whatever phase_unit the file was opened with — or None without a gauge length. quantization_step_rad and quantization_max_error_rad stay in radians: times this factor, they are in nm/m.

strain_rate_per_rad property

strain_rate_per_rad

The factor a phase increment between two lines of this file is multiplied by to read in nm/m/s: NANOSTRAIN_PER_RAD_METRE / gauge_length_m × trig_frequency_real_hz, computed once in float64 and rounded once to float32 (the factor of the float32 samples), whatever phase_unit the file was opened with — or None without a gauge length or a trigger frequency.

time_gaps property

time_gaps

The gaps of the file's time axis, as (first, end) ranges of lines (end excluded): every line i ≥ 1 that comes more than 1.5 line periods (1 / trig_frequency_real_hz) after line i − 1 on the corrected time axis (:meth:line_time_ns) — the line after shots the card lost. Their strain increment spans more than one line period: phase_unit="strain_rate" reads them NaN.

Only a file stamped from the card's time map carries the times of its lines (:attr:time_correction "cardclock-v1", HDF5); on any other file the lines are timed by their count and this is (): every increment is taken as one line period. Shots lost inside a stretch the acquisition could only interpolate (:attr:time_correction_state "provisional") are spread over it and not seen here. Metadata only: works on a closed file.

source_content_type property

source_content_type

An archive export of zone variances (content type 27 or 28, HDF5): the content type of the column the variance was computed from; None otherwise.

sibling_path property

sibling_path

The other file of a split pair, when it is on disk: the amplitude/ file of a phase/ file (and back), magnitude/ of arctan/, q_component/ of i_component/. Since data format v1 a recording writes each member of an interleaved stream to its own file, same name, sibling directories. None for any other file or when the sibling is missing.

compression property

compression

The FileWriter compression an HDF5 was written with: "NONE", "ZSTD" (lossless) or "ZSTD_LOSSY_1E4" (phase rounded, see :attr:quantization_step_rad); a filter pipeline no Audace writer makes is named by its filters. None for DAT, TDMS and SEG-Y, which are never compressed.

quantization_step_rad property

quantization_step_rad

ZSTD_LOSSY_1E4 only: the grid every phase sample was rounded to, in radians (2⁻¹³), or None when the samples are exact (any other file).

quantization_max_error_rad property

quantization_max_error_rad

ZSTD_LOSSY_1E4 only: the largest difference, in radians, between a stored phase sample and the acquired one (half the step, ≤ 6.1·10⁻⁵ rad), or None when the samples are exact.

flags property

flags

Raw header flag bitmask (see FLAG_* constants).

range property

range

Voltage range in volts (header field is mV).

trigger_delay property

trigger_delay

Trigger pre-roll in metres of fibre, whole metres, at the file's speed of light (:attr:light_speed_in_fiber_m_s; rescaled to the nearest metre with File(path, fiber_group_index=…)).

0 means no delay — which is also what captures written before the field existed report, and for them it says the same thing.

is_mozart property

is_mozart

Whether the samples are the Mozart software phase (Mozart or Mozart+), or None when the question does not apply.

  • A file that carries a content type (:attr:content_type ≠ 0) is answered by it alone: True for sw_mozart and sw_mozart_plus, None for raw (no demodulation ran) and for a content type this SDK does not know, False for every other one.
  • A capture written before the content type existed (0) keeps the flag-based answer: None when the DEMODULATED bit is clear, else whether the MOZART bit is set. So do the files written before data format v1 whose content type does not describe them: a sw_custom file of an older Sandbox and an archive export of the console under a stream-only value without the INTERLEAVED flag (see :meth:Mode.from_header).

False only says "not Mozart" — it names no other pipeline (the SCHUBERT flag is deprecated). Treat None as "not applicable", never as a default.

dtype property

dtype

numpy dtype :meth:read_lines returns: the content type's sample type (int16, uint16 — a magnitude —, float32); for a file written before the content type existed (and the files whose mode comes from the flags, see :meth:Mode.from_header), (sample_size, FLOAT), signed integers except a single-column UNSIGNED file (uint16) and 1-byte samples (uint8).

shape property

shape

Total (num_lines, line_size) of the wire payload.

spatial_shape property

spatial_shape

(num_lines, positions_per_line) — shape returned by the channel extractors.

duration property

duration

Total duration of the recording in seconds: num_lines / trig_frequency_real_hz.

On a recording without a real rate (older files, external trigger) this is num_lines / trig_frequency, exactly as before. A file stamped from the card's time map (:attr:time_correction = "cardclock-v1") is measured on its corrected times instead: num_lines mean line periods, the first line to the last (timestamp_last_ns − timestamp_ns) spread over num_lines − 1 periods — lost shots inside the file included.

distance property

distance

Length of fibre (m) one line covers, measured one way along the fibre.

positions_per_line · spatial_step_m when the file carries its spatial step (data format v1; the zone spacing of an archive export); otherwise positions_per_line · v / (2 · sample_rate) with v the speed of light in the fibre (:attr:light_speed_in_fiber_m_s: the file's, 2·10⁸ m/s on a recording made before the acquisition wrote it): a sample spans 1 / sample_rate of the pulse's round trip, hence the 2 — the result is the distance along the fibre, not the path the light travels. Both give the same length for the acquisition's own samples.

is_demodulated property

is_demodulated

True if the samples come out of a demodulation, on board or in software (phase, arctan, amplitude, I or Q).

is_interleaved property

is_interleaved

True if the file carries 2 samples per spatial position (a file of pairs written before data format v1).

is_float property

is_float

True if samples are IEEE-754 floats.

is_phase property

is_phase

True if the file carries a phase in radians (alone, or as the first member of phase/amplitude pairs).

is_unsigned property

is_unsigned

True if (some of) the integer samples are unsigned: a uint16 magnitude column, or the magnitude lane of arctan/magnitude pairs.

is_ac property

is_ac

True if the ADC was AC-coupled during acquisition.

is_hiz property

is_hiz

True if the ADC ran in high-impedance mode.

close

close()

Release the underlying OS file handle, immediately.

Idempotent: calling it a second time (or after a with block) is a no-op and never raises.

The reference to the backend is dropped before the handle is closed, so the descriptor goes away at this call and not whenever the garbage collector happens to reclaim this object.

Closing gives up the descriptor, not the knowledge. What was already read stays readable: every metadata accessor (:attr:header, :attr:mode, :attr:num_lines, :attr:dtype, :attr:shape, :attr:duration, :attr:distance, the is_* predicates…) keeps answering from the values captured at open, and numpy arrays already returned by :meth:read_lines (and the channel extractors) own their memory and stay valid. Only what genuinely needs the file back — :meth:read_lines, :meth:read_all, :meth:rewind, :meth:seek_lines, iteration and :attr:lines_left (the cursor of a handle that no longer exists) — raises :class:ValueError.

One caveat, and it is the only case where the descriptor does not go away at this call: closing a .dat while another thread is inside :meth:read_lines on the same object. The native reader is mutably borrowed for the length of that read, so the release is deferred until it finishes; this call still returns without raising, and a :class:ResourceWarning says so. Do not share one :class:File across threads.

line_time_ns

line_time_ns(i, *, nominal=False)

Acquisition time of line (trigger pulse) i, 0-based, in nanoseconds since the Unix epoch.

  • A file stamped from the card's time map (HDF5 with time_correction = "cardclock-v1", see :attr:time_correction): the time on the file's axis — from the last node k at or before i, time_map_ns[k] + ⌊(i − time_map_line[k]) · time_map_period_fs[k] / 10⁶⌋ (a period 0 counts on the card's rational). The corrected time: the card's oscillator drift and its lost shots taken out, exactly the nanosecond the acquisition's live modules gave this line.
  • Any other file: header.acquisition_ns + ⌊i · trig_period_ticks · 10⁹ / trig_clock_hz⌋ when it carries the card's rational, else header.acquisition_ns + ⌊i · 10⁹ / trig_frequency⌋ — the integer 1.3.0 gave. A DAT whose header says :attr:Header.time_corrected starts at the corrected time of its first line and counts from there. TDMS and SEG-Y carry no absolute time (only the display string :attr:timestamp) and no time flags: header.acquisition_ns is 0 and the result is the offset from the first line.

nominal=True gives the count instead, as 1.3.0 computed it: from the file's timestamp_nominal_ns when it carries one, else from its start time.

Exact integer arithmetic. When the file has no anchor (header.acquisition_ns == 0: legacy ASCII timestamp) the result is the offset from the first line. i may exceed :attr:num_lines (the last segment extrapolates). Raises :class:ValueError for a negative i and :class:TypeError for a non-integer.

times_ns

times_ns(start=0, count=None, *, nominal=False)

The times of lines start .. start + count (default: to the end of the file), ns since the Unix epoch, as an int64 numpy vector — :meth:line_time_ns of each line, the same integers, computed in the native core. Metadata only: no sample is read, and it works on a closed file.

count is clamped to the lines the file holds: the vector never runs past :attr:num_lines (use :meth:line_time_ns to extrapolate beyond the last line). Raises :class:MemoryError when the vector cannot be allocated (a file that declares more lines than memory can time).

is_acquisition_ac

is_acquisition_ac()

Alias of :attr:is_ac kept for backwards compatibility.

is_acquisition_hiz

is_acquisition_hiz()

Alias of :attr:is_hiz kept for backwards compatibility.

read_lines

read_lines(n=1)

Read up to n consecutive pulses (rows). Returns a (rows, line_size) typed numpy array — dtype is :attr:dtype. With phase_unit="nanostrain" the phase samples come in nm/m (converted in place on the buffer just read); with phase_unit="strain_rate" in nm/m/s, differenced against the line before the first one read (NaN on line 0 and after a gap, see :class:File).

Short-reads are tolerated: when fewer than n pulses remain, returns what's left. Raises :class:OSError only when the reader is already exhausted; raises :class:ValueError if n <= 0.

read_all

read_all()

Read every remaining pulse in one allocation. Use only when the file fits comfortably in RAM (num_lines × line_size × sample_size bytes). For large captures, prefer :meth:read_lines in a loop or iterate the file directly.

rewind

rewind()

Reset the read cursor back to the start of the sample stream.

seek_lines

seek_lines(n)

Move the read cursor to pulse n (0-based) without reading the skipped pulses.

For .dat/.hdf5 this is an O(1) seek; the next :meth:read_lines continues from n. n is clamped to :attr:num_lines. Lets a viewer jump to --start-time on a multi-GB file without streaming past the skipped data.

export_dat

export_dat(path, *, start=0, count=None, chunk_lines=65536)

Write lines start .. start + count (default: to the end) to a .dat, with this file's whole header: content type, card, steps, gauge length, trigger pre-roll, the card's rational, time flags (see :func:export_dat). The first line's time is :meth:line_time_ns of start — the corrected time on a file stamped from the card's time map. The data is copied chunk_lines lines at a time; the read cursor is put back where it was. The samples are the file's own, as stored: a file opened with phase_unit="nanostrain" or "strain_rate" still exports its phase in radians.

get_i

get_i(data=None, *, n=1)

The card's I: the i_component/ file (:attr:Mode.I) or the I lane of I/Q pairs (:attr:Mode.IQ).

Returns a (rows, positions_per_line) int16 array. Raises :class:ValueError for any other mode.

get_q

get_q(data=None, *, n=1)

The card's Q: the q_component/ file (:attr:Mode.Q) or the Q lane of I/Q pairs (:attr:Mode.IQ).

get_iq

get_iq(data=None, *, n=1)

Combined complex64 view of I/Q pairs (:attr:Mode.IQ): result[r, j] = I[r, j] + j·Q[r, j]. Returns (rows, positions_per_line) complex64. A recording of data format v1 keeps I and Q in two files: read :meth:get_i from one and :meth:get_q from its :attr:sibling_path.

get_arctan

get_arctan(data=None, *, n=1)

The card's wrapped arctan(Q/I): the arctan/ file (:attr:Mode.ARCTAN) or the arctan lane of arctan/magnitude pairs (:attr:Mode.ARCTAN_MAGNITUDE). Returns (rows, positions_per_line) int16 — the fixed-point scale is 32767 ↔ +π (:meth:get_arctan_radians converts).

get_amplitude

get_amplitude(data=None, *, n=1)

The amplitude: the column of an amplitude file (:attr:Mode.AMPLITUDE — the card's magnitude as uint16 (magnitude/ of an arctan/magnitude recording) or float32 (amplitude/ of a demodulation that kept it), or a software front end's float32), or the amplitude member of a file of pairs (:attr:Mode.ARCTAN_MAGNITUDE: uint16; :attr:Mode.PHASE_AMPLITUDE: float32). Returns (rows, positions_per_line).

get_magnitude

get_magnitude(data=None, *, n=1)

The √(I²+Q²) magnitude — :meth:get_amplitude under the name the card's arctan/magnitude tap gives it: the uint16 lane of arctan/magnitude pairs (the wire buffer is typed i16 end to end but the card sends magnitudes as unsigned), or the column of an amplitude file (:attr:Mode.AMPLITUDE), or the amplitude member of phase/amplitude pairs.

get_phase

get_phase(data=None, *, n=1)

Phase samples (float32 radians): the column of a phase file (:attr:Mode.PHASE — the card's phase or a software demodulation's, :attr:content_type_name says which) or the phase member of phase/amplitude pairs (:attr:Mode.PHASE_AMPLITUDE). Returns (rows, positions_per_line) float32. On a file opened with phase_unit="nanostrain": strain, in nm/m; with phase_unit="strain_rate": strain rate, in nm/m/s (NaN on line 0 and after a gap, see :class:File).

On a phase file passing data returns it unchanged; passing nothing reads n new pulses. data is taken as :meth:read_lines of this file returned it (already in nm/m or nm/m/s on a file opened with phase_unit="nanostrain" or "strain_rate"): it is never converted again.

get_variance

get_variance(data=None, *, n=1)

Zone variances of a console archive export, float32, in the square of the source column's unit (:attr:source_content_type): the column of a viz_variance file (:attr:Mode.VARIANCE), or a viz_logvar file (:attr:Mode.LOG_VARIANCE) converted back, 10^v − 1.

get_log_variance

get_log_variance(data=None, *, n=1)

Zone variances on the console's Log scale, log10(1 + max(variance, 0)), float32: the column of a viz_logvar file (:attr:Mode.LOG_VARIANCE), or a viz_variance file (:attr:Mode.VARIANCE) put on that scale.

get_i_volts

get_i_volts(data=None, *, n=1)

Like :meth:get_i but returns I as a float32 numpy array scaled to volts: f32 = i16 × range / 32768. Use this when you want physically-meaningful values without having to remember the ADC scaling.

get_q_volts

get_q_volts(data=None, *, n=1)

Like :meth:get_q but returns Q as float32 volts.

get_iq_volts

get_iq_volts(data=None, *, n=1)

Like :meth:get_iq but returns a complex64 array whose real / imaginary parts are in volts. Convenient for envelope / phase computations that need physical units::

iq = f.get_iq_volts()
envelope_v = np.abs(iq)         # volts
phase_rad  = np.angle(iq)       # radians (wrapped)

get_arctan_radians

get_arctan_radians(data=None, *, n=1)

Like :meth:get_arctan but returns the arctan as a float32 numpy array in radians, scaled with the card's convention 32767 ↔ +π (f32 = i16 × π / 32768). Range is [-π, +π], the raw wrapped output of the card's arctan2.

get_magnitude_volts

get_magnitude_volts(data=None, *, n=1)

Like :meth:get_magnitude but returns the card's magnitude as a float32 numpy array in volts: f32 = magnitude × range / 32768.

The LSB scaling matches the I/Q lanes (the card computes √(I²+Q²) from the same i16 I/Q codes and keeps the same per-LSB voltage). The output is always ≥ 0. Only for the card's magnitude (unit count): a software front end's amplitude (sw_amplitude_sac) is on another scale and is refused.

channels

channels(data=None, *, n=1)

Return all channels of the file in one call, as a dict whose keys depend on the :attr:mode::

Mode.RAW              -> {"samples": ndarray}
Mode.CUSTOM           -> {"samples": …}
Mode.PHASE            -> {"phase": …}
Mode.AMPLITUDE        -> {"amplitude": …}
Mode.ARCTAN           -> {"arctan": …}
Mode.I / Mode.Q       -> {"i": …} / {"q": …}
Mode.VARIANCE         -> {"variance": …}
Mode.LOG_VARIANCE     -> {"log_variance": …}
Mode.IQ               -> {"i": …, "q": …, "iq": complex64}
Mode.ARCTAN_MAGNITUDE -> {"arctan": …, "magnitude": …}
Mode.PHASE_AMPLITUDE  -> {"phase": …, "amplitude": …}

Convenience for ad-hoc scripts: pass a pre-read buffer if you already have one, otherwise the method reads n pulses.


Mode

What a file holds, from its content type (from its header flags on a file written before the content type existed, and on the few older files whose content type does not describe them, see Mode.from_header). Use this enum to dispatch on what the file contains (if / elif: Python 3.9 has no match):

from invisensing import File, Mode

with File("acquisition.h5") as f:
    mode = f.mode
    if mode is Mode.RAW: ...
    elif mode is Mode.PHASE: ...
    elif mode is Mode.AMPLITUDE: ...
    elif mode is Mode.ARCTAN: ...
    elif mode in (Mode.I, Mode.Q): ...
    elif mode is Mode.IQ: ...                  # pairs, files written before data format v1
    elif mode is Mode.ARCTAN_MAGNITUDE: ...
    elif mode is Mode.PHASE_AMPLITUDE: ...
    elif mode in (Mode.CUSTOM, Mode.VARIANCE, Mode.LOG_VARIANCE): ...

Mode

Bases: Enum

What a file holds, and therefore which extractor reads it. Derived from the file's content type (:attr:File.content_type) — from its header flags, exactly as before, on a file written before the content type existed (content_type == 0) and on the few files written before data format v1 whose content type does not describe them (Header.mode_from_flags) — so a script can dispatch on it instead of bit-twiddling::

mode = file.mode
if mode is Mode.RAW:
    samples = file.read_lines(n)
elif mode is Mode.PHASE:
    phase = file.get_phase()
elif mode is Mode.AMPLITUDE:
    amp = file.get_amplitude()
elif mode is Mode.ARCTAN:
    rad = file.get_arctan_radians()
elif mode in (Mode.I, Mode.Q):
    column = file.read_lines(n)
elif mode is Mode.IQ:
    i, q = file.get_i(), file.get_q()
elif mode is Mode.ARCTAN_MAGNITUDE:
    a, m = file.get_arctan(), file.get_magnitude()
elif mode is Mode.PHASE_AMPLITUDE:
    p, m = file.get_phase(), file.get_amplitude()

Since data format v1 every recording holds one quantity per file: an interleaved stream is split into two files (phase/ and amplitude/, arctan/ and magnitude/, i_component/ and q_component/; see :attr:File.sibling_path). The paired modes (IQ, ARCTAN_MAGNITUDE, PHASE_AMPLITUDE) are the files written before, which may still hold both.

from_flags classmethod

from_flags(flags)

Decode the mode from a raw header flag mask — the rule of a file written before the content type existed (content type 0).

from_header classmethod

from_header(h)

The mode of a file of header h: from its content type; from its flags (:meth:from_flags) for content type 0, a value this SDK does not know, a sample_size the content type contradicts, a sw_custom file of a Sandbox older than data format v1, which kept its input's flags, and a file written before v1 under a stream-only content type without the INTERLEAVED flag — an archive export of the console, which kept its source's header over one column per zone (Header.mode_from_flags).


Parsed 128-byte Audace DataHeader. The format-specific backends (HDF5 / TDMS / SEG-Y) reconstruct one of these from their native metadata so the channel extractors take a uniform path regardless of the source file.

You rarely need to instantiate one directly — File.header returns it for you. The constructor is exposed for advanced users (e.g. synthesising files in tests).

Header

128-byte Audace DataHeader parsed into Python-friendly fields.

Exposed as invisensing._core.Header. The HDF5 / TDMS / SEG-Y wrappers reconstruct one of these from format-native metadata so the channel extractors take a single uniform path.

The fields are the header as stored. The is_* predicates, the positions and the sample encoding follow the content type when it fixes them (data format v1: a v1 file writes its FLOAT, UNSIGNED, INTERLEAVED, DEMODULATED and PHASE flags as 0); for content type 0 (a capture written before the byte existed), an unassigned value or a sample_size the content type contradicts, they follow the flags exactly as before.

acquisition_ns property

acquisition_ns

Precise acquisition time in i64 nanoseconds (DataHeader timestamp bytes [0..8]). 0 when the file uses the legacy ASCII timestamp string.

card property

card

The code of the card that produced the data — "p18", "p21", "s125" or "s500" — or None when the file does not say (an older single-card capture, a file converted without it). Stamped on every run since data format v1 (DAT bytes 65..81, HDF5 / TDMS card, SEG-Y CARD: line); the tag a run wrote there before v1 (every run from 2026-07-15 to 2026-10-13, two-card runs only afterwards) reads as its code.

content_type property

content_type

content_type descriptor byte (DataHeader byte 64): what the samples are. 0 = Undefined (a capture written before the byte existed). Use content_type_name for the lowercase tag.

content_type_name property

content_type_name

Lowercase content_type tag (e.g. "dui_coherent_phase"), "undefined" for a capture written before the byte existed (0), and "unknown(<n>)" for a value this SDK does not know (a newer producer).

derived_spatial_step_m property

derived_spatial_step_m

The spatial step the header's other fields give, m: v / (2 · sample_rate) — v the speed of light in the fibre (light_speed_m_s; 1e8 / sample_rate at the legacy 2·10⁸ m/s) — for a content type whose positions are the producer's samples (not a script's output, a zone variance or an unassigned value), else 0.0. What a reader uses when spatial_step_m is absent.

derived_temporal_step_s property

derived_temporal_step_s

The line period the cadence gives, s: trig_period_ticks / trig_clock_hz on a consistent rational, else 1 / trig_frequency; 0.0 without a cadence.

duration_s property

duration_s

Data format v1 — duration of the file in whole seconds, rounded down, written when the file was closed (DAT bytes 104..108, attribute duration_s). 0 = unknown: a file written before v1, a file under one second, a recording cut by a crash.

fiber_group_index property

fiber_group_index

The fibre's group index exactly as the acquisition was configured with, as the file stores it (HDF5 attribute and TDMS property fiber_group_index, SEG-Y line FIBER GROUP INDEX); 0.0 when the file does not store one (a DAT carries the speed only; every file recorded before the field). Use group_index for the index of the header (this one when it gives the header's speed, else the index of the speed).

flags property

flags

format_version property

format_version

Data format version (DAT byte 108, attribute format_version): 1 for a file of data format v1, 0 before.

gauge_length_m property

gauge_length_m

The gauge length the producer applied to a phase, metres of fibre, as the file stores it: DAT f32 bytes 120..124, read back exactly as the f64 the other formats store (HDF5 attribute and TDMS property gauge_length_m, SEG-Y line GAUGE LENGTH) — k · v / (2 · sample_rate) when the f32 is that value rounded, for a whole k (v the header's light_speed_m_s; Audace-Lib exact_gauge_length_m), so float32(gauge_length_m) is the stored f32. 0.0 when absent (every file recorded before the Audace release that writes it, every non-phase file). Kept as stored whatever the content type; File.gauge_length_m answers it for a phase only.

group_index property

group_index

The fibre's group index of this header: fiber_group_index when the file stores one that gives light_speed_m_s, else the index of that speed — the legacy 1.49896229 for 2·10⁸ m/s (and for a file without a speed), 1.4682 for 204 190 477 m/s, c / v otherwise (Audace-Lib header::fiber_group_index).

is_ac property

is_ac

is_demodulated property

is_demodulated

True if the samples come out of a demodulation (on board or in software): phase, arctan, amplitude, I or Q, or a pair of them. From the content type; from the DEMODULATED flag when the mode comes from the flags (mode_from_flags).

is_float property

is_float

True if samples are IEEE-754 floats (from the content type when it fixes the sample type, else the FLOAT flag).

is_hiz property

is_hiz

is_interleaved property

is_interleaved

True when the samples come in pairs per position: a stream-only (interleaved) content type — except in a file written before v1 whose INTERLEAVED flag is clear (see mode_from_flags) — or the INTERLEAVED flag for content type 0, 12 and an unassigned value. Never for a v1 file.

is_mozart property

is_mozart

Whether the samples are the Mozart software phase (Mozart or Mozart+), or None when the question does not apply or cannot be answered.

  • A file that carries a content_type (non-zero) is answered by it alone — the flags are not consulted: True for sw_mozart and sw_mozart_plus, None for raw (no demodulation ran) and for a value this SDK does not know, False for every other content type.
  • A capture written before content_type existed (0) keeps the flag-based answer: None when DEMODULATED is clear, else whether the MOZART bit is set. So do the files written before v1 whose content type does not describe them: a sw_custom (12) file of an older Sandbox and an unpaired file of a stream-only value (see mode_from_flags).

False only says "not Mozart"; it names no other pipeline (the SCHUBERT flag is deprecated). Treat None as "not applicable", never as a default.

is_phase property

is_phase

True if the samples are (or include, as member 0 of a pair) a phase in radians. From the content type; from the PHASE flag when the mode comes from the flags (mode_from_flags).

is_unsigned property

is_unsigned

True when (some of) the integer samples are unsigned: a u16 column (content types 5, 25), the magnitude member of an arctan/magnitude pair (7) — or, read from the flags (content type 0, 12, an unassigned value, a contradicted sample_size, a pre-v1 file of an unpaired stream-only value), the UNSIGNED bit: on an INTERLEAVED pair the odd lane is u16; on a single column every integer sample is (read as uint16).

light_speed_in_fiber_m_s property

light_speed_in_fiber_m_s

The speed of light in the fibre the positions were acquired at, whole m/s, as the file stores it: DAT bytes 124..128, HDF5 attribute and TDMS property light_speed_in_fiber_m_s, SEG-Y line FIBER GROUP INDEX: n (LIGHT SPEED v M/S). 0 = absent: every file recorded before the Audace release that writes it, acquired at the legacy 2·10⁸ m/s. Use light_speed_m_s for the speed every metre is converted with (this one when it is a speed, the legacy one otherwise).

light_speed_m_s property

light_speed_m_s

The speed of light in the fibre every metre of this header is converted with, whole m/s: light_speed_in_fiber_m_s when it is the speed of a group index from 1 to 100, else the legacy 200 000 000 m/s — what every file recorded before the field (0) was acquired at.

line_offset property

line_offset

DataHeader bytes 96..100: line m of a wire stream is line m + line_offset of the card's time map. 0 in files and on every older capture.

line_size property

line_size

line_timing property

line_timing

The cadence lines are timed with, (clock, ticks): the card's rational when known and consistent, else (trig_frequency, 1); None without any cadence.

mode_from_flags property

mode_from_flags

True when what the samples are — Mode, is_phase, is_demodulated — comes from the flags, as it did for every file before data format v1: content type 0, a value this SDK does not know, a sample_size the content type contradicts, a sw_custom (12) file of a Sandbox older than v1 (format_version 0, or the PHASE or INTERLEAVED bit set), which kept its input's flags, or a file written before v1 under a stream-only value (6, 7, 8, …) whose INTERLEAVED flag is clear — an archive export of the console, which kept its source's header over one column per zone: its sample type and layout come from the flags too. The sample type and the pairs of 0 and 12 always come from the flags.

normalized_content_type property

normalized_content_type

The content type a reader applies: content_type, except value 5 with 4-byte samples (the f32 magnitude an older demodulation labelled 5), which is 16 (hw_amplitude_f32), whatever format_version says.

num_channels property

num_channels

positions_per_line property

positions_per_line

Physical spatial positions per pulse — line_size / 2 for interleaved pairs (see is_interleaved), line_size otherwise. Mirrors Audace-Lib's header::file_positions_per_line.

pulse_width property

pulse_width

range property

range

sample_encoding property

sample_encoding

(bytes, float, unsigned): how each sample is stored — from the content type when it fixes it, else from sample_size and the flags (content type 0, 12, an unassigned value, a contradicted sample_size, a pre-v1 file of a stream-only value without INTERLEAVED). unsigned is True when every sample of the array is unsigned (a single u16 column).

sample_rate property

sample_rate

sample_size property

sample_size

sample_size_contradicts_content_type property

sample_size_contradicts_content_type

True when the content type fixes a sample size this header does not have (a file of the retired software PHASE method, say): the samples are then read from the flags, as for content type 0.

spatial_step_m property

spatial_step_m

Metres of fibre between two adjacent positions (columns), as the file stores it (DAT f32 bytes 112..116, read back exactly as the f64 the other formats store); 0.0 when absent.

temporal_step_s property

temporal_step_s

Seconds between two lines, as the file stores it (DAT f32 bytes 116..120, same rule); 0.0 when absent. Informative: times come from the anchor, the card's rational and the time map, never from it.

time_corrected property

time_corrected

True when the header's start time is the corrected time of the file's first line (time_flags & TIME_FLAG_CORRECTED): a DAT stamped from the card's time map, or an HDF5 whose time_correction is "cardclock-v1". Always False for TDMS and SEG-Y: neither format carries the time flags.

time_flags property

time_flags

DataHeader bytes 100..104, bits TIME_FLAG_MAP_V1 / TIME_FLAG_CORRECTED. For an HDF5, TIME_FLAG_CORRECTED when its time_correction attribute is "cardclock-v1". 0 on older files, and always 0 for TDMS and SEG-Y, which carry no time flags.

timestamp property

timestamp

trig_clock_hz property

trig_clock_hz

Clock the card counts its trigger period in, Hz (DataHeader bytes 88..92; HDF5 attribute trig_clock_hz). Raw value as stored: 0 when unknown. Use trig_timing for the value the timing helpers act on (it drops a rational that does not describe trig_frequency).

trig_frequency property

trig_frequency

trig_frequency_is_exact property

trig_frequency_is_exact

True when the card fires exactly at the requested trig_frequency (trig_clock_hz == trig_frequency × trig_period_ticks), and when the real rate is unknown.

trig_frequency_real_hz property

trig_frequency_real_hz

The trigger rate the card really fires at, Hz: trig_clock_hz / trig_period_ticks when trig_timing is known, else float(trig_frequency) (the requested rate, which is then the only one known).

trig_period_ticks property

trig_period_ticks

Trigger period in ticks of trig_clock_hz (DataHeader bytes 92..96; HDF5 attribute trig_period_ticks). Raw value as stored: 0 when unknown.

trig_timing property

trig_timing

The card's trigger rational (trig_clock_hz, trig_period_ticks), or None when the header does not carry one (both fields 0: a capture written before the fields existed, an external trigger) or carries one that does not describe this header — clock / ticks further from trig_frequency than any card's quantization puts it (see consistent_rational), a rational left behind by a header whose frequency was rewritten. Such a rational is ignored by every timing helper.

trigger_delay property

trigger_delay

Trigger pre-roll in metres of fibre (DataHeader bytes 84..88).

Metres rather than a sample count: a count is only meaningful against the rate it was counted at, and that is not always this header's sample_rate (a decimating tap counts its delay in ADC clocks while publishing the decimated rate). The producer converts. 0 means no pre-roll, and is also what captures written before the field hold.

line_time_ns method descriptor

line_time_ns(index)

Acquisition time of trigger line index (0-based), ns since the Unix epoch: acquisition_ns + lines_to_ns(index). Relative to the start of the file when the header carries no anchor (acquisition_ns == 0).

lines_to_ns method descriptor

lines_to_ns(lines)

Time of lines trigger periods, ns: ⌊lines · ticks · 10⁹ / clock⌋ on the card's rational, or ⌊lines · 10⁹ / trig_frequency⌋ without it — the same integer at an exact frequency. Saturates at i64::MAX; 0 when the header has no cadence at all (trig_frequency <= 0).

with_fiber_group_index method descriptor

with_fiber_group_index(n)

A copy of this header labelled at the fibre group index n: the speed of light round(c / n) and the exact n stamped in place of the file's, and every metre the header states converted from the file's speed v to the new one v' — the samples do not depend on the speed, only their labels do (File(path, fiber_group_index=n)):

  • spatial_step_m: the new pitch v' / (2 · sample_rate) when the stored step is the pitch of the acquisition's own positions at v; any other step (an archive export's zone spacing) × v' / v;
  • gauge_length_m: k · v' / (2 · sample_rate) when it is a whole number k of positions at v (what a producer stamps), else × v' / v;
  • trigger_delay (whole metres): × v' / v, to the nearest metre, halves up.

At the file's own speed nothing but the index changes. Raises ValueError for an index that is not a number from 1 to 100.


HostClockSync and StartTimeGuard

The node's clock and the console's time guard when the run's START was sent (Audace-Lib docs/DATA_FORMAT.md §8.7), as File.host_clock_synchronized and File.start_time_guard return them. Both are str enums: a member compares equal to the tag the file stores.

from invisensing import File, StartTimeGuard

with File("recording.h5") as f:
    if f.start_time_guard is not None and f.start_time_guard.forced:
        print("started past a lifted time guard: the times come from an unproven clock")

HostClockSync

Bases: str, Enum

The node's clock when the console sent the run's START.

A str enum: a member compares equal to the tag the file stores (File.host_clock_synchronized == "synchronized").

synchronized property

synchronized

True / False, or None when unknown.

from_tag classmethod

from_tag(tag)

The member a file's tag names: None for no tag, UNKNOWN for a tag this SDK does not know.

StartTimeGuard

Bases: str, Enum

How the run's START passed the console's time guard.

A str enum: a member compares equal to the tag the file stores.

forced property

forced

True for a START forced past a lifted guard, False for one the guard let through (open or waived), None when unknown.

from_tag classmethod

from_tag(tag)

The member a file's tag names: None for no tag, UNKNOWN for a tag this SDK does not know.


DatReader

Low-level streaming reader for .dat files. The File class wraps this for the common path; use it directly if you need access to the raw cursor (rare).

DatReader

Streaming reader for an Audace .dat file. Holds an open BufReader positioned past the 128-byte header, advanced one chunk per read_lines call so the user can iterate large acquisitions without loading the whole file.

Owns a parsed [Header]; the Python wrapper accesses fields via the header property.

Thread safety: the reader holds a mutable file cursor, so it is not safe to share between Python threads. The Python facade ensures each File has its own DatReader. PyO3 holds the GIL across method calls except during the read_exact itself (where we release it explicitly via Python::allow_threads) — concurrent reads from the same instance are still serialised by the GIL even on a release-build extension, but read_exact runs without it so a second Python thread can make progress while the first is blocked on disk I/O.

Lifetime: [DatReader::close] drops the BufReader — and with it the OS descriptor — at a point the caller chooses, instead of leaving it to whenever Python reclaims the object. It is idempotent, and any later read raises ValueError rather than reading from a handle that is no longer there. The parsed header and num_lines are kept, so a closed reader can still describe the file it read.

header property

header

is_closed property

is_closed

True once close() has run.

lines_left property

lines_left

num_lines property

num_lines

path property

path

trailing_bytes property

trailing_bytes

Bytes past the last whole line — 0 for a complete file. A non-zero value is a file cut short in the middle of a line (a recording that stopped mid-write, a partial copy); those bytes are never read.

close method descriptor

close()

Release the OS file descriptor. Idempotent — closing twice is a no-op, matching File.close() on the Python side. Every later read (read_lines, rewind, seek_lines) raises ValueError; header, num_lines and path keep answering.

read_lines method descriptor

read_lines(n=1)

Read up to n pulses of samples and return them as a (rows, line_size) numpy array. The dtype is the header's sample encoding (Header.sample_encoding: the content type's sample type, or (sample_size, FLOAT, UNSIGNED, INTERLEAVED) for content type 0, 12 and an unassigned value) — see [bytes_to_typed_array]: signed integers (negative ADC codes stay negative) except a single unsigned column, which is unsigned.

The actual read_exact runs with the GIL released so other Python threads can do work while the OS blocks on disk I/O.

  • Raises ValueError if n <= 0.
  • Raises IOError if the file is already exhausted.
  • Caps n at lines_left (does not raise on a short read).

rewind method descriptor

rewind()

Rewind back to the start of the sample stream (just past the header). Useful to make multiple passes over the same reader without re-opening the file.

seek_lines method descriptor

seek_lines(n)

Move the read cursor to pulse n (0-based) without reading the skipped samples — an O(1) seek past the header plus n lines. n is clamped to num_lines; lines_left is updated to match. Subsequent read_lines continues from n.


Functions

parse_header

parse_header builtin

parse_header(bytes)

Parse a 128-byte .dat header. Useful for callers that already hold the bytes (memory-mapped files, in-memory buffers).

export_dat

export_dat

export_dat(
    path,
    data,
    *,
    sample_rate=None,
    trig_frequency=None,
    range_v=None,
    timestamp=None,
    flags=None,
    pulse_width=None,
    num_channels=None,
    header=None,
    content_type=None,
    card=None,
    acquisition_ns=None,
    gauge_length_m=None,
    fiber_group_index=None
)

Write a 2-D numpy array out as an Audace .dat file (128-byte header + raw samples). The array's shape[1] becomes line_size and its dtype sample_size.

Two ways to describe the samples:

  • header= (e.g. f.header of the file the data was read from): every field is copied — timestamp, card, trigger pre-roll, the card's trigger rational, time flags, content type, steps — as the acquisition's conversions do. A content type of the registry gives a file of data format v1 (format_version 1, the file flags, the steps filled, duration_s of the lines written; data must be of the content type's sample type: f.read_lines() of a v1 file is); content type 0, pairs and unknown values give a legacy copy, as they are. :meth:File.export_dat does this for a range of a file's lines.
  • the keyword fields below, as in earlier versions: a file of content type 0 described by flags, or, with content_type=, a file of data format v1.

Keyword fields given with header= override its values. As in earlier versions, every integer field goes through int() (250e6, a numpy scalar, 100.0 are taken; a fraction is dropped) and timestamp and card through str().

Parameters

path Output file path. Overwritten if it exists. data (num_lines, line_size) 2-D array. Any contiguous-or-not C-order layout is accepted; the data is densified on write. sample_rate Rate of the positions along the fibre in Hz (required without header). trig_frequency Trigger pulse rate in Hz, a whole number (required without header). Without header the file carries no card rational (header bytes 88..96 are left zero), so a reader times it on this integer: a DAT cannot record a rate that is not a whole number of hertz — the Audace acquisition refuses DAT for such rates and records them in HDF5. range_v ADC voltage range in volts (stored as mV in the header). timestamp Free-form acquisition timestamp (≤ 32 bytes UTF-8), for a file without acquisition_ns. flags Raw header flag mask. On a file of content type 0 the FLOAT bit is set automatically when data.dtype.kind == 'f'; a file of data format v1 keeps only AC and HIZ. pulse_width Trigger pulse width in ns. num_channels Number of active socket channels in the original acquisition. header A :class:Header to copy (see above). content_type The content type of the samples (see :mod:invisensing.content). card The card code ("p18", "p21", "s125", "s500"). acquisition_ns Time of the first line, ns since the Unix epoch (UTC): with header=, the time of the first line written when it is not the source's first (f.line_time_ns(start)). gauge_length_m The gauge length the phase was measured over, metres (header bytes 120..124, stored as float32): a phase content type only. With fiber_group_index, metres at that index. fiber_group_index The fibre group index the samples' metres are labelled at: the file carries its speed of light round(c / n) (header bytes 124..128; a DAT stores the speed, not the index). Without header, the steps the file states follow it. With header, the header is relabelled at it first, exactly as File(path, fiber_group_index=n) does (its step, gauge and trigger pre-roll converted to the new speed), then the other keywords apply. Without it, the header's speed is kept (none: the legacy 2·10⁸ m/s).

Raises

ValueError If data is not 2-D, if a required field is missing, if the data is not of the content type's sample type, if gauge_length_m is given for a content type that is not a phase or is not a length, or if fiber_group_index is below 1, above 100 or not finite. OSError If the write fails.

light_speed_of_group_index

light_speed_of_group_index builtin

light_speed_of_group_index(n)

The speed of light in a fibre of group index n, whole m/s: round(c / n), half away from zero — the speed the acquisition stamps in every header for a configured index (Audace-Lib fibre::speed_m_s). light_speed_of_group_index(1.4682) == 204190477, light_speed_of_group_index(1.49896229) == 200000000. Raises ValueError for an index that is not a number from 1 to 100 (the only values refused).

group_index_of_light_speed

group_index_of_light_speed builtin

group_index_of_light_speed(v)

The group index a speed of light in the fibre stands for (a reader that has only the speed, a DAT): the legacy 1.49896229 for 200 000 000 m/s (and for 0, absent), 1.4682 for 204 190 477 m/s — the two indexes the acquisition writes, given back exactly — c / v otherwise (Audace-Lib fibre::group_index_of_speed).


content

The content_type registry of the Audace data format v1 and its helpers.

content

The content_type registry of the Audace data format v1.

A file's content_type (header byte 64; HDF5 attribute and TDMS property content_type; SEG-Y textual line CONTENT-TYPE) says what its samples are: one value stands for one quantity, one sample type and one producing chain. In a file of data format v1 the sample type comes from the content type alone — its FLOAT / UNSIGNED / INTERLEAVED flags are written 0. Two values are not typed: 0 (a file written before the byte existed, described by its flags as it always was) and 12 (a script output typed by its flags).

Stream-only values (6, 7, 8, 15, 20, 21, 22, 31, 32) carry two values per position ([m0, m1, m0, m1, …]). Recordings split them into two single-column files, one per member, in the member's sub-directory (phase/ and amplitude/, arctan/ and magnitude/, i_component/ and q_component/); files written before data format v1 may still hold the pair.

These helpers mirror the acquisition's own (same names, same answers) and are checked against the registry the acquisition publishes.

Usage::

from invisensing import File, content

with File("phase/2026-11-03_10-00-00.h5") as f:
    content.quantity_of(f.content_type)   # "phase"
    content.unit(f.content_type)          # "rad"
    content.method_of(f.content_type)     # "DUI_COHERENT"

CARD_CODES module-attribute

CARD_CODES = ['p18', 'p21', 's125', 's500']

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

FORMAT_VERSION module-attribute

FORMAT_VERSION = 1

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

Member

Bases: NamedTuple

One of the two values a stream-only content type carries per position.

Conversion

Bases: NamedTuple

How a stored value v becomes a physical one (expr, in to).

ContentInfo

Bases: NamedTuple

One row of the registry.

card_code builtin

card_code(value)

The card code a header slot or a file's card attribute stands for: "p18", "p21", "s125" or "s500" as is, a variant tag written before data format v1 mapped to its code, None for anything else (empty, another producer's bytes).

info

info(ct)

The registry row of ct; None for a value this SDK does not know (a newer producer).

from_tag

from_tag(tag)

The value of a tag ("dui_coherent_phase" → 19), or None.

quantity_of

quantity_of(ct)

What a single column of ct is; None for 0 (the flags say), for a stream-only value (see :func:members) and an unknown one.

members

members(ct)

The two :class:Member of a stream-only value, member 0 first; None for a single column.

member_of

member_of(ct, quantity)

(index, sample_type) of the member of ct carrying quantity (member_of(22, "amplitude") == (1, "f32")), or None.

sample_type

sample_type(ct)

"i16", "u16", "f32", or "from_flags" for 0 and 12; None for a stream-only value and an unknown one.

sample_size

sample_size(ct)

Bytes per sample (per member for a stream-only value); None for 0, 12 and an unknown value.

is_phase

is_phase(ct)

A single column of phase, in radians (2, 4, 9, 10, 17, 18, 19, 23, 29, 30).

is_amplitude

is_amplitude(ct)

A single column of amplitude (5, 11, 16).

is_stream_only

is_stream_only(ct)

A value that carries pairs (6, 7, 8, 15, 20, 21, 22, 31, 32): split into two files by every recording since data format v1.

is_file_value

is_file_value(ct)

Every known value but the stream-only ones.

is_legacy

is_legacy(ct)

0, 4, 8 and 12: never written by a producer of data format v1.

split_children

split_children(ct)

The content types of the two files a stream-only value is split into (split_children(7) == (3, 5)), or None.

method_of

method_of(ct)

The demodulation method that produced ct (method_of(29) == "DUI_ARCTAN"), or None: for a card value, for the magnitudes several methods write (sw_amplitude_sac, 11, the software front end's; hw_amplitude_f32, 16, the card's) and for the values no method produces.

unit

unit(ct)

The unit of a single column of ct ("rad", "count"…).

to_physical

to_physical(ct)

How a stored value of ct becomes a physical one, or None: hw_arctan (3) to radians (v · π / 32768), raw (1) to mV (informative), viz_logvar (28) back to the variance (10^v − 1).


Header-flag constants

The raw flag bits used by the Audace wire-format header. You typically don't need these — File.is_* properties and File.mode cover the common cases, from the content type. They're exposed for callers who need to inspect or build a Header by hand. A file of data format v1 writes every flag but AC and HIZ as 0 (the content type says the rest); the others describe the files written before it.

Constant Hex Meaning
FLAG_DEMODULATED 0x001 Samples are the output of on-board DSP
FLAG_FLOAT 0x002 Samples are IEEE-754 floats
FLAG_AC 0x004 ADC was AC-coupled
FLAG_HIZ 0x008 ADC ran in high-impedance mode
FLAG_SCHUBERT 0x010 Deprecated: nothing is read from it (the content type is the reference)
FLAG_RESERVED 0x020 Reserved: never set by any producer
FLAG_MOZART 0x040 Software-Mozart pipeline marker (read on legacy files only; content_type sw_mozart otherwise)
FLAG_PHASE 0x080 Carries unwrapped DAS phase (rad)
FLAG_INTERLEAVED 0x100 Wire carries 2 samples per spatial position
FLAG_UNSIGNED 0x200 Odd lane of an INTERLEAVED pair is u16; on a single column, every sample is (read as uint16)
HEADER_SIZE 128 Size of the wire header in bytes
FORMAT_VERSION 1 The data format version this SDK reads in full (File.format_version)

Strain constant

File(path, phase_unit="nanostrain") reads a phase as strain, in nm/m: phase_rad / gauge_length_m * NANOSTRAIN_PER_RAD_METRE (see the Guide). File(path, phase_unit="strain_rate") reads it as strain rate, in nm/m/s: (phase[n] - phase[n-1]) * NANOSTRAIN_PER_RAD_METRE / gauge_length_m * trig_frequency_real_hz, NaN on line 0 and after a gap of the time axis (see the Guide).

Constant Value Meaning
NANOSTRAIN_PER_RAD_METRE 110.37 nm/m of strain per rad/m of phase over the gauge, from ΔΦ = 2β(n + Cε)·ε·L at λ = 1550.12 nm and n = 1.46 (the core's phase index: it does not follow the fibre group index below)

The native core underneath (invisensing._core, not part of the stable API): nanostrain_factor(gauge_length_m) (the float32 factor), phase_to_nanostrain(array, gauge_length_m, *, interleaved=False, simd=None) (in place on a C-contiguous float32 / float64 array; returns the kernel used), simd_level() (the kernel in use: "avx512", "avx2" or "scalar", capped by INVISENSING_SIMD) and simd_levels() (every kernel this CPU runs); for the strain rate, strain_rate_factor( gauge_length_m, trig_frequency_hz) (the float32 factor) and phase_to_strain_rate(array, previous, gauge_length_m, trig_frequency_hz, *, interleaved=False, simd=None) (in place on whole lines; previous holds the line before the block on entry — NaN for none — and the block's last line as stored on return).

Fibre group index constants

Every metre of a file is labelled at the speed of light in the fibre it was acquired at, round(c / n) of the fibre group index n (File.light_speed_in_fiber_m_s, File.fiber_group_index; File(path, fiber_group_index=n) relabels; see the Guide).

Constant Value Meaning
SPEED_OF_LIGHT_M_S 299792458 Speed of light in vacuum, m/s (exact)
DEFAULT_FIBER_GROUP_INDEX 1.4682 The acquisition's default index: Corning SMF-28e+ at 1550 nm (204 190 477 m/s)
LEGACY_FIBER_GROUP_INDEX 1.49896229 c / 2·10⁸: the index of every recording made before the field
LEGACY_LIGHT_SPEED_IN_FIBER_M_S 200000000 The speed a file without one was acquired at, m/s
FIBER_GROUP_INDEX_MIN 1.0 Lowest accepted index (inclusive)
FIBER_GROUP_INDEX_MAX 100.0 Highest accepted index (inclusive)

Time-flag constants

Bits of the header's time_flags (bytes 100..104, Header.time_flags).

Constant Value Meaning
TIME_FLAG_MAP_V1 1 Wire streams: the acquisition published a time map for the run
TIME_FLAG_CORRECTED 2 Files: the header's start time is the corrected time of the first line (Header.time_corrected)