NuRadioReco.utilities.signal_processing module

This module contains various functions for signal processing.

Functions for filtering, delaying, and upsampling traces:

It also contains functions to calculate the electric field or voltage amplitude from a given noise temperature and bandwidth:

See Also

NuRadioReco.utilities.trace_utilities

Contains functions to calculate observables from traces.

NuRadioReco.utilities.signal_processing.half_hann_window(length, half_percent=None, hann_window_length=None)[source]

Produce a half-Hann window. This is the Hann window from SciPY with ones inserted in the middle to make the window length long. Note that this is different from a Hamming window.

Parameters:
lengthint

The desired total length of the window

half_percentfloat, default=None

The percentage of length at the beginning and end that should correspond to half of the Hann window

hann_window_lengthint, default=None

The length of the half the Hann window. If half_percent is set, this value will be overwritten by it.

NuRadioReco.utilities.signal_processing.resample(trace, sampling_factor)[source]

Resample a trace by a given resampling factor.

Parameters:
tracendarray

The trace to resample. Can have multiple dimensions, but the last dimension should be the one to resample.

sampling_factorfloat

The resampling factor. If the factor is a fraction, the denominator should be less than 5000.

Returns:
resampled_tracendarray

The resampled trace.

NuRadioReco.utilities.signal_processing.upsampling_fir(trace, original_sampling_frequency, int_factor=2, ntaps=128)[source]

This function performs an upsampling by inserting a number of zeroes between samples and then applying a finite impulse response (FIR) filter.

Parameters:
trace: array of floats

Trace to be upsampled

original_sampling_frequency: float

Sampling frequency of the input trace

int_factor: integer

Upsampling factor. The resulting trace will have a sampling frequency int_factor times higher than the original one

ntaps: integer

Number of taps (order) of the FIR filter

Returns:
upsampled_trace: array of floats

The upsampled trace

NuRadioReco.utilities.signal_processing.get_filter_response(frequencies, passband, filter_type, order, rp=None, roll_width=None)[source]

Convenience function to obtain a bandpass filter response

Parameters:
frequencies: array of floats

the frequencies the filter is requested for

passband: list

passband[0]: lower boundary of filter, passband[1]: upper boundary of filter

filter_type: string or dict
  • ‘rectangular’: perfect straight line filter

  • ‘butter’: butterworth filter from scipy

  • ‘butterabs’: absolute of butterworth filter from scipy

  • ‘gaussian_tapered’ : a rectangular bandpass filter convolved with a Gaussian

or any filter that is implemented in NuRadioReco.detector.filterresponse. In this case the passband parameter is ignored

order: int

for a butterworth filter: specifies the order of the filter

rp: float

The maximum ripple allowed below unity gain in the passband. Specified in decibels, as a positive number. (Relevant for chebyshev filter)

roll_widthfloat, default=None

Determines the sigma of the Gaussian to be used in the convolution of the rectangular filter. (Relevant for the Gaussian tapered filter)

Returns:
f: array of floats

The bandpass filter response. Has the same shape as frequencies.

NuRadioReco.utilities.signal_processing.butterworth_filter_trace(trace, sampling_frequency, passband, order=8)[source]

Filters a trace using a Butterworth filter.

Parameters:
trace: array of floats

Trace to be filtered

sampling_frequency: float

Sampling frequency

passband: (float, float) tuple

Tuple indicating the cutoff frequencies

order: integer

Filter order

Returns:
filtered_trace: array of floats

The filtered trace

NuRadioReco.utilities.signal_processing.apply_butterworth(spectrum, frequencies, passband, order=8)[source]

Calculates the response from a Butterworth filter and applies it to the input spectrum

Parameters:
spectrum: array of complex

Fourier spectrum to be filtere

frequencies: array of floats

Frequencies of the input spectrum

passband: (float, float) tuple

Tuple indicating the cutoff frequencies

order: integer

Filter order

Returns:
filtered_spectrum: array of complex

The filtered spectrum

NuRadioReco.utilities.signal_processing.delay_trace(trace, sampling_frequency, time_delay, crop_trace=True)[source]

Delays a trace by transforming it to frequency and multiplying by phases.

A positive delay means that the trace is shifted to the right, i.e., its delayed. A negative delay would mean that the trace is shifted to the left. Since this method is cyclic, the delayed trace will have unphysical samples at either the beginning (delayed, positive time_delay) or at the end (negative time_delay). Those samples can be cropped (optional, default=True).

