pycsamt.seg.validation#
SEG-EDI validators (no base-class deps).
Classes
|
Abstract base for SEG-EDI validation helpers. |
- class pycsamt.seg.validation.IsEdi[source]#
Bases:
ABCAbstract 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 existingIsEdiinstance. The check is heuristic, fast, and tolerant of minor formatting issues.The validator recognizes three EDI families:
Impedance-style files that contain a
>FREQblock and a measurement section such as>=MTSECT,>=DEFINEMEAS,>=EMAPSECTor>=OTHERSECT.Spectra-style files that include
>=SPECTRASECTand or at least one>SPECTRAblock.Time-series files that include
>=TSERIESSECTand or at least one>TSERIESblock.
In addition, the first top-level tag must be
>HEADand the last must be>END. On failure the method raises a descriptiveEdIDataError.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-sigwitherrors="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_fileParse
>=MTSECT/>=EMAPSECTheaders.pycsamt.seg.spectra.SpectraSECT.from_fileParse
>=SPECTRASECTheaders.pycsamt.seg.time_series.TSect.from_fileParse
>=TSERIESSECTheaders.
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 concreteIsEdiinstance is provided instead of a file path.- Returns:
Truewhen the instance is valid. Subclasses decide the exact criteria.- Return type:
Notes
Implementations should be lightweight and side-effect free. Heavy validation belongs to dedicated readers (e.g., MTEMAP, Spectra, Time-Series parsers).