pycsamt.seg.edi#

Classes

EDIFile([path, verbose])

High–level EDI dispatcher for SEG/EMAP/CSAMT archives.

EDIMixin()

Lightweight registry and helpers used by EDI readers.

EDIOMixin()

Tolerant >BLOCK parser and TF (Z/Tipper) builder.

class pycsamt.seg.edi.EDIMixin[source]#

Bases: CoreObject

Lightweight registry and helpers used by EDI readers.

The mixin stores parsed section objects (e.g. >HEAD, >=MTSECT, >=SPECTRASECT) in a simple dictionary, and provides tiny utilities to manage and query them.

It does not perform I/O. Host classes remain free to decide when and how sections are discovered and populated. This keeps the orchestration logic small and testable.

Variables:

sections (dict[str, object]) – Case–insensitive mapping from a logical section key (e.g. "head", "mtsect", "spectra") to the parsed object that represents that section.

add_section(key, obj)[source]#

Register obj under key. Keys are normalized to lower case.

Parameters:
Return type:

None

get_section(key)[source]#

Retrieve a previously added section or None.

Parameters:

key (str)

Return type:

Any

has_section(key)[source]#

Return True if a section exists under key.

Parameters:

key (str)

Return type:

bool

_tag2name(tag)[source]#

Translate a raw >=... header tag to a canonical registry key (e.g. ">=MTSECT" "mtsect").

Notes

The registry is intentionally untyped so that different parser implementations can coexist. For instance, a project may store a header object (SpectraSECT) and also the decoded payload object (Spectra) under separate keys.

Examples

>>> mix = EDIMixin()
>>> mix._init_registry()
>>> mix.add_section("HEAD", object())
>>> mix.has_section("head")
True
>>> isinstance(mix.get_section("head"), object)
True

See also

EDIFile

High level reader that uses the registry to expose parsed sections to callers.

References

add_section(key, obj)[source]#
Parameters:
Return type:

None

get_section(key)[source]#
Parameters:

key (str)

Return type:

Any

has_section(key)[source]#
Parameters:

key (str)

Return type:

bool

class pycsamt.seg.edi.EDIOMixin[source]#

Bases: CoreObject

Tolerant >BLOCK parser and TF (Z/Tipper) builder.

The mixin provides two core utilities used by EDIFile after headers are discovered:

The reader accepts both complex tensor blocks and the scalar families (RHO* and PHS*). When complex blocks are missing, the impedance tensor is reconstructed from resistivity and phase if possible.

Variables:

None

_scan_blocks(path, start=None, empty_val=1e32)[source]#

Return a mapping key list[float] by streaming lines until the next section or EOF. Unknown keys are ignored. Values equal to empty_val are converted to zeros.

_build_from_comp(comp, z_obj, tip_obj)[source]#

Populate z_obj and tip_obj from the components. Frequency order is normalized to descending. Z–error arrays are converted from variance blocks (.VAR).

Notes

  • Frequency order is unified to high→low. This follows a common practice in EDI archives and simplifies plotting.

  • The tipper is optional. If no tipper blocks are found, tip_obj is left untouched.

  • For RHO*/PHS* the method also carries *.ERR if present. Otherwise zero errors are assumed.

Examples

>>> comp = {"freq": [10, 1], "zxxr": [1, 2], "zxxi": [0, 0]}
>>> from pycsamt.z.z import Z
>>> from pycsamt.z.tipper import Tipper
>>> mix = EDIOMixin()
>>> z, t = Z(), Tipper()
>>> mix._build_from_comp(comp, z_obj=z, tip_obj=t)
>>> z.n_freq
2

See also

EDIFile

Uses these utilities during read_data().

References

class pycsamt.seg.edi.EDIFile(path=None, *, verbose=0)[source]#

Bases: EDIMixin, EDIOMixin

High–level EDI dispatcher for SEG/EMAP/CSAMT archives.

The class discovers top–level headers (e.g. >=MTSECT, >=SPECTRASECT, >=TSERIESSECT), loads the matching data blocks, and exposes convenient Python containers for impedance tensors, tippers, spectra, and time series.

It also writes EDI files by reusing the in–memory sections, preserving headers when possible, and regenerating block payloads from the current objects.

Parameters:
  • path (str or Path, optional) – File to open. If given, read() is executed on construction.

  • verbose (int, optional) – Verbosity level propagated to subcomponents.

