pycwb.modules.likelihoodWP package¶
Submodules¶
pycwb.modules.likelihoodWP.callbacks module¶
Callable contracts for optional replacements within this scientific module.
These describe individual operations, not a required workflow or stage order. Prepared inputs are shared read-only; cluster mutations stay job-owned.
- class pycwb.modules.likelihoodWP.callbacks.ChirpUpdater(*args, **kwargs)[source]¶
Bases:
ProtocolMutate only cluster chirp metadata, retaining native resets and fallbacks.
pycwb.modules.likelihoodWP.chirp_bootstrap module¶
Shared native-order host sampling and finalization for CPU and CUDA chirp scoring.
- pycwb.modules.likelihoodWP.chirp_bootstrap.PICKS_PER_TRIAL = 6¶
Micropixels drawn per trial by the release algorithm.
- pycwb.modules.likelihoodWP.chirp_bootstrap.TRIALS = 1000¶
Number of bootstrap trials; fixed by the release algorithm.
- pycwb.modules.likelihoodWP.chirp_bootstrap.finish_bootstrap(x: ndarray, f: ndarray, weights: ndarray, mindt: float, slope: float, merger: float, selected: int, ellipticity: float, symmetry: float, cursor: int) tuple[ndarray, int][source]¶
Compute the native chirp metadata for the winning trial.
- Parameters:
x (numpy.ndarray) – Float64 micropixel times, frequencies and sampling weights.
f (numpy.ndarray) – Float64 micropixel times, frequencies and sampling weights.
weights (numpy.ndarray) – Float64 micropixel times, frequencies and sampling weights.
mindt (float) – Minimum time resolution used for the energy-fraction window.
slope (float) – Winning trial’s chirp slope and merger time.
merger (float) – Winning trial’s chirp slope and merger time.
selected (int) – Number of micropixels the winning trial classified as on-track.
ellipticity (float) – Metadata computed earlier for the winning trial.
symmetry (float) – Metadata computed earlier for the winning trial.
cursor (int) – Number of uniforms consumed, returned unchanged.
- Returns:
([mass, merger, ellipticity, energy_fraction, symmetry], cursor); five zeros when fewer than four micropixels were selected.- Return type:
tuple[numpy.ndarray, int]
- pycwb.modules.likelihoodWP.chirp_bootstrap.prepare_bootstrap(x: ndarray, f: ndarray, energy: ndarray, mindt: float, uniforms: ndarray) tuple[ndarray, ndarray, ndarray, ndarray, ndarray, float, int, bool][source]¶
Preserve native sampling order; emit independent trial slopes and times.
- Parameters:
x (numpy.ndarray) – Float64 micropixel times, frequencies and energies, equal length
n.f (numpy.ndarray) – Float64 micropixel times, frequencies and energies, equal length
n.energy (numpy.ndarray) – Float64 micropixel times, frequencies and energies, equal length
n.mindt (float) – Minimum time resolution; unused here, kept for signature symmetry with the native bootstrap.
uniforms (numpy.ndarray) – Float64 uniform stream consumed sequentially in native order.
- Returns:
(y, weights, slopes, mergers, valid, ellipticity, cursor, ready):yandweightsare float64 arrays of lengthn;slopesandmergersare float64 arrays of lengthTRIALS;validis a boolean array of lengthTRIALSmarking trials with a well-defined fit;cursoris the number of uniforms consumed andreadyisFalsewhen the stream ran out before all trials were sampled (the caller then returns NaN and retries with a longer stream).- Return type:
tuple
pycwb.modules.likelihoodWP.chirp_hough module¶
Hough-track chirp fitting and cluster chirp-statistic updates.
This is the netcluster::mchirp path. The distinct micropixel estimator lives in chirp_micropixel.py. Both consume likelihood-populated cluster pixels.
- pycwb.modules.likelihoodWP.chirp_hough.update_chirp_mass_statistics(cluster: Cluster, xgb_rho_mode: bool = False, pat0: bool = False, *, seed: int = 1)[source]¶
Python implementation of C++ netcluster::mchirp().
Runs Hough selection, the release errors-in-both-axes line fit and a seeded half-sample bootstrap. Populates the original 2G mass, uncertainty, merger time and morphology fields in cluster metadata. Pixels must have likelihoods set by populate_detection_statistics. Updates net_rho2 with rho1 = rho0 * chirpEllip * sqrt(chirpEfrac), matching netevent.cc line 977:
rho[1] = pcd->netRHO * chirp[3] * sqrt(chirp[5]) (pat0=false branch)XGB mode uses a different estimator and leaves its metadata untouched. In pat0 mode, chirp fields are populated but the pre-existing net_rho2 is preserved (mirrors netevent.cc lines 974-981). The default tmerger cut in cWB is 1e20, so this path does not remove any pixels.
pycwb.modules.likelihoodWP.chirp_micropixel module¶
Array implementation of the cWB 6.4.6.9 CBC micropixel chirp estimator.
The histogram is local to one accepted event; no pixels are removed from the cluster. Bootstrap randomness is an explicit input so CPU and future device implementations can share the same trial sequence.
- class pycwb.modules.likelihoodWP.chirp_micropixel.ChirpResult(mass: float = 0.0, mass_error: float = 0.0, merger_time: float = 0.0, merger_time_error: float = 0.0, ellipticity: float = 0.0, energy_fraction: float = 0.0, symmetry: float = 0.0)[source]¶
Bases:
objectStore release chirp outputs after float32 narrowing.
Mass is in solar masses; merger time uses the pixel time origin in seconds. Inactive fits use zero values. The estimator uses -1 for unavailable mass and merger-time errors where required by the release convention.
- ellipticity: float = 0.0¶
- energy_fraction: float = 0.0¶
- mass: float = 0.0¶
- mass_error: float = 0.0¶
- merger_time: float = 0.0¶
- merger_time_error: float = 0.0¶
- symmetry: float = 0.0¶
- pycwb.modules.likelihoodWP.chirp_micropixel.build_micropixels(pixels, analysis_rate)[source]¶
Return ordered occupied TH2F-equivalent cells and minimum time step.
Use only the occupied frequency extent, retaining ROOT’s underflow row and excluding its overflow row. Each overlapping contribution is rounded to float32 in original pixel order, as in TH2F::SetBinContent.
- Parameters:
pixels (PixelArrays) – Core flags, pixel coordinates, rates, layers and likelihood weights.
analysis_rate (float) – Analysis sampling rate in Hz.
- Returns:
cells (numpy.ndarray) – Occupied (time in seconds, frequency in Hz, likelihood) rows.
minimum_step (float) – Smallest histogram time step in seconds.
- pycwb.modules.likelihoodWP.chirp_micropixel.estimate_chirp(pixels: PixelArrays, analysis_rate: float, seed: int, *, bootstrap: Callable[[ndarray, ndarray, ndarray, float, ndarray], tuple[ndarray, int]] | None = None) ChirpResult[source]¶
Estimate release micropixel chirp morphology with a reproducible bootstrap.
- Parameters:
pixels (PixelArrays) – Accepted cluster pixels; the histogram selects core pixels.
analysis_rate (float) – Analysis sampling rate in Hz.
seed (int) – Nonzero uint32 run seed for the local uniform stream.
bootstrap (callable, optional) – Process-owned trial scorer accepting an explicit uniform stream; defaults to the CPU implementation. Return metadata and the consumed stream count.
- Returns:
Narrowed release outputs, or the release sentinel values for small clusters.
- Return type:
- Raises:
ValueError – If the input seed, pixel geometry or bootstrap sampling is invalid.
Notes
Growing the random stream restarts from the same seed, preserving the prefix and reference sampling order. Do not replace this with a global RNG.
- pycwb.modules.likelihoodWP.chirp_micropixel.root_uniforms(seed, count)[source]¶
TRandom3’s one-word MT19937 uniforms for a positive explicit seed.
Seed zero means time-dependent seeding in ROOT and is intentionally unsupported here. Random state is local, including under lag concurrency.
- Parameters:
seed (int) – Nonzero uint32 seed matching the run identifier.
count (int) – Number of nonzero uniform samples to return.
- Returns:
Float64 samples in (0, 1), in release generator order.
- Return type:
pycwb.modules.likelihoodWP.detection_statistics module¶
Event reconstruction, detection cuts, and sky-localization updates.
populate_detection_statistics reconstructs detector waveforms and populates cluster/pixel event quantities. get_likelihood_rejection_reason evaluates cuts; populate_sky_localization attaches posterior probabilities and error regions. Hough chirp fitting and its cluster updates live in chirp_hough.py.
- pycwb.modules.likelihoodWP.detection_statistics.get_likelihood_rejection_reason(sky_statistics: SkyStatistics, network_energy_threshold: float, netEC_threshold: float, net_rho_threshold: float | None = None, xgb_rho_mode: bool = False) str[source]¶
Apply threshold cuts based on the sky statistics and network energy threshold.
- Parameters:
sky_statistics (SkyStatistics) – The statistics calculated for the sky location.
network_energy_threshold (float) – The threshold for network energy.
netEC_threshold (float) – The threshold for net correlation energy (
netEC).net_rho_threshold (float or None, optional) – Absolute
netRHOthreshold. In XGB mode C++ compares againstfabs(netRHO)directly.xgb_rho_mode (bool, optional) – If True, apply XGB.rho0 cuts instead of the original 2G cuts.
- Returns:
A rejection reason string if any cut fails;
Noneif the cluster passes.- Return type:
str or None
- pycwb.modules.likelihoodWP.detection_statistics.populate_detection_statistics(sky_statistics: SkyStatistics, skymap_statistics: SkyMapStatistics, cluster: Cluster, n_ifo: int, xtalk: XTalk, network_energy_threshold: float, xgb_rho_mode: bool = False, config: Config = None, cluster_xtalk: ndarray | None = None, cluster_xtalk_lookup: ndarray | None = None, wdm_list=None) None[source]¶
Fill the detection statistics into the cluster and pixels.
- Parameters:
sky_statistics (SkyStatistics) – The sky statistics object containing the calculated statistics.
skymap_statistics (SkyMapStatistics) – The skymap statistics object to be filled.
cluster (Cluster) – The cluster object containing the pixels.
n_ifo (int) – Number of interferometers.
xtalk (XTalk) – The XTalk object for cross-talk calculations.
network_energy_threshold (float) – Energy threshold for the network.
xgb_rho_mode (bool, optional) – If True, use XGB.rho0 statistics (rho0 without cc division). Default False.
config (Config) – Pipeline configuration object. Required for MRA waveform reconstruction (hrss, strain, accurate gps_time and central_freq). Raises ValueError if None.
cluster_xtalk (np.ndarray or None, optional) – Pre-computed CSR xtalk coefficient array from
xtalk.get_xtalk_pixels. When provided together withcluster_xtalk_lookup, the internalget_xtalk_pixelscall is skipped (saves ~0.4 s for N=2600).cluster_xtalk_lookup (np.ndarray or None, optional) – Pre-computed CSR lookup array (shape (N, 2)) from
xtalk.get_xtalk_pixels.wdm_list (list or None, optional) – Pre-built WDM filter-bank list from
_create_wdm_set_python(config). When provided,_create_wdm_set_pythonis not called again (saves ~1 s per cluster). Pass fromlikelihood()where it is built once.
- Returns:
Modifies
clusterandskymap_statisticsin place.- Return type:
None
pycwb.modules.likelihoodWP.dpf module¶
Dominant-polarization-frame transforms and the DPF energy regulator.
compute_dpf and compute_dpf_into return the frame and per-pixel quantities; compute_dpf_regulator returns the scalar energy regulator used by the scan.
- pycwb.modules.likelihoodWP.dpf.compute_dpf(Fp0, Fx0, noise_weights)[source]¶
Compute the dominant polarization frame (DPF)
- Parameters:
Fp0 (np.ndarray) – The Fp0 vector for the current sky location.
Fx0 (np.ndarray) – The Fx0 vector for the current sky location.
noise_weights (np.ndarray) – Normalized inverse-noise weights for the pixels, shape (NPIX, NIFO).
- Returns:
- NIfloat
Scalar network index used by the regulator.
- f: np.ndarray
The plus polarization component in the DPF.
- F: np.ndarray
The cross polarization component in the DPF.
- fp: np.ndarray
|f+|^2
- fx: np.ndarray
|fx|^2
- si: np.ndarray
The sine component of the DPF.
- co: np.ndarray
The cosine component of the DPF.
- ni: np.ndarray
The network index for each pixel.
- Return type:
tuple
- pycwb.modules.likelihoodWP.dpf.compute_dpf_into(Fp0, Fx0, noise_weights, scratch)[source]¶
Compute the dominant polarization frame into caller-owned arrays.
- Parameters:
Fp0 (np.ndarray) – The Fp0 vector for the current sky location.
Fx0 (np.ndarray) – The Fx0 vector for the current sky location.
noise_weights (np.ndarray) – Normalized inverse-noise weights for the pixels, shape (NPIX, NIFO).
scratch (tuple of numpy.ndarray) – Writable float32 buffers: (f, F, si, co, fp, fx, ni): f/F have shape (n_pix, n_ifo); the remaining arrays have shape (n_pix,). fx/ni are reset before accumulation. Every buffer is overwritten before use and must not alias any input or another scratch buffer. Returned arrays borrow these buffers and remain valid only until the next call with the same scratch tuple.
- Returns:
- NIfloat
Scalar network index used by the regulator.
- f: np.ndarray
The plus polarization component in the DPF.
- F: np.ndarray
The cross polarization component in the DPF.
- fp: np.ndarray
|f+|^2
- fx: np.ndarray
|fx|^2
- si: np.ndarray
The sine component of the DPF.
- co: np.ndarray
The cosine component of the DPF.
- ni: np.ndarray
The network index for each pixel.
- Return type:
tuple
- pycwb.modules.likelihoodWP.dpf.compute_dpf_regulator(FP, FX, noise_weights, n_sky, n_ifo, gamma_regulator, network_energy_threshold, sky_valid_indices)[source]¶
Return the sky-averaged DPF energy regulator, not frame arrays.
Antenna patterns have shape (n_sky, n_ifo); normalized inverse-noise weights have shape (n_pix, n_ifo). Only sky_valid_indices enter the average.
pycwb.modules.likelihoodWP.dpf_regulator module¶
Allocation-reduced scalar DPF calculation for the regulator pass.
- pycwb.modules.likelihoodWP.dpf_regulator.compute_dpf_index(Fp0, Fx0, noise_weights)[source]¶
Compute compute_dpf(…)[0], preserving float32 rounding/order.
The regulator discards the per-pixel output arrays. Two detector-sized work arrays suffice here; the sky scan still computes its full DPF.
- Parameters:
Fp0 (numpy.ndarray) – Float32 plus/cross antenna patterns for one direction, shape (n_ifo,).
Fx0 (numpy.ndarray) – Float32 plus/cross antenna patterns for one direction, shape (n_ifo,).
noise_weights (numpy.ndarray) – Float32 pixel noise weights, shape (n_pix, n_ifo).
- Returns:
Scalar network index, matching element zero of compute_dpf.
- Return type:
float
- pycwb.modules.likelihoodWP.dpf_regulator.compute_dpf_regulator_scalar(FP, FX, noise_weights, n_sky, n_ifo, gamma_regulator, network_energy_threshold, sky_valid_indices)[source]¶
Compute the regulator without retaining per-pixel DPF output arrays.
- Parameters:
FP (numpy.ndarray) – Antenna patterns, shape (n_sky, n_ifo); narrowed to float32.
FX (numpy.ndarray) – Antenna patterns, shape (n_sky, n_ifo); narrowed to float32.
noise_weights (numpy.ndarray) – Pixel noise weights, shape (n_pix, n_ifo); narrowed to float32.
n_sky (int) – Sky-grid and detector dimensions used to validate inputs.
n_ifo (int) – Sky-grid and detector dimensions used to validate inputs.
gamma_regulator (float) – Threshold for counting valid directions by scalar DPF index.
network_energy_threshold (float) – Multiplier applied to the final regulator.
sky_valid_indices (numpy.ndarray) – Int64 indices of sky directions to evaluate.
- Returns:
Regulator using the original float64 count reduction and offset.
- Return type:
float
pycwb.modules.likelihoodWP.likelihood module¶
Likelihood orchestration and public entry points for likelihoodWP.
Use prepare_likelihood_inputs, evaluate_cluster_likelihood, and evaluate_fragment_clusters (also exported at package level). Setup, scan kernels, selected-direction statistics, and event population live in their corresponding modules. Hough chirp updates live in chirp_hough.py; chirp_micropixel.py contains the alternative micropixel estimator.
- pycwb.modules.likelihoodWP.likelihood.evaluate_cluster_likelihood(nIFO: int, cluster: Cluster, config: Config, MRAcatalog: str | None = None, strains: list[TimeSeries] | None = None, cluster_id: int | None = None, nRMS: list[TimeFrequencyMap] | None = None, setup: dict | None = None, xtalk: XTalk | None = None, supercluster_setup: dict | None = None, chirp_seed: int = 1, *, scalar_regulator: ScalarRegulator | None = None, sky_scan: SkyScanner | None = None, chirp_update: ChirpUpdater | None = None) tuple[Cluster | None, SkyMapStatistics | None][source]¶
Evaluate the likelihood for a single cluster.
When
setupandxtalkare pre-computed (the normal multi-lag workflow), they are used directly. For one-off standalone use, passMRAcatalogandstrains(orsupercluster_setup) and they are built automatically. For multi-cluster / multi-lag processing, preferevaluate_fragment_clusters().- Parameters:
nIFO (int) – Number of interferometers.
cluster (Cluster) – Cluster with
td_ampalready set on every pixel (guaranteed bysupercluster_single_lag()).config (Config) – Analysis configuration.
MRAcatalog (str or None, optional) – Path to the MRA catalog; used to load
xtalkwhenxtalkis None.strains (list or None, optional) – Whitened strain time series; used to build
setupwhensetupis None andsupercluster_setupis also None.cluster_id (int or None, optional) – Opaque cluster identifier for logging.
nRMS (list or None, optional) – Per-IFO TF noise maps from data conditioning. When provided each pixel’s
noise_rmsis populated so that physical-unit quantities (hrss, noise) are correct.setup (dict or None, optional) – Pre-computed segment-level inputs from
prepare_likelihood_inputs(). Built automatically when None ifstrainsorsupercluster_setupis provided.xtalk (XTalk or None, optional) – Pre-loaded cross-talk catalog. Loaded from
MRAcatalogautomatically when None.supercluster_setup (dict or None, optional) – If provided and
setupis None, its sky-pattern arrays are reused to avoid duplicate computation.
- Returns:
tuple[Cluster or None, SkyMapStatistics or None] – The updated cluster and full skymap statistics, or
(None, None)if the cluster is rejected.Backend callbacks
—————–
scalar_regulator, sky_scan, chirp_update (callable, optional) – Process-owned implementations with the corresponding native signatures. None selects the native implementation. Shared prepared inputs must remain immutable; cluster/output mutation follows the native contract. These callbacks are not serialized or sent between workers. A supplied scalar regulator requires execution_profile.scalar_dpf=true.
- pycwb.modules.likelihoodWP.likelihood.evaluate_fragment_clusters(config: Config, fragment_clusters: list[FragmentCluster], strains: list[TimeSeries], MRAcatalog: str, nRMS: list[TimeFrequencyMap] | None = None, xtalk: XTalk | None = None) list[list[tuple[Cluster, SkyMapStatistics]]][source]¶
Convenience wrapper for interactive / legacy use.
Internally calls
prepare_likelihood_inputs()once and then callsevaluate_cluster_likelihood()for every surviving cluster across all lags, avoiding repeated sky-pattern computation and runtime-parameter resolution.- Parameters:
config (Config) – Analysis configuration.
fragment_clusters (list[FragmentCluster]) – One
FragmentClusterper lag — the direct output ofsupercluster_wrapper(). Clusters withcluster_status > 0are skipped automatically.strains (list) – Whitened strain time series (one per IFO); used for sky-pattern computation inside
prepare_likelihood_inputs().MRAcatalog (str) – Path to the MRA catalog (cross-talk coefficients).
nRMS (list | None) – Per-IFO TF noise maps from data conditioning. When provided, each pixel’s
noise_rmsis populated so physical-unit quantities (hrss, noise) are correct.xtalk (XTalk | None) – Pre-loaded cross-talk catalog. When None it is loaded from
MRAcatalog.
- Returns:
results[lag]is a list of(result_cluster, sky_stats)tuples for every cluster that passed the likelihood veto in that lag. Empty inner lists indicate no accepted clusters for that lag.- Return type:
list[list[tuple[Cluster, SkyMapStatistics]]]
- pycwb.modules.likelihoodWP.likelihood.likelihood(*args: Any, **kwargs: Any) Any¶
Deprecated alias for
evaluate_cluster_likelihood; removed in pycwb 1.2.0.
- pycwb.modules.likelihoodWP.likelihood.likelihood_wrapper(*args: Any, **kwargs: Any) Any¶
Deprecated alias for
evaluate_fragment_clusters; removed in pycwb 1.2.0.
- pycwb.modules.likelihoodWP.likelihood.setup_likelihood(*args: Any, **kwargs: Any) Any¶
Deprecated alias for
prepare_likelihood_inputs; removed in pycwb 1.2.0.
pycwb.modules.likelihoodWP.likelihood_setup module¶
Likelihood setup: segment-level precomputation.
Provides prepare_likelihood_inputs() which computes all job-segment-level
(lag/cluster-independent) inputs for the likelihood pipeline.
Also includes populate_pixel_noise_from_maps() for per-pixel noise
initialization.
- pycwb.modules.likelihoodWP.likelihood_setup.populate_pixel_noise_from_maps(pixels: list[Pixel], nRMS: list[TimeFrequencyMap]) None[source]¶
Populate legacy pixel objects using the shared detector-aware RMS lookup.
Detector indices select the lagged noise anchors. Mixed-resolution pixels use the same harmonic frequency-band averaging as the native SoA pipeline.
- pycwb.modules.likelihoodWP.likelihood_setup.prepare_likelihood_inputs(config: Config, strains: list[TimeSeries], nIFO: int, ml: ndarray | None = None, FP: ndarray | None = None, FX: ndarray | None = None, ml_big: ndarray | None = None, FP_big: ndarray | None = None, FX_big: ndarray | None = None, big_cluster_healpix_order: int | None = None) dict[source]¶
Pre-compute all job-segment-level inputs for likelihood evaluation.
Call this once per job segment, then pass the returned dict as
setup=to everylikelihood()call. This avoids repeating:Runtime parameter resolution from config
Sky delay / antenna pattern computation
_build_sky_directionshealpix grid constructionFP / FX transpose + float32 cast
- Parameters:
config (Config) – Analysis configuration.
strains (list[TimeSeries]) – Whitened strain data (one per IFO); used only to determine GPS time and sample rate for sky-delay computation when
ml/FP/FXare not provided.nIFO (int) – Number of interferometers.
ml (np.ndarray, optional) – Pre-computed sky-delay index array (nIFO, n_sky) from
setup_supercluster. When provided,compute_sky_delay_and_patternsis skipped entirely.FP (np.ndarray, optional) – Pre-computed f+ antenna patterns (nIFO, n_sky) from
setup_supercluster.FX (np.ndarray, optional) – Pre-computed fx antenna patterns (nIFO, n_sky) from
setup_supercluster.
- Returns:
Keys:
network_energy_threshold,gamma_regulator,delta_regulator,net_rho_threshold,netEC_threshold,netCC,ml,FP,FX,FP_t,FX_t,n_sky,healpix_order,ra_arr,dec_arr.- Return type:
dict
pycwb.modules.likelihoodWP.packet_ops module¶
Wavelet packet construction, normalization, noise, and network-plane operations.
The public names describe the operations. Original cWB symbols are recorded in the README migration table and the reference comments below for traceability.
- pycwb.modules.likelihoodWP.packet_ops.build_wavelet_packet(v00, v90, mask)[source]¶
calculates packet rotation sin/cos, amplitudes and unit vectors, initialize unit vector arrays
- Parameters:
v00 (np.ndarray) – The v00 component of the packet. v00[ifo][pixel]
v90 (np.ndarray) – The v90 component of the packet. v90[ifo][pixel]
mask (np.ndarray) – The mask indicating valid pixels. mask[pixel]
- Returns:
- Epfloat
The packet energy p[er quadrature
- v00_updatednp.ndarray
Updated v00 component of the packet after normalization and rotation.
- v90_updatednp.ndarray
Updated v90 component of the packet after normalization and rotation.
- Enp.ndarray
Energy of the packet for each interferometer.
- sinp.ndarray
Sine component of the rotation for each interferometer.
- conp.ndarray
Cosine component of the rotation for each interferometer.
- a_savenp.ndarray
Amplitude of the first component for each interferometer.
- A_savenp.ndarray
Amplitude of the second component for each interferometer.
- Return type:
tuple
- pycwb.modules.likelihoodWP.packet_ops.compute_gaussian_noise_correction(p, q, et, MK, ec, gn, rn)[source]¶
get G-noise correction
- Parameters:
p (np.ndarray) – The p component of the signal.
q (np.ndarray) – pointer to pixel norms
et (np.ndarray) – The total energy
MK (np.ndarray) – The mask indicating valid pixels.
ec (np.ndarray) – The coherent energy.
gn (np.ndarray) – The G-noise component.
rn (np.ndarray) – The residual noise.
- Returns:
NS : float
- Return type:
tuple
- pycwb.modules.likelihoodWP.packet_ops.compute_null_packet(d, D, h, H)[source]¶
Load NULL packet amplitudes for all detectors and pixels. These amplitudes are used for reconstruction of data time series.
- Parameters:
n (np.ndarray) – The n component of the signal.
N (np.ndarray) – The N component of the signal.
d (np.ndarray) – The d component of the signal.
D (np.ndarray) – The D component of the signal.
h (np.ndarray) – The h component of the signal.
H (np.ndarray) – The H component of the signal.
- Return type:
None
- pycwb.modules.likelihoodWP.packet_ops.compute_packet_norms(p, q, xtalks, xtalks_lookup, mk, q_E)[source]¶
Compute packet norms with cWB 6.4.6.9 float32 arithmetic.
Accumulation and reduction order follow network::_avx_norm_ps(I>0). Float64 promotion changes the ratio >= 1 decision for near-unit pixels, which can change waveform amplitudes and event acceptance. Keep explicit float32 rounding and do not enable fastmath/reassociation. Inputs are not modified; all four output arrays use float32.
- Parameters:
p (np.ndarray) – The p component of the packet. p[ifo][pixel]
q (np.ndarray) – The q component of the packet. q[ifo][pixel]
xtalks (np.ndarray) – The cross-talk matrix. xtalks[pixel]
xtalks_lookup (np.ndarray) – Lookup table for cross-talk ranges. xtalks_lookup[pixel]
mk (np.ndarray) – Mask indicating valid pixels. mk[pixel]
q_E (np.ndarray) – Packet energy for the q component. q_E[ifo]
- Returns:
- detector_snrnp.ndarray
The detector SNR for each interferometer.
- normnp.ndarray
The norm of the packet for each interferometer. Was II + 5 in cWB
- rnnp.ndarray
Halo noise
- q_normnp.ndarray
The 90 degree component norms for each interferometer. Was I + i in cWB
- Return type:
tuple
- pycwb.modules.likelihoodWP.packet_ops.compute_signal_norms(q_norm, q_E, p_E, ec)[source]¶
set signal norms, return signal SNR
- Parameters:
data_norm (np.ndarray) – The normalized data for each interferometer. data_norm[ifo][pixel]
q_norm (np.ndarray) – The 90 degree component norms for each interferometer. q_norm[ifo][pixel]
p_E (np.ndarray) – The energy threshold for the p component. p_E[ifo], was p[II+4]**2 / 2 in cWB
ec (np.ndarray) – The energy component for each interferometer. ec[ifo][pixel]
- Returns:
- total_normfloat
The total SNR
- normnp.ndarray
The detector SNR for each interferometer.
- p_norm_II5np.ndarray
Was II5 in cWB
- p_normnp.ndarray
The 00 degree component norms for each interferometer.
- Return type:
tuple
- pycwb.modules.likelihoodWP.packet_ops.normalize_packet_amplitudes(p, q, q_norm, q_si, q_co, q_a, q_A, MK)[source]¶
set packet amplitudes for waveform reconstruction returns number of degrees of freedom - effective # of pixels per detector
- Parameters:
p (np.ndarray) – The p component of the signal.
q (np.ndarray) – The q component of the signal.
q_norm (np.ndarray) – Pointer to pixel norms.
q_si (np.ndarray) – The second component of the q signal. q_II2 : np.ndarray
q_co (np.ndarray) – The third component of the q signal. q_II3 : np.ndarray
q_E (np.ndarray) – The fourth component of the q signal. q_II4 : np.ndarray
MK (np.ndarray) – The mask indicating valid pixels.
- Returns:
- Nfloat
Number of effective pixels per detector.
- new_pnp.ndarray
Updated p component.
- new_qnp.ndarray
Updated q component.
- Return type:
tuple
- pycwb.modules.likelihoodWP.packet_ops.project_onto_network_plane(p, q, MK, fp, fx, f, F)[source]¶
Calculates the polar coordinates of the input vector v in the DPF frame.
- Parameters:
p (np.ndarray) – The p component of the signal.
q (np.ndarray) – The q component of the signal.
MK (np.ndarray) – Event mask array.
fp (np.ndarray) – The FP component.
fx (np.ndarray) – The FX component.
f (np.ndarray) – Array of antenna patterns for each detector.
F (np.ndarray) – Array of antenna patterns for each detector.
- Returns:
Projected/rotated phase-0 and phase-90 arrays, followed by (radius, angle_radians) pairs for the two quadratures.
- Return type:
tuple
- pycwb.modules.likelihoodWP.packet_ops.sum_xtalk_corrected_energy(p, q, xtalks, xtalks_lookup, mk)[source]¶
Compute the raw xtalk-convolved energy sum (C++ _avx_norm_ps with I<0).
Mirrors the I<0 branch of network::_avx_norm_ps: accumulates the xtalk- convolved inner products for each IFO WITHOUT the SNR-ratio computation and WITHOUT clamping to >=2. Used for Em (data energy, C++ D_snr[0]) and Np (null energy, C++ N_snr[0]) in the pixel-domain statistics.
- Parameters:
xtalks (2-D array — packed xtalk entries)
xtalks_lookup (numpy.ndarray) – Two-dimensional array of (start, end) slice indices per pixel.
mk (array-like, length n_pix — event mask (>0 → active pixel))
- Returns:
Total xtalk-convolved energy: sum over IFOs and masked pixels.
- Return type:
float
pycwb.modules.likelihoodWP.pixel_data module¶
Extract time-delay quadratures and normalized noise weights from pixels.
extract_pixel_time_delay_data uses PixelArrays when available, with a legacy Pixel-list fallback. build_sky_delay_and_antenna_patterns bridges detector geometry to the scan array layout.
- pycwb.modules.likelihoodWP.pixel_data.build_sky_delay_and_antenna_patterns(nIFO: int, strains: list[TimeSeries] | None = None, config: Config | None = None, ml: ndarray | None = None, FP: ndarray | None = None, FX: ndarray | None = None) tuple[ndarray, ndarray, ndarray][source]¶
Build sky-delay and antenna-pattern arrays for numba processing.
- Parameters:
nIFO (int) – Number of interferometers.
strains (list[TimeSeries] or None, optional) – Whitened strain time series; required when
ml/FP/FXare not provided.config (Config or None, optional) – Analysis configuration; required when
ml/FP/FXare not provided.ml (np.ndarray or None, optional) – Pre-computed sky-delay index array (nIFO, n_sky). When provided together with
FPandFX, the sky-pattern computation is skipped.FP (np.ndarray or None, optional) – Pre-computed f+ antenna patterns (nIFO, n_sky).
FX (np.ndarray or None, optional) – Pre-computed fx antenna patterns (nIFO, n_sky).
- Returns:
ml_arr (np.ndarray) – Array of time-delay indices for each sky location, shape (nIFO, n_sky).
fp_arr (np.ndarray) – f+ polarization data for each interferometer, shape (nIFO, n_sky).
fx_arr (np.ndarray) – fx polarization data for each interferometer, shape (nIFO, n_sky).
- pycwb.modules.likelihoodWP.pixel_data.extract_pixel_time_delay_data(pixels: list[Pixel], nifo: int, pixel_arrays=None) tuple[ndarray, ndarray, ndarray, ndarray][source]¶
Extract pixel time-delay quadrature arrays for numba / JAX processing.
Fast path¶
When
pixel_arrays(aPixelArrays) is provided and itstd_ampis populated, the function reads directly from the pre-computed SoA arrays — zero per-pixel Python iteration.Fallback¶
Otherwise delegates to
_extract_legacy_pixel_time_delay_data(), which extracts arrays from legacy Pixel objects.- returns:
noise_weights ((nifo, n_pix) float32) – Normalised inverse-RMS weights.
td_phase0 ((nifo, n_pix, tsize2) float32) – Time-delay samples in the 0-degree WDM phase.
td_phase90 ((nifo, n_pix, tsize2) float32) – Time-delay samples in the 90-degree WDM phase.
td_energy ((nifo, n_pix, tsize2) float32) –
td_phase0 ** 2 + td_phase90 ** 2.
pycwb.modules.likelihoodWP.pixel_selection module¶
Apply the reference likelihood TD-pixel limit without losing cluster volume.
- pycwb.modules.likelihoodWP.pixel_selection.restore_likelihood_pixels(cluster, state)[source]¶
Restore excluded non-core pixels so event volume retains its meaning.
- pycwb.modules.likelihoodWP.pixel_selection.select_likelihood_pixels(cluster, batch)[source]¶
Return a working cluster and restoration state for cWB’s BATCH limit.
cwb2G::Likelihood calls loadTDampSSE(…, BATCH, BATCH), selecting the loudest BATCH pixels before sky scanning. BATCH=0 disables this limit. Retain input order within the selected set, as monster::getXTalk does.
pycwb.modules.likelihoodWP.results module¶
Result records for one sky direction and the complete likelihood sky scan.
- class pycwb.modules.likelihoodWP.results.SkyMapStatistics(l_max: int, nAntennaPrior: ndarray, nAlignment: ndarray, nLikelihood: ndarray, nNullEnergy: ndarray, nCorrEnergy: ndarray, nCorrelation: ndarray, nSkyStat: ndarray, nDisbalance: ndarray, nNetIndex: ndarray, nEllipticity: ndarray, nPolarisation: ndarray, sky_stat_max: float = 0, nProbability: ndarray | None = None, stage_timings: dict | None = None)[source]¶
Bases:
objectStatistics over the full sky grid, with the selected direction index.
- Variables:
l_max (int) – Index of the selected sky direction (not the statistic value).
- ARRAY_DTYPES: ClassVar[dict] = {'nAlignment': <class 'numpy.float32'>, 'nAntennaPrior': <class 'numpy.float32'>, 'nCorrEnergy': <class 'numpy.float32'>, 'nCorrelation': <class 'numpy.float32'>, 'nDisbalance': <class 'numpy.float32'>, 'nEllipticity': <class 'numpy.float32'>, 'nLikelihood': <class 'numpy.float32'>, 'nNetIndex': <class 'numpy.float32'>, 'nNullEnergy': <class 'numpy.float32'>, 'nPolarisation': <class 'numpy.float32'>, 'nProbability': <class 'numpy.float64'>, 'nSkyStat': <class 'numpy.float32'>}¶
- l_max: int¶
- sky_stat_max: float = 0¶
- stage_timings: dict | None = None¶
- class pycwb.modules.likelihoodWP.results.SkyStatistics(Gn: float32, Ec: float32, Dc: float32, Rc: float32, Eh: float32, Es: float32, Np: float32, Em: float32, Lm: float32, norm: float32, cc: float32, rho: float32, xrho: float32, Lo: float32, Eo: float32, N_pix_effective: float32, energy_array_plus: ndarray, energy_array_cross: ndarray, v00: ndarray, v90: ndarray, pd: ndarray, pD: ndarray, ps: ndarray, pS: ndarray, pixel_mask: ndarray, gaussian_noise_correction: ndarray, noise_amplitude_00: ndarray, noise_amplitude_90: ndarray, coherent_energy: ndarray, p00_POL: ndarray, p90_POL: ndarray, r00_POL: ndarray, r90_POL: ndarray, S_snr: ndarray, f: ndarray, F: ndarray)[source]¶
Bases:
objectDataclass that encapsulates various sky-related statistical measurements derived from time-frequency data.
- Variables:
Gn (np.float32) – Gaussian noise correction factor.
Ec (np.float32) – Core coherent energy in the time-frequency (TF) domain.
Dc (np.float32) – Signal core coherent energy in the TF domain.
Rc (np.float32) – Normalization factor for the EC measurements.
Eh (np.float32) – Satellite energy in the TF domain.
Es (np.float32) – Sideband energy in the TF domain.
Np (np.float32) – Cross-talk-corrected null-packet energy.
Lm (np.float32) – Likelihood map value.
norm (np.float32) – Overall normalization factor.
cc (np.float32) – Cross-correlation value.
rho (np.float32) – cWB Signal-to-Noise Ratio (SNR).
xrho (np.float32) – New cWB SNR used for XGBoost analysis.
Lo (np.float32) – Likelihood offset or related parameter.
Eo (np.float32) – Energy offset or related parameter.
energy_array_plus (np.ndarray) – Energy array for plus polarization.
energy_array_cross (np.ndarray) – Energy array for cross polarization.
v00 (np.ndarray) – Time-delayed data slice at a specific sky location for polarization 00.
v90 (np.ndarray) – Time-delayed data slice at a specific sky location for polarization 90.
p00_POL (np.ndarray) – Polar angle component of the signal packet for polarization 00.
p90_POL (np.ndarray) – Polar angle component of the signal packet for polarization 90.
r00_POL (np.ndarray) – Radius component of the residual packet for polarization 00.
r90_POL (np.ndarray) – Radius component of the residual packet for polarization 90.
- Dc: float32¶
- Ec: float32¶
- Eh: float32¶
- Em: float32¶
- Eo: float32¶
- Es: float32¶
- Gn: float32¶
- Lm: float32¶
- Lo: float32¶
- N_pix_effective: float32¶
- Np: float32¶
- Rc: float32¶
- cc: float32¶
- norm: float32¶
- rho: float32¶
- xrho: float32¶
pycwb.modules.likelihoodWP.sky_delay_groups module¶
Sky scan grouped by identical detector delays; per-direction math is unchanged.
The group order is prepared once for a sky grid. Only data loads, pixel energy and the initial mask are shared within a group. DPF and every sky statistic are recomputed for each valid direction. Final tie-breaking uses the original sky_valid_indices order, independent of group traversal order.
- pycwb.modules.likelihoodWP.sky_delay_groups.delay_groups_for_grid(setup, ml, big_cluster=False, reuse_delays=True)[source]¶
Cache immutable setup geometry separately for main and coarse grids.
Per-cluster sky masks are deliberately not cached here. As with the other prepared sky geometry, callers must replace/rebuild ml rather than mutate its contents in place after preparing a setup.
- Parameters:
setup (dict) – Job-owned setup mutated to retain main and coarse delay-group caches.
ml (numpy.ndarray) – Immutable-by-contract integer delay grid, shape (n_ifo, n_sky).
big_cluster (bool, optional) – Select the separate coarse-grid cache when true.
reuse_delays (bool, optional) – Group equal delays by default; false prepares one group per direction.
- Returns:
Cached (order, offsets), reused while the grid object is unchanged.
- Return type:
tuple of numpy.ndarray
Notes
Cache invalidation tests object identity, not contents. Do not mutate the grid or cached arrays in place. Replace the grid to rebuild its groups. Sky masks remain per-cluster inputs and are never stored in this geometry cache.
- pycwb.modules.likelihoodWP.sky_delay_groups.make_delay_groups(ml, reuse_delays=True)[source]¶
Return all sky indices grouped by equal integer detector-delay tuples.
- Parameters:
ml (numpy.ndarray) – Integer detector delays, shape (n_ifo, n_sky).
reuse_delays (bool, optional) – Group equal delays by default; false prepares one group per direction.
- Returns:
order (numpy.ndarray) – Int64 permutation grouping identical detector-delay columns; ties are stable.
offsets (numpy.ndarray) – Int64 group boundaries, including zero and the final permutation length.
pycwb.modules.likelihoodWP.sky_kernels module¶
Numba kernels for coherent response, quadrature rotation, and statistics.
These are shared by the sky scan and the detailed evaluation of one direction. Allocating wrappers delegate to matching _into kernels with caller-owned buffers. Original cWB symbols: project_signal_packet (_avx_GW_ps), orthogonalize_quadratures (_avx_ort_ps), compute_coherent_statistics (_avx_stat_ps).
- pycwb.modules.likelihoodWP.sky_kernels.compute_coherent_statistics(v00, v90, s, S, si, co, mask)[source]¶
returns coherent statistics in the format {cc,ec,ed,gn}
- Parameters:
v00 (np.ndarray) – The 00 polarization component of the packet. v00[ifo][pixel]
v90 (np.ndarray) – The 90 polarization component of the packet. v90[ifo][pixel]
s (np.ndarray) – The updated 00 component of the packet. s[ifo][pixel]
S (np.ndarray) – The updated 90 component of the packet. S[ifo][pixel]
si (np.ndarray) – The sin of the rotation angle for each pixel. si[pixel]
co (np.ndarray) – The cos of the rotation angle for each pixel. co[pixel]
mask (np.ndarray) – The mask indicating active pixels. mask[pixel]
- Returns:
- corr_coefffloat
The network correlation coefficient.
- EC: float
The total coherent energy.
- NN: int
The number of pixels
- total_noise: float
The total noise
- ec: np.ndarray
The coherent energy for each pixel.
- gn: np.ndarray
The G-noise correction for each pixel.
- rn: np.ndarray
The residual noise in the TF domain for each pixel.
- Return type:
tuple
- pycwb.modules.likelihoodWP.sky_kernels.compute_coherent_statistics_into(v00, v90, s, S, si, co, mask, scratch)[source]¶
Compute coherent statistics into caller-owned per-pixel arrays.
- Parameters:
v00 (np.ndarray) – The 00 polarization component of the packet. v00[ifo][pixel]
v90 (np.ndarray) – The 90 polarization component of the packet. v90[ifo][pixel]
s (np.ndarray) – The updated 00 component of the packet. s[ifo][pixel]
S (np.ndarray) – The updated 90 component of the packet. S[ifo][pixel]
si (np.ndarray) – The sin of the rotation angle for each pixel. si[pixel]
co (np.ndarray) – The cos of the rotation angle for each pixel. co[pixel]
mask (np.ndarray) – The mask indicating active pixels. mask[pixel]
scratch (tuple of numpy.ndarray) – Writable float32 buffers: (ec, gn, rn), each with shape (n_pix,). Every buffer is overwritten before use and must not alias any input or another scratch buffer. Returned arrays borrow these buffers and remain valid only until the next call with the same scratch tuple.
- Returns:
- corr_coefffloat
The network correlation coefficient.
- EC: float
The total coherent energy.
- NN: int
The number of pixels
- total_noise: float
The total noise
- ec: np.ndarray
The coherent energy for each pixel.
- gn: np.ndarray
The G-noise correction for each pixel.
- rn: np.ndarray
The residual noise in the TF domain for each pixel.
- Return type:
tuple
- pycwb.modules.likelihoodWP.sky_kernels.compute_pixel_energy_and_mask(v00, v90, network_energy_threshold)[source]¶
Compute the total energy for each pixel and the mask based on the network energy threshold.
Parameters:¶
- v00np.ndarray
The phase-0 quadrature data for each interferometer and pixel.
- v90np.ndarray
The phase-90 quadrature data for each interferometer and pixel.
- network_energy_thresholdfloat
The threshold for the network energy to determine if a pixel is active.
Returns:¶
- tuple
- EEfloat
The total energy of the network.
- NNint
The number of active pixels.
- energy_totalnp.ndarray
The total energy for each pixel.
- masknp.ndarray
A mask indicating which pixels are active based on the network energy threshold.
- pycwb.modules.likelihoodWP.sky_kernels.orthogonalize_quadratures(v00, v90, mask)[source]¶
orthogonalize data vectors v00 and v90, calculate norms of orthogonal vectors and rotation sin & cos
- Parameters:
v00 (np.ndarray) – The 00 polarization component of the packet. v00[ifo][pixel]
v90 (np.ndarray) – The 90 polarization component of the packet. v90[ifo][pixel]
mask (np.ndarray) – The mask indicating active pixels. mask[pixel]
- Returns:
- E: float
signal energy
- si: np.ndarray
sin of the rotation angle for each pixel. si[pixel]
- co: np.ndarray
cos of the rotation angle for each pixel. co[pixel]
- ee: np.ndarray
plus component energy for each pixel. ee[pixel]
- EE: np.ndarray
cross component energy for each pixel. EE[pixel]
- Return type:
tuple
- pycwb.modules.likelihoodWP.sky_kernels.orthogonalize_quadratures_into(v00, v90, mask, scratch)[source]¶
Orthogonalize quadratures into caller-owned rotation and energy arrays.
- Parameters:
v00 (np.ndarray) – The 00 polarization component of the packet. v00[ifo][pixel]
v90 (np.ndarray) – The 90 polarization component of the packet. v90[ifo][pixel]
mask (np.ndarray) – The mask indicating active pixels. mask[pixel]
scratch (tuple of numpy.ndarray) – Writable float32 buffers: (si, co, ee, EE), each with shape (n_pix,). Every buffer is overwritten before use and must not alias any input or another scratch buffer. Returned arrays borrow these buffers and remain valid only until the next call with the same scratch tuple.
- Returns:
- E: float
signal energy
- si: np.ndarray
sin of the rotation angle for each pixel. si[pixel]
- co: np.ndarray
cos of the rotation angle for each pixel. co[pixel]
- ee: np.ndarray
plus component energy for each pixel. ee[pixel]
- EE: np.ndarray
cross component energy for each pixel. EE[pixel]
- Return type:
tuple
- pycwb.modules.likelihoodWP.sky_kernels.project_signal_packet(v00, v90, f, F, fp, fx, ni, et, mask, reg)[source]¶
GW strain packet
- Parameters:
v00 (np.ndarray) – The 00 polarization component of the packet. v00[ifo][pixel]
v90 (np.ndarray) – The 90 polarization component of the packet. v90[ifo][pixel]
f (np.ndarray) – The plus polarization component in the DPF. f[pixel][ifo]
F (np.ndarray) – The cross polarization component in the DPF. F[pixel][ifo]
fp (np.ndarray) – The plus polarization component in the DPF, normalized.
|f+|^2. fp[pixel][ifo]fx (np.ndarray) – The cross polarization component in the DPF, normalized.
|fx|^2. fx[pixel][ifo]ni (np.ndarray) – The noise index for each pixel. ni[pixel][ifo]
et (np.ndarray) – The total energy for each pixel. et[pixel][ifo]
mask (np.ndarray) – The mask indicating active pixels. mask[pixel]
reg (tuple) – The regularization parameters.
- Returns:
- NNint
The number of pixels above threshold
- p_updatednp.ndarray
The updated 00 component of the packet. p_updated[ifo][pixel]
- q_updatednp.ndarray
The updated 90 component of the packet. q_updated[ifo][pixel]
- mask_updatednp.ndarray
The updated mask for the pixels. mask_updated[pixel]
- aunp.ndarray
Amplitude component
- AUnp.ndarray
Amplitude component
- avnp.ndarray
Amplitude component
- AVnp.ndarray
Amplitude component
- Return type:
tuple
- pycwb.modules.likelihoodWP.sky_kernels.project_signal_packet_into(v00, v90, f, F, fp, fx, ni, et, mask, reg, scratch)[source]¶
Project a GW strain packet into caller-owned arrays.
- Parameters:
v00 (np.ndarray) – The 00 polarization component of the packet. v00[ifo][pixel]
v90 (np.ndarray) – The 90 polarization component of the packet. v90[ifo][pixel]
f (np.ndarray) – The plus polarization component in the DPF. f[pixel][ifo]
F (np.ndarray) – The cross polarization component in the DPF. F[pixel][ifo]
fp (np.ndarray) – The plus polarization component in the DPF, normalized.
|f+|^2. fp[pixel][ifo]fx (np.ndarray) – The cross polarization component in the DPF, normalized.
|fx|^2. fx[pixel][ifo]ni (np.ndarray) – The noise index for each pixel, shape (n_pix,).
et (np.ndarray) – The total energy for each pixel, shape (n_pix,).
mask (np.ndarray) – The mask indicating active pixels. mask[pixel]
reg (tuple) – The regularization parameters.
scratch (tuple of numpy.ndarray) – Writable float32 buffers: (au, AU, av, AV, mask_updated, p_updated, q_updated): the first five arrays have shape (n_pix,); the final two have shape (n_ifo, n_pix). Every buffer is overwritten before use and must not alias any input or another scratch buffer. Returned arrays borrow these buffers and remain valid only until the next call with the same scratch tuple.
- Returns:
- NNint
The number of pixels above threshold
- p_updatednp.ndarray
The updated 00 component of the packet. p_updated[ifo][pixel]
- q_updatednp.ndarray
The updated 90 component of the packet. q_updated[ifo][pixel]
- mask_updatednp.ndarray
The updated mask for the pixels. mask_updated[pixel]
- aunp.ndarray
Amplitude component
- AUnp.ndarray
Amplitude component
- avnp.ndarray
Amplitude component
- AVnp.ndarray
Amplitude component
- Return type:
tuple
pycwb.modules.likelihoodWP.sky_localization module¶
Background HEALPix localization using the cWB 2G probability prescription.
The detection sky maximizes the correlation statistic. Localization additionally uses the final waveform normalization, noise scale and optional antenna prior. No ROOT objects or global network state are needed here.
- class pycwb.modules.likelihoodWP.sky_localization.SkyLocalization(probability: ndarray, indices: ndarray, selected_probability: ndarray, error_regions: ndarray)[source]¶
Bases:
objectStore the full posterior, selected sky indices/probabilities and area deciles.
- pycwb.modules.likelihoodWP.sky_localization.localize_sky(statistic, antenna_prior, posterior_scale, *, use_prior=False, n_sky=0)[source]¶
Return posterior and cWB’s sqrt(area) deciles for a full HEALPix grid.
Nonpositive sky statistics carry zero probability. Invalid scales/maps and grids below the release’s minimum size return None rather than fabricated zero uncertainties. Regions 0 and 10 require an injection/target location; they remain zero for ordinary background events, as in the reference.
- Parameters:
statistic (array-like) – Aligned one-dimensional sky-statistic and antenna-sensitivity maps.
antenna_prior (array-like) – Aligned one-dimensional sky-statistic and antenna-sensitivity maps.
posterior_scale (float) – Posterior scale; its absolute value is used.
use_prior (bool, optional) – Multiply probabilities by the normalized fourth-power antenna prior.
n_sky (int, optional) – Release output selection control: positive values cap the pixel count, zero uses the release default, and negative values encode a probability cut.
- Returns:
Posterior and square-root area deciles in degrees, or None for invalid maps.
- Return type:
SkyLocalization or None
pycwb.modules.likelihoodWP.sky_mask module¶
Sky masks for the Earth-fixed native likelihood grid.
- pycwb.modules.likelihoodWP.sky_mask.compute_sky_valid_indices(phi_geo_arr, latitude_arr, sky_mask_config, t_ref=None)[source]¶
Return valid Earth-fixed sky-grid indices for a configured mask.
Parameters are radians.
phi_geo_arris cWB Earth-fixed longitude andlatitude_arris geographic latitude (numerically equal to declination, but not an ICRS coordinate until longitude is rotated at a GPS epoch).The ICRS transformation matches
cwb-core/skymap.hhand the celestial mask loop incwb-core/network.cc:RA = phi_geo + GMST(trigger_time).
pycwb.modules.likelihoodWP.sky_order module¶
Index sorting with the release wavearray::waveSort tie convention.
Posterior ties can represent widely separated sky directions. Matching only sorted values is insufficient: the release’s pointer permutation determines which tied direction is exported as the reconstructed location.
- pycwb.modules.likelihoodWP.sky_order.wave_sort_indices(values, initial_order=None)[source]¶
Return ascending indices, preserving cWB’s nonstable tie behavior.
The posterior’s second sort starts from the first statistic sort’s permutation, rather than restarting from sky-index order.
- Parameters:
values (array-like) – One-dimensional sky values to order.
initial_order (array-like or None, optional) – Starting permutation. Copied before sorting; the caller’s array is unchanged.
- Returns:
Int64 indices in the release sort order, including its nonstable ties.
- Return type:
pycwb.modules.likelihoodWP.sky_scan module¶
Grouped-delay sky scan with scratch arrays reused within each group.
This is the single numerical scan kernel, also used for singleton groups. No buffer escapes the group; returned sky maps own their storage.
- pycwb.modules.likelihoodWP.sky_scan.scan_sky(geometry, cluster, settings, *, reuse_delays=True, setup=None, big_cluster=False)[source]¶
Scan prepared geometry and cluster data using one compiled kernel.
geometry is (FP, FX, ml); cluster is (rms, td00, td90); settings is (REG, netCC, delta_regulator, network_energy_threshold, sky_valid_indices). Arrays retain the shapes/dtypes of scan_sky_kernel. When supplied, setup owns the immutable geometry cache. False reuse_delays uses singleton groups.
- pycwb.modules.likelihoodWP.sky_scan.scan_sky_kernel(n_ifo, n_pix, n_sky, FP, FX, rms, td00, td90, ml, REG, netCC, delta_regulator, network_energy_threshold, sky_valid_indices, group_order, group_offsets)[source]¶
Compute direction statistics while reusing equal-delay input data.
- Parameters:
n_ifo (int) – Detector, cluster-pixel and sky-grid sizes.
n_pix (int) – Detector, cluster-pixel and sky-grid sizes.
n_sky (int) – Detector, cluster-pixel and sky-grid sizes.
FP (numpy.ndarray) – Float32 plus/cross antenna patterns, shape (n_sky, n_ifo).
FX (numpy.ndarray) – Float32 plus/cross antenna patterns, shape (n_sky, n_ifo).
rms (numpy.ndarray) – Float32 pixel noise weights, shape (n_pix, n_ifo).
td00 (numpy.ndarray) – Float32 delayed quadratures, shape (n_delay, n_ifo, n_pix).
td90 (numpy.ndarray) – Float32 delayed quadratures, shape (n_delay, n_ifo, n_pix).
ml (numpy.ndarray) – Integer delay offsets, shape (n_ifo, n_sky); zero addresses n_delay // 2.
REG (numpy.ndarray) – Regularization parameters, narrowed to float32 locally.
netCC (float) – Minimum reduced-correlation statistic for retaining a direction.
delta_regulator (float) – Sign selects the probability statistic convention.
network_energy_threshold (float) – Pixel energy threshold passed to the delayed-data loader.
sky_valid_indices (numpy.ndarray) – Nonempty int64 sky indices. Their original order determines tie-breaking.
group_order (numpy.ndarray) – Complete delay-group permutation and boundaries from make_delay_groups.
group_offsets (numpy.ndarray) – Complete delay-group permutation and boundaries from make_delay_groups.
- Returns:
Best sky index; float32 maps for antenna prior, alignment, likelihood, null energy, coherent energy, correlation, sky statistic, disbalance, network index, ellipticity and polarization; and the best sky statistic.
- Return type:
tuple
Notes
Per-direction DPF and statistics are recomputed. Only delay-dependent input loads, initial energy and masks are reused. Singleton groups disable reuse of delay-dependent work without changing the numerical calculation.
Scratch belongs to one group worker. Returned maps own separate storage; no scratch array may escape or be shared with a concurrent group.
pycwb.modules.likelihoodWP.sky_statistics module¶
Sky statistics: compute detailed statistics at a sky position.
Provides compute_statistics_at_sky_position() which computes per-pixel
statistics (packet energies, SNRs, noise corrections) at the
best-fit sky direction.
Legacy alias compute_statistics_at_sky_position remains available.
- pycwb.modules.likelihoodWP.sky_statistics.compute_statistics_at_sky_position(sky_idx: int, n_ifo: int, n_pix: int, FP: ndarray, FX: ndarray, noise_weights: ndarray, td00: ndarray, td90: ndarray, ml: ndarray, REG: ndarray, network_energy_threshold: float, cluster_xtalk: ndarray, cluster_xtalk_lookup_table: ndarray, DEBUG: bool = False, xgb_rho_mode: bool = False) SkyStatistics[source]¶
Compute detailed statistics for a specific sky location. :param sky_idx: Index of the sky location. :type sky_idx: int :param n_ifo: Number of interferometers. :type n_ifo: int :param n_pix: Number of pixels. :type n_pix: int :param FP: f+ polarization data for each interferometer, shape (n_sky, nIFO). :type FP: np.ndarray :param FX: fx polarization data for each interferometer, shape (n_sky, nIFO). :type FX: np.ndarray :param noise_weights: Normalized inverse-noise weights, shape (n_pix, n_ifo). :type noise_weights: np.ndarray :param td00: Time-delayed in-phase data, shape (ndelay, nIFO, n_pix). :type td00: np.ndarray :param td90: Time-delayed quadrature data, shape (ndelay, nIFO, n_pix). :type td90: np.ndarray :param ml: Sky-delay index array, shape (nIFO, n_sky). :type ml: np.ndarray :param REG: Regularization parameters, shape (3,). :type REG: np.ndarray :param network_energy_threshold: Energy threshold for the network. :type network_energy_threshold: float :param cluster_xtalk: Cluster XTalk object containing cross-talk coefficients. :type cluster_xtalk: object :param cluster_xtalk_lookup_table: Lookup table for cross-talk. :type cluster_xtalk_lookup_table: object :param DEBUG: If True, emit extra debug output. Default is False. :type DEBUG: bool, optional
- Returns:
Dataclass containing the sky statistics for the specified sky location.
- Return type:
pycwb.modules.likelihoodWP.waveform_statistics module¶
Release waveform summary conventions, independent of waveform synthesis.
- pycwb.modules.likelihoodWP.waveform_statistics.compute_final_detection_statistics(eo, eh, ew, nw, gn, dc, ec, rc, count, nifo, rho, xrho)[source]¶
Float scalar operations from the final network::likelihood2G block.
Retain native guards for invalid/degenerate energies. Ordinary accepted packets follow the release arithmetic and narrowing points.
- pycwb.modules.likelihoodWP.waveform_statistics.compute_sky_posterior_scale(norm, rc, pixel_count, disbalance)[source]¶
Compute the release sky-posterior scale with float32 arithmetic.
- Parameters:
norm (float) – Waveform normalization.
rc (float) – Correlation coefficient.
pixel_count (float) – Effective selected pixel count.
disbalance (float) – Network energy disbalance.
- Returns:
Scale used by sky-localization postprocessing.
- Return type:
float
- pycwb.modules.likelihoodWP.waveform_statistics.network_centroids(signal_energy, times, frequencies)[source]¶
Combine detector centroids with release float32 stores.
- Parameters:
signal_energy (numpy.ndarray) – Per-detector energies.
times (numpy.ndarray) – Per-detector time centroids in seconds.
frequencies (numpy.ndarray) – Per-detector frequency centroids in Hz.
- Returns:
Float32 total energy, network time and network frequency.
- Return type:
tuple
- pycwb.modules.likelihoodWP.waveform_statistics.waveform_frequency(data, rate)[source]¶
Match detector::getWFfreq, including its packed Nyquist-at-DC convention.
Native WDM synthesis returns an even number of samples. The release method accesses beyond its storage for odd lengths; reject that unsupported case explicitly instead of reproducing an invalid read.
- Parameters:
data (numpy.ndarray) – One-dimensional waveform of even length.
rate (float) – Sampling rate in Hz.
- Returns:
Energy-weighted frequency in Hz, or zero for an empty/zero-energy waveform.
- Return type:
float
- pycwb.modules.likelihoodWP.waveform_statistics.waveform_rms(data)[source]¶
Compute mean-subtracted RMS in the release grouped reduction order.
- Parameters:
data (numpy.ndarray) – One-dimensional float64 waveform samples.
- Returns:
RMS amplitude, or zero for an empty waveform.
- Return type:
float
- pycwb.modules.likelihoodWP.waveform_statistics.waveform_time(data, start, rate)[source]¶
Compute the energy-weighted waveform time.
- Parameters:
data (numpy.ndarray) – One-dimensional waveform samples.
start (float) – Time of the first sample in seconds.
rate (float) – Sampling rate in Hz.
- Returns:
Energy centroid in seconds, or zero for zero energy.
- Return type:
float
Module contents¶
pycwb.modules.likelihoodWP — Numba-accelerated coherent likelihood (CPU).
Computes sky localization (full HEALPix scan), coherent SNR, null energy,
correlation, and per-cluster detection statistics using per-pixel
time-delay data and antenna patterns. Uses @njit + prange
for CPU-bound inner loops.