2.9.1.6. pycsamt.seg.heads#
Classes
|
EDI |
|
Mixin that exposes |
|
Convenience aggregator for |
|
EDI |
|
Mixin that exposes |
- class pycsamt.seg.heads.Head(edi_header_list=None, verbose=0, logger=None, **kwargs)[source]
Bases:
EDIComponentBaseEDI
>HEADblock container.The
Headclass parses and serializes the header metadata of SEG-EDI files. It normalizes common variations in field names (for example LON → LONG) and supports latitude/longitude given either in decimal degrees or DMS strings (with or without cardinal letters).- Parameters:
- Variables:
Location (
Location) – Container for geographic coordinates. TheHead.lat,Head.longandHead.elevproperties delegate to this object.fileby (dataid, acqby,) – Dataset identifier, acquisition contractor, and file author.
filedate (acqdate, enddate,) – Acquisition start/end dates and the file timestamp.
filedatedefaults to current UTC.loc (country, state, county, prospect,) – Descriptive location metadata.
elev (lat, long,) – Coordinates as decimal degrees and elevation in the current
Head.units. DMS inputs are converted to decimal when reading; writers emit DMS strings.units ({'m', 'ft'}) – Elevation units (default
'm').progdate (stdvers, progvers,) – EDI standard version, program version, and revision date.
progversdefaults topyCSAMT <version>.coordsys (str) – Coordinate system description (default
'Geomagnetic North').declination (float or None) – Geomagnetic declination in degrees.
datum (str) – Geodetic datum (default
'WGS84').maxsect (int or None) – Maximum section count in file when present.
bindata (str or None) – Optional tag for external binary payload.
survey (project,) – Project and survey names if supplied.
empty (float) – Missing-value sentinel (default
1.0e32).edi_header (list of str or None) – Normalized
KEY=VALUElines retained after parse.
Notes
Key names are normalized to lower case and stored in a canonical set (for example lon is exposed as
Head.long).Latitude and longitude accept DMS strings of the form
'DD:MM:SS'with optional decimals and optional cardinal letters. Seepycsamt.gis.utils.Writers quote some text fields to match common EDI formatting tools.
Examples
Read and access coordinates:
h = Head.from_file("E01.edi") (h.lat, h.long, h.elev)
Create and serialize a header block:
h = Head(dataid="E1_2", acqby="ULTREM", units="m") lines = h.write() print("".join(lines))
See also
InfoCompanion container for the
>INFOblock.HeadsAggregator that bundles
HeadandInfo.pycsamt.gis.utils.dms_to_decimalRobust DMS → decimal converter.
pycsamt.gis.utils.decimal_to_dmsDecimal → DMS formatter.
pycsamt.seg.properties.IsEdiFile validator used by
from_file().
References
[Head-1]SEG MT/EMAP EDI specification (1987/2006). MTNet: https://www.mtnet.info/
- head_keys: list[str] = ['dataid', 'acqby', 'fileby', 'acqdate', 'enddate', 'filedate', 'country', 'state', 'county', 'prospect', 'loc', 'lat', 'long', 'elev', 'chainage', 'declination', 'datum', 'units', 'stdvers', 'coordsys', 'progvers', 'progdate', 'maxsect', 'bindata', 'project', 'survey', 'empty']
- classmethod from_file(edi_fn)[source]
Extract and parse the >HEAD block from an EDI file path.
- read(edi_header_list=None)[source]
Parse HEAD KV lines and set attributes.
- write(head_list_infos=None, stamp=True)[source]
Build formatted >HEAD lines (including trailing blank line).
- update(**kwargs)[source]
Update fields (accepts both known and unknown keys).
- Return type:
Head
- compute_chainage(origin, azimuth, *, set_attr=True)[source]
Compute chainage (meters) along a profile defined by an origin and azimuth, using a local flat metric.
Chainage is positive in the forward profile direction and negative behind the origin.
- Parameters:
- Returns:
Chainage in meters. Returns
nanif coordinates are missing.- Return type:
- class pycsamt.seg.heads.Info(edi_info_list=None, *, verbose=0, logger=None, info_text=None, **kwargs)[source]
Bases:
EDIComponentBaseEDI
>INFOblock container.The
Infoclass collects survey-level metadata and processing provenance. It supports both classicKEY=VALUEblocks and spectra-style free-text INFO blocks. Non-KV lines are preserved inInfo.info_textand are written back unmodified.- Parameters:
edi_info_list (sequence of str, optional) – Raw
KEY=VALUElines for the INFO block. If provided, they are parsed immediately viaread(). Non-KV lines should be passed viaInfo.info_textor supplied throughfrom_file().verbose (int, optional) – Verbosity level forwarded to the base component.
logger (logging.Logger, optional) – Logger instance to use for diagnostics.
info_text (sequence of str, optional) – Free-text lines from spectra-style INFO blocks that should be preserved.
**kwargs – Attribute overrides; unknown keys are accepted.
- Variables:
maxinfo (int) – Maximum number of textual entries (default
999).Source (
Source) – Survey provenance (project, survey, site name, and creation date).Processing (
Processing) – Processing meta-information (software, run list, sign convention, etc.).Copyright (
Copyright) – Optional copyright container.filter (str or None) – Optional filter tag.
ediinfo (list of str) – Normalized KV lines retained after parse.
info_text (list of str) – Free-form text preserved and written back.
Notes
Known keys are routed into nested containers (for example
processedby→Info.Processing).If an INFO block contains no KV lines, parse is still successful; fields remain at defaults and
Info.info_textcarries the original text.
Examples
Parse INFO from file with mixed content:
i = Info.from_file("15125A_spe.edi") i.Source.project len(i.info_text) # free-text lines preserved
Build and write a KV-only INFO block:
i = Info() i.Source.project = "Demo" i.Processing.processedby = "pyCSAMT" print("".join(i.write()))
See also
HeadHeader metadata companion.
HeadsAggregator that bundles
HeadandInfo.
pycsamt.seg.property.Source,pycsamt.seg.property.Processing,pycsamt.seg.property.CopyrightReferences
[Info-1]SEG MT/EMAP EDI specification (1987/2006). MTNet: https://www.mtnet.info/
- infokeys = ['maxinfo', 'project', 'survey', 'creationdate', 'processedby', 'processingsoftware', 'processingtag', 'sitename', 'runlist', 'remoteref', 'remotesite', 'signconvention']
- maxinfo: int
- classmethod from_file(edi_fn)[source]
Extract and parse the
>INFOblock from an EDI file.Works for both KV-style INFO and free-text INFO blocks.
- read(edi_info_list=None)[source]
Parse an INFO key-value list and set attributes.
If there are no KEY=VALUE items (e.g., spectra-style free-text INFO), this method simply leaves metadata at defaults and returns without error. Any non-KV lines should be provided via
info_text(from_file handles this).
- write(edi_info_list=None)[source]
Build formatted
>INFOlines ready to write to an EDI file.If
edi_info_listis provided, it is normalized and written.Otherwise, current attributes are serialized in canonical order, followed by any preserved free-text lines stored in
info_text.
- update(**kwargs)[source]
Update INFO fields (routes to nested containers where appropriate).
- Return type:
Info
- class pycsamt.seg.heads.Heads(head=None, info=None, verbose=0, logger=None)[source]
Bases:
EDIComponentBaseConvenience aggregator for
>HEADand>INFO.The
Headshelper wraps a parsedHeadandInfopair and provides simple I/O helpers to extract or write both blocks together. It is useful when a workflow wants to treat the top matter of an EDI file as a single unit.- Parameters:
head (
Head, optional) – Parsed header. One will be created byfrom_file()when reading from disk.info (
Info, optional) – Parsed INFO. One will be created byfrom_file()when reading from disk.verbose (int)
- Variables:
head (
Head) – Header container.info (
Info) – INFO container.
Notes
from_file()validates the input viaIsEdi, then slices the two blocks and delegates toHeadandInfo.write()serializes in canonical order (>HEADfirst, then>INFO), preserving free-text INFO content when present.
Examples
Read both blocks at once and re-emit them:
hs = Heads.from_file("000CSA_csamt.edi") lines = hs.write() open("out.edi", "w", encoding="utf-8").writelines(lines)
Access nested objects directly:
hs.head.dataid, hs.info.Source.project
See also
Head,Infopycsamt.seg.properties.IsEdiValidator used at read time.
References
[Heads-1]SEG MT/EMAP EDI specification (1987/2006). MTNet: https://www.mtnet.info/
- head: Head
- info: Info
- classmethod from_file(edi_fn)[source]
Load >HEAD and >INFO from EDI path and return an aggregate container.
- read(text_or_lines)[source]
Parse >HEAD and >INFO from provided content (string or list of lines).
- class pycsamt.seg.heads.HeadMixin[source]
Bases:
objectMixin that exposes
Headhelpers on a host class.HeadMixinadds convenience constructors for reading the>HEADblock without forcing the host to inherit fromHeaddirectly. This is primarily used by higher-level SEG components that contain a header but are not themselvesHeadobjects.- from_file(edi_fn)[source]
Return a new
Headparsed from edi_fn.
- read(lines)[source]
Shortcut to
Head.read().
- write(...)[source]
Shortcut to
Head.write().
Notes
The mixin does not own any state; it simply forwards to
Head.Examples
Use the mixin inside a host container:
class Host(HeadMixin): pass h = Host.from_file("E01.edi") print(h.dataid)
See also
Head,InfoMixin- head: Head
- classmethod from_file(edi_fn)[source]
Return a parsed Head instance from EDI path.
- read(edi_header_list=None)[source]
Parse HEAD KV lines into self.head and return it.
- class pycsamt.seg.heads.InfoMixin[source]
Bases:
objectMixin that exposes
Infohelpers on a host class.InfoMixinadds convenience constructors for reading the>INFOblock while keeping the host class focused on its domain logic. It forwards calls toInfoand returns anInfoinstance.- from_file(edi_fn)[source]
Return a new
Infoparsed from edi_fn.
- read(lines)[source]
Shortcut to
Info.read().
- write(...)[source]
Shortcut to
Info.write().
Notes
Free-text INFO blocks (for example spectra-style RUN INFORMATION) are supported transparently by
Info. The mixin needs no special handling.Examples
Mix in the helpers:
class Host(InfoMixin): pass info = Host.from_file("15125A_spe.edi") len(info.info_text) # preserved text lines
See also
Info,HeadMixin- info: Info
- classmethod from_file(edi_fn)[source]
Return a parsed Info instance from EDI path.
- read(edi_info_list=None)[source]
Parse INFO KV lines into self.info and return it.