Data flagging (ps_eor.flagger)#
Configurable frequency- and spatial-mode flagging for data cubes.
Flaggers inspect a data cube and a noise proxy, usually a Stokes-I cube paired
with Stokes V, then either remove outlying channels / spatial modes
(action='filter') or retain them with zero weight
(action='zero_weight'). FlaggerRunner applies an ordered pipeline
and records the combined selection so it can be replayed on another cube:
runner = FlaggerRunner.load('flagger.ini')
filtered_i, filtered_v = runner.run(i_cube.copy(), v_cube.copy())
filtered_noise = runner.apply_last(noise_cube)
Flaggers may modify their input cubes; pass copies when the originals must be preserved. Pipelines can be assembled in Python or loaded from an INI file.
- class ps_eor.flagger.BaseFlagger(**kargs)[source]#
Bases:
SimpleConfigBase configuration shared by all flaggers.
Every flagger has a display
nameand anaction:'filter'removes selected modes, while'zero_weight'keeps their data and sets their weights to zero.
- class ps_eor.flagger.BaseUVFlagger(**kargs)[source]#
Bases:
BaseFlaggerBase class for flaggers that select spatial modes.
- do_flag(i_cube, v_cube, verbose=True)[source]#
Apply the spatial-mode mask returned by
get_outliers.get_outliersreturnsTruefor modes to flag. Filtering removes those columns; zero-weighting retains the data and changes both cubes’ weight arrays in place.- Returns:
the flagged
(i_cube, v_cube).- Return type:
- class ps_eor.flagger.BaseFreqsFlagger(**kargs)[source]#
Bases:
BaseFlaggerBase class for flaggers that remove or zero-weight channels.
- do_flag(i_cube, v_cube, verbose=True)[source]#
Apply the channel mask returned by
get_outliers.get_outliersreturnsTruefor channels to flag. Filtering returns frequency-sliced cubes; zero-weighting retains the channels and changes both cubes’ weight arrays in place.- Returns:
the flagged
(i_cube, v_cube).- Return type:
- class ps_eor.flagger.FixedFreqsFlagger(**kargs)[source]#
Bases:
BaseFreqsFlaggerFlag configured frequencies or frequency ranges.
Frequencies are specified in MHz as comma-separated values or half-open ranges, for example
'121.3,123.1-124.0'. By default every configured channel is flagged.ratio_min_v_varcan instead retain a configured block unless its foreground-subtracted noise-proxy variance exceeds the variance outside all configured blocks by that factor.
- class ps_eor.flagger.UVDirectionFlagger(**kargs)[source]#
Bases:
BaseUVFlaggerFlag Cartesian UV cells along a configured angular direction.
The direction is interpreted modulo 180 degrees.
extendcontrols the half-width of the selected UV line relative to the median U-cell spacing.
- class ps_eor.flagger.SigmaClipper(**kargs)[source]#
Bases:
SimpleConfigShared robust detrending and one-sided sigma clipping.
The statistic is optionally polynomial-detrended after excluding an initial set of extreme samples. Only positive residual outliers are selected.
- class ps_eor.flagger.FreqsSigmaClipFlagger(**kargs)[source]#
Bases:
SigmaClipper,BaseFreqsFlaggerSigma-clip channel noise or variance.
For each frequency, clip either the estimated SEFD (
sefd=True) or the standard deviation across spatial modes.stokes='I'usesi_cube; other values use the noise-proxyv_cube.
- class ps_eor.flagger.FreqsWeightsFlagger(**kargs)[source]#
Bases:
BaseFreqsFlaggerFlag channels whose median weight falls below a smooth trend.
A polynomial is fitted after excluding zero and five-MAD weight outliers. Channels whose median effective weight divided by that trend is below
ratioare selected.
- class ps_eor.flagger.UVWeightsFlagger(**kargs)[source]#
Bases:
BaseUVFlaggerFlag UV samples with insufficient weight across the band.
For each UV sample, take its minimum effective weight over frequency and compare it with the largest such minimum. Values below
thresholdtimes that reference are selected.
- class ps_eor.flagger.UVSigmaClipFlagger(**kargs)[source]#
Bases:
SigmaClipper,BaseUVFlaggerSigma-clip SEFD or variance across Cartesian UV samples.
The clipped statistic is evaluated per UV sample and detrended against baseline radius.
stokesselects'I','V','dI', or'dV'; thedvariants first difference adjacent frequency channels.
- class ps_eor.flagger.LMThetaMaxFlagger(**kargs)[source]#
Bases:
BaseUVFlaggerFlag spherical modes beyond a variance-derived angular boundary.
The boundary is inferred from frequency variance as a function of
m / ell.th_indefines the inner region used to set the reference variance;relative_thresholdselects the low-variance modes from which the limiting angle is estimated.
- class ps_eor.flagger.Flag(freqs, uu, vv, idx_uv, idx_uv_zero_weights, idx_freqs, idx_freqs_zero_weights)[source]#
Bases:
objectSerializable frequency and spatial masks produced by a flagging run.
idx_freqsandidx_uvselect the channels and spatial modes kept from the original cube. The corresponding*_zero_weightsmasks refer to the retained grid and select samples whose weights are set to zero.- save(filename)[source]#
Save the masks and their coordinate grids to HDF5.
- Parameters:
filename – Destination HDF5 filename.
- apply(cube)[source]#
Apply these masks to a compatible cube.
The input is copied. Rejected channels and spatial modes are removed, then the zero-weight masks are applied to the retained grid.
- Parameters:
cube – Cube with the same original frequency and spatial layout as the cube used to create this flag.
- Returns:
A flagged copy of
cube.
- class ps_eor.flagger.FlaggerRunner(verbose=True, min_weights=2)[source]#
Bases:
objectRun an ordered flagger pipeline on two matched cubes.
Every flagger derives a mask from the Stokes-I and noise cubes and applies it to both, keeping their sampling identical. The runner retains the inputs, outputs, and combined
Flagfrom the most recent run for plotting or reuse.The pipeline can modify the supplied cubes. Pass copies to
run()when their original state must be retained.- add(flagger)[source]#
Append a flagger to the pipeline.
- Parameters:
flagger – A
BaseFlaggerinstance.
- run(i_cube, v_cube)[source]#
Run the pipeline on two cubes with matching sampling.
Flaggers that do not support the supplied cube type or metadata are skipped. Filtering and zero-weight selections are applied identically to both cubes.
- Parameters:
i_cube – Stokes-I data cube.
v_cube – Noise or Stokes-V cube with the same geometry.
- Returns:
Tuple containing the flagged Stokes-I and noise cubes.
Note
The input cubes can be modified. Use
cube.copy()when their original state is needed later.
- apply_last(cube)[source]#
Apply the most recently generated flag to a compatible cube.
- Parameters:
cube – Cube with the same original geometry as the last inputs.
- Returns:
A flagged copy of
cube.
- plot(figsize=(10, 12), **fig_kargs)[source]#
Plot diagnostics from the most recent run.
Removed samples are marked with crosses and retained samples whose weights were set to zero with plus signs.
- Parameters:
figsize – Matplotlib figure size.
**fig_kargs – Additional arguments passed to
matplotlib.pyplot.subplots().
- Returns:
The Matplotlib figure containing frequency and spatial diagnostics.
- static load(filename)[source]#
Build a flagger pipeline from an INI configuration file.
The
[flagger]section defines an ordered, comma-separatedpipeline. Each named section must provide atypematching a flagger class from this module. Its remaining values are passed to the class as keyword arguments.For example:
[flagger] pipeline = bad_channels, noisy_baselines [bad_channels] type = FixedFreqsFlagger freqs = 115.0-115.2, 121.5 action = filter [noisy_baselines] type = UVSigmaClipFlagger nsigma = 5 action = zero_weight
- Parameters:
filename – Path to the configuration file.
- Returns:
A
FlaggerRunnercontaining the configured pipeline.