2.11.1.7. pycsamt.jones.heads#
Classes
|
Parse and serialize the top provenance comment line. |
|
Parse and serialize a single J-format head triple. |
Mixin that provides a |
|
|
|
|
Parse and serialize the J-format information block. |
Mixin that provides an |
- class pycsamt.jones.heads.Head(j_header_list=None, *, verbose=0, **kwargs)[source]
Bases:
JComponentBaseParse and serialize a single J-format head triple.
This lightweight component represents one data-block header consisting of the station line, the data-type line, and the row count. It provides a consistent constructor and the
read/writeround-trip expected by the package.- Parameters:
j_header_list (sequence of str, optional) – Three logical header lines. The sequence may be a clean triple
[station, dtype, n]or a longer slice from a file; the parser will extract the first valid triple.verbose (int, default=0) – Verbosity for warnings during parsing.
**kwargs – Accepted for API forwards-compatibility; ignored here.
- Variables:
station (str or None) – Upper-cased station identifier. Trailing azimuth tokens on the same line are supported and ignored here (but see
az_hint).dtype (DataType or None) – Parsed data-type token (e.g.,
ZXY,RTE) with optional normalized units and a TE/TM tensor hint.n (int or None) – Number of data rows that follow this header.
az_hint (float or None) – Optional azimuth extracted from the station line when present (e.g.,
KB0001 -30). This is not the same as siteAZIMUTHfrom the info block.path (pathlib.Path or None) – Source path when constructed via
from_file().encoding (str) – Text encoding used by
from_file().verbose (int) – Verbosity level inherited from
JComponentBase.
- from_file(j_fn, \*, verbose=0)[source]
Read a file and return a
Head. Only the first valid triple is parsed.
- from_lines(j_header_list, \*, verbose=0)[source]
Build a
Headfrom an in-memory sequence. If the sequence is longer than three lines, the first valid triple is extracted.
- read(j_header_list)[source]
Parse the header triple into attributes and mark the instance as read (see
__has_read__).
- write(head_list_infos=None)[source]
Return a list of three strings representing the header triple. If
head_list_infosis given, it is parsed first and then serialized.
Notes
The station regex accepts common field variants, including hyphens and underscores, and an optional numeric azimuth token after the station id. The data-type parser is liberal with whitespace and recognizes
SI(S.I.) andFIELDunits.Examples
>>> Head().read(["KB0001 -30", "ZXY SI", "29"]) Head(station='KB0001', n=29) >>> h = Head.from_file("data/j/kb0-s001.txt") >>> h.station 'KB0001'
See also
References
[Head-1]A. G. Jones (1994). Magnetotelluric data file J-format, version 2.0.
[Head-2]MTNet. “J format documentation”.
- classmethod from_file(j_fn, *, verbose=0)[source]
- classmethod from_lines(j_header_list=None, *, verbose=0)[source]
- write(head_list_infos=None)[source]
- class pycsamt.jones.heads.Info(j_info_list=None, *, verbose=0, **kwargs)[source]
Bases:
JComponentBaseParse and serialize the J-format information block.
This component collects
>KEY=VALUErecords along with leading comment lines. It exposes a small set of convenience properties derived fromJSiteProperty.- Parameters:
j_info_list (sequence of str, optional) – A sequence containing the comment and information records. The parser stops at the first non-info, non-comment, non-blank line.
verbose (int, default=0) – Verbosity for warnings during parsing.
**kwargs – Accepted for API forwards-compatibility; ignored here.
- Variables:
items (dict of (str -> str)) – Mapping of upper-cased keys to unmodified string values.
comments (list of str) – Preserved leading comment lines (starting with
#).site (JSiteProperty) – Lazily parsed view providing normalized latitude, longitude, azimuth and elevation (see properties below).
latitude (float or None) – Decimal degrees; hemisphere and DMS tolerated.
longitude (float or None) – Decimal degrees in
[-180, 180).azimuth (float or None) – Site X-axis azimuth (degrees, true north).
elevation (float or None) – Elevation in metres.
path (pathlib.Path or None) – Source path when constructed via
from_file().encoding (str) – Text encoding used by
from_file().verbose (int) – Verbosity level inherited from
JComponentBase.
- from_file(j_fn, \*, verbose=0)[source]
Read only the comment/info header from a file.
- from_lines(j_info_list, \*, verbose=0)[source]
Build from an in-memory sequence.
- read(j_info_list)[source]
Parse the header and mark the instance as read.
- write(j_info_list=None)[source]
Render comments and
>KEY = VALUElines.
Notes
Unknown keys are preserved verbatim. Coordinate and azimuth values are normalized via
JSiteProperty, which handles ranges, hemispheres and DMS.Examples
>>> info = Info.from_file("data/j/kb0-s001.txt") >>> info.latitude, info.longitude (41.9782, 140.8958) >>> lines = info.write() >>> Info.from_lines(lines).azimuth == info.azimuth True
See also
References
[Info-1]A. G. Jones (1994). Magnetotelluric data file J-format, version 2.0.
- classmethod from_file(j_fn, *, verbose=0)[source]
- classmethod from_lines(j_info_list=None, *, verbose=0)[source]
- write(j_info_list=None)[source]
- property site: JSiteProperty[source]
- class pycsamt.jones.heads.Heads(head=None, info=None, *, verbose=0)[source]
Bases:
JComponentBaseMinimal container for one
Headand oneInfo.The class provides convenient accessors for station and site-level properties, and a small banner recorder for the top provenance line (
#WRITTEN BY ...). It is intended as the lightest useful representation of a single J header section.- Parameters:
- Variables:
head (Head) – The parsed header triple.
info (Info) – The parsed site information block.
banner (Banner) – Parsed top comment provenance. The writer defaults the
softwarefield toPYSCAMTif missing.n (int) –
0or1depending on whether a head has been parsed.station (str or None) – Shortcut to
head.station.azimuth (latitude, longitude, elevation,) – Shortcuts to values provided by
info.azimuthfalls back tohead.az_hintwhen the info block does not containAZIMUTH.
- from_file(j_fn, \*, verbose=0)[source]
Read the file then delegate to
read().
- from_lines(lines, \*, verbose=0)[source]
Build from an in-memory line sequence.
- read(text_or_lines)[source]
Extract info + head lists and parse both.
Notes
This class does not parse the subsequent data rows. It is focused on fast, dependency-free header discovery to support scanning tasks and metadata extraction.
Examples
>>> h = Heads.from_file("data/j/kb0-s001.txt") >>> h.station, h.latitude, h.software ('KB0001', 41.9782, 'GEOTOOLS')
References
[Heads-1]A. G. Jones (1994). Magnetotelluric data file J-format, version 2.0.
- classmethod from_lines(lines, *, verbose=0)[source]
- classmethod from_file(j_fn, *, verbose=0)[source]
- class pycsamt.jones.heads.HeadMixin[source]
Bases:
objectMixin that provides a
Headon host classes.The mixin offers class-level and instance-level helpers that delegate to
Headwhile keeping a single copy of the header on the host.- Variables:
head (Head) – Lazily created and cached on first use.
- from_file(edi_fn)[source]
Class method that returns
Head.from_file(edi_fn).
- read(j_header_list=None)[source]
Ensure a
Headexists on the host, parse into it, and return it.
- write(head_list_infos=None)[source]
Serialize the host’s
Headto three header lines.
Examples
>>> class Host(HeadMixin): ... pass >>> Host.from_file("file.j") Head(...)
- head: Head
- class pycsamt.jones.heads.InfoMixin[source]
Bases:
objectMixin that provides an
Infoon host classes.The mixin mirrors
HeadMixinbut for the information block. It centralizes parsing and writing of>KEY=VALUElines.- Variables:
info (Info) – Lazily created and cached on first use.
- from_file(edi_fn)[source]
Class method that returns
Info.from_file(edi_fn).
- read(j_info_list=None)[source]
Ensure an
Infoexists on the host, parse into it, and return it.
- write(j_info_list=None)[source]
Serialize the host’s
Infoto comment and info lines.
Examples
>>> class Host(InfoMixin): ... pass >>> Host().read([">LATITUDE=10"]) Info(items=1)
- info: Info
- class pycsamt.jones.heads.Banner(top_lines=None, *, software=None, station=None, date=None, note=None, verbose=0)[source]
Bases:
JComponentBaseParse and serialize the top provenance comment line.
This helper targets lines such as:
# WRITTEN BY GEOTOOLS: kb0-s001 10/06/95 RAW RECSIt extracts the producer software name, an optional station hint, a free-form date token, and an optional trailing note. The writer defaults the software field to
PYSCAMTwhen none is provided.- Parameters:
top_lines (sequence of str, optional) – An initial slice of file lines. The constructor scans these lines and parses the first matching banner.
software (str, optional) – Producer software name (e.g.,
'GEOTOOLS'). When omitted and the banner is not present, the writer uses'PYSCAMT'as a default.station (str, optional) – Station identifier hint found in the banner. This does not replace the station found in the
Head.date (str, optional) – Free-form date token as found in the banner line.
note (str, optional) – Extra text following the date token on the same line.
verbose (int, default=0) – Verbosity for warnings during parsing.
- Variables:
software (str or None) – Producer software parsed from the banner or provided by the user.
station_hint (str or None) – Station token parsed from the banner; may differ from the station found in the
Head.date (str or None) – Banner date token as text; not parsed into a datetime.
note (str or None) – Trailing free-form text after the date token.
path (pathlib.Path or None) – Source path when constructed via
from_file().encoding (str) – Text encoding used by
from_file().verbose (int) – Verbosity level inherited from
JComponentBase.
- read(top_lines)[source]
Parse the first matching banner from the given lines and mark the instance as read.
- write()[source]
Render a banner line. Defaults the software field to
PYSCAMTif missing.
Notes
The banner parser is intentionally liberal: it ignores leading whitespace, is case-insensitive on the
WRITTEN BYmarker, and preserves the raw text of the trailing note. It does not validate dates or enforce a specific date format.Examples
>>> b = Banner().read( ... [ ... "#WRITTEN BY GEOTOOLS: kb0-s001 10/06/95 RAW RECS" ... ] ... ) >>> b.software, b.station_hint, b.date ('GEOTOOLS', 'kb0-s001', '10/06/95') >>> Banner().write()[0].startswith("#WRITTEN BY PYSCAMT:") True
See also
References
[Banner-1]A. G. Jones (1994). Magnetotelluric data file J-format, version 2.0.
[Banner-2]MTNet. “J format documentation”.
- classmethod from_file(j_fn, *, verbose=0)[source]
- classmethod from_lines(lines, *, verbose=0)[source]
- write(*, new=True, include_origin=False)[source]