Skip to content

Utils

baseband_utils

get_file_from_timestamp

get_file_from_timestamp(ts, dir_parent, search_type, force_ts=False, acclen=393216)

Given a timestamp, return the file inside of which that timestamp lies. The function works with both baseband and direct spectra files.

Parameters:

Name Type Description Default
ts int or str

The timestamp you're interested in. (ctime)

required
dir_parent str

The directory which contains 5 digit folders.

required
search_type d or f

'd' (directory) if you are using this function for direct spectra, 'f' (file) for baseband.

required
force_ts bool

Return the next available file if a file containing ts is not found.

False

Returns:

Type Description
str

Absolute path to the file which contains your timestamp.

Raises:

Type Description
NotFoundError

If there is no matching file, the user is required to start their integration from the next available timestamp that's helpfully suggested.

time2fnames

time2fnames(time_start, time_stop, dir_parent, search_type, fraglen=5, mind_gap=False)

Gets a list of filenames within specified time-rage.

Given a start and stop ctime, retrieve list of corresponding files. This function assumes that the parent directory has the directory structure /<5-digit coarse time fragment>/<10-digit fine time stamp>.

Parameters:

Name Type Description Default
time_start int

start time in ctime

required
time_stop int

stop time in ctime

required
dir_parent str

parent directory, e.g. /path/to/data_100MHz

required
fraglen int

number of digits in coarse time fragments

5

Returns:

Type Description
list of str

List of files in specified time range.

get_init_info

get_init_info(init_t, end_t, dir_parent, force_ts=False)

Get relevant indices from timestamps.

Returns the index of file in a folder and the index of the spectra in that file corresponding to init_timestamp

Parameters:

Name Type Description Default
init_t

Start timestamp of time we are interested in. (ctime)

required
end_t

End of time window we are interested in. (ctime)

required
parent_dir

The directory we search in.

required

Returns:

Name Type Description
idxstart int

The index of the starting row of interest to us within a baseband data file.

fileidx int

The index of the file in the sorted directory.

files list of str

Sorted list of path strings to all files in 'parent_dir'.

get_plot_lims

get_plot_lims(pol, acclen)

Get limits for display settings for pretty plots!

Parameters:

Name Type Description Default
pol

Baseband from a baseline. (channelized data.) Is this a 2d array??

required
acclen

Depricated, doesn't get used.

required

Returns:

Name Type Description
med float

Mean power in pol.

vmin float

Two standard deviations below mean.

vmax float

Two standard deviations above mean.

plot_4bit

plot_4bit(pol00, pol11, pol01, channels, acclen, time_start, vmin, vmax, opath, minutes=False, logplot=True)

Waterfall plotting routine for 4-bit spectrum integrated data.

Plots and saves figure.

Parameters:

Name Type Description Default
pol00

Channelized autocorr data from pol0.

required
pol11

Channelized autocorr data from pol1.

required
pol01

Channelized x-corr data (pol0 x pol1).

required
channels

Indices of channels of interest.

required
acclen

??

required
time_start

??In what format??

required
vmin

Plotting parameter. Two standard deviations below mean. Used to set colorbar scale.

required
vmax

Plotting parameter. Two standard deviations above mean. Used to set colorbar scale.

required
opath

Ouput path. Path to image of figure to be saved.

required
minutes

Whether to display time in minutes. Defaults to False, displaying seconds.

False
logplot

Defaults to True. Logarithmic scale on y-axis.

True

plot_1bit

plot_1bit(pol01, channels, acclen, time_start, opath, minutes=False, logplot=False)

Waterfall plotting routine for 1-bit spectrum integrated data.

Plots and saves figure.

Parameters:

Name Type Description Default
pol01

Channelized x-corr data (pol0 x pol1).

required
channels

Indices of channels of interest.

required
acclen

??

required
time_start

??In what format; is this relative time or absolute timestamp?

required
opath

Ouput path. Path to image of figure to be saved.

required
minutes

Whether to display time in minutes. Defaults to False, displaying seconds.

False
logplot

Depricated. Defaults to True. Logarithmic scale on y-axis.

False

load_antenna_power

load_antenna_power(init_t, end_t, dir_parent, chans=None, tags=['pol00', 'pol11'])

