NuRadioReco.modules.LOFAR.stationRFIFilter module
- NuRadioReco.modules.LOFAR.stationRFIFilter.num_double_zeros(data, threshold=None, ave_shift=False)[source]
if data is a numpy array, give number of points that have zero preceded by a zero
- NuRadioReco.modules.LOFAR.stationRFIFilter.median_sorted_by_power(psort)[source]
This function takes a list psort, which is assumed to be a sorted list (of indices). This function returns a list beginning with the median (i.e. the middle element) and subsequently the elements right and left of it, in increasing distance from the median.
- Parameters:
- psort: 1D array_like
The list of elements to reoder.
Examples
>>> median_sorted_by_power([1,2,3,4,5]) [3, 4, 2, 5, 1]
In the example above, the middle element is 3. Therefore, the resulting array starts with 3. From there the algorithm takes the first element right (4) and left (2) of it. Then it takes the second element right (5) and left (1). This continues until all elements have been added to the output list.
- NuRadioReco.modules.LOFAR.stationRFIFilter.FindRFI_LOFAR(tbb_filename, metadata_dir, target_trace_length=65536, rfi_cleaning_trace_length=8192, flagged_antenna_ids=None, num_dbl_z=1000)[source]
A code that basically reads given LOFAR TBB H5 file and returns an array of dirty channels. Some values are hard coded based on LOFAR Experience.
- Parameters:
- tbb_filenamelist[Path-like str]
A list of paths to the TBB file to be analysed.
- metadata_dirPath-like str
The path to the directory containing the LOFAR metadata (required to open TBB file correctly).
- target_trace_lengthint
Size of total block of trace to be evaluated for finding dirty rfi channels.
- rfi_cleaning_trace_lengthint
Size of one chunk of trace to be evaluated at a time for calculating spectrum from.
- flagged_antenna_idslist, default=[]
List of antennas which are already flagged. These will not be considered for the RFI detection process.
- num_dbl_zint, default=100
The number of double zeros allowed in a block, if there are too many, then there could be data loss.
- Returns:
- output_dictdict
A dictionary with the following key-value pairs:
“avg_power_spectrum”: array that contains the average of the magnitude for each frequency channel over all antennas.
“avg_antenna_power”: array that contains the average power in frequency domain for each antenna.
“antenna_names”: the antenna IDs of which the data was used.
“cleaned_power”: array containing the power in each antenna after contaminated channels have been removed. Note that the result is multiplied by a factor of 2 to account for the negative frequencies.
“phase_stability”: 2-dimensional array with the average phase for every frequency channel in each antenna.
“dirty_channels”: array of indices indicating the channels that are contaminated with RFI.
“dirty_channels_block_size”: the number of samples per block used to detect phase stability.
- Raises:
- ValueError
If the target_trace_length is not a multiple of the rfi_cleaning_trace_length.
- class NuRadioReco.modules.LOFAR.stationRFIFilter.stationRFIFilter[source]
Bases:
object
Remove the RFI from all stations in an Event, by using the phase-variance method described in the notes section. This algorithm returns the frequency channels which are contaminated, which are subsequently put to zero in the traces.
Note: currently the class uses hardcoded values for LOFAR, this needs to be improved later.
Notes
The algorithm compares the phase stability of each frequency channel between a reference antenna and every other antenna in the station. If the phase is stable, this indicates a constant source contaminating the data. More information can be found in Section 3.2.2 of this paper .
- Attributes:
- metadata_dir
- station_list
Methods
begin
([rfi_cleaning_trace_length, reader, ...])Set the variables used for RFI detection.
run
(event)Run the filter on the event.
end
- property station_list
- property metadata_dir
- begin(rfi_cleaning_trace_length=65536, reader=None, logger_level=0)[source]
Set the variables used for RFI detection. The reader object can be used to retrieve the filenames associated with the loaded stations, as well as the metadata directory.
- Parameters:
- rfi_cleaning_trace_lengthint
The number of samples to use per block to construct the frequency spectrum.
- readerreadLOFARData object, default=None
If provided, the reader will be used to set the metadata directory and find the TBB files paths.
- logger_levelint, default=logging.NOTSET
Use this parameter to override the logging level for this module.
Notes
If no reader is provided here, the user should set the self.station_list and self.metadata_dir variables manually before attempting to execute the stationRFIFilter.run() function.
- run(event)[source]
Run the filter on the event. The method currently uses
FindRFI_LOFAR()
to find the contaminated channels and then puts the corresponding frequency bands to zero in every channel (in place).- Parameters:
- eventEvent object
The event on which to run the filter.