Parameters:
trace: array of floats or `NuRadioReco.framework.base_trace.BaseTrace`

Array containing the trace

sampling_frequency: float

Sampling rate for the trace

time_delay: float

Time delay used for transforming the trace. Must be positive or 0

crop_trace: bool (default: True)

If True, the trace is cropped to remove samples what are unphysical after delaying (rolling) the trace.

Returns:
delayed_trace: array of floats

The delayed, cropped trace

dt_start: float (optional)

The delta t of the trace start time. Only returned if crop_trace is True.

NuRadioReco.utilities.signal_processing.get_electric_field_from_temperature(frequencies, noise_temperature, solid_angle)[source]

Calculate the electric field amplitude from the radiance of a radio signal.

The radiance is calculated using the Rayleigh-Jeans law per frequency bin, by adjusting the value with the frequency spacing. After this, the electric field amplitude per bin is calculated using the radiance and the vacuum permittivity.

Parameters:
frequencies: array of floats

The frequencies at which to calculate the electric field amplitude

noise_temperature: float

The noise temperature to use in the Rayleigh-Jeans law

solid_angle: float

The solid angle over which the radiance is integrated

Returns:
efield_amplitude: array of floats

The electric field amplitude at each frequency

NuRadioReco.utilities.signal_processing.calculate_vrms_from_temperature(temperature, bandwidth=None, response=None, impedance=8.01088231e-09, freqs=None)[source]

Helper function to calculate the noise vrms from a given noise temperature and bandwidth.

For details see https://en.wikipedia.org/wiki/Johnson%E2%80%93Nyquist_noise (sec. “Maximum transfer of noise power”) or our wiki https://nu-radio.github.io/NuRadioMC/NuRadioMC/pages/HDF5_structure.html

Parameters:
temperature: float

The noise temperature of the channel in Kelvin

bandwidth: float or tuple of 2 floats (list of 2 floats) (default: None)

If single float, this argument is interpreted as the effective bandwidth. If tuple, the argument is interpreted as the lower and upper frequency of the bandwidth. Can be None if response is specified.

response: `NuRadioReco.detector.response.Response` (default: None)

If not None, the response of the channel is taken into account to calculate the noise vrms.

impedance: float (default: 50)

Electrical impedance of the channel in Ohm.

freqs: array_like (default: None -> np.arange(0, 2500, 0.1) * units.MHz)

Frequencies at which the response is evaluated. Only used if response is not None.

Returns:
vrms_per_channel: float

The vrms of the channel

NuRadioReco.utilities.signal_processing.get_efield_antenna_factor(station, frequencies, channels, detector, zenith, azimuth, antenna_pattern_provider, efield_is_at_antenna=False)[source]

Returns the antenna response to a radio signal coming from a specific direction

Parameters:
station: Station
frequencies: array of complex

frequencies of the radio signal for which the antenna response is needed

channels: array of int

IDs of the channels

detector: Detector
zenith, azimuth: float, float

incoming direction of the signal. Note that refraction and reflection at the ice/air boundary are taken into account

antenna_pattern_provider: AntennaPatternProvider
efield_is_at_antenna: bool (defaul: False)

If True, the electric field is assumed to be at the antenna. If False, the effects of an air-ice boundary are taken into account if necessary. The default is set to False to keep backwards compatibility.

Returns:
efield_antenna_factor: list of array of complex values

The antenna response for each channel at each frequency

See also

NuRadioReco.utilities.geometryUtilities.fresnel_factors_and_signal_zenith

function that calculates the Fresnel factors

NuRadioReco.utilities.signal_processing.get_channel_voltage_from_efield(station, electric_field, channels, detector, zenith, azimuth, antenna_pattern_provider, return_spectrum=True)[source]

Returns the voltage traces that would result in the channels from the station’s E-field.

Parameters:
station: Station
electric_field: ElectricField
channels: array of int

IDs of the channels for which the expected voltages should be calculated

detector: Detector
zenith, azimuth: float

incoming direction of the signal. Note that reflection and refraction at the air/ice boundary are already being taken into account.

antenna_pattern_provider: AntennaPatternProvider
return_spectrum: boolean

if True, returns the spectrum, if False return the time trace