Complex outputs¶
Complex dtype alone does not identify a value's meaning. Deterministic
amplitudes and Fourier-domain coefficients follow different conventions from
second-order statistics and spectral densities. The
gragra.results reference documents descriptors for
Fourier transforms, amplitude spectra, phasors, PSD, ASD and CSD.
Two different meanings of a complex array¶
A complex-valued gragra result is not a single concept. Which of the two
meanings below applies depends on the order, in input amplitude, of the
quantity being returned — not on which subpackage the function lives in.
plane_wave_mass_weights (order A) lives in coherent/; coherent_point_acceleration
(order A) and coherent_gravitoelastic_tensor (order B) both live in
observables/. Check the disclaimer text in the function's own docstring,
not its import path.
A. Linear complex amplitudes¶
Which functions return one¶
point_potential, point_acceleration, point_gravity_gradient,
displacement_transfer_acceleration, coherent_point_acceleration,
coherent_point_gravity_gradient, plane_wave_phase,
plane_wave_complex_factor, plane_wave_displacement,
plane_wave_mass_weights, evanescent_complex_factor,
rayleigh_displacement, stochastic_ps_realization — any observable given
a complex-weighted source becomes complex the moment the source's
weights_kg is complex (see Point sources).
How to interpret it¶
Complex outputs represent linear complex amplitudes or transfer-function-like responses, not directly real-valued time-domain gravitational fields.
To recover a physical, real-valued signal you must attach your own time
factor and take the real part — gragra never does this for you and cannot
know which sign convention (exp(-iωt) vs exp(+iωt)) your upstream data
used.
"""A first-order complex amplitude, and how to turn it back into a real field.
The complex number an observable returns here is the amplitude of a linear
response, not a field value. Recovering something measurable takes an explicit
time factor and a real part, and the sign convention of that time factor is
the caller's -- gragra never applies one.
"""
import numpy as np
from gragra import G_SI, WeightedPointSource, point_acceleration
# One oscillating mass element with amplitude 1 kg and a phase of +pi/2
# relative to whatever reference the caller has chosen: delta_m = 1j kg.
source = WeightedPointSource(positions_m=[[0.0, 0.0, 0.0]], weights_kg=[1.0j])
amplitude_m_s2 = point_acceleration(source, [[1.0, 0.0, 0.0]])
# The output dtype follows the weights: a complex source gives complex128.
assert amplitude_m_s2.dtype == np.complex128
# The x component is -G_SI * 1j. Modulus G_SI, argument -pi/2 -- the response
# lags the source by half a turn relative to the source's own +pi/2, because
# the acceleration points back towards the mass. Both parts are exact here.
assert amplitude_m_s2[0, 0] == complex(0.0, -G_SI)
assert abs(amplitude_m_s2[0, 0]) == G_SI
# Attaching a time factor and taking the real part is what produces a physical
# acceleration. This snippet uses exp(-i omega t); a caller whose amplitudes
# came out of a forward FFT with the opposite sign convention must use
# exp(+i omega t) instead, and gragra cannot tell the difference.
angular_frequency_rad_s = 2.0 * np.pi # one cycle per second
times_s = np.array([0.0, 0.25, 0.5, 0.75])
real_signal_m_s2 = np.real(
amplitude_m_s2[0, 0] * np.exp(-1j * angular_frequency_rad_s * times_s)
)
# At t = 0 the real part starts at zero. That target value is zero, so the
# residual is bounded relative to the amplitude rather than compared to zero
# with a bare tolerance.
assert abs(real_signal_m_s2[0]) < 1e-15 * G_SI
# A quarter cycle later it reaches its negative extreme.
assert np.isclose(real_signal_m_s2[1], -G_SI, rtol=1e-12, atol=0.0)
# Half a cycle after that, the positive one.
assert np.isclose(real_signal_m_s2[3], +G_SI, rtol=1e-12, atol=0.0)
# A real-valued source needs no such reconstruction: the result is already the
# field, and its dtype says so.
static = WeightedPointSource(positions_m=[[0.0, 0.0, 0.0]], weights_kg=[1.0])
assert point_acceleration(static, [[1.0, 0.0, 0.0]]).dtype == np.float64
B. Second-order cross statistics¶
Which functions return one¶
directional_cross_average, directional_outer_cross_average,
ensemble_outer_cross_average, coherent_gravitoelastic_tensor,
coherent_acceleration_csd — these consume amplitudes and produce a
second-order (cross-spectral) quantity, not an amplitude itself.
coherent_acceleration_csd is a weighted raw second-order sum and does not
automatically have CSD density semantics. A CSD descriptor denotes a one-sided
density under its stated units and conversion conditions.
How to interpret it¶
Complex outputs are second-order cross statistics (cross-spectral quantities such as ⟨A·B*⟩), not time-domain fields; the phase encodes the relative propagation delay or coherence between the two inputs, not an absolute field phase.
See Coherent responses and cross statistics for the
conjugation convention (element-wise, second argument conjugated), the
G-order distinction (coherent_gravitoelastic_tensor is G¹,
coherent_acceleration_csd is G²), and why mixed-sign weights make a
negative cross(A, A, w) a legitimate, non-buggy result.
Telling the two apart¶
If a function's docstring carries the order-A disclaimer text verbatim, its
output is a linear amplitude — attach a time factor and take the real part
to get something physical. If it carries the order-B text, its output is
already a cross-spectral quantity — the phase itself is the answer (a delay
or coherence), and there is no time factor to attach. plane_wave_bulk_mass_weights
is order A (it returns a source weight, one input amplitude in) even though
its name resembles the order-B functions; do not infer order from the name
alone.