sigpyproc.core.kernels#
Numba kernel functions for the core of sigpyproc.
This module contains kernel functions for the core of sigpyproc.
Functions
Compute central moments in one pass through the data. |
|
Compute central moments in one pass through the data. |
|
Convolve the data with the templates in the template bank. |
|
Detrend a 1D array using a linear fit. |
|
Detrend a 2D array using a linear fit. |
|
Roll the 2D array along the second axis. |
|
Downsample a 1D array by averaging over bins. |
|
Downsample a 1D array by averaging over bins. |
|
Downsample a flattened 2D array by averaging over bins in both dimensions. |
|
Downsample a flattened 2D array by averaging over bins in both dimensions. |
|
Convolve two 1D arrays using FFT in mode "full". |
|
Get the good size for FFT. |
|
Compute the 1D FFT of a real array. |
|
Roll array elements along a given axis. |
|
Normalize the template to have zero mean and unit power. |
|
Remove zero DM from an input array. |
|
Remove zero DM from an input array. |
|
Roll each row of a 2D array along columns by per-row shifts. |
|
Roll each row of a 2D array by per-row shifts, keeping only valid columns. |
|
Convolve the input signal with the ISM effects. |
|
- sigpyproc.core.kernels.add_online_moments(a, b, c)#
- sigpyproc.core.kernels.circular_pad_goodsize(arr)#
- sigpyproc.core.kernels.compute_online_moments(array, moments, startflag=0)#
Compute central moments in one pass through the data.
- sigpyproc.core.kernels.compute_online_moments_basic(array, moments, startflag=0)#
Compute central moments in one pass through the data.
- sigpyproc.core.kernels.convolve_templates(data, temp_bank, ref_bin)#
Convolve the data with the templates in the template bank.
- Parameters:
- data
np.ndarray Input data array.
- temp_bank
list[np.ndarray] List of template arrays.
- ref_bin
list[int] List of reference bin indices.
- data
- Returns:
np.ndarrayConvolved array.
Notes
The reference bin is aligned to the index 0 and the template is time-reversed (to perform convolution rather than correlation). The template is then normalised to zero mean and unity power.
- sigpyproc.core.kernels.dedisperse(in_arr, out_arr, delays, nchans, nsamps, out_start_index)#
- sigpyproc.core.kernels.dedisperse_par(in_arr, out_arr, delays, nchans, nsamps, out_start_index)#
- sigpyproc.core.kernels.detrend_1d(arr)#
Detrend a 1D array using a linear fit.
Similar to scipiy.signal.detrend. Currently for 1d arrays only.
- Parameters:
- arr
np.ndarray Input 1D array.
- arr
- Returns:
np.ndarrayDetrended array.
- Raises:
ValueErrorIf the input array is empty.
- sigpyproc.core.kernels.detrend_2d(arr)#
Detrend a 2D array using a linear fit.
- Parameters:
- arr
np.ndarray Input 2D array.
- arr
- Returns:
np.ndarrayDetrended array.
- sigpyproc.core.kernels.disperse_block(arr, shifts, nsamps_out=1, tfactor=1)#
Roll the 2D array along the second axis.
- Parameters:
- arr
np.ndarray Input 2D array.
- shifts
np.ndarray Array of shifts for each row.
- nsamps_out
int, optional Desired minimum number of samples in the output, by default 1.
- tfactor
int, optional Time factor to decimate the output, by default 1.
- arr
- Returns:
np.ndarrayDispersed 2D array.
- sigpyproc.core.kernels.dmt_block(arr, dm_delays)#
- sigpyproc.core.kernels.dmt_block_valid(arr, dm_delays)#
- sigpyproc.core.kernels.downsample_1d_mean(array, factor)#
Downsample a 1D array by averaging over bins.
- Parameters:
- Returns:
ndarrayDownsampled array
Notes
Uses float64 accumulator to avoid overflow.
- sigpyproc.core.kernels.downsample_1d_mean_par(array, factor)#
Downsample a 1D array by averaging over bins.
- Parameters:
- Returns:
ndarrayDownsampled array
Notes
Uses float64 accumulator to avoid overflow.
- sigpyproc.core.kernels.downsample_2d_mean_flat(array, factor1, factor2, dim1, dim2)#
Downsample a flattened 2D array by averaging over bins in both dimensions.
- Parameters:
- array
np.ndarray Input flattened 2D array to be downsampled.
- factor1
int Downsampling factor for the first dimension. Must be a positive integer.
- factor2
int Downsampling factor for the second dimension. Must be a positive integer.
- dim1
int Number of bins in the first dimension.
- dim2
int Number of bins in the second dimension.
- array
- Returns:
np.ndarrayDownsampled flattened 2D array
Notes
dim2 must ve the fastest varying dimension.
- sigpyproc.core.kernels.downsample_2d_mean_par(array, factor1, factor2, dim1, dim2)#
Downsample a flattened 2D array by averaging over bins in both dimensions.
- Parameters:
- array
np.ndarray Input flattened 2D array to be downsampled.
- factor1
int Downsampling factor for the first dimension. Must be a positive integer.
- factor2
int Downsampling factor for the second dimension. Must be a positive integer.
- dim1
int Number of bins in the first dimension.
- dim2
int Number of bins in the second dimension.
- array
- Returns:
np.ndarrayDownsampled flattened 2D array
Notes
dim2 must ve the fastest varying dimension.
- sigpyproc.core.kernels.extract_bpass(in_arr, out_arr, nchans, nsamps)#
- sigpyproc.core.kernels.extract_bpass_par(in_arr, out_arr, nchans, nsamps)#
- sigpyproc.core.kernels.extract_tim(in_arr, out_arr, nchans, nsamps, out_start_index)#
- sigpyproc.core.kernels.extract_tim_par(in_arr, out_arr, nchans, nsamps, out_start_index)#
- sigpyproc.core.kernels.fftconvolve(in1, in2)#
Convolve two 1D arrays using FFT in mode “full”.
- Parameters:
- in1
np.ndarray First input array.
- in2
np.ndarray Second input array.
- in1
- Returns:
np.ndarrayConvolved array in mode “full”.
Notes
Return full discrete linear convolution of in1 and in2.
- sigpyproc.core.kernels.fold(inarray, fold_ar, count_ar, delays, maxdelay, tsamp, period, accel, total_nsamps, nsamps, nchans, nbins, nints, nsubs, index)#
- sigpyproc.core.kernels.form_interp_mspec(fspec)#
- sigpyproc.core.kernels.form_mspec(fspec)#
- sigpyproc.core.kernels.fs_running_median(spec_arr, start_width, end_width, end_freq_bin)#
- sigpyproc.core.kernels.invert_freq(in_arr, nchans, nsamps)#
- sigpyproc.core.kernels.invert_freq_par(in_arr, nchans, nsamps)#
- sigpyproc.core.kernels.mask_channels(in_arr, chan_mask, mask_value, nchans, nsamps)#
- sigpyproc.core.kernels.mask_channels_par(in_arr, chan_mask, mask_value, nchans, nsamps)#
- sigpyproc.core.kernels.nb_fft(arr, n=None)#
- sigpyproc.core.kernels.nb_fft_good_size(n, real=False)#
Get the good size for FFT.
- sigpyproc.core.kernels.nb_ifft(arr, n=None)#
- sigpyproc.core.kernels.nb_irfft(arr, n=None)#
- sigpyproc.core.kernels.nb_rfft(arr, n=None)#
Compute the 1D FFT of a real array.
- Parameters:
- arr
np.ndarray Input array (real).
- n
int|None, optional Length of the FFT, by default None
- arr
- Returns:
np.ndarrayReal part of the FFT.
- sigpyproc.core.kernels.nb_roll(arr, shift, axis=None)#
Roll array elements along a given axis.
This is a Numba-compiled wrapper around
numpy.roll(), implemented via rocket_fft to support theaxisargument.- Parameters:
- Returns:
np.ndarrayRolled array with the same shape as
arr.
- sigpyproc.core.kernels.normalize_template(arr)#
Normalize the template to have zero mean and unit power.
- Parameters:
- arr
np.ndarray Template array.
- arr
- Returns:
np.ndarrayNormalized template array.
- sigpyproc.core.kernels.pack1_8_big(array, packed)#
- sigpyproc.core.kernels.pack1_8_little(array, packed)#
- sigpyproc.core.kernels.pack1_8_vect(array, packed, *, big_endian=True)#
- sigpyproc.core.kernels.pack2_8_big(array, packed)#
- sigpyproc.core.kernels.pack2_8_little(array, packed)#
- sigpyproc.core.kernels.pack4_8_big(array, packed)#
- sigpyproc.core.kernels.pack4_8_little(array, packed)#
- sigpyproc.core.kernels.remove_zerodm(in_arr, out_arr, bpass, nchans, nsamps)#
Remove zero DM from an input array.
- Parameters:
- in_arr
np.ndarray Input 2D flattened array to remove zero DM from.
- out_arr
np.ndarray Output 2D flattened array with zero DM removed.
- bpass
np.ndarray Bandpass to be added back to the data.
- nchans
int Number of frequency channels in the 2D data.
- nsamps
int Number of samples in the 2D data.
- in_arr
- sigpyproc.core.kernels.remove_zerodm_par(in_arr, out_arr, bpass, nchans, nsamps)#
Remove zero DM from an input array.
- Parameters:
- in_arr
np.ndarray Input 2D flattened array to remove zero DM from.
- out_arr
np.ndarray Output 2D flattened array with zero DM removed.
- bpass
np.ndarray Bandpass to be added back to the data.
- nchans
int Number of frequency channels in the 2D data.
- nsamps
int Number of samples in the 2D data.
- in_arr
- sigpyproc.core.kernels.resample_tim(array, accel, tsamp)#
- sigpyproc.core.kernels.roll_block(arr, shifts)#
Roll each row of a 2D array along columns by per-row shifts.
Applies a circular shift to each row independently, wrapping elements around the column axis. Positive shifts move elements right, negative shifts move left.
- Parameters:
- arr
np.ndarray Input 2D array of shape (nrows, ncols).
- shifts
np.ndarray 1D array of integer shifts, length equal to nrows. Can be positive or negative.
- arr
- Returns:
np.ndarrayRolled 2D array with the same shape as
arr.
- Raises:
ValueErrorIf
arris not 2D orshiftslength does not match number of rows.
- sigpyproc.core.kernels.roll_block_valid(arr, shifts)#
Roll each row of a 2D array by per-row shifts, keeping only valid columns.
Similar to
roll_blockbut only keeps the valid region where no wrapping occurs. Positive shifts move elements right, negative shifts move elements left.- Parameters:
- arr
np.ndarray Input 2D array of shape (nrows, ncols).
- shifts
np.ndarray 1D array of integer shifts, length equal to nrows. Can be positive or negative.
- arr
- Returns:
np.ndarrayRolled 2D array with shape (nrows, ncols - shift_range).
- Raises:
ValueErrorIf
arris not 2D orshiftslength doesn’t match number of rows. If the shift range exceeds the number of columns.
- sigpyproc.core.kernels.simulate_ism(signal, spectrum, dm_smear, tau_nus, over_sampling=1)#
Convolve the input signal with the ISM effects.
- Parameters:
- signal
np.ndarray 1D pulse profile template.
- spectrum
np.ndarray Spectrum of the pulse profile (length = number of frequency channels).
- dm_smear
np.ndarray DM smearing (in samples) for each frequency channel.
- tau_nus
np.ndarray Scattering timescale (in samples) for each frequency channel.
- over_sampling
int, optional Oversampling factor for higher time resolution, by default 1.
- signal
- Returns:
np.ndarrayConvolved 2D pulse dynamic spectrum (nchans x nsamps).
Notes
The function performs the following steps for each frequency channel: - Replicate the signal across all frequency channels. - Apply DM smearing via convolution with a boxcar function. - Apply scattering via convolution with an exponential decay function. - Normalize the scattering kernel to maintain the signal area.
- sigpyproc.core.kernels.subband(inarray, outarray, delays, chan_to_sub, maxdelay, nchans, nsubs, nsamps)#
- sigpyproc.core.kernels.sum_harmonics(pow_spec, nfolds)#
- sigpyproc.core.kernels.unpack1_8_big(array, unpacked)#
- sigpyproc.core.kernels.unpack1_8_little(array, unpacked)#
- sigpyproc.core.kernels.unpack2_8_big(array, unpacked)#
- sigpyproc.core.kernels.unpack2_8_little(array, unpacked)#
- sigpyproc.core.kernels.unpack4_8_big(array, unpacked)#
- sigpyproc.core.kernels.unpack4_8_little(array, unpacked)#
- sigpyproc.core.kernels.update_moments(val, m1, m2, m3, m4, n)#
- sigpyproc.core.kernels.update_moments_basic(val, m1, m2, n)#