sigpyproc.core.rfi#

RFI masking functions.

This module contains functions for masking RFI.

Classes

RFIMask

Class to handle RFI masking.

Functions

double_mad_mask

Calculate the mask of an array using the double MAD (Modified z-score).

iqrm_mask

Calculate the mask of an array using the IQRM (Interquartile Range Method).

class sigpyproc.core.rfi.RFIMask(threshold, header, chan_mean, chan_var, chan_skew, chan_kurt, chan_maxima, chan_minima, chan_mask=NOTHING, user_mask=NOTHING, stats_mask=NOTHING, custom_mask=NOTHING)[source]#

Bases: object

Class to handle RFI masking.

Parameters:
thresholdfloat

Threshold for the mask.

headerHeader

Header object containing the observation metadata.

chan_meanndarray

Mean of each channel.

chan_varndarray

Variance of each channel.

chan_skewndarray

Skewness of each channel.

chan_kurtndarray

Kurtosis of each channel.

chan_maximandarray

Maximum of each channel.

chan_minimandarray

Minimum of each channel.

chan_maskndarray, optional

Final mask of the channels, by default None.

user_maskndarray, optional

User-defined mask, by default None.

stats_maskndarray, optional

Mask calculated using channel statistics, by default None.

custom_maskndarray, optional

Custom mask, by default None.

Attributes:
threshold
header
chan_mean
chan_var
chan_skew
chan_kurt
chan_maxima
chan_minima
chan_mask
user_mask
stats_mask
custom_mask
num_masked

Get the number of masked channels.

masked_fraction

Get the fraction of channels masked.

Methods

apply_funcn(custom_funcn)

Apply a custom function to the existing mask.

apply_mask(freq_mask)

Apply a frequency range mask.

apply_method([method])

Apply a mask method using channel statistics.

from_file(filename)

Load a mask from a HDF5 file.

plot([figsize, dpi])

Plot the mask.

to_file([filename])

Write the mask to a HDF5 file.

threshold#
header#
chan_mean#
chan_var#
chan_skew#
chan_kurt#
chan_maxima#
chan_minima#
chan_mask#
user_mask#
stats_mask#
custom_mask#
property num_masked#

Get the number of masked channels.

Returns:
int

Number of masked channels.

property masked_fraction#

Get the fraction of channels masked.

Returns:
float

Fraction of channels masked.

apply_mask(freq_mask)[source]#

Apply a frequency range mask.

Parameters:
freq_masklist[tuple[float, float]]

List of frequency ranges to mask.

apply_method(method='mad')[source]#

Apply a mask method using channel statistics.

Parameters:
method{‘iqrm’, ‘mad’}, optional

Method to apply, by default ‘mad’.

Raises:
ValueError

If the method is not supported.

apply_funcn(custom_funcn)[source]#

Apply a custom function to the existing mask.

Parameters:
custom_funcnCallable[[ndarray], ndarray]

Custom function to apply to the mask. The function should take the existing mask as input and return additional channels to mask.

Raises:
ValueError

If the custom_funcn is not callable.

to_file(filename=None)[source]#

Write the mask to a HDF5 file.

Parameters:
filenamestr, optional

Filename to write the mask, by default None.

Returns:
str

Filename written to.

plot(figsize=(12, 6.5), dpi=100)[source]#

Plot the mask.

Parameters:
figsizetuple[float, float], optional

Figure size in inches, by default (12, 6).

dpiint, optional

Dots per inch, by default 100.

Returns:
Figure

Matplotlib figure object.

classmethod from_file(filename)[source]#

Load a mask from a HDF5 file.

Parameters:
filenamestr

Filename to load the mask from.

Returns:
RFIMask

The loaded mask.

sigpyproc.core.rfi.double_mad_mask(array, threshold=3)[source]#

Calculate the mask of an array using the double MAD (Modified z-score).

Parameters:
arrayndarray

The input array to calculate the mask of.

thresholdfloat, optional

Threshold in sigmas, by default 3.0.

Returns:
ndarray

The mask for the array.

Raises:
ValueError

If the threshold is not positive.

sigpyproc.core.rfi.iqrm_mask(array, threshold=3, radius=5)[source]#

Calculate the mask of an array using the IQRM (Interquartile Range Method).

Parameters:
arrayndarray

The input array to calculate the mask of.

thresholdfloat, optional

Threshold in sigmas, by default 3.0.

radiusint, optional

Radius to calculate the IQRM, by default 5.

Returns:
ndarray

The mask for the array.

Raises:
ValueError

If the threshold is not positive.