2.9.1.5. pycsamt.seg.edi#
Classes
|
High–level EDI dispatcher for SEG/EMAP/CSAMT archives. |
|
Lightweight registry and helpers used by EDI readers. |
Tolerant |
- class pycsamt.seg.edi.EDIMixin[source]
Bases:
CoreObjectLightweight 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
objunderkey. Keys are normalized to lower case.
- get_section(key)[source]
Retrieve a previously added section or
None.
- has_section(key)[source]
Return
Trueif a section exists underkey.
- _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
EDIFileHigh level reader that uses the registry to expose parsed sections to callers.
References
[EDIMixin-1]SEG EDI MT/EMAP standard (1987). MTNet.
- class pycsamt.seg.edi.EDIOMixin[source]
Bases:
CoreObjectTolerant
>BLOCKparser and TF (Z/Tipper) builder.The mixin provides two core utilities used by
EDIFileafter headers are discovered:_scan_blocks()reads numeric blocks starting at a given line (e.g.>FREQ,>ZXXR,>TXR.EXP)._build_from_comp()converts the scanned dictionary intopycsamt.z.z.Zandpycsamt.z.tipper.Tipperobjects.
The reader accepts both complex tensor blocks and the scalar families (
RHO*andPHS*). 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 toempty_val(the EDI missing- data sentinel) are converted to NaN, never to zero – zero is a valid measured value and must not be invented for a period the instrument never recorded.
- _build_from_comp(comp, z_obj, tip_obj)[source]
Populate
z_objandtip_objfrom 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_objis left untouched.For
RHO*/PHS*the method also carries*.ERRif 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
EDIFileUses these utilities during
read_data().
References
[EDIOMixin-1]SEG EDI MT/EMAP standard (1987). MTNet.
- class pycsamt.seg.edi.EDIFile(path=None, *, verbose=0)[source]
-
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:
- 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
ZandTip. Also attachesSpectraandTimeSeriesif present.
- compose_headers()[source]
Serialize only the headers (no data blocks).
- 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.
- interpolate(new_freq, kind="slinear", ...)[source]
Interpolate
Zon a new frequency grid. The grid is rounded to two decimals for stable serialization.
- 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().
Notes
Frequency order is normalized to descending on read. Therefore, a file written by
write()and read back will exposeZ.freqin high→low order.The interpolation routine enforces the new grid to live strictly inside the source span when
bounds_errorisTrue.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
EDIMixinRegistry and convenience helpers used internally.
EDIOMixinNumeric block reader and TF builder used by
read_data().
pycsamt.seg.spectra.Spectra,pycsamt.seg.time_series.TimeSeriesReferences
[EDIFile-1]SEG EDI MT/EMAP standard (1987). MTNet.
[EDIFile-2]B. Groom, R. Bailey (1989). Decomposition of the magnetotelluric impedance tensor. Geophysics.
- compose_headers(*, stamp_head=True)[source]
Serialize structural EDI headers without numeric data blocks.
stamp_headpreserves the historical default in which>HEADfile/program timestamps are refreshed byHead. Format converters may disable stamping when they need to retain mapped provenance metadata exactly.
- write(edi_fn=None, new_edifn=None, datatype=None, savepath=None, add_filter_array=None, synthesize_spectra=False, preserve_zero=False, stamp_headers=True, force_tipper=None, **kwargs)[source]
- interpolate(new_freq, *, kind='slinear', bounds_error=True, period_buffer=None)[source]
- interpolate_z(new_freq, *, kind='slinear', bounds_error=True, period_buffer=None)
- write_new_edi(edi_fn=None, Z=None, Tipper=None, *, Spectra=None, TimeSeries=None, sections=None, **kwargs)[source]
- 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.