pycsamt.seg.time_series#

Classes

TSIO(*args[, verbose, logger])

Reader and writer for >TSERIES data blocks.

TSect(*args[, verbose, logger])

Minimal container for the >=TSERIESSECT header block.

TimeSeries([name, verbose])

Container for >TSERIES data aggregated by channel.

TimeSeriesMixin()

Convenience mixin that exposes two helpers so host classes can read time-series content without depending on concrete implementations.

class pycsamt.seg.time_series.TSect(*args, verbose=0, logger=None, **kws)[source]#

Bases: EDIComponentBase

Minimal container for the >=TSERIESSECT header block. It parses the section header and the ordered list of measurement IDs that follow the header. The class keeps a pointer to where the first >TSERIES data block starts so downstream readers can jump straight to the data.

Parameters:
  • verbose (int or bool, optional) – Verbosity flag inherited from EDIComponentBase.

  • logger (object, optional) – Logger instance inherited from EDIComponentBase.

  • **kws – Keyword overrides for any public attribute. Unknown keys are ignored.

  • args (Any)

Variables:
  • sectid (str or None) – Section identifier. If absent in file it remains None.

  • nchan (int or None) – Number of channels declared in the header.

  • nmeas (int or None) – Number of measurements declared in the header.

  • npts (int or None) – Number of samples per trace if provided.

  • maxblks (int or None) – Hint for the maximum number of data blocks.

  • dt (float or None) – Sampling interval in seconds when present.

  • meas_ids (list of str) – Ordered list of measurement IDs collected from the header tail. One ID per line.

  • extra (dict) – Any non standard key–value options preserved as strings.

  • start_data_lines_num (int or None) – Absolute line index where the first >TSERIES block begins. Useful for fast data scans.

from_file(edi_path)[source]#

Parse a single >=TSERIESSECT from an EDI file. The method validates the file structure with validation.IsEdi._assert_edi() before parsing.

Parameters:

edi_path (str)

Return type:

TSect

write()[source]#

Serialize the section back to EDI lines including the measurement ID list.

Return type:

list[str]

Notes

Parsing is tolerant. Unknown keys are stored in extra. Blank lines and comment lines beginning with // are ignored. If multiple time-series sections exist, call from_file() on the desired file view or use a higher level iterator to locate the right header first.

Examples

>>> sect = TSect.from_file("sound.edi")
>>> sect.nchan, sect.dt
(3, 0.01)
>>> print("IDs:", sect.meas_ids[:2])
IDs: ['HX', 'HY']

See also

TSIO

Reader and writer for >TSERIES data blocks.

validation.IsEdi

Lightweight EDI file validator used during reading.

References

KEY_ORDER: list[str] = ['sectid', 'nchan', 'nmeas', 'npts', 'maxblks', 'dt']#
classmethod from_file(edi_path)[source]#
Parameters:

edi_path (str)

Return type:

TSect

write()[source]#
Return type:

list[str]

class pycsamt.seg.time_series.TSIO(*args, verbose=0, logger=None, **kws)[source]#

Bases: EDIComponentBase

Reader and writer for >TSERIES data blocks. Each data block line starts with a flexible option list (e.g. ID=HX NPTS=4 DT=0.25) followed by a // N hint and then one or more lines of numeric samples.

Parameters:
  • verbose (int or bool, optional) – Verbosity flag inherited from EDIComponentBase.

  • logger (object, optional) – Logger instance inherited from EDIComponentBase.

  • **kws – Keyword overrides for public attributes.

  • args (Any)

Variables:

blocks (list of _TSBlock) –

Parsed time-series blocks in file order. Every block exposes:

  • options : dict of parsed header options.

  • nvals_hint : int or None from the // count.

  • values : list[float] of samples.

  • id : str or None (alias of options['id']).

  • npts : int or None (alias of options['npts']).

  • dt : float or None (alias of options['dt']).

from_file(edi_path, start_line=None, \*, verbose=0, logger=None)[source]#

Parse all >TSERIES blocks starting at start_line. If start_line is None the first block is located automatically. The method assumes the file already passed validation.IsEdi._assert_edi() upstream.

Parameters:
Return type:

TSIO

write(per_line=None, float_fmt=None)[source]#

Serialize every block. per_line controls how many samples are printed per line. float_fmt controls the numeric format (e.g. "{: .6E}").

Parameters:
  • per_line (int | None)

  • float_fmt (str | None)

Return type:

list[str]

Notes

Header options are typed heuristically. Integer-like tokens become integers. Otherwise they are parsed as floats when possible, and finally left as strings. The common aliases id, npts and dt are mirrored onto block fields for convenience.

Examples

>>> sect = TSect.from_file("sound.edi")
>>> io = TSIO.from_file("sound.edi",
...                     start_line=sect.start_data_lines_num)
>>> len(io.blocks)
2
>>> io.blocks[0].id, io.blocks[0].dt
('HX', 0.25)
>>> lines = io.write(per_line=5, float_fmt="{: .3E}")
>>> print("".join(lines).splitlines()[0])
>TSERIES ID=HX NPTS=4 DT=0.25 // 4

See also

TSect

Header reader for >=TSERIESSECT.

SpectraIO

Similar reader for >SPECTRA blocks.

References

blocks: list[_TSBlock]#
classmethod from_file(edi_path, start_line=None, *, verbose=0, logger=None)[source]#
Parameters:
Return type:

TSIO

write(per_line=None, float_fmt=None)[source]#
Parameters:
  • per_line (int | None)

  • float_fmt (str | None)

Return type:

list[str]

class pycsamt.seg.time_series.TimeSeriesMixin[source]#

Bases: object

Convenience mixin that exposes two helpers so host classes can read time-series content without depending on concrete implementations.

read_tseries_header(edi_fn, \*, verbose=0, logger=None)[source]#

Return a TSect parsed from edi_fn. The result holds the header fields and the position of the first data block.

Parameters:
Return type:

TSect

read_tseries_blocks(edi_fn, \*, verbose=0, logger=None)[source]#

Return a TSIO built from the same file. The method internally calls TSect to find the first >TSERIES and then streams all blocks.

Parameters:
Return type:

TSIO

Notes

Use this mixin in higher level readers or project classes to offer a thin, stable API. The methods only read data and do not modify files on disk.

Examples

>>> class Reader(TimeSeriesMixin):
...     pass
>>> hdr = Reader.read_tseries_header("sound.edi")
>>> ts = Reader.read_tseries_blocks("sound.edi")
>>> hdr.nchan, len(ts.blocks)
(2, 3)

See also

TSect

Header parser for time-series sections.

TSIO

Data block reader and writer.

References

classmethod read_tseries_header(edi_fn, *, verbose=0, logger=None)[source]#
Parameters:
Return type:

TSect

classmethod read_tseries_blocks(edi_fn, *, verbose=0, logger=None)[source]#
Parameters:
Return type:

TSIO