pycsamt.jones.blocks#
Classes
|
Abstract base for J-format data blocks. |
|
Container for a sequence of parsed J data blocks. |
|
Resistivity/phase (R/S) block implementation. |
|
One parsed resistivity/phase row of a J R/S block. |
|
Transfer-function (Z/Q/C/T) block implementation. |
|
One parsed transfer-function row of a J Z/Q/C/T block. |
- class pycsamt.jones.blocks.RRow(period, rho, pha, rhomax, rhomin, phamax, phamin, wrho, wpha, rej=False)[source]#
Bases:
objectOne parsed resistivity/phase row of a J R/S block.
The row stores period (s), apparent resistivity (Ω·m), phase (deg), their 1σ bounds, and per-column weights. A derived boolean flag
rejmarks a row as rejected according to the J-format rules.- Parameters:
period (float) – Period in seconds. If input stored frequency (Hz) as a negative number, it is normalized to a positive period.
rho (float) – Apparent resistivity. Values
< 0mark the estimate as rejected.pha (float) – Phase in degrees.
rhomax (float) – Upper and lower 1σ bounds of resistivity. May be missing.
rhomin (float) – Upper and lower 1σ bounds of resistivity. May be missing.
phamax (float) – Upper and lower 1σ bounds of phase. May be missing.
phamin (float) – Upper and lower 1σ bounds of phase. May be missing.
wrho (float) – Weights. A negative weight marks the estimate as rejected.
wpha (float) – Weights. A negative weight marks the estimate as rejected.
rej (bool) – Convenience rejection flag derived from the rules above.
Notes
Missing numeric values are often written as
-999.0in J files. The higher-level APIs convert them toNaNfor numeric workflows.Examples
>>> row = RRow( ... period=1.0, rho=100.0, pha=45.0, ... rhomax=110.0, rhomin=90.0, ... phamax=50.0, phamin=40.0, ... wrho=1.0, wpha=1.0, rej=False, ... ) >>> row.rho, row.rej (100.0, False)
References
- class pycsamt.jones.blocks.TFRow(period, real, imag, error, weight, rej=False)[source]#
Bases:
objectOne parsed transfer-function row of a J Z/Q/C/T block.
The row stores period (s), real/imag parts, a standard error, a row weight, and a derived
rejflag based on J-format rules.- Parameters:
period (float) – Period in seconds. If input stored frequency (Hz) as a negative number, it is normalized to a positive period.
real (float) – Real and imaginary parts of the transfer function.
imag (float) – Real and imaginary parts of the transfer function.
error (float) – Standard error (format-specific). May be missing.
weight (float) – Row weight. Negative values mark the row as rejected.
rej (bool) – Convenience rejection flag derived from the rules above.
Notes
The J specification allows several TF families (Z/Q/C/T). The row schema stays the same; only the physical meaning differs.
Examples
>>> tf = TFRow( ... period=0.1, real=1.0, imag=-2.0, ... error=0.1, weight=1.0, rej=False, ... ) >>> tf.period, tf.rej (0.1, False)
References
[1] A. G. Jones (1994). Magnetotelluric data file J-format, version 2.0.
- class pycsamt.jones.blocks.JBlock(head=None, *, rows=None, verbose=0)[source]#
Bases:
JComponentBaseAbstract base for J-format data blocks.
A block ties a parsed header (
Head) to a homogeneous sequence of rows (RRoworTFRow). Subclasses implement the row parser, normalization, serialization, and simple QA summaries.- Parameters:
- Variables:
head (Head) – Block header with
station,kind,comp,n.nrows (int) – Number of parsed data rows.
units (station, kind, comp,) – Convenience views onto
head.dtype.columns (tuple of str) – Column names for the structured numeric view.
shape ((int, int)) –
(nrows, ncols)derived from the current rows.
- from_file(j_fn, \*, verbose=0)[source]#
Build a block from a file slice. The concrete subclass is chosen from the header’s
kind.
- read((head, body_lines))[source]#
Populate the block from an existing
Headand the subsequent body lines. Marks the instance as read.
- to_numpy()[source]#
Structured array view with numeric normalization (period sign, missing sentinels, rejection flags).
Notes
The base class is intentionally minimal to keep the parser light. Subclasses define the row regex, column names, and row-level normalization logic.
Examples
>>> # Pseudocode; subclass chosen from header >>> blk = JBlock.from_lines(['S01', 'RXY', '1', '...']) >>> blk.station, blk.nrows ('S01', 1)
References
[1] A. G. Jones (1994). Magnetotelluric data file J-format, version 2.0.
- class pycsamt.jones.blocks.RBlock(head=None, *, rows=None, verbose=0)[source]#
Bases:
JBlockResistivity/phase (R/S) block implementation.
Parses rows of the form
period rho pha rhomax rhomin phamax phamin wrho wpha. Applies J-format rules to normalize period sign and to mark rejected estimates.- Parameters:
- Variables:
columns (tuple of str) –
('period', 'rho', 'pha', 'rhomax', 'rhomin', 'phamax', 'phamin', 'wrho', 'wpha', 'rej').
Notes
Normalization rules:
If input period is negative, the value stores frequency in Hz and is converted to period (s).
rho < 0orwrho < 0marks the row as rejected.-999.0sentinels are converted toNaNin numeric views.
Examples
>>> lines = [ ... 'S01', 'RXY', '2', ... '-1.0 100 45 110 90 50 40 1 1', ... ' 2.0 -5 30 35 25 40 20 1 1', ... ] >>> blk = RBlock.from_lines(lines) >>> a = blk.to_numpy() >>> a['period'][0] # 1/Hz -> s 1.0 >>> a['rej'][1] # rho < 0 True
References
[1] A. G. Jones (1994). Magnetotelluric data file J-format, version 2.0.
- class pycsamt.jones.blocks.TFBlock(head=None, *, rows=None, verbose=0)[source]#
Bases:
JBlockTransfer-function (Z/Q/C/T) block implementation.
Parses rows of the form
period real imag error weight. Applies J-format rules to normalize period sign and to mark rejected estimates.- Parameters:
- Variables:
columns (tuple of str) –
('period', 'real', 'imag', 'error', 'weight', 'rej').
Notes
Normalization rules:
If input period is negative, the value stores frequency in Hz and is converted to period (s).
weight < 0marks the row as rejected.-999.0sentinels are converted toNaNin numeric views.
Examples
>>> lines = [ ... 'S02', 'ZXY SI', '2', ... '-1.0e+1 1.0 -2.0 0.1 1.0', ... ' 5.0 -999 3.0 -999 -1.0', ... ] >>> blk = TFBlock.from_lines(lines) >>> a = blk.to_numpy() >>> round(a['period'][0], 3) 0.1 >>> a['rej'][1] # weight < 0 True
References
[1] A. G. Jones (1994). Magnetotelluric data file J-format, version 2.0.
- class pycsamt.jones.blocks.JBlocks(blocks=None, *, verbose=0)[source]#
Bases:
JComponentBaseContainer for a sequence of parsed J data blocks.
Provides discovery from raw text, iteration, selection by family or component, serialization, and quick QA roll-ups across blocks.
- Parameters:
- Variables:
Notes
Header discovery is tolerant to real-world quirks, including optional azimuth on the station line and the count-before-dtype pattern seen in some files.
Examples
>>> col = JBlocks.from_file('data/j/kb0-s001.txt') >>> col.n >= 1 True >>> [b.station for b in col.select(kind='R')] ['KB0001', ...]
References
[1] A. G. Jones (1994). Magnetotelluric data file J-format, version 2.0.
- property station: str | None[source]#
Return the single, unique station name for the block collection. Returns None if no blocks are present.