pycwb.modules.super_cluster_native package¶
Submodules¶
pycwb.modules.super_cluster_native.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.
pycwb.modules.super_cluster_native.sub_net_cut module¶
- pycwb.modules.super_cluster_native.sub_net_cut.mra_statistics(n_ifo, n_pix, FP, FX, rms, td00, td90, td_energy, ml, network_energy_threshold, e2or, subcut, xtalks, xtalks_lookup, l_max)[source]¶
- pycwb.modules.super_cluster_native.sub_net_cut.mra_statistics_from_td(n_ifo, n_pix, FP, FX, rms, td00, td90, ml, network_energy_threshold, e2or, subcut, xtalks, xtalks_lookup, l_max)[source]¶
- pycwb.modules.super_cluster_native.sub_net_cut.optimize_sky_loc_from_td(n_ifo: int, n_pix: int, n_sky: int, FP: ndarray, FX: ndarray, rms: ndarray, td00: ndarray, td90: ndarray, ml: ndarray, network_energy_threshold: float, e2or: float, subcut: float) tuple[int, float, float, float, int, int, float, float][source]¶
Scan prepared detector/sky arrays and return the native eight-value subnet result.
- pycwb.modules.super_cluster_native.sub_net_cut.optimze_sky_loc(n_ifo, n_pix, n_sky, FP, FX, rms, td00, td90, td_energy, ml, network_energy_threshold, e2or, subcut)[source]¶
- pycwb.modules.super_cluster_native.sub_net_cut.optimze_sky_loc_from_td(n_ifo: int, n_pix: int, n_sky: int, FP: ndarray, FX: ndarray, rms: ndarray, td00: ndarray, td90: ndarray, ml: ndarray, network_energy_threshold: float, e2or: float, subcut: float) tuple[int, float, float, float, int, int, float, float]¶
Scan prepared detector/sky arrays and return the native eight-value subnet result.
- pycwb.modules.super_cluster_native.sub_net_cut.sse_MRA_ps(Eo, K, rNRG, v_00, v_90, xtalks, xtalks_lookup, DEBUG=False)[source]¶
fast multi-resolution analysis inside sky loop select max E pixel and either scale or skip it based on the value of residual
- pycwb.modules.super_cluster_native.sub_net_cut.sse_like_ps(fp, fx, am, AM)[source]¶
input fp,fx - antenna patterns in DPF input am,AM - network amplitude vectors returns: (xp*xp+XP*XP)/|f+|^2+(xx*xx+XX*XX)/(|fx|^2)
- pycwb.modules.super_cluster_native.sub_net_cut.sub_net_cut(pixels, ml, FP, FX, acor, e2or, n_ifo, n_sky, subnet, subcut, subnorm, subrho, xtalk: XTalk, timing: dict | None = None)[source]¶
This function is used to cut the subnet from the lag and return the new lag
- pycwb.modules.super_cluster_native.sub_net_cut.sub_net_cut_from_pixel_arrays(pixels, pixel_indices, ml, FP, FX, acor, e2or, n_ifo, n_sky, subnet, subcut, subnorm, subrho, xtalk: XTalk, arrays_prepared: bool = False, timing: dict | None = None, *, packet_cut: Callable | None = None)[source]¶
Internal fast path that avoids building a sliced
PixelArraysobject.
pycwb.modules.super_cluster_native.super_cluster module¶
- pycwb.modules.super_cluster_native.super_cluster.calculate_supercluster_data(clusters: list[Cluster], atype: str, core: bool, pair: bool, nPIX: int, S: float, dF: float) Cluster[source]¶
Merge a group of clusters into one supercluster and compute its statistics.
- Parameters:
clusters (list[Cluster]) – Clusters to merge (already linked by
supercluster()).atype (str) – Statistics type:
'L'(likelihood),'E'(energy), or'P'(power).core (bool) – If
True, only core pixels contribute to the statistics.pair (bool) – If
True, require at least two resolution levels.nPIX (int) – Minimum pixel count; candidates with fewer pixels are rejected.
S (float) – Minimum amplitude/likelihood threshold per resolution level.
dF (float) – Frequency correction term passed to
calculate_statistics().
- Returns:
Merged supercluster with
cluster_status=0(accepted) orcluster_status=1(rejected by statistics cut).- Return type:
- pycwb.modules.super_cluster_native.super_cluster.defragment(clusters: list[Cluster], t_gap: float, f_gap: float, n_ifo: int, profile=ExecutionProfile(scalar_dpf=False, sky_delay_reuse=True, coherence_early_cuts=False, preindex_shifts=False, cluster_runs=False, compact_coherence=False, tiled_wdm=False, compact_td_cache=False, staged_td=False, bounded_jax_max_energy=False, numba_max_energy_mode='parallel', regression_engine='numba', gc_full_interval=1, perf_diagnostics=False, require_gpu=False, wdm_bounded_jax_forward=False, wdm_bounded_jax_inverse=False, wdm_deterministic_jax_inverse=False, wdm_bounded_numba=False, wdm_compact_complex=False)) list[Cluster][source]¶
Defragmentation algorithm — merge clusters that are close in time and frequency.
- Parameters:
clusters (list[Cluster]) – Input clusters to defragment.
t_gap (float) – Maximum time separation (seconds) for merging two clusters.
f_gap (float) – Maximum frequency separation (Hz) for merging two clusters.
n_ifo (int) – Number of interferometers.
- Returns:
Defragmented clusters; may have fewer elements than clusters if any were merged together.
- Return type:
list[Cluster]
- pycwb.modules.super_cluster_native.super_cluster.setup_supercluster(config: Any, gps_time: float) dict[source]¶
Compute lag-independent supercluster resources: sky delay / antenna-pattern matrices and the K_td delay range.
Call this once per job segment, then pass the returned dict together with a separately built
td_inputs_cachetosupercluster_single_lag().- Parameters:
config (Config)
gps_time (float) – GPS time of the first strain sample (used for sky-delay computation).
- Returns:
Keys:
ml,FP,FX,n_sky,ml_likelihood,FP_likelihood,FX_likelihood,n_sky_likelihood,K_td.- Return type:
dict
- pycwb.modules.super_cluster_native.super_cluster.supercluster(clusters: list[Cluster], atype: str, gap: float, threshold: float, n_ifo: int, mini_pix: int = 3, core: bool = False, pair: bool = False, profile=ExecutionProfile(scalar_dpf=False, sky_delay_reuse=True, coherence_early_cuts=False, preindex_shifts=False, cluster_runs=False, compact_coherence=False, tiled_wdm=False, compact_td_cache=False, staged_td=False, bounded_jax_max_energy=False, numba_max_energy_mode='parallel', regression_engine='numba', gc_full_interval=1, perf_diagnostics=False, require_gpu=False, wdm_bounded_jax_forward=False, wdm_bounded_jax_inverse=False, wdm_deterministic_jax_inverse=False, wdm_bounded_numba=False, wdm_compact_complex=False)) list[Cluster][source]¶
Supercluster algorithm
- Parameters:
cluster (List[Cluster]) – List of clusters
atype (str) – Statistics type: ‘L’ for likelihood, ‘E’ for energy, ‘P’ for power
gap (float) – Time-frequency gap used to link clusters
threshold (float) – Threshold for discarding clusters
n_ifo (int) – Number of interferometers
mini_pix (int) – Minimum number of pixels in a cluster
core (bool) – true - use only core pixels, false - use core & halo pixels
pair (bool) – true - 2 resolutions, false - 1 resolution
- pycwb.modules.super_cluster_native.super_cluster.supercluster_single_lag(setup: dict, config: Any, fragment_clusters_single_lag: list, lag_idx: int, xtalk: XTalk, td_inputs_cache: dict, *, subnet_cut: Callable | None = None, populate_td: TimeDelayPopulator | None = None) Any | None[source]¶
Run the full supercluster pipeline for a single lag.
- Parameters:
setup (dict) – Returned by
setup_supercluster().config (Config) – Configuration object — all thresholds and parameters are read directly from config rather than being pre-parsed into setup.
fragment_clusters_single_lag (list[FragmentCluster]) – One
FragmentClusterper resolution for this lag only (i.e. the output ofcoherence_single_lag()).lag_idx (int) – Zero-based lag index (used for logging only).
xtalk (XTalk) – Pre-loaded cross-talk catalog instance.
td_inputs_cache (dict) – Pre-built TD inputs cache keyed by layer → list of per-IFO
TDBatchInputs.
- Returns:
FragmentCluster or None – Processed cluster ready for likelihood, or
Noneif all candidates were rejected at the subnet-cut stage.Backend callbacks
—————–
subnet_cut, populate_td (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.
- pycwb.modules.super_cluster_native.super_cluster.supercluster_wrapper(config: Any, fragment_clusters: list, strains: list, xtalk_coeff: ndarray, xtalk_lookup_table: ndarray, layers: ndarray, return_td_cache: bool = False, job_seg: Any | None = None) list | tuple | None[source]¶
Convenience wrapper for interactive / legacy use.
Internally calls
setup_supercluster(),build_td_inputs_cache(), andsupercluster_single_lag()for every lag, avoiding all the duplicated WDM/sky-pattern setup code that was previously inlined here.- Parameters:
config (Config)
fragment_clusters (list[list[FragmentCluster]]) –
fragment_clusters[res][lag]— output ofcoherence().strains (list) – Whitened strain time series (one per IFO).
xtalk_coeff (np.ndarray)
xtalk_lookup_table (np.ndarray)
layers (np.ndarray)
return_td_cache (bool) – If True, return
(result, td_inputs_cache)instead ofresult.job_seg (WaveSegment) – Job segment supplying lag count.
- Returns:
One FragmentCluster per lag, or None if any lag produces no clusters.
- Return type:
list[FragmentCluster] or None
pycwb.modules.super_cluster_native.utils module¶
- pycwb.modules.super_cluster_native.utils.aggregate_clusters(links: ndarray) List[source]¶
Build connected components from a list of (i, j) edge pairs.
- Parameters:
links (np.ndarray of shape (N, 2), dtype int32) – Pairs of cluster indices that should be merged.
- Returns:
Each inner list contains the indices belonging to one component. Single-element components (isolated nodes) are excluded.
- Return type:
numba.typed.List[numba.typed.List[int32]]
- pycwb.modules.super_cluster_native.utils.aggregate_clusters_from_links(cluster_ids: ndarray, cluster_links: ndarray) list[list[int]][source]¶
Merge cluster ids using the provided edge list and append singleton clusters.
- Parameters:
- Returns:
Each inner list holds the cluster indices belonging to one component. Isolated clusters appear as single-element lists.
- Return type:
list[list[int]]
- pycwb.modules.super_cluster_native.utils.apply_subnet_cut(superclusters: list[Cluster], n_loudest_local: int, ml_local: np.ndarray, FP_local: np.ndarray, FX_local: np.ndarray, acor_local: float, e2or_local: float, n_ifo_local: int, n_sky_local: int, subnet_local: float, subcut_local: float, subnorm_local: float, subrho_local: float, xtalk_local: XTalk, arrays_prepared: bool = False, *, pixel_cut: Callable | None = None) list[Cluster][source]¶
Apply the sub-network cut and mark clusters that pass or fail.
- Parameters:
superclusters (list[Cluster]) – Candidate clusters to evaluate.
n_loudest_local (int) – Number of loudest pixels to pass to
sub_net_cut().ml_local (np.ndarray) – Sky-delay matrix (reduced resolution for subnet check).
FP_local (np.ndarray) – Plus-polarisation antenna-pattern matrix.
FX_local (np.ndarray) – Cross-polarisation antenna-pattern matrix.
acor_local (float) – Correlation threshold.
e2or_local (float) – Energy-to-overfit-ratio threshold.
n_ifo_local (int) – Number of interferometers.
n_sky_local (int) – Number of sky pixels.
subnet_local (float) – Sub-network statistic threshold.
subcut_local (float) – Sub-network cut threshold.
subnorm_local (float) – Sub-network normalisation factor.
subrho_local (float) – Sub-network SNR threshold.
xtalk_local (XTalk) – Cross-talk catalogue instance.
- Returns:
list[Cluster] – Clusters with
cluster_status <= 0, i.e. those that passed the cut.Backend callbacks
—————–
pixel_cut (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.
- pycwb.modules.super_cluster_native.utils.calculate_statistics(pixels: ndarray, atype: str, core: bool, pair: bool, nPIX: int, S: float, dF: float) list[float] | None[source]¶
Compute summary statistics for a merged supercluster candidate.
- Parameters:
pixels (np.ndarray of shape (N, 6+n_ifo)) – Per-pixel feature matrix. Columns:
[core, time, freq, rate, layers, likelihood, asnr_ifo0, …].atype (str) – Statistics type:
'L'(likelihood),'E'(energy), or'P'(power).core (bool) – If
True, skip non-core pixels.pair (bool) – If
True, require at least two resolution levels.nPIX (int) – Minimum pixel count; clusters with fewer pixels are rejected.
S (float) – Minimum amplitude/likelihood threshold per resolution level.
dF (float) – Frequency correction term added to each pixel’s frequency bin.
- Returns:
[cTime, cFreq, rate_max, rate_min, total_energy]when the cluster passes all cuts, orNoneif it should be rejected.- Return type:
list[float] or None
- pycwb.modules.super_cluster_native.utils.calculate_statistics_arrays(core_arr: ndarray, time_arr: ndarray, freq_arr: ndarray, rate_arr: ndarray, layers_arr: ndarray, likelihood_arr: ndarray, asnr_arr: ndarray, atype: str, core: bool, pair: bool, nPIX: int, S: float, dF: float) tuple[bool, float, float, float, float, float][source]¶
Array-argument version of
calculate_statistics().Returns
(ok, cTime, cFreq, rate_max, rate_min, total_energy)and keeps the public matrix-wrapper available for compatibility.
- pycwb.modules.super_cluster_native.utils.expected_td_vec_len(td_size: int | float) int[source]¶
Return the expected length of a time-delay amplitude vector.
- Parameters:
td_size (int or float) – Number of time-delay steps (
K_td).- Returns:
Vector length
4 * td_size + 2.- Return type:
int
- pycwb.modules.super_cluster_native.utils.extract_timeseries_data(strain: TimeSeries) tuple[np.ndarray, float, float][source]¶
Extract raw data, sample rate, and start time from a strain object.
- Parameters:
strain (TimeSeries or compatible) – Object exposing
.data,.sample_rate, and.t0attributes.- Returns:
values (np.ndarray) – Strain samples as float64.
sample_rate (float) – Sampling frequency in Hz.
start (float) – GPS start time of the time series.
- pycwb.modules.super_cluster_native.utils.find(parent: ndarray, x: int) int[source]¶
Find the representative of the set containing x with iterative path compression.
- Parameters:
parent (np.ndarray) – Parent array for the union-find structure.
x (int) – Element whose root is to be found.
- Returns:
Root representative of the set.
- Return type:
int
- pycwb.modules.super_cluster_native.utils.get_cluster_links(pixels: ndarray, gap: float, n_ifo: int) tuple[ndarray, float][source]¶
Find (i, j) links between clusters whose pixels are close enough to merge.
Pixels are represented as rows in pixels where columns are:
[time_s, 2*freq_hz, 1/rate, rate/2, cluster_id, td_time_ifo0, …].- Parameters:
pixels (np.ndarray of shape (N, 5+n_ifo)) – Per-pixel feature array sorted by time.
gap (float) – Dimensionless overlap parameter; two pixels are linked when the combined time-frequency distance satisfies
eps <= gap.n_ifo (int) – Number of interferometers (determines how many td-index columns exist).
- Returns:
np.ndarray of shape (M, 2), dtype int32 – Unique pairs of cluster indices that should be merged.
float – Last computed frequency gap value
dF(used as a cluster-level proxy; see FIXME insupercluster()).
- pycwb.modules.super_cluster_native.utils.get_defragment_link(pixels: ndarray, t_gap: float, f_gap: float, n_ifo: int) ndarray[source]¶
Find (i, j) links between clusters for defragmentation.
Two clusters are linked when the time and frequency separations between their representative pixels are both within the supplied thresholds.
- Parameters:
pixels (np.ndarray of shape (N, 5+n_ifo)) – Per-pixel feature array:
[time_s, 2*freq_hz, 1/rate, rate/2, cluster_id, td_time_ifo0, …].t_gap (float) – Maximum allowed time separation in seconds.
f_gap (float) – Maximum allowed frequency separation in Hz.
n_ifo (int) – Number of interferometers.
- Returns:
Unique cluster-index pairs satisfying the defragmentation condition, or an empty
(0, 2)array when no links exist.- Return type:
- pycwb.modules.super_cluster_native.utils.remove_duplicates_sorted(arr: ndarray) ndarray[source]¶
Remove consecutive duplicate rows from a sorted 2-D array.
- Parameters:
arr (np.ndarray of shape (N, 2)) – Sorted array whose duplicate rows are to be removed.
- Returns:
View of arr with consecutive duplicates stripped.
- Return type:
np.ndarray
- pycwb.modules.super_cluster_native.utils.resolve_wdm_context(layer_tag: int | float, context_map: dict) object[source]¶
Look up the WDM context for layer_tag, falling back to
layer_tag - 1.- Parameters:
layer_tag (int or float) – WDM layer identifier (will be cast to
int).context_map (dict) – Mapping from integer layer tag to context object.
- Returns:
The context object from context_map.
- Return type:
object
- Raises:
ValueError – If neither
layer_tagnorlayer_tag - 1is present in context_map.
- pycwb.modules.super_cluster_native.utils.union(parent: ndarray, rank: ndarray, x: int, y: int) None[source]¶
Merge the sets containing x and y using union-by-rank.
- Parameters:
parent (np.ndarray) – Parent array for the union-find structure.
rank (np.ndarray) – Rank array used to keep the tree shallow.
x (int) – First element.
y (int) – Second element.
Module contents¶
pycwb.modules.super_cluster_native — Native multi-resolution super-clustering.
Merges pixel clusters across resolution levels, applies sub-net cuts, and defragments using Numba-accelerated link-matrix computation.