High-level impedance tensor container built on
ResPhase.
Z stores complex impedances with shape (n,2,2) and
manages absolute uncertainties of the same shape. A single
(2,2) matrix is promoted to a one-row stack.
Frequency is held as a 1-D vector (n,) in Hz. When either
:pyattr:`z` or :pyattr:`freq` is set, apparent resistivity
\(\rho\) and phase \(\phi\) are recomputed via the
parent class.
Parameters:
z_array (ndarray, shape (n,2,2) or (2,2), optional) – Complex impedance tensor(s). Real arrays are cast to
complex.
z_err_array (ndarray, optional) – Absolute per-component errors on :pyattr:`z`. Shapes as
for z_array after any promotion.
freq (array-like of float, optional) – Frequency vector in Hz. Must be 1-D and strictly
positive. Length must equal the number of rows in
:pyattr:`z`.
name (str, optional) – Display name forwarded to
BaseEM.
meta (dict, optional) – Arbitrary metadata forwarded to BaseEM.
verbose (int, default 0) – Verbosity forwarded to BaseEM.
Variables:
z (ndarray or None) – Complex impedance stack, shape (n,2,2).
z_err (ndarray or None) – Absolute errors on :pyattr:`z`.
freq (ndarray or None) – Frequency vector in Hz.
rotation_angle (float or ndarray) – Accumulated rotation(s) in degrees (CW positive). A
scalar before data are set; a length-n vector once
data exist.
Notes
The index convention is
Zxx → [:,0,0]
Zxy → [:,0,1]
Zyx → [:,1,0]
Zyy → [:,1,1]
Uncertainties are absolute (not relative) and are
propagated to \(\rho\) and \(\phi\) when available.
Build a Z instance from
\((\rho, \phi, f)\) (with errors).
This convenience constructor reconstructs complex
impedances from apparent resistivity \(\rho\),
phase \(\phi\) (deg), and frequency, and attaches
optional uncertainties. Internally it calls
set_res_phase().
Rotate :pyattr:`z` by angle(s) alpha (degrees, CW
positive).
The rotation is referenced to geographic axes (X→North,
Y→East). A single angle is applied to all frequencies; a
length-n sequence applies element-wise angles. Errors
are rotated consistently when present.
Parameters:
alpha (float or sequence of float) – Rotation angle(s) in degrees. If a sequence is given,
its length must be 1 or equal to n.
Rotation uses
rotatematrix_incl_errors()
per frequency.
Examples
>>> importnumpyasnp>>> frompycsamt.z.zimportZ>>> z=np.zeros((2,2,2),complex)>>> f=np.array([10.0,1.0])>>> obj=Z(z_array=z,freq=f)>>> obj.rotate(30.0)# single angle for all rows>>> obj.rotation_angle.shape(2,)
Remove galvanic distortion D from the observed impedance
tensor \(Z\) to obtain the undistorted tensor
\(Z_0 = D^{-1} Z\).
Uncertainty propagation is included (first-order, 1-norm). If
either z_err or distortion_err_tensor is missing, zeros
are assumed for the corresponding errors.
Parameters:
distortion_tensor (ndarray, shape (2, 2) or (n, 2, 2)) – Real 2×2 galvanic distortion matrix D. If a stack is
provided, only the first slice is used (distortion is assumed
time-invariant).
distortion_err_tensor (ndarray, shape (2, 2) or (n, 2, 2), ) – optional
Absolute errors on D. If omitted, zeros are assumed.
If a stack is provided, only the first slice is used.
Returns:
D (ndarray, shape (2, 2)) – The (real) distortion tensor used.
The diagonal entries are set to zero. The off-diagonal
entries retain their complex signs, but their magnitudes are
set to the mean of the original off-diagonal magnitudes
at each frequency:
|Z01|, |Z10| → m = 0.5 (|Z01| + |Z10|)
Z01 := sign(Z01) * m
Z10 := sign(Z10) * m
If z_err is available, returns an array with
shape (n_freq,) computed by summing the diagonal
errors \(\Delta Z_{00} + \Delta Z_{11}\). Otherwise
None.
lambda_± are simple combinations frequently used in
analytic manipulations of 2×2 matrices. sigma_± follow the
historical form found in legacy code; they reduce to simple
combinations of \(\lVert Z \rVert_F\) and \(|\det|\).
ResPhase computes apparent resistivity
\(\rho\) and phase \(\phi\) from a complex
impedance tensor Z, and supports the inverse map
\((\rho,\ \phi) \rightarrow \mathbf{Z}\) with error
propagation. It is a light, independent container;
Z inherits from it to add
higher-level conveniences.
z_err_array (ndarray, shape (n_freq, 2, 2), optional) – Absolute per-component uncertainty on Z. If omitted,
uncertainties on \(\rho\) and \(\phi\) remain
None.
freq (ndarray, shape (n_freq,), optional) – Frequency vector in Hz. Must be 1-D, finite and strictly
positive.
**kwargs – Forwarded to BaseEM (e.g., name,
meta).
Error propagation (forward). If Z errors are available,
the per-entry relative amplitude error is \(\Delta Z/|Z|\).
We use
z_error2r_phi_error()
to map this to the \(\rho\) relative error (×2) and to an
absolute phase uncertainty (deg, capped at
\(90^{\circ}\)).
Inverse path. Given \(\rho\) and \(\phi\), we
recover \(|Z|\) from
\[|Z| \;=\; \sqrt{\,5\,f\,\rho\,},\]
then build Z in Euler form. When \(\rho\) and
\(\phi\) errors are given, the \(|Z|\) error follows
z_array (ndarray, shape (n_freq, 2, 2), optional) – Complex impedance tensor Z. If given, it replaces the
internal value used for the computation.
z_err_array (ndarray, shape (n_freq, 2, 2), optional) – Absolute Z error. If omitted, ρ and φ uncertainties are
set to None.
freq (ndarray, shape (n_freq,), optional) – Frequency vector in Hz. Must be 1-D, finite and > 0.
Returns:
Results are stored on the instance.
Return type:
None
Raises:
ZError – If Z is missing, shapes are inconsistent, values are not
finite, or frequencies are not strictly positive.
Notes
We use \(\rho = 0.2\,|Z|^2 / f\) and
\(\phi = \angle Z\) (in degrees).
If z_err_array is given, per-entry uncertainties are
computed via
z_error2r_phi_error(). The
resistivity error is absolute (Ω·m). The phase error is
absolute (deg) and is capped at \(90^\circ\).
Attach \(rho\) and \(phi\) (with optional errors)
and reconstruct Z.
This inverse path accepts apparent resistivity (ρ) and phase (φ)
at each frequency, reconstructs |Z| via |Z|=sqrt(5fρ),
and builds the complex tensor Z. If both ρ and φ errors are
supplied, a per-entry absolute Z uncertainty is propagated in
polar coordinates and converted to rectangular form.
Parameters:
res_array (ndarray, shape (n_freq, 2, 2)) – Apparent resistivity (Ω·m). Must be real and finite.
phase_array (ndarray, shape (n_freq, 2, 2)) – Phase in degrees. Must be real and finite.
freq (ndarray, shape (n_freq,)) – Frequency in Hz (1-D, finite, strictly positive).
res_err_array (ndarray, shape (n_freq, 2, 2), optional) – Absolute error on ρ (Ω·m). If omitted, Z error is left
None.
When error arrays are supplied, |Z| error follows the above and
is combined with phase error by
propagate_error_polar2rect() to yield
a single absolute Z error per component.
z_array (ndarray, shape (n_freq, 2, 2), optional) – Complex impedance tensor Z. If given, it replaces the
internal value used for the computation.
z_err_array (ndarray, shape (n_freq, 2, 2), optional) – Absolute Z error. If omitted, ρ and φ uncertainties are
set to None.
freq (ndarray, shape (n_freq,), optional) – Frequency vector in Hz. Must be 1-D, finite and > 0.
Returns:
Results are stored on the instance.
Return type:
None
Raises:
ZError – If Z is missing, shapes are inconsistent, values are not
finite, or frequencies are not strictly positive.
Notes
We use \(\rho = 0.2\,|Z|^2 / f\) and
\(\phi = \angle Z\) (in degrees).
If z_err_array is given, per-entry uncertainties are
computed via
z_error2r_phi_error(). The
resistivity error is absolute (Ω·m). The phase error is
absolute (deg) and is capped at \(90^\circ\).
Attach \(rho\) and \(phi\) (with optional errors)
and reconstruct Z.
This inverse path accepts apparent resistivity (ρ) and phase (φ)
at each frequency, reconstructs |Z| via |Z|=sqrt(5fρ),
and builds the complex tensor Z. If both ρ and φ errors are
supplied, a per-entry absolute Z uncertainty is propagated in
polar coordinates and converted to rectangular form.
Parameters:
res_array (ndarray, shape (n_freq, 2, 2)) – Apparent resistivity (Ω·m). Must be real and finite.
phase_array (ndarray, shape (n_freq, 2, 2)) – Phase in degrees. Must be real and finite.
freq (ndarray, shape (n_freq,)) – Frequency in Hz (1-D, finite, strictly positive).
res_err_array (ndarray, shape (n_freq, 2, 2), optional) – Absolute error on ρ (Ω·m). If omitted, Z error is left
None.
When error arrays are supplied, |Z| error follows the above and
is combined with phase error by
propagate_error_polar2rect() to yield
a single absolute Z error per component.