gwsignal using incompatible np.trim_zeros in time_array_condition_stage1
Description of problem
For context, I was trying to implement a new time-domain waveform natively in python
using the new waveform interface (kudos to the gwsignal
development team!). Since almost all of our parameter estimation analyses are done in frequency domain, a FFT is needed and I was delighted to see that gwsignal
has a built-in conditioning going from time domain to frequency domain.
As far as I understand, I am supposed to implement a generate_td_waveform
(e.g., here) which returns a tuple of gwpy
TimeSeries for the plus and cross polarization, respectively.
If this is indeed the case, then I think in the time_array_condition_stage1
uses an incompatible numpy function, namely np.trim_zeros
. This routine compares the content in the array with 0.
using something like if i != 0.
, which gwpy
will be very unhappy about. For example, see screenshot below
Expected behavior
There should not be an error message
Steps to reproduce
Simply try to generate a waveform with conditioning by gwsignal
turned on.
Suggested solutions
A simple fix would be to pass a numpy
array to np.trim_zeros
and then reconstruct the appropriate gwpy
TimeSeries back. There might be a more elegant solution within gwpy
(could not find one after browsing through the documentation), but here is my fix:
def time_array_condition_stage1(hp, hc, dt, t_extra, fmin):
"""
Stage 1 of time-series conditioning - add taper and high-pass the time-series
Parameters
----------
hp : `TimeSeries`
GwPy TimeSeries object
hc : `TimeSeries`
GwPy TimeSeries object
dt : `float`
Sampling value of time series
t_extra : `float`
Initial extra time for conditioning
fmin : `float`
Minimum frequency for high-pass
"""
# Following XLALSimInspiralTDConditionStage1
# Generate the cos taper
Ntaper = np.round(t_extra/dt)
taper_array = np.arange(Ntaper)
w = 0.5 - 0.5*np.cos(taper_array*np.pi/Ntaper)
w_ones = np.ones(len(hp))
w_ones[:int(Ntaper)] *= w
hp *= w_ones
hc *= w_ones
# High pass filter the waveform.
hp = high_pass_time_series(hp, dt, fmin, 0.99, 8.)
hc = high_pass_time_series(hc, dt, fmin, 0.99, 8.)
# Remove trailing zeroes from array
# FIXME np.trim_zeros does not work on gwpy timeseries
hp = TimeSeries(
np.trim_zeros(hp.value, trim='b'),
unit=hp.unit,
t0=hp.t0,
dt=hp.dt,
name=hp.name,
channel=hp.channel
)
hc = TimeSeries(
np.trim_zeros(hc.value, trim='b'),
unit=hc.unit,
t0=hc.t0,
dt=hc.dt,
name=hc.name,
channel=hc.channel
)
return hp, hc
I can confirm that this fixes my problem.