Load direct spectra for a given antenna. Internally, this function finds all files between two timestamps, loads specified pols (00,11, 01r, 01i) for each file and returns an array of dimensions (npol,nchan,ntime), where ntime ~ (end_t - init_t)/6.44.

Parameters:

Name Type Description Default
init_t

Unix C-time for data start.

required
end_t

Indices of channels of interest.

required
dir_parent

Parent directory for direct data (should contain 5 digit dirs)

required
chans

List of frequency channels in range [0, 2048) that need to be loaded. Default None, (set to the full range)

None
tags

List of polarizations that need to be read. Default ['pol00', 'pol11']

['pol00', 'pol11']

Returns:

Name Type Description
large_arr ndarray

(npol,nchan,ntime) array of all data found between two timestramps

ctime_arr ndarray

(ntime,) array of C timestamps corresponding to each of the ntime spectra in the data.

get_present_files

get_present_files(t_start, t_end, ant_path_list, T_SCAN=10, tolerance=70)

Given a path to several antenna, will tell you when data is present for each antenna

Args: t_start (int): starting time of when we're scanning t_end (int): ending time of when we're scanning ant_path_list (list of strings): just the directory location for all antenna data T_SCAN (int): the time interval between scans, basically just the dt tolerance (int): maximum time that we tolerate between a point in time and the last present file

Returns: arr (array): array of binary entries, of shape (ntimes, nants). 1 means data is present, 0 means it is absent ntimes is in units of T_SCAN

fig (figure): just visualizes arr, with time on y axis, in human time

get_simul_files

get_simul_files(arr, time_start, dt, desired_ant_indices)

Returns a list of [t_start, t_end] for times during which data is present for all antenna in desired_ant_indices

Parameters:

Name Type Description Default
arr array

array shape (ntimes, nants) of binary entries, with 1 meaning data is present and 0 meaning data is not present

required
time_start

starting unix time of array, point at which we start counting

required
dt int

difference in time (seconds) between entries in array

required
desired_ant_indices list

the antenna (index on arr) for which we want data to be present. If it's -1, it considers ALL antenna in arr.

required

Returns:

Name Type Description
runs list

list of two-element lists [t_start, t_end] which indicate the times of simultaneous continuous data in all desired antenna.

check_data_holes

check_data_holes(t_start, t_end, dir, min_filesize=500001224, tol=60, verbose=False, force_ts=False)

This is a measure for abundance of caution when opening up files. Returns True if there is data missing, or any holes between the data. Returns False if there are no problems (i.e. no data holes)

sat_utils

get_MAD

get_MAD(data, axis=None)

Find real median absolute deviation

get_haversine_dist

get_haversine_dist(p1, p2, radius=6371000)

Vectorized Haversine distance using NumPy.

Parameters:

Name Type Description Default
p1 array-like of shape (..., 2)

lat, lon in degrees

required
p2 array-like of shape (..., 2)

lat, lon in degrees

required
radius float

Earth radius (km by default)

6371000

Returns:

Name Type Description
distances ndarray

Distance(s) in the same unit as radius.

get_bline_dist

get_bline_dist(coord1, coord2)

returns the physical distance between two coordinates in meters (i.e. magnitude of baseline vectors)

get_risen_sats2

get_risen_sats2(tle_file, coords, t_start, satlist, dt=5, niter=560, good=None, altitude_cutoff=1)

Get all satellites risen at a particular point on earth at a list of epochs. Epochs start at t_start and a list of risen satellites is returned for every t_start + i * dt epoch The satellites are read form a TLE file.

Parameters:

Name Type Description Default
coords tuple of floats

(latitude, longitude, elevation) of the position on Earth. Elevation is measured in meteres.

required
t_start float

Start timestamp (ctime). Converted to JD internally.

required
dt float

Delta between epochs, by default None which sets it to 6.44 seconds internally (accumulation time of direct spectra).

5
niter int

Number of iterations, by default 560

560
elevation_cutoff float

Altitude cutoff (in degrees) above which a satellite is considered risen, by default 1 degree.

required

Returns:

Name Type Description
risen_sats list of lists

