pycsamt.zonge.tensor#
TensorBase – generic 2×2 impedance-like tensor adapter.
This mixin-like base sits on top of AVGComponentBase. It provides helpers to move between tidy per-component tables and 3D/4D tensor blocks suitable for numerical work:
(freq, 2, 2) – single-station view (station, freq, 2, 2) – multi-station view
- Supported component labels:
MT style: Zxx, Zxy, Zyx, Zyy
CSAMT style: ExHx, ExHy, EyHx, EyHy
Classes
|
Adds impedance-like tensor helpers to a component. |
- class pycsamt.zonge.tensor.TensorBase(data=None, meta=None, *, name=None, verbose=0)[source]#
Bases:
AVGComponentBaseAdds impedance-like tensor helpers to a component.
This class acts as a mixin, providing methods to transform data between a tidy DataFrame format (one measurement per row) and a dense, multi-dimensional tensor format suitable for numerical computations.
It is agnostic to the actual physical quantity being reshaped; the var parameter in its methods specifies which column from the internal DataFrame to use for the tensor’s values.
Notes
Subclasses must provide a tidy _frame attribute containing at least the columns
['freq', 'comp']and optionally'station'.The tensor axes are consistently ordered: - 3D (single station):
(frequency, E-field, H-field)- 4D (multi-station):(station, frequency, E, H)The E-field and H-field axes are of size 2, corresponding to the x and y components.
- Parameters:
data (pd.DataFrame | None)
meta (MutableMapping[str, Any] | None)
name (str | None)
- to_tensor(var, station=None, ...)[source]#
Converts a data column into a NumPy ndarray with a shape of
(..., 2, 2).
- from_tensor(tensor, freqs, var, stations=None, ...)[source]#
Reconstructs a tidy DataFrame from a NumPy tensor.
- to_xarray_tensor(var, station=None, ...)[source]#
Converts a data column into a labeled xarray.DataArray.
See also
ZA key subclass that uses these tensor operations.
ResistivityAnother subclass that benefits from this mixin.
PhaseA third subclass that uses this mixin.
- to_tensor(*, var, station=None, agg='mean', fill_value=nan, sort_freq=True, align='union')[source]#
Convert per-component values into a 2×2 tensor per frequency.
- Returns:
tensor (np.ndarray) – If station is provided → shape (n_freq, 2, 2). Else (multi-station) → shape (n_station, n_freq, 2, 2).
freqs (np.ndarray) – Sorted unique frequencies used in the tensor grid.
stations (np.ndarray) – Stations used (size 0 for single-station request).
- Parameters:
- Return type:
- static from_tensor(tensor, freqs, *, var, stations=None, comp_style='mt')[source]#
Reconstruct a tidy frame from a (…×2×2) tensor.
- Parameters:
tensor (ndarray) – Either (n_freq, 2, 2) or (n_station, n_freq, 2, 2).
freqs (Sequence[float]) – Frequencies corresponding to axis 0 (or 1).
var (str) – Column name to emit for the tensor values.
stations (Sequence[int | float | str] | None) – If provided and tensor is 4-D, labels for station axis.
comp_style (str) – ‘mt’ → Zxx/Zxy/Zyx/Zyy ; ‘csamt’ → ExHx/ExHy/EyHx/EyHy
- Return type:
- to_xarray_tensor(*, var, station=None, agg='mean', fill_value=nan, attrs=None)[source]#
- Return a 3-D or 4-D xarray.DataArray with dims:
single-station → (freq, e, h) multi-station → (station, freq, e, h)