pycsamt.zonge.meas#

pycsamt.zonge.meas

Lightweight, robust containers for measurement columns that appear in Zonge AVG tables. These components follow the new table-centric design (inherit from AVGComponentBase), so they can be fed with a tidy DataFrame and later serialize as small CSV blocks if desired.

Exports#

  • CompMeas : validator/normaliser for component labels (‘ExHy’, …)

  • Amps : transmitter current amplitude handler (A)

Both classes keep context columns (‘station’, ‘freq’, ‘comp’) when available, which helps downstream grouping and reshaping.

Classes

Amps([data, meta, name])

Transmitter current amplitude container (unit: A).

CompMeas([data, meta, name, verbose])

Enumeration/validator for classical CSAMT component labels.

Frequency([data, meta, name])

Frequency axis manager (Hz) for AVG tables.

class pycsamt.zonge.meas.CompMeas(data=None, meta=None, *, name=None, verbose=0)[source]#

Bases: AVGComponentBase

Enumeration/validator for classical CSAMT component labels.

The class guarantees a canonical comp column with allowed values (case-sensitive): {'ExHy','ExHx','EyHy','EyHx'}. A few common case variants are accepted and normalized.

Typical usage#

>>> cm = CompMeas.from_avg((df, meta))
>>> cm.unique
['ExHy']  # for a scalar survey with one component
required: set[str] = {}#
provides: set[str] = {'comp'}#
read(source, meta=None)[source]#

Ensure a normalised comp column exists.

  • If missing, default to ‘ExHy’ (legacy kind-1 style).

  • If present, normalise values and validate membership.

Parameters:
Return type:

None

write()[source]#

Serialise the component block as a compact CSV fragment.

Only the context columns and comp are emitted to keep files readable. Disk I/O is the caller’s responsibility.

Return type:

Sequence[str]

property unique: list[str][source]#

Sorted unique component labels.

Parameters:
class pycsamt.zonge.meas.Amps(data=None, meta=None, *, name=None)[source]#

Bases: AVGComponentBase

Transmitter current amplitude container (unit: A).

The class normalises the amps column to numeric, tracks a few useful stats, and can (optionally) export itself as a small CSV block. Context columns are preserved.

Examples

>>> amps = Amps.from_avg((df, meta))
>>> amps.stats.mean
12.7
>>> ds = amps.to_xarray()   # optional grid for convenience
Parameters:
required: set[str] = {}#
provides: set[str] = {'amps'}#
read(source, meta=None)[source]#

Parse source and populate the amps column as float.

Non-numeric entries (‘*’, blanks) become NaN. Context columns (station/freq/comp) are kept when present.

Parameters:
Return type:

None

property stats: _AmpStats[source]#

Return min/max/mean/median/count snapshot.

as_series()[source]#

Return the amps column as a Series (copy).

Return type:

Series

to_frame()[source]#

Return a small table with context + amps only.

Return type:

DataFrame

to_xarray(*, coords=('station', 'freq', 'comp'), attrs=None)[source]#

Optional convenience: grid the column into an xarray dataset (dims: station × freq × comp) with a single data-variable called amps.

Parameters:
write()[source]#

Serialise as a compact CSV fragment. We keep context columns if present so the block remains useful alone.

Return type:

Sequence[str]

class pycsamt.zonge.meas.Frequency(data=None, meta=None, *, name=None)[source]#

Bases: AVGComponentBase

Frequency axis manager (Hz) for AVG tables.

Goals#

  • Read from legacy and modern frames (column aliases handled)

  • Enforce positivity (> 0 Hz) while tolerating missing markers

  • Offer stable unique grids across stations/components

  • Provide a compact to_xarray() for downstream use

Notes

  • Legacy decimals like ‘.5’ are parsed correctly.

  • Missing values (‘*’, ‘’, None) become NaN and are ignored in summaries. Non-positive numeric entries raise FrequencyError.

required: set[str] = {}#
provides: set[str] = {'freq'}#
read(source, meta=None, **kws)[source]#

Load frequency values from a tidy frame or a flat vector.

If source is a DataFrame, we try to keep station / comp when present. Otherwise we inject conservative defaults: station=NaN, comp=’ExHy’.

Parameters:
Return type:

None

write()[source]#

Emit a compact CSV block with the contextual columns that we manage (station, freq, comp), suitable for round-tripping.

Return type:

list[str]

unique(*, sort=True, dropna=True, rtol=1e-06, atol=1e-12)[source]#

Unique global frequency grid with tolerance deduplication.

Parameters:
Return type:

ndarray

by_station(*, rtol=1e-06, atol=1e-12)[source]#

Per-station unique frequency grids (sorted).

Parameters:
Return type:

dict[float, ndarray]

property n_unique: int[source]#

Number of unique frequencies in the table.

static logspace(decade_start, decade_stop, n_points)[source]#

Canonical log-spaced grid (10**start → 10**stop), inclusive.

Parameters:
  • decade_start (int)

  • decade_stop (int)

  • n_points (int)

Return type:

ndarray

to_xarray(*, coords=('station', 'freq', 'comp'), attrs=None)[source]#

Convert to an xarray.Dataset. We include freq as a data variable as well, which is helpful in some consumers; the coordinate is still the same freq axis created by coords.

Parameters:
Parameters: