setigen package¶
Subpackages¶
Submodules¶
setigen.fil_utils module¶
-
setigen.fil_utils.
get_data
(fil, db=False)[source]¶ Gets time-frequency data from filterbank file as a 2d NumPy array.
Parameters: fil (str or Waterfall) – Name of filterbank file or Waterfall object Returns: - data (ndarray) – Time-frequency data
- Note (when multiple Stokes parameters are supported, this will have to)
- be expanded.
-
setigen.fil_utils.
get_fs
(fil)[source]¶ Gets frequency values from filterbank file.
Parameters: fil (str or Waterfall) – Name of filterbank file or Waterfall object Returns: fs – Frequency values Return type: ndarray
-
setigen.fil_utils.
get_ts
(fil)[source]¶ Gets time values from filterbank file.
Parameters: fil (str or Waterfall) – Name of filterbank file or Waterfall object 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_time=False, samples=10, average_f_pos=False)[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_time (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
- average_f_pos (bool, optional) – Option to average path along frequency to get better position in t-f space
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_array
(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
(fil_fn, output_dir, f_window, 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: - fil_fn (str) – Filterbank filename with .fil extension
- output_dir (str) – Directory for new filterbank files
- f_window (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_window so that there is no overlap between new filterbank files
Returns: split_fns – List of new filenames
Return type: list of str
-
setigen.split_utils.
split_fil_generator
(fil_fn, f_window, f_shift=None)[source]¶ Creates a generator that returns smaller Waterfall objects by ‘splitting’ an input filterbank file according to the number of frequency samples.
Parameters: - fil_fn (str) – Filterbank filename with .fil extension
- f_window (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_window so that there is no overlap between new filterbank files
- Yields –
- ------- –
- split (Waterfall) – A blimpy Waterfall object containing a smaller section of the data
setigen.time_freq_utils module¶
-
setigen.time_freq_utils.
choose_from_dist
(dist, shape)[source]¶ Load random values from a loaded NumPy array in the specified shape
-
setigen.time_freq_utils.
gaussian_frame_from_dist
(means_dist, stds_dist, mins_dist, shape)[source]¶ Make a Gaussian noise frame from given distributions for the mean, standard deviation, and minimums for data in the shape provided.
-
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.
make_normal
(means_dist, stds_dist, mins_dist, shape)[source]¶ Grab means, standard deviations, and minimums from the loaded distributions (each NumPy arrays) in the shape provided.
-
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