Variables:
  • path (Path or None) – Bound file path (if any).

  • Z (pycsamt.z.z.Z) – Impedance tensor container with errors and rotations.

  • Tip (pycsamt.z.tipper.Tipper) – Tipper container (optional).

  • sections (dict[str, object]) – Registry populated via EDIMixin.

  • block_size (int) – Numbers per line when writing numeric payloads.

  • float_fmt (str) – Float formatter used for numeric blocks.

  • header_tpl (str) – Template used for logical block titles.

  • Properties

  • ----------

  • station (str or None) – Shortcut to >HEAD.DATAID. Setter also mirrors the value to the MT/EMAP section id.

  • processingsoftware (str or None) – Shortcut to the name of the processing software from >INFO.

read(path=None)[source]#

Load headers and sections. Parse numeric blocks into Z and Tip. Also attaches Spectra and TimeSeries if present.

Parameters:

path (str | Path | None)

Return type:

EDIFile

read_data()[source]#

Low–level numeric parsing used by read().

Return type:

EDIFile

compose_headers()[source]#

Serialize only the headers (no data blocks).

Return type:

str

write(...)[source]#

Write a full EDI assembled from current objects and sections. MT or EMAP numeric families are chosen from the MT/EMAP header or inferred from context.

Parameters:
  • edi_fn (str | None)

  • new_edifn (str | None)

  • datatype (str | None)

  • savepath (str | Path | None)

  • add_filter_array (ndarray | None)

  • synthesize_spectra (bool)

Return type:

str

interpolate(new_freq, kind="slinear", ...)[source]#

Interpolate Z on a new frequency grid. The grid is rounded to two decimals for stable serialization.

Parameters:
Return type:

Z

write_new_edi(edi_fn=None, Z=None, Tipper=None, ...)[source]#

Rebuild a clean container bound to the same source, swap selected transfer functions, and delegate to write().

Parameters:
Return type:

str

Notes

  • Frequency order is normalized to descending on read. Therefore, a file written by write() and read back will expose Z.freq in high→low order.

  • The interpolation routine enforces the new grid to live strictly inside the source span when bounds_error is True.

  • Missing blocks are handled gracefully. If complex impedances are absent, the reader tries to reconstruct them from RHO*/PHS* families.

Examples

>>> ed = EDIFile("site.edi")
>>> ed.station
'SITE'
>>> ed.Z.n_freq > 0
True
>>> out = ed.write(savepath="outdir")
>>> Path(out).exists()
True
>>> fnew = np.geomspace(ed.Z.freq.min()*1.1,
...                     ed.Z.freq.max()*0.9, 16)
>>> z2 = ed.interpolate(fnew, kind="linear")
>>> ed.write_new_edi(edi_fn="interp.edi", Z=z2)

See also

EDIMixin

Registry and convenience helpers used internally.

EDIOMixin

Numeric block reader and TF builder used by read_data().

pycsamt.seg.spectra.Spectra, pycsamt.seg.time_series.TimeSeries

References

read(path=None)[source]#
Parameters:

path (str | Path | None)

Return type:

EDIFile

read_data()[source]#
Return type:

EDIFile

compose_headers()[source]#
Return type:

str

write(edi_fn=None, new_edifn=None, datatype=None, savepath=None, add_filter_array=None, synthesize_spectra=False, **kwargs)[source]#
Parameters:
  • edi_fn (str | None)

  • new_edifn (str | None)

  • datatype (str | None)

  • savepath (str | Path | None)

  • add_filter_array (ndarray | None)

  • synthesize_spectra (bool)

Return type:

str

interpolate(new_freq, *, kind='slinear', bounds_error=True, period_buffer=None)[source]#
Parameters:
Return type:

Z

interpolate_z(new_freq, *, kind='slinear', bounds_error=True, period_buffer=None)#
Parameters:
Return type:

Z

write_new_edi(edi_fn=None, Z=None, Tipper=None, *, Spectra=None, TimeSeries=None, sections=None, **kwargs)[source]#
Parameters:
Return type:

str

property n_freq: int[source]#

Number of frequencies in Z or Spectra.

property station: str | None[source]#

Return DATAID from >HEAD if present.

property empty: float | None[source]#

Return EMPTY sentinel from >HEAD if present.

property dtype: str | None[source]#

Infer ‘mt’ or ‘emap’ from >=MT/EMAPSECT or tipper.

property has_tipper: bool[source]#

True if non-zero tipper array present.

property spectra_sect[source]#
property timeseries_sect[source]#
property spectra[source]#

Return high-level Spectra object if present.

property spectra_io[source]#

Return SpectraIO if present.

property timeseries[source]#

Return high-level TimeSeries object if present.

property timeseries_io[source]#

Return TSIO if present.

property channels: list[str][source]#

Return TS channels if any, else [].

property path_str: str[source]#

EDI path as string or empty if not set.

property edi_dir: Path | None[source]#

Parent directory of EDI file if path set.

property processingsoftware: str | None[source]#

Return INFO.Processing.ProcessingSoftware.name.