sage.data.noise.real_noise
Classes
Duration-weighted random noise sampler from GW noise datasets. |
|
Duration-weighted random noise sampler from GW noise datasets. |
|
GPU-resident batch sampler for monolithic |
Module Contents
- class HDF5SingleNoiseSampler(source)[source]
Duration-weighted random noise sampler from GW noise datasets.
Supports: - single monolithic HDF5 file - directory of monolithic HDF5 files
Sampling: - segment chosen ∝ usable duration - random contiguous slice returned
- Parameters:
source (Union[str, pathlib.Path]) –
path to monolithic HDF5 file
OR directory containing multiple monolithic files
- class MemmapSingleNoiseSampler(source, return_tensor=False, tensor_dtype=torch.float32)[source]
Duration-weighted random noise sampler from GW noise datasets.
Supports: - single monolithic .bin file with sidecar *_segments.json
Sampling: - segment chosen ∝ usable duration - random contiguous slice returned
- Parameters:
source (Union[str, pathlib.Path]) –
path to monolithic .bin file
- class MemmapNoiseSampler(postprocess_fn=None, prefetch=3, seed=None, training=True, hard_dataset_path=None, hard_dataset_dir=None, hard_bias_prob=0.0, num_read_workers=16)[source]
Bases:
torch.nn.ModuleGPU-resident batch sampler for monolithic
.binnoise files with asynchronous prefetching.Each detector’s noise data is stored as a flat binary file (
float32orfloat64) accompanied by a sidecar*_segments.jsonfile that records the GPS start/end times, sample indices, and per-segment metadata for every contiguous data segment.Sampling is duration-weighted: longer segments are proportionally more likely to be drawn so that no useful data is wasted. Within each chosen segment, a uniformly random start offset is selected.
An async daemon thread continuously fills a bounded
queue.Queuewith pre-processed FD batches so that the GPU is never starved waiting for disk I/O. Callers consume batches throughsample_batch(), which performs a thread-safequeue.get().Warning
_read_batch()and_sample_starts_batch()access a non-thread-safe NumPy RNG and must not be called from the main thread while the prefetch daemon is running. Always usesample_batch()(queue pop) to consume batches safely.- Parameters:
postprocess_fn (callable or None) – Applied to
(batch_td, segment_ids)to convert from TD to FD. IfNone, a plaintorch.fft.rfftis used. The typical choice isRecolourPostprocess.prefetch (int) – Maximum number of batches held in the prefetch queue.
seed (int or None) – Seed for the internal NumPy RNG (for reproducibility).
training (bool) – If
True, reads fromdata_cfg.training_noise_files; otherwise fromdata_cfg.validation_noise_files.hard_bias_prob (float)
num_read_workers (int)
- Initialize internal Module state, shared by both nn.Module and ScriptModule.
- set_hard_dataset(dataset, hard_bias_prob=None, epoch=None, save_dir=None)[source]
Replace the hard-noise dataset and optionally persist it to disk.
Thread-safe: can be called from the main thread while the prefetch daemon is running. The change takes effect on the next batch the prefetch thread starts reading.
Versioned saving
When
epochandsave_dirare both given, the dataset is saved as{save_dir}/hard_noise_epoch_{epoch:04d}.npz. Files from earlier epochs are left untouched. If two miners both fire at the same epoch (explorer then refiner), the second call overwrites the first for that epoch number — only the refiner’s file survives on disk, though the explorer’s GPS findings remain in the shared bank. On the next training restart,MemmapNoiseSampler(hard_dataset_dir=save_dir)automatically picks up the latest epoch file.- param dataset:
A freshly mined dataset. Pass
Noneto disable biasing.- type dataset:
StartTimeDataset or None
- param hard_bias_prob:
New bias probability.
Nonekeeps the existing value.- type hard_bias_prob:
float or None
- param epoch:
Training epoch at which this dataset was mined. Used in the filename when
save_diris also provided.- type epoch:
int or None
- param save_dir:
Directory in which to save the versioned file.
- type save_dir:
str or Path or None
- Parameters:
hard_bias_prob (float | None)
epoch (int | None)
save_dir (str | pathlib.Path | None)