lunapi.lwf

Reader for Luna’s .lwf (Luna Waveform) binary format.

Public functions

lwf_summary(paths, *, recur=False) -> pd.DataFrame

Scan one or more .lwf files and return a per-file summary without loading any signal data.

read_lwf(paths, *, recur=False) -> LWFResult

Load one or more .lwf files into a single result object containing a numpy array of signal data, a per-event metadata DataFrame, and a per-channel metadata DataFrame.

Classes

LWFResult

Return value of read_lwf().

Functions

lwf_summary(→ pandas.DataFrame)

Summarise one or more .lwf files without loading signal data.

read_lwf(→ LWFResult)

Load one or more .lwf files into an LWFResult.

Module Contents

class lunapi.lwf.LWFResult[source]

Bases: NamedTuple

Return value of read_lwf().

data[source]

Signal data decoded to physical units (µV etc.). When the file was written with annot-ch-match=T, n_channels is 1 and the detecting channel for each event is in meta['annot_ch'].

Type:

np.ndarray, shape (n_waves, n_channels, n_samples)

meta[source]

Per-event metadata columns: id, tag, file, annot, instance, annot_ch, meta, anchor_sec, annot_start_sec, annot_stop_sec, wave_start_sec, wave_stop_sec.

Type:

pd.DataFrame, shape (n_waves, …)

channels[source]

Per-channel metadata: label, unit, sr, phys_min, phys_max. In annot-ch-match mode this has a single placeholder row; consult meta['annot_ch'] for the actual channel per event.

Type:

pd.DataFrame, shape (n_channels, …)

attrs[source]

File-level attributes: sfreq, align, source_files, annot_ch_match.

Type:

dict

data: numpy.ndarray[source]
meta: pandas.DataFrame[source]
channels: pandas.DataFrame[source]
attrs: dict[source]
lunapi.lwf.lwf_summary(paths: str | pathlib.Path | Iterable, *, recur: bool = False) pandas.DataFrame[source]

Summarise one or more .lwf files without loading signal data.

Parameters:
  • paths – A .lwf file, a directory, or a list of either.

  • recur – Recurse into subdirectories when paths is a directory.

Returns:

  • pd.DataFrame with one row per file and columns

  • file, id, tag, startdate, starttime, align,

  • annots, n_waves, n_channels, channels, srs,

  • n_features.

lunapi.lwf.read_lwf(paths: str | pathlib.Path | Iterable, *, recur: bool = False) LWFResult[source]

Load one or more .lwf files into an LWFResult.

All files must share the same channel labels and sample rates. All waveform events must have the same number of samples.

Parameters:
  • paths – A .lwf file, a directory, or a list of either.

  • recur – Recurse into subdirectories when paths is a directory.

Returns:

Named tuple with fields data, meta, channels, attrs. data has shape (n_waves, n_channels, n_samples) with values in physical units. When written with annot-ch-match=T, n_channels is 1 and each event’s channel is in meta['annot_ch'].

Return type:

LWFResult