pycsamt.seg.validation#

SEG-EDI validators (no base-class deps).

Classes

IsEdi()

Abstract base for SEG-EDI validation helpers.

class pycsamt.seg.validation.IsEdi[source]#

Bases: ABC

Abstract base for SEG-EDI validation helpers.

Subclasses implement :pyattr:`is_valid`. The static method _assert_edi() provides a robust, file-level validator that accepts either a path or an existing IsEdi instance. The check is heuristic, fast, and tolerant of minor formatting issues.

The validator recognizes three EDI families:

  1. Impedance-style files that contain a >FREQ block and a measurement section such as >=MTSECT, >=DEFINEMEAS, >=EMAPSECT or >=OTHERSECT.

  2. Spectra-style files that include >=SPECTRASECT and or at least one >SPECTRA block.

  3. Time-series files that include >=TSERIESSECT and or at least one >TSERIES block.

In addition, the first top-level tag must be >HEAD and the last must be >END. On failure the method raises a descriptive EdIDataError.

Notes

The check is structural rather than semantic. It does not validate numerical values or cross-block consistency. Files are read as text using utf-8-sig with errors="replace" to gracefully handle odd encodings.

Examples

Validate an EDI file path:

>>> from pycsamt.seg.validation import IsEdi
>>> IsEdi._assert_edi("path/to/site.edi")
True

Use with an object that implements is_valid:

>>> class MyEdi(IsEdi):
...     @property
...     def is_valid(self):
...         return True
...
>>> IsEdi._assert_edi(MyEdi())
True

See also

pycsamt.seg.mtemap.MTEMAP.from_file

Parse >=MTSECT / >=EMAPSECT headers.

pycsamt.seg.spectra.SpectraSECT.from_file

Parse >=SPECTRASECT headers.

pycsamt.seg.time_series.TSect.from_file

Parse >=TSERIESSECT headers.

References

abstract property is_valid: bool[source]#

Indicate whether the current instance represents a structurally valid EDI object.

This property is used by IsEdi._assert_edi() when a concrete IsEdi instance is provided instead of a file path.

Returns:

True when the instance is valid. Subclasses decide the exact criteria.

Return type:

bool

Notes

Implementations should be lightweight and side-effect free. Heavy validation belongs to dedicated readers (e.g., MTEMAP, Spectra, Time-Series parsers).