setigen package¶
Subpackages¶
Submodules¶
setigen.fil_utils module¶
-
setigen.fil_utils.
get_data
(input)[source]¶ Gets time-frequency data from filterbank file as a 2d NumPy array.
Parameters: input (str) – Name of filterbank file Returns: data – Time-frequency data Return type: ndarray
-
setigen.fil_utils.
get_fs
(input)[source]¶ Gets frequency values from filterbank file.
Parameters: input (str) – Name of filterbank file Returns: fs – Frequency values Return type: ndarray
-
setigen.fil_utils.
get_ts
(input)[source]¶ Gets time values from filterbank file.
Parameters: input (str) – Name of filterbank file Returns: ts – Time values Return type: ndarray
setigen.generate_signal module¶
-
setigen.generate_signal.
generate
(ts, fs, path, t_profile, f_profile, bp_profile, integrate=False, samples=10)[source]¶ Generates synthetic signal.
Computes synethic signal using given path in time-frequency domain and brightness profiles in time and frequency directions.
Parameters: - ts (ndarray) – Time samples
- fs (ndarray) – Frequency samples
- path (function) – Function in time that returns frequencies
- t_profile (function) – Time profile: function in time that returns an intensity (scalar)
- f_profile (function) – Frequency profile: function in frequency that returns an intensity (scalar), relative to the signal frequency within a time sample
- bp_profile (function) – Bandpass profile: function in frequency that returns an intensity (scalar)
- integrate (bool, optional) – Option to integrate t_profile in the time direction
- samples (int, optional) – Number of bins to integrate t_profile in the time direction, using Riemann sums
Returns: signal – Two-dimensional NumPy array containing synthetic signal data
Return type: ndarray
Examples
A simple example that creates a linear Doppler-drifted signal:
>>> import setigen as stg >>> import numpy as np >>> tsamp = 18.25361108 >>> fch1 = 6095.214842353016 >>> df = -2.7939677238464355e-06 >>> fchans = 1024 >>> tchans = 16 >>> fs = np.arange(fch1, fch1 + fchans * df, df) >>> ts = np.arange(0, tchans * tsamp, tsamp) >>> signal = stg.generate(ts, fs, stg.constant_path(f_start = fs[200], drift_rate = -0.000002), stg.constant_t_profile(level = 1), stg.box_f_profile(width = 0.00001), stg.constant_bp_profile(level = 1))
The synthetic signal can then be visualized and saved within a Jupyter notebook using
>>> %matplotlib inline >>> import matplotlib.pyplot as plt >>> fig = plt.figure(figsize=(10,6)) >>> plt.imshow(signal, aspect='auto') >>> plt.colorbar() >>> fig.savefig("image.png", bbox_inches='tight')
To run within a script, simply exclude the first line:
%matplotlib inline
.
setigen.split_utils module¶
-
setigen.split_utils.
split_data
(data, f_sample_num=None, t_sample_num=None, f_shift=None, t_shift=None, f_trim=False, t_trim=False)[source]¶ Splits NumPy arrays into a list of smaller arrays according to limits in frequency and time. This doesn’t reduce/combine data, it simply cuts the data into smaller chunks.
Parameters: data (ndarray) – Time-frequency data Returns: split_data – List of new time-frequency data frames Return type: list of ndarray
-
setigen.split_utils.
split_fil
(input_fn, output_dir, f_sample_num, f_shift=None)[source]¶ Creates a set of new filterbank files by ‘splitting’ an input filterbank file according to the number of frequency samples.
Parameters: - input_fn (str) – Filterbank filename with .fil extension
- output_dir (str) – Directory for new filterbank files
- f_sample_num (int) – Number of frequency samples per new filterbank file
- f_shift (int, optional) – Number of samples to shift when splitting filterbank. If None, defaults to f_shift=f_sample_num so that there is no overlap between new filterbank files
Returns: split_fns – List of new filenames
Return type: list of str
setigen.time_freq_utils module¶
-
setigen.time_freq_utils.
gaussian_noise
(data, mean, sigma)[source]¶ Create an array of Gaussian noise with the same dimensions as an input data array
-
setigen.time_freq_utils.
inject_noise
(data, modulate_signal=False, modulate_width=0.1, background_noise=True, noise_sigma=1)[source]¶ Normalize data per frequency channel so that the noise level in data is controlled.
Uses a sliding window to calculate mean and standard deviation to preserve non-drifted signals. Excludes a fraction of brightest pixels to better isolate noise.
Parameters: - data (ndarray) – Time-frequency data
- modulate_signal (bool, optional) – Modulate signal itself with Gaussian noise (multiplicative)
- modulate_width (float, optional) – Standard deviation of signal modulation
- background_noise (bool, optional) – Add gaussian noise to entire image (additive)
- noise_sigma (float, optional) – Standard deviation of background Gaussian noise
Returns: noisy_data – Data with injected noise
Return type: ndarray
-
setigen.time_freq_utils.
normalize
(data, cols=0, exclude=0.0, to_db=False, use_median=False)[source]¶ Normalize data per frequency channel so that the noise level in data is controlled; using mean or median filter.
Uses a sliding window to calculate mean and standard deviation to preserve non-drifted signals. Excludes a fraction of brightest pixels to better isolate noise.
Parameters: - data (ndarray) – Time-frequency data
- cols (int) – Number of columns on either side of the current frequency bin. The width of the sliding window is thus 2 * cols + 1
- exclude (float, optional) – Fraction of brightest samples in each frequency bin to exclude in calculating mean and standard deviation
- to_db (bool, optional) – Convert values to decibel equivalents before normalization
- use_median (bool, optional) – Use median and median absolute deviation instead of mean and standard deviation
Returns: normalized_data – Normalized data
Return type: ndarray