pycsamt.seg.mtemap#

Classes

EMAPComponents(*args[, verbose, logger])

Lightweight view of EMAP/MT component IDs.

EMAPMixin()

Thin facade that lets a host class load an MTEMAP with a consistent API.

MTEMAP([mt_or_emap_section_list, verbose, ...])

Minimal header container for >=MTSECT and >=EMAPSECT blocks.

class pycsamt.seg.mtemap.MTEMAP(mt_or_emap_section_list=None, verbose=0, logger=None, **kwargs)[source]#

Bases: EDIComponentBase

Minimal header container for >=MTSECT and >=EMAPSECT blocks.

The class stores option key-values from the section header. It keeps measurement IDs as strings to avoid loss of formatting (e.g. "251.025"). Count fields are parsed as integers where possible.

Notes

  • If SECTID is missing or looks numeric, the value from >HEAD/DATAID is used as a fallback.

  • Presence of NDIPOLE or TYPE marks the block as EMAP when writing.

  • NFREQ in the header should match the number of items in the following >FREQ block [1].

  • The class does not validate that the referenced measurement IDs exist. That is handled elsewhere.

Variables:
  • sectid (str or None) – Section identifier. May be replaced by DATAID when numeric or missing.

  • nfreq (int or None) – Number of frequencies expected in the section.

  • maxblks (int or None) – Optional maximum count of data blocks.

  • hz (hx, hy,) – Magnetic measurement IDs. May be absent.

  • ey (ex,) – Electric measurement IDs. May be absent.

  • ry (rx,) – Reference measurement IDs. May be absent.

  • ndipole (int or None) – EMAP dipole count. Presence implies EMAP.

  • type (str or None) – Optional EMAP type tag.

  • chksum (int or None) – Optional checksum reported by some writers.

  • start_data_lines_num (int or None) – Index in the source file where data blocks start.

  • temp_sectid (str or None) – Internal cache of DATAID used for fallback.

Parameters:
  • mt_or_emap_section_list (list[str] | None)

  • verbose (int)

  • kwargs (Any)

See also

EMAPComponents

Small container exposing only component IDs.

EMAPMixin

Thin facade to build an MTEMAP from a file.

References

Examples

Parse a header from an EDI file and write it back:

from pycsamt.seg.mtemap import MTEMAP

m = MTEMAP.from_file("site.edi")
lines = m.write()
print("".join(lines))
KEY_ORDER: list[str] = ['sectid', 'nfreq', 'maxblks', 'hx', 'hy', 'hz', 'ex', 'ey', 'rx', 'ry', 'ndipole', 'type', 'chksum']#
start_data_lines_num: int | None = None#
temp_sectid: str | None = None#
sectid: str | None#
nfreq: int | None#
maxblks: int | None#
hx: str | None#
hy: str | None#
hz: str | None#
ex: str | None#
ey: str | None#
rx: str | None#
ry: str | None#
ndipole: int | None#
type: str | None#
chksum: int | None#
classmethod from_file(edi_path)[source]#

Build an instance from an EDI path. The file is first validated, then the header lines between the section tag and the next block are parsed.

Parameters:

edi_path (str) – Path to a readable EDI file.

Returns:

Parsed header object.

Return type:

MTEMAP

Raises:
  • FileNotFoundError – If the path does not point to a file.

  • EdIDataError – If no >=MTSECT or >=EMAPSECT is found.

Notes

The method also caches DATAID from >HEAD and uses it to replace a numeric or missing SECTID. This helps with writers that output numeric section labels.

Examples

>>> m = MTEMAP.from_file("site.edi")
>>> m.sectid
'SITE_A'
read(mt_or_emap_section_list=None)[source]#

Parse key-value tokens into attributes.

Parameters:

mt_or_emap_section_list (list of str, optional) – Items like ["NFREQ=60", "HX=251.025"]. If omitted, the list passed at construction is used.

Returns:

The instance itself, for chaining.

Return type:

MTEMAP

Notes

Unknown keys are ignored. Values are normalized by stripping quotes and whitespace. Integer fields are parsed with a best-effort cast.

write(nfreq=None)[source]#

Serialize the header to text lines.

Parameters:

nfreq (int, optional) – Override for NFREQ in the output.

Returns:

Lines including the opening section tag.

Return type:

list of str

Notes

If either NDIPOLE or TYPE is present the opening tag is >=EMAPSECT. Otherwise >=MTSECT is used. For EMAP, the fields EX, EY and HZ are omitted by convention.

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

Bases: EDIComponentBase

Lightweight view of EMAP/MT component IDs.

The container exposes only component identifiers and does not include section counts or metadata. It is useful when you need the mapping from channel type to measurement ID without other header details.

Variables:
  • hz (hx, hy,) – Magnetic component measurement IDs.

  • ey (ex,) – Electric component measurement IDs.

  • ry (rx,) – Reference component measurement IDs.

Parameters:

Notes

The class does not normalize or validate that the IDs exist in the >=DEFINEMEAS block. It simply carries the strings.

See also

MTEMAP

Full section header with counts and flags.

Examples

Create from an existing MTEMAP:

m = MTEMAP.from_file("site.edi")
comp = EMAPComponents.from_mtemap(m)
comp.as_dict()
hx: str | None#
hy: str | None#
hz: str | None#
ex: str | None#
ey: str | None#
rx: str | None#
ry: str | None#
classmethod from_mtemap(m)[source]#

Construct a component view from an MTEMAP.

Parameters:

m (MTEMAP) – A parsed section header.

Returns:

Container populated with IDs from m.

Return type:

EMAPComponents

as_dict()[source]#

Return a plain mapping of component names to IDs.

Returns:

Keys are "hx", "hy", "hz", "ex", "ey", "rx", "ry". Values are strings or None.

Return type:

dict

class pycsamt.seg.mtemap.EMAPMixin[source]#

Bases: object

Thin facade that lets a host class load an MTEMAP with a consistent API.

Attach this mixin to any class that should expose a from_file constructor returning an MTEMAP. The mixin does not keep state; it only forwards the call.

See also

MTEMAP.from_file

The underlying constructor that performs parsing.

Examples

Add the mixin and use it on a host type:

class Host(EMAPMixin):
    pass

hdr = Host.from_file("site.edi")
assert hdr.nfreq is not None
classmethod from_file(edi_fn)[source]#
Parameters:

edi_fn (str)

Return type:

MTEMAP