pycwb.modules.reconstruction package¶
Submodules¶
pycwb.modules.reconstruction.getINJwaveform module¶
- pycwb.modules.reconstruction.getINJwaveform.estimate_central_frequency(tf_map, t_start, t_stop)[source]¶
- pycwb.modules.reconstruction.getINJwaveform.estimate_snr(h1, h2=None)[source]¶
calculate power snr of the given waveform
- pycwb.modules.reconstruction.getINJwaveform.estimate_waveform(h)[source]¶
estimate windowed waveform that contains 99.9% of the entire energy threshold
- pycwb.modules.reconstruction.getINJwaveform.get_INJ_waveform(hot, tf_map, gps_time, window, offset, in_rate) list[source]¶
get INJ waveforms and calculate injection statistics
estimate central time based on energy distribution (central time)
estimate injected waveforms
apply window in time domain to contain 99.9% of the total energy
apply frequency cut for search frequency band
calculate injection statistics (e.g., injected SNR, duration, central frequency, bandwidth, injected hrss)
- Parameters:
hot (list of pycwb.types.time_series.TimeSeries) – list of pycwb.types.time_series.TimeSeries objects
tf_map (list of pycwb.types.wdm.WDM) – list of WDM objects
gps_times (float) – Injection GPS time in seconds.
window (half of the time window to contain the waveform) – float
offset (#)
waveforms (# type of)
'strain' (the value can be 'signal' or)
in_rate (float) – sample rate of the original input data
- Returns:
output – list of dictionaries containing injection statistics and waveforms
- Return type:
list of dict
pycwb.modules.reconstruction.getMRAwaveform module¶
MRA waveform reconstruction with optional Numba JIT acceleration.
When numba is available, the per-pixel base-wave computation and accumulation loop runs entirely inside @njit-compiled code. When rocket-fft is also installed, the time-of-flight phase-shift correction is JIT-compiled too.
- pycwb.modules.reconstruction.getMRAwaveform.get_MRA_wave(cluster, wdmList, rate, ifo, a_type, mode, nproc, whiten=False, _pixel_arrays=None, _wdm_njit_data=None) TimeSeries | None[source]¶
Get MRA waveforms of type a_type in time domain given lag number and cluster ID.
- Parameters:
cluster (pycwb.types.network_cluster.Cluster) – cluster object
wdmList (list of _PyWDMKernel) – list of WDM kernel objects
rate (float) – sampling rate
ifo (int) – IFO id
a_type (str) – type of waveforms, ‘signal’ or ‘strain’
mode (int) – -1/0/1 - return 90/mra/0 phase
nproc (int) – number of processes (unused, kept for API compat)
whiten (bool) – if True, reconstruct whitened waveforms
_pixel_arrays (tuple or None) – pre-extracted SOA pixel arrays (internal, for reuse across IFOs)
_wdm_njit_data (tuple or None) – pre-built (wdm_keys, wdm_max_layers, wdm_filters) for njit kernel
- Returns:
waveform – reconstructed waveform
- Return type:
- pycwb.modules.reconstruction.getMRAwaveform.get_base_wave(max_layer: int, wdm_filter: ndarray, tf_index: int, quad: bool) tuple[int, ndarray][source]¶
Compute base wavelet vector for a single pixel.
- pycwb.modules.reconstruction.getMRAwaveform.get_network_MRA_wave(config, cluster, rate, nIFO, rTDF, a_type, mode, tof, whiten=False, in_rate=None, start_time=None)[source]¶
Get MRA waveforms of type a_type in time domain given lag number and cluster ID.
- Parameters:
config (pycwb.config.Config) – configuration object
cluster (pycwb.types.network_cluster.Cluster) – cluster object
rate (float) – sampling rate
nIFO (int) – number of IFOs
rTDF (float) – effective time-delay
a_type (str) – type of waveforms, ‘signal’ or ‘strain’
mode (int) – -1/0/1 - return 90/mra/0 phase
tof (bool) – if True, apply time-of-flight corrections
whiten (bool) – if True, reconstruct whitened waveforms
in_rate (float, optional) – input rate of the original data, used for rescaling the waveforms.
start_time (float, optional) – if set, shift waveform start times by this value.
- Returns:
waveforms – reconstructed waveforms
- Return type:
pycwb.modules.reconstruction.getResiduals module¶
- pycwb.modules.reconstruction.getResiduals.get_ASD(residuals, method='Fast', m=1500)[source]¶
Calculate the one-sided amplitude spectral density (ASD) of the residuals.
pycwb.modules.reconstruction.injection_timing module¶
Reference injection-arrival metadata (cWB injection::fill_in convention).
- pycwb.modules.reconstruction.injection_timing.cwb_arrival_times(centroids, snr_squared, injection, ifos, config)[source]¶
Use configured geometry, retaining measured times for skyless strains.
Already projected detector-strain generators need not supply a source sky position. Their measured detector centroids remain the arrival metadata; no geometric network reference can be inferred in that case.
- pycwb.modules.reconstruction.injection_timing.network_reference_times(centroids, snr_squared, delays)[source]¶
Anchor detector arrivals on cWB’s SNR^4-weighted network centroid.
detector::ISNR stores energy (SNR squared); injection::fill_in squares ISNR again. Geometrical offsets are relative to the first detector. Work in relative GPS time to avoid loss of precision in weighted sums.
pycwb.modules.reconstruction.waveform_report module¶
- pycwb.modules.reconstruction.waveform_report.generate_reconstruction_report(wave_file: str, ifo: str, output_folder: str, whitened: bool = False, confidence_level: float = 0.95, **kwargs) None[source]¶
Generate aggregate waveform reconstruction plots and result arrays.
Reads event waveforms from the consolidated wave.h5 file written by
add_wf_to_wave.
pycwb.modules.reconstruction.waveform_report_io module¶
- pycwb.modules.reconstruction.waveform_report_io.create_save_directories(analysis_directory)[source]¶
Create the waveform report output directories.
- pycwb.modules.reconstruction.waveform_report_io.load_one_waveform_OLD(args)[source]¶
Load a single waveform from the specified folder and subfolder.
Returns a Waveform object or None if loading fails.
- pycwb.modules.reconstruction.waveform_report_io.load_wf_from_wave(wave_file: str, ifo: str, keys: list[str]) dict[str, list][source]¶
Load IFO waveforms from a consolidated wave HDF5 file.
This is the paired reader for
add_wf_to_wavein the workflow subflow.
- pycwb.modules.reconstruction.waveform_report_io.pad_waveforms(waveform, reference)[source]¶
Pad two waveforms with zeros so they share the same start and end times.
Returns both padded waveforms.
- pycwb.modules.reconstruction.waveform_report_io.save(figure, results_dictionary, directory, filename, extension='pdf')[source]¶
Save a waveform report figure and its numerical results.
- pycwb.modules.reconstruction.waveform_report_io.slice_waveforms(waveform, reference, early_start=0)[source]¶
Slice a waveform pair to the reference waveform’s active time range.
Returns the sliced waveform and reference waveform.
pycwb.modules.reconstruction.waveform_report_metrics module¶
- pycwb.modules.reconstruction.waveform_report_metrics.BCa_confidence_intervals(waveforms, reference_waveform, confidence_level=0.95)[source]¶
Compute bias-corrected and accelerated confidence intervals.
- pycwb.modules.reconstruction.waveform_report_metrics.compute_confidence_intervals(waveforms, confidence_level=0.95, method='percentiles', reference_waveform=None)[source]¶
Compute confidence intervals for a collection of waveforms.
- pycwb.modules.reconstruction.waveform_report_metrics.compute_cumulative_hrss(waveform, delta_t, axis=1)[source]¶
Compute cumulative hrss of a waveform.
- pycwb.modules.reconstruction.waveform_report_metrics.compute_fitting_factor(ifos: Sequence[str], injected: Mapping[str, object], reconstructed: Mapping[str, object], start: float | None = None, end: float | None = None, *, missing: Literal['raise', 'zero'] = 'raise') float[source]¶
Compute the network fitting factor for already-whitened waveforms.
Both inputs must be whitened using the same detector-specific noise PSD and whitening normalization for each IFO, with consistent normalization across the network. This function does not whiten raw strain. The plain dot products below represent a noise-weighted match only for such whitened inputs. In pycWB, use
whitened_injected_waveformand reconstruct withwhiten=True.The normalization is the same as
CWB::mdc::GetMatchFactor("ff", ...); the window and missing-coverage policies below are explicit extensions:\[\mathrm{FF} = \frac{\sum_{I,t} r_{I,t}s_{I,t}} {\sqrt{\left(\sum_{I,t}r_{I,t}^2\right) \left(\sum_{I,t}s_{I,t}^2\right)}}.\]Each input series is converted with
TimeSeries.from_input()before the calculation. Therefore, inputs must be a pycWB, PyCBC-compatible, or GWPy-compatible time series. The series may have different start times or lengths, extending cWB’s equal-start/equal-length interface. All series must have identical sampling intervals. Paired samples must lie on the same grid; no interpolation or time/phase maximization is performed.Bounds and epoch offsets within propagated floating-point roundoff of an integer sample are treated as that sample. Genuine fractional-sample offsets are rejected, as are timestamps too imprecise to resolve the sample grid.
- Parameters:
ifos – IFO names and the order in which they are checked. The result is a network FF, not an average of per-IFO FFs.
injected – Mapping from IFO name to the whitened injected (reference) time series.
reconstructed – Mapping from IFO name to the whitened reconstructed time series.
start – Optional common time bounds in seconds, in the same frame as each series’
t0. Samples follow cWB’s conventionstart < t <= end. Omitted bounds include all stored samples in each IFO’s union of injection and reconstruction support, including the first sample. Explicit bounds restrict this union; they do not discard unmatched samples within the selected window.end – Optional common time bounds in seconds, in the same frame as each series’
t0. Samples follow cWB’s conventionstart < t <= end. Omitted bounds include all stored samples in each IFO’s union of injection and reconstruction support, including the first sample. Explicit bounds restrict this union; they do not discard unmatched samples within the selected window.missing –
"raise"(default) requires both waveforms to cover the selected window for each IFO."zero"treats samples outside stored support as zero, retaining unmatched energy in the normalization. Use it only for known-zero support, never to hide unknown or truncated data.
- Returns:
Signed network fitting factor.
- Return type:
float
- Raises:
ValueError – If inputs are incomplete, sampling grids are incompatible, the selected interval contains no samples, coverage is incomplete under
missing="raise", or either network norm is zero.- Warns:
UserWarning – If a selected nonzero waveform has peak absolute amplitude below
1e-12. This heuristic flags possible raw-strain inputs, twelve orders below unit noise amplitude in cWB’s whitening convention. Amplitude alone cannot verify whitening; exceptionally weak whitened signals can also trigger it. No amplitude correction is applied.
Notes
Whitened signals need not have unit RMS or equal amplitudes. FF is invariant under independent positive overall scaling of either network waveform and therefore cannot measure absolute amplitude recovery. Relative detector amplitudes still contribute to the network match. Internally, each network is divided by its own maximum absolute selected amplitude before taking dot products, avoiding overflow/underflow from the overall amplitude scale. No individual detector is normalized separately and inputs are not modified.
- pycwb.modules.reconstruction.waveform_report_metrics.compute_hrss(waveform, delta_t)[source]¶
Compute hrss for a waveform.
- pycwb.modules.reconstruction.waveform_report_metrics.compute_leakage(reconstructed, reference_waveform, time)[source]¶
Compute time leakage after the injected signal’s end time.
pycwb.modules.reconstruction.waveform_report_plots module¶
- pycwb.modules.reconstruction.waveform_report_plots.plot_auto_overlap(reconstructed, injected)[source]¶
Plot paired reconstructed/injected overlap.
- pycwb.modules.reconstruction.waveform_report_plots.plot_frequency_bias(reconstructed, reference, confidence_level=0.95, **kwargs)[source]¶
Plot the frequency-domain bias of the waveform reconstruction.
- pycwb.modules.reconstruction.waveform_report_plots.plot_frequency_cumulative_hrss(reconstructed, reference, injected=None, confidence_level=0.95, plot_median=True, **kwargs)[source]¶
Plot the cumulative HRSS distribution in the frequency domain.
- pycwb.modules.reconstruction.waveform_report_plots.plot_frequency_waveform_reconstruction(reconstructed, reference=None, injected=None, confidence_level=0.95, **kwargs)[source]¶
Plot frequency-domain waveform reconstruction with confidence intervals.
- pycwb.modules.reconstruction.waveform_report_plots.plot_hrss(reconstructed, injected)[source]¶
Plot HRSS of reconstructed waveforms compared to the injected waveform.
- pycwb.modules.reconstruction.waveform_report_plots.plot_leakage(reconstructed, injected)[source]¶
Plot leakage of reconstructed waveforms after the injected waveform.
- pycwb.modules.reconstruction.waveform_report_plots.plot_overlap(reconstructed, reference, **kwargs)[source]¶
Plot overlap between reconstructed waveforms and one injected waveform.
- pycwb.modules.reconstruction.waveform_report_plots.plot_time_bias(reconstructed, reference, confidence_level=0.95, **kwargs)[source]¶
Plot the time-domain bias of the waveform reconstruction.
Module contents¶
pycwb.modules.reconstruction — Waveform reconstruction from pixel data.
Reconstructs GW waveforms from coherent pixel sums using multi-resolution analysis (MRA). Computes injected waveform statistics, residuals, matched-filter SNR, and amplitude spectral densities (ASD).