The mixin groups small, allocation-friendly utilities
that many parsers need. It keeps math, alignment and
token-handling logic out of higher-level classes.
Notes
The helpers are intentionally tiny and avoid importing
heavy libraries beyond numpy. They favor pure
functions that accept and return arrays.
Return a tuple (p_common,i0,i1) where
p_common are periods present in both sequences,
ordered like p0; i0 and i1 are indices
to select the matching rows in the original arrays.
This mixin concentrates the I/O-oriented parts for J
files: scanning blocks, aligning periods, normalizing
rows, and assembling higher-level objects (Z,
Tipper, and ResPhase).
It aims to be robust against non-canonical header
orders and minor format quirks.
Notes
Data rows are normalized before assembly. Period
sign conventions (negative means Hz) are corrected.
Missing sentinels (e.g., -999) are mapped to
nan for numeric arrays, but objects are pre-
allocated with zeros to keep shapes consistent.
When only rho/phi are present, impedance is rebuilt
using \(|Z|=\sqrt{\mu_0 \,\omega\, \rho}\) and
\(\phi\) for the phase. The vacuum permeability
\(\mu_0\) is imported from
pycsamt.constants.
Parse the file into a component dictionary indexed
by tokens like 'ZXY', 'RXX' or 'TZX'.
Values include period, real/imag/error (TF) or rho/
phi (+ auxiliary columns for R blocks).
Assemble Z,
Tipper, and
ResPhase from the
scanned components. Returns a triple
(Z|None,Tipper|None,ResPhase|None).
Examples
>>> mix=JIOMixin()>>> # (typically used via JFile; direct use shown here)>>> # comp = mix._scan_blocks(Path("data/j/site.j"))>>> # z, tip, rp = mix._build_from_comp(comp)
The class reads a J file, extracts headers and blocks,
and builds analysis-ready objects for impedance (Z),
resistivity/phase (Res), and tipper (Tip). It
also writes new J files from the in-memory state.
Parameters:
path (str or Path, optional) – Input J file. If omitted, call read() later.
verbose (int, default=0) – Verbosity level. Non-zero emits informational
messages during parsing and writing.
Variables:
path (Path or None) – Source path when set via __init__ or
from_file().
This convenience constructor mirrors __init__ +
read(). It resolves path to a filesystem
location, parses headers and data blocks, and builds
analysis-ready objects (Z, Tip, Res) when
present or derivable.
Parameters:
path (str or Path) – Path to a J-format text file (Jones v2.0 style).
verbose (int, default=0) – Verbosity flag. When non-zero, progress/info
messages may be emitted during parsing.
The method reads the banner, info block and the first
head triple, then scans all following data blocks.
Transfer functions (Zxx, Zxy, …) and tipper
(Tzx, Tzy) are assembled when present. If only
resistivity/phase blocks exist, a synthetic impedance
is rebuilt from \(\rho\) and \(\phi\).
Parameters:
path (str or Path, optional) – If given, set as the source and read from it.
If omitted, reuse self.path set at construction.
start (int, optional) – Line index hint to start scanning blocks. Most
users can leave this as None.
The writer renders a banner, info lines and one or more
data blocks selected via datatype. When uncertainties
are unavailable, zero-filled error columns are emitted to
preserve column layout. Periods are derived from the
active frequency vector.
Parameters:
j_fn (str, optional) – Base filename to use. If omitted, derive from
:pyattr:`path` or default to 'out.j'.
new_jfn (str, optional) – Replacement filename. Takes precedence over
j_fn when provided.
datatype ({'Z','R','T','ZR','RT','ZT','ZRT','ALL'}, optional) – Select families to emit. If None, the writer
auto-detects from available objects on the instance.
savepath (str or Path, optional) – Folder where to save. Defaults to the parent of
:pyattr:`path` or the current directory.