One list of risen satellites per epoch. Each epoch's list carries the name of the risen satellite at that epoch. E.g. [["FM118","NOAA15"], ["NOAA15"]]

get_detections

get_detections(cx, snr_array, temp_satmap)

determines detections given a coarse-cross correlation and SNR of a satellite pass

for each frequency channel, we sort the SNR across all correlations (uncorrected and per-sat beamform) we skip the channel if uncorrected (cx[0]) has highest SNR (i.e. if beamforming didn't improve SNR) if beamform SNR improves uncorr SNR by factor of (5 * √2) or more, count as detection get detections for each chan for each sat get reliability ratio from the cxcorr peak shape

note that we limit each channel to one detection (i.e. multiple sats cannot be detected in the same chan)

Parameters:

Name Type Description Default
Returns
required
detected_sats
required
detected_peaks
required
detected_snrs
required
rel_ratios
required

get_vis

get_vis(pulse_start_t, pulse_end_t, paths, offsets, T_SPECTRA=4096 / 250000000.0, v_acclen=5000)

Computes visibilities for one baseline for a set interval, given a specnumoffset.

Different to version in helper_finetiming as this must load up the data as BFI object.

Parameters:

Name Type Description Default
Returns
required
Notes

note that this is just a regular CPU visibility computation, mainly useful for sanity checks also note that this should be tested with two non-ref antenna (usually run with one ref one non ref)

unix_to_lst_with_fix

unix_to_lst_with_fix(start_unix, end_unix, coords)

Assume that interval can be no longer than 24 hrs, so that we can unwrap safely by 360

snr2db

snr2db(snrarr)

Sends snr as ratio to dB By convention of snr_times output, sends snr of zero to 0 dB.

sat_utils_gpu

get_cxcorr_many_sats

get_cxcorr_many_sats(p0_ref, p0_nref, tle_path, times, sats_present, satmap, coords, dN, T_SPECTRA=4096 / 250000000.0, c_acclen=10 ** 6)

get the coarse cross-correlation for a given chunk of data, for a given set of sats

Parameters:

Name Type Description Default
p0_ref

Data array of reference/non-reference antenna, shape (c_acclen, nchans). 'Reference' means it is the second in spectrum number, and lower in index. By convention, we always write specnumoffset (and therefore delays) as (nref-ref).

required
tle_path

Directory path of TLE file containing satellite positions for pulse time we care about This allows us to beamform accurately.

required
times

List of [start_time, end_time] for the pulse, in unix time. Lets us know where to beamform

required
sats_present

List of length nsats which tells us which satellites to try and beamform on. Sats are in index form, of legacy hard-coded satlist [28654,25338,33591,57166,59051,44387].

required
satmap

Dictionary that maps each sat_idx to it satID, and vice versa. Lets us move between these forms for utility and ease, depending on which is needed. To perhaps phase out later down the line

required
coords

List of the two sets of coordinates [ref_coords, nref_coords]. Each coord is in form [lat, lon, alt]

required
dN

Gives how many spectra of shift (per direction) we actually include in our cxcorr data. So for example, if dN is 10e5, we will have 2*10e5 different attempted offsets

required
T_SPECTRA

period of spectra

4096 / 250000000.0
c_acclen

Number of spectra in each chunk. Integration time of the cxcorr.

10 ** 6

Returns:

Name Type Description
cx list of arrays

A list of the coarse cross-correlations for each sat in sats_present, and also for no beamforming. Uncorrected always given first. ['Uncorrected', sat1, sat2] Each coarse xcorr has shape (nchans, 2*dN)

get_vis_gpu

get_vis_gpu(pulse_start_t, pulse_end_t, paths, offsets, T_SPECTRA=4096 / 250000000.0, v_acclen=30000)

computes visibilities for one baseline for a set period, given a specnumoffset

note that this is just a regular CPU visibility computation, mainly useful for sanity checks also note that this should be tested with two non-ref antenna (usually run with one ref one non ref)

get_chunk_data

get_chunk_data(files, idxs, chanstart, chanend, nchunks=None, c_acclen=10 ** 6)

Get chunk data for two antenna given times and paths, using bfi.

Purpose of wrapping in a function is to minimize cached memory usage (which is very heavy for bfi files) for modules using large loops.

Parameters:

Name Type Description Default
files

Paths for the two antenna, in form [ref_path, nref_path]

required
idxs

List of starting indices within the first file for the timestream. In form [ref_idx, nref_idx]

required
chanstart

starting/ending channel index in baseband file index

required
c_acclen

length of chunk in spectra

10 ** 6
ref_bool

tells you if you have to switch the order of files and idx lists. used when fitting for coordinates. If true, ref ant is fit ant, so all good. If False, then must switch, since convention is that we write ref ant first, fitting ant first.

required

Returns:

Name Type Description
p0_ref_copy/p0_nref_copy: cupy array

array shape (c_acclen, nchans), with one chunk of data for ref/nref antenna

specnum_offset int

initial offset of absolute spectrum numbers between the data streams. i.e. for this set of data (this load), what the clock tells you the offset is. The calculated relative offset for THIS chunk load will then update this specnum offset, and give the actual absolute offset between timestreams.

get_snr_from_coords

get_snr_from_coords(fit_coords, nfit_coords, fit_p0, nfit_p0, times, satmap, satID, chan_s_idx, dN=100000, T_SPECTRA=4096 / 250000000.0, c_acclen=10 ** 6)

Get the SNR of a pulse for ONE pulse on ONE baseline using ONE chunk.

Parameters:

Name Type Description Default
Returns
required

get_snr_from_coords_many

get_snr_from_coords_many(fit_coords, fit_path, other_coords, other_paths, pulse_times, pulse_chans, pulse_sats, satmap, dN=1000000.0, T_SPECTRA=4096 / 250000000.0, c_acclen=10000000.0)

Get the total summed SNR for all desired pulses for all desired blines, using a certain fixed fitting antenna.

Purpose is to fit for that desired fitting antenna's coordinates.

Parameters:

Name Type Description Default
Returns
required

orbcomm_utils

ctime2mjd

ctime2mjd(tt=None, type='Dublin')

Return Various Julian Dates given ctime. Options include Dublin, MJD, JD

get_coarse_xcorr

get_coarse_xcorr(f1, f2, Npfb=4096)

Get coarse xcorr of each channel of two channelized timestreams. The xcorr is 0-padded, so length of output is twice the original length (shape[0]).

Parameters:

Name Type Description Default
f1 ndarray of complex64

First and second timestreams. Both n_spectrum x n_channel complex array.

required
f2 ndarray of complex64

First and second timestreams. Both n_spectrum x n_channel complex array.

required
chans

Channels (columns) of f1 and f2 that should be correlated.

required

Returns:

Type Description
ndarray of complex128

xcorr of each channel's timestream. 2*n_spectrum x n_channel complex array.

get_coarse_xcorr_fast

get_coarse_xcorr_fast(f1, f2, dN, chans=None, Npfb=4096)

Get coarse xcorr of each channel of two channelized timestreams. The xcorr is 0-padded, so length of output is twice the original length (shape[0]).

Parameters:

Name Type Description Default
f1 ndarray of complex64

First and second timestreams. Both n_spectrum x n_channel complex array.

required
f2 ndarray of complex64

First and second timestreams. Both n_spectrum x n_channel complex array.

required
chans

Channels (columns) of f1 and f2 that should be correlated.

None

Returns:

Type Description
ndarray of complex128

xcorr of each channel's timestream. 2*n_spectrum x n_channel complex array.

get_interp_xcorr

get_interp_xcorr(coarse_xcorr, chan, sample_no, coarse_sample_no)

Get a upsampled xcorr from coarse_xcorr by adding back the carrier frequency.

Parameters:

Name Type Description Default
coarse_xcorr

1-D array of coarse xcorr of one channel.

required
chan int

Channel for the passed coarse xcorr.

required
osamp

Number of times to over sample over the default 4 ns time-resolution. E.g. osamp=4 means 1 ns time-resolution.

required

Returns:

Name Type Description
final_xcorr_cwave ndarray

Complex upsampled xcorr.

get_interp_xcorr_fast

get_interp_xcorr_fast(coarse_xcorr, chan, sample_no, coarse_sample_no, shift, out=None, shift_phase=False)

Get a upsampled xcorr from coarse_xcorr by adding back the carrier frequency.

Parameters:

Name Type Description Default
coarse_xcorr

1-D array of coarse xcorr of one channel.

required
chan int

Channel for the passed coarse xcorr.

required
osamp

Number of times to over sample over the default 4 ns time-resolution. E.g. osamp=4 means 1 ns time-resolution.

required

Returns:

Name Type Description
final_xcorr_cwave ndarray

Complex upsampled xcorr.

gauss_smooth

gauss_smooth(data, sigma=5)

Gaussian smooth an N-dim signal. The user should take care about 0-padding. This function will simply smooth whatever is provided with a gaussian kernel of the same size/dimensions with an N-dim FFT.

Parameters:

Name Type Description Default
data ndarray

Data to smooth

required
sigma int

width of gaussian in no. of samples, by default 5

5

Returns:

Type Description
ndarray

Smoothened data

get_risen_sats

get_risen_sats(tle_file, coords, t_start, dt=None, niter=560, good=None, altitude_cutoff=1)

Get all satellites risen at a particular point on earth at a list of epochs. Epochs start at t_start and a list of risen satellites is returned for every t_start + i * dt epoch The satellites are read form a TLE file (currently hardcoded).

Parameters:

Name Type Description Default
coords tuple of floats

(latitude, longitude, elevation) of the position on Earth. Elevation is measured in meteres.

required
t_start float

Start timestamp (ctime). Converted to JD internally.

required
dt float

Delta between epochs, by default None which sets it to 6.44 seconds internally (accumulation time of direct spectra).

None
niter int

Number of iterations, by default 560

560
elevation_cutoff float

Altitude cutoff (in degrees) above which a satellite is considered risen, by default 1 degree.

required

Returns:

Name Type Description
risen_sats list of lists

One list of risen satellites per epoch. Each epoch's list carries the name of the risen satellite at that epoch. E.g. [["FM118","NOAA15"], ["NOAA15"]]

find_pulses

find_pulses(x, cond='==', thresh=None, pulses=True)

Given a signal "x", find locations where the signal is ON. Whether or not the signal is ON is determined by the comparison condition passed. Comparison done is x cond 0.

Parameters:

Name Type Description Default
x ndarray(float or int)

Signal timestream

required
cond str

One of "==", ">", "<", ">=", "<=", "!=" Consider the effect of round-off error if you are using "eq" with a float array.

'=='
thresh float

If passed, (x - thresh) is compared against the condition, by default None

None

get_per_ant_sat_delay

get_per_ant_sat_delay(antpos, tle_path, time_start, niter, satnorad, dt=1)

Generate a delay timestream for each antenna for a given satellite.

Parameters:

Name Type Description Default
antpos list of array-like

List of (latitude, longitude, altitude) for each antenna in decimal degrees. For one antenna, must be a single-element list.

required
tle_path str

Path to directory with TLE files.

required
time_start float

Start unix-time of the pass.

required
niter int

Number of iterations in the pass. Default 1 second per iteration.

required
satnorad int

Satellite NORAD catalog number.

required
dt float

delta-time (in seconds) per iteration, by default 1.0

1

Returns:

Type Description
ndarray

(n_ant x n_time) array of delays

pred

pred(coord1, coord2, start_t, end_t, channel, satID, T_SPECTRA=4096 / 250000000.0, v_acclen=30000)

predicted phase given satellite

orbcomm_utils_gpu

apply_delay

apply_delay(arr, delay, freqs, out=None, copy=True)

Apply a time-dependent exponential phase to a timestream. Timestream can be E-field, or visibility, or anything else a user desires. Output = Input * exp(-j 2 pi freq tau)

Parameters:

Name Type Description Default
arr ndarray

Usually n_time x n_chan

required
delay ndarray

Delay timestream of length n_time

required
freqs ndarray

Frequency array of length n_chan

required
out ndarray

Write to this array, should be of the same shape as input array, by default None. Overrides copy, if passed.

None
copy bool

Make a copy of the input array for the output, by default True

True

Returns:

Type Description
ndarray

out array

finetiming_utils

get_MAD

get_MAD(data, axis=None)

Find real median absolute deviation

haversine

haversine(p1, p2, radius=6371000)

Vectorized Haversine distance using NumPy.

Parameters:

Name Type Description Default
p1 array-like of shape (..., 2)

lat, lon in degrees

required
p2 array-like of shape (..., 2)

lat, lon in degrees

required
radius float

Earth radius (km by default)

6371000

Returns:

Name Type Description
distances ndarray

Distance(s) in the same unit as radius.

apply_delay

apply_delay(arr, out, delay, freqs)

Apply phase delay to visibilities.

Parameters:

Name Type Description Default
arr np.ndarry shape (nspec, nchan)

Input array

required
out np.ndarray shape (nspec, nchan)

Output array

required
delay float

Time delay between the timestreams, in seconds.

required
freqs np.ndarray shape (nchan)

Frequencies corresponding to each channel

required

Returns:

Name Type Description
out np.ndarray shape ()

Same object but now with delayed data from 'arr' in it.

xcorr_avg

xcorr_avg(arr1, arr2, acclen)

Computes cross-correlation between two timestreams.

Takes chunks of size 'acclen' and computes averaged conjugate product for each chunk.

Parameters:

Name Type Description Default
arr1 np.ndarray shape (nspec, nchan)

First array for correlation

required
arr2 np.ndarray shape (nspec, nchan)

Second array for correlation

required
acclen int

number of spectra to include in single chunk of correlated data

required

Returns:

Type Description
np.ndarray shape (nspec//acclen, nfreq)

Cross-correlated data.

xcorr_avg_1d

xcorr_avg_1d(arr1, arr2, acclen)

Computes cross-correlation between two timestreams, but for only one channel.

Takes chunks of size 'acclen' and computes averaged conjugate product for each chunk.

Parameters:

Name Type Description Default
arr1 np.ndarray shape (nspec)

First array for correlation

required
arr2 np.ndarray shape (nspec)

Second array for correlation

required
acclen int

number of spectra to include in single chunk of correlated data

required

Returns:

Name Type Description
out np.ndarray shape (nspec//acclen)

Cross-correlated data.

beamformed_xcorr

beamformed_xcorr(data, a1, a2, p1, p2, delay, freqs, acclen)

Compute beamformed visibilities for single baseline for specific polarizations.

Parameters:

Name Type Description Default
data np.ndarray shape (nblines, npol, nspec, nchans)

Raw baseband data

required
a1 int

Antenna 1 index

required
a2 int

Antenna 2 index

required
p1 int

Polarization 1 index

required
p2 int

Polarization 2 index

required
delay np.ndarray shape (nspec)

Time delays between antenna 1 and 2

required
freqs np.ndarray shape (nchans)

Frequencies for each channel

required
acclen int

Accumulation length for single visibility

required

Returns:

Name Type Description
V np.npdarray shape (nspec//acclen, nchans)

Beamformed visibility data for single baseline and single polarization pair.

get_vis

get_vis(data, satID, freqs, pstart, pend, antpos, ant_idxs, tle_path, T_SPECTRA, acclen)

Computes beamformed visibilities for N antenna over time.

Different to version in sat_utils because this uses data already present on hard drive after upsampling.

Parameters:

Name Type Description Default
data np.ndarray shape (nblines, npols, nspectra, nchans)

Contains channelized data for each baseline, for the same corresponding spectra

required
satID int

NORAD satellite ID of the satellite we want to beamform onto

required
freqs np.ndarray shape (nchans)

Frequencies in Hz corresponding to each channel

required
pstart int

Pulse start time in 10 digit UNIX timestamp

required
pend int

Pulse end time in 10 digit UNIX timestamp

required
antpos list

List of coordinates for each antenna, each entry in form [lat, lon, alt]

required
ant_idxs list

List of indicies of antenna that we wish to use. Some antenna may have corrupted data.

required
tle_path string

File path leading to TLE files, which contain satellite position information.

required
T_SPECTRA float

Period of spectrum, e.g. 1.04 ms for x64 upsampled baseband data

required
acclen int

Number of spectra to include in each visibility chunk

required

Returns:

Type Description
np.ndarray shape (nblines, ntimes, nchans)

Visibility Data.

func

func(x, data, freq, weights, fit_phi=False)

Get residuals for given tau at single time sample, for all blines

Parameters:

Name Type Description Default
x np.ndarray shape (nant-1)

The time offsets for each non-reference antenna

required
data np.ndarray shape (nblines, nchan)

Visibility data for single timestamp

required
freq np.npdarray shape (nchan)

Frequencies corresponding to each channel

required
weights np.npdarray shape (nblines)

Weights (from phase noise) for each baseline.

required
fit_phi bool

If you want to have an phase offset as well

False

Returns:

Name Type Description
np.ndarray shape (2*nblines*nchan)

Residuals with real and imaginary parts separated for fitting.

Notes
Reference antenna has zero delay, all other ants are with respect to it.
That's why tau_t has length nant-1.
Convention is reference - nonreference.
Weights can also be per-channel, so shape (nblines, nchan).

func2

func2(x, data, freq, weights, fit_phi=False)

Get residuals for given tau (and optionally phase offsets) at a single time sample.

Parameters:

Name Type Description Default
x ndarray

If fit_phi=False: x = tau, shape (nant-1,) If fit_phi=True: x = [tau, phi], shape (2*(nant-1),)

required
data ndarray

Visibility phases for a single timestamp, flattened to shape (nblines * nchan,).

required
freq ndarray

Frequencies corresponding to each channel.

required
weights ndarray

Baseline or baseline/channel weights.

required
fit_phi bool

Whether to fit a constant phase offset for each antenna.

False

Returns:

Type Description
ndarray

Residual vector with real and imaginary parts concatenated.

jac

jac(tau_t, data, freq, weights)

Get the Jacobian for given tau at single time sample, for all blines

Parameters:

Name Type Description Default
tau_t np.ndarray shape (nant-1)

Delays for each non-reference antenna

required
data np.npdarray shape (nblines, nchan)

Visibility data for single timestamp

required
freq np.npdarray shape (nchans)

Frequency values for each channel

required
weights

Weights for each baseline determined by phase noise.

required

Returns:

Type Description
np.npdarray shape (2*nblines*nchan, nant-1)

Jacobian of objective function at given tau values.

See also

helper_finetiming.func() The parent objective function.

jac2

jac2(x, data, freq, weights, fit_phi=False)

Jacobian for a single time sample.

Parameters:

Name Type Description Default
x ndarray

If fit_phi=False: x = tau, shape (nant-1,) If fit_phi=True: x = [tau, phi], shape (2*(nant-1),)

required

find_signal_channels

find_signal_channels(data, sat_type)

Cuts channels by taking median power in time. Isolates signal channels for later.

Parameters:

Name Type Description Default
data np.ndarray shape (nblines, ntimes, nchan)

Visibility data

required
sat_type str

Type of satellite (determines bandwidth)

required

Returns:

Type Description
slice

Slice of data array in channel axis, of corresponding bandwidth to sat_type

find_highest_amp

find_highest_amp(data, chan_slice, window_size=120)

Determine contiguous window of highest median SNR (in terms of amplitude).

Parameters:

Name Type Description Default
data np.ndarray shape (nblines, ntimes, nchans)

Visibility data

required
chan_slice slice

Slice along frequency axis where signal is found. Determined by find_signal_channels()

required
window_size int

Desired number of visibility times inside of which to maximize median SNR (amplitude)

120

Returns:

Type Description
(start, end)

Start and end indices of visibility times corresponding to optimal window

find_lowest_noise

find_lowest_noise(noise, window_size=120)

Determine continuous window of lowest median phase noise for multi-baseline visibility data.

Parameters:

Name Type Description Default
noise np.npdarray shape (nblines, ntimes)

Array of phase noise for all baselines at all times.

required
window_size int

Desired number of visibility times inside of which to minimize median phase noise.

120

Returns:

Type Description
(int, int)

The best starting and ending time indices (from array noise) Give window of size specified in window_size

discrep_cutting

discrep_cutting(V, satID, acclen=1024)

Full function that goes from beamformed visibilities to final amplitude cut

Eventually phase out.

cost_surface

cost_surface(data, guesses, freqs_normalized, wts, antidx=0, timeidx=0, N1=10001, N2=40, err=None)

Compute and plot the cost surface for func() given initial offsets, and a single antenna direction to vary.

Also includes: weightings, vertical line showing guess value, shaded region showing error on guess fit. Will also determine the offset value of the nearest cost minimum (trough).

Parameters:

Name Type Description Default
data np.ndarray shape (nblines, ntimes, nchans)

Visibility data

required
guesses np.ndarray shape (nant-1)

Offset values for each non-reference antenna (units of ns)

required
freqs_normalized np.ndarray shape (nchans)

Frequencies for each channel (units of GHz)

required
wts np.npdarray shape (nblines)

Weights corresponding to phase noise

required
antidx int

Antenna index for which we want to vary tau (the x-axis variable)

0
timeidx int

The timestamp for which we want to look at the data

0
N1 int

Number of data points to have in the figures

10001
N2 int

Units of tau (in ns) to zoom into, either side of the guess

40
err float

Error in the guess tau we want to plot (units of ns)

None

Returns:

Name Type Description
cost1 np.ndarray shape (N1)

Zoomed out cost surface

cost2 np.ndarray shape (N1)

Zoomed in cost surface.

trough float

Location of nearest cost minimum to guess value

fig matplotlib figure

Figure with zoomed out and zoomed in cost surfaces.

get_mask

get_mask(vis, tol=1.5)

get_thermal_noise

get_thermal_noise(vis, ant_idxs, mask=None, T_SPECTRA=4096 / 250000000.0 * 64, acclen=1024)

Computes thermal noise for visibility data, and also plots all visibility phase angles.

Parameters:

Name Type Description Default
vis np.npdarray shape (nblines, ntimes, nchans)

Visibiilty Data

required
ant_idxs list

Indices of antenna that we want to use

required
mask np.npdarray shape (nblines, ntimes, nchans)

Optional way to mask high noise regions out of the main data (RFI masking)

None
T_SPECTRA float

Single spectrum sampling period

4096 / 250000000.0 * 64
acclen int

Number of spectra in single visibility time sample

1024

Returns:

Name Type Description
thermal_noise np.npdarray shape (nblines, ntimes)

Phase noise for all blines and all times

fig matplotlib figure

Figure of all baseline visibility plots

get_prediction_error

get_prediction_error(res, spectra)

Get the error on the predicted UTC discrepancy given residual matrix

symmetrize

symmetrize(A)

Symmetrize a matrix

get_grammian

get_grammian(nant)

Determine grammian for nant anntena.

get_AtA_Atd

get_AtA_Atd(data, Ag, noise_var, nu, nant, nfreq, ntime, fit_constant=True)

Determine both A^T A and A^T d for OLS fitting.

Parameters:

Name Type Description Default
data np.ndarray shape (ntimes, nchans, nblines)

Data input. Different form than usual, as in column-major ordering

required
Ag

XXXX

required
noise_var

XXXX

required
nu

XXXX

required
nant int

Number of antenna in entire system (including reference antenna)

required
nfreqs int

Number of channels

required
ntime int

Number of time samples we are fitting over

required
fit_constant bool

XXXX

True

pfb_utils

StreamingPFB

StreamingPFB(nant, npol, timestream_size=50000, lblock=4096, ntap=4, window='hamming', dtype='float')

Works for arbitrary timestream sizes. Can be less than lblock.

StreamingPFB_

StreamingPFB_(nant, npol, timestream_size=50000, lblock=4096, ntap=4, window='hamming', dtype='float')

Works for arbitrary timestream sizes. Can be less than lblock.

cupy_ipfb

cupy_ipfb(dat, matft, thresh=0.0)

On-device ipfb. Expects the data to be iPFB'd to live in GPU memory.

Parameters:

Name Type Description Default
dat ndarray

nspec x nchan array of complex64

required
matft ndarray

lblock x nspec array of float32. Note that this is transpose of Jon's original convention for speed reasons. [w0 wN w2N w3N 0 0 . . . ][w1 . 0 0 ] [ . . . . ][wN-1 . . . w4N-1 . 0 ]

required
thresh float

Wiener filter threshold, by default 0.0

0.0

Returns:

Type Description
ndarray

nspec*nchan timestream values as a C-major matrix of shape (nspec x nchan)

math_utils