dsacalib package

Submodules

dsacalib.calib module

Functions for calibration of DSA-110 visibilities.

These functions use the CASA package casatools to calibrate visibilities stored as measurement sets.

Author: Dana Simard, dana.simard@astro.caltech.edu, 10/2019

dsacalib.calib.apply_and_correct_calibrations(msname, calibration_tables)

Applies and corrects calibration tables in an ms.

Parameters:
  • msname (str) – The measurement set filepath. Will open msname.ms.
  • calibration_tables (list) – Calibration tables to apply. Each entry is a dictionary containing the keywords ‘type’ (calibration type, e.g. ‘K’), ‘spwmap’ (spwmap for the calibration), and ‘table’ (full path to the calibration table).
Returns:

The number of errors that occured during calibration.

Return type:

int

dsacalib.calib.apply_calibration(msname, calname, msnamecal=None, combine_spw=False, nspw=1, blbased=False)

Applies the calibration solution.

Applies delay, bandpass and complex gain tables to a measurement set.

Parameters:
  • msname (str) – The name of the measurement set to apply calibration solutions to. Opens msname.ms
  • calname (str) – The name of the calibrator. Tables that start with msnamecal_`calname` will be applied to the measurement set.
  • msnamecal (str) – The name of the measurement set used to model the calibration solutions Calibration tables prefixed with msnamecal_`calname` will be opened and applied. If None, msnamecal is set to msname. Defaults to None.
  • combine_spw (bool) – Set to True if multi-spw ms and spws in the ms were combined before calibration.
  • nspw (int) – The number of spws in the ms.
  • blbased (bool) – Set to True if the calibration was baseline-based.
Returns:

The number of errors that occured during calibration.

Return type:

int

dsacalib.calib.apply_calibration_tables(cb, calibration_tables)

Applies calibration tables to an open calibrater object.

Parameters:
  • cb (cc.calibrater() instance) – Measurement set should be opened already.
  • calibration_tables (list) – Calibration tables to apply. Each entry is a dictionary containing the keywords ‘type’ (calibration type, e.g. ‘K’), ‘spwmap’ (spwmap for the calibration), and ‘table’ (full path to the calibration table).
Returns:

The number of errors that occured during calibration.

Return type:

int

dsacalib.calib.apply_delay_bp_cal(msname, calname, blbased=False, msnamecal=None, combine_spw=False, nspw=1)

Applies delay and bandpass calibration.

Parameters:
  • msname (str) – The name of the measurement set containing the visibilities. The measurement set msname.ms will be opened.
  • calname (str) – The name of the calibrator source used in calibration of the measurement set. The tables msname_`calname`_kcal and msnamecal_`calname`_bcal will be applied to the measurement set.
  • blbased (boolean) – Set to True if baseline-based calibration routines were done. Defaults False.
  • msnamecal (str) – The prefix of the measurement set used to derive the calibration solutions. If None, set to msname.
  • combine_spw (boolean) – Set to True if the spws were combined when deriving the solutions. Defaults False.
  • nspw (int) – The number of spws in the dataset. Only used if combine_spw is set to True. Defaults 1.
Returns:

The number of errors that occured during calibration.

Return type:

int

dsacalib.calib.calc_delays(vis, df, nfavg=5, tavg=True)

Calculates power as a function of delay from the visibilities.

This uses scipy fftpack to fourier transform the visibilities along the frequency axis. The power as a function of delay can then be used in fringe-fitting.

Parameters:
  • vis (ndarray) – The complex visibilities. 4 dimensions, (baseline, time, frequency, polarization).
  • df (float) – The width of the frequency channels in GHz.
  • nfavg (int) – The number of frequency channels to average by after the Fourier transform. Defaults to 5.
  • tavg (boolean) – If True, the visibilities are averaged in time before the Fourier transform. Defaults to True.
Returns:

  • vis_ft (ndarray) – The complex visibilities, Fourier-transformed along the time axis. 3 (or 4, if tavg is set to False) dimensions, (baseline, delay, polarization) (or (baseline, time, delay, polarization) if tavg is set to False).
  • delay_arr (ndarray) – Float, the values of the delay pixels in nanoseconds.

dsacalib.calib.calibrate_gain(msname, calname, caltable_prefix, refant, tga, tgp, blbased=False, combined=False)

Calculates gain calibration only.

Uses existing solutions for the delay and bandpass.

Parameters:
  • msname (str) – The name of the measurement set for gain calibration.
  • calname (str) – The name of the calibrator used in calibration.
  • caltable_prefix (str) – The prefix of the delay and bandpass tables to be applied.
  • refant (str) – The name of the reference antenna.
  • tga (str) – A casa-understood integration time for gain amplitude calibration.
  • tgp (str) – A casa-understood integration time for gain phase calibration.
  • blbased (boolean) – Set to True if using baseline-based calibration for gains. Defaults False.
  • combined (boolean) – Set to True if spectral windows are combined for calibration.
Returns:

The number of errors that occured during calibration.

Return type:

int

dsacalib.calib.calibrate_phases(filenames, refant, msdir='/mnt/data/dsa110/calibration/')

Calibrate phases only for a group of calibrator passes.

Parameters:
  • filenames (dict) – A dictionary containing information on the calibrator passes to be calibrated. Same format as dictionary returned by dsacalib.utils.get_filenames()
  • refant (str) – The reference antenna name to use. If int, will be interpreted as the reference antenna index instead.
  • msdir (str) – The full path to the measurement set, with the .ms extension omitted.
dsacalib.calib.delay_calibration(msname, sourcename, refant, t='inf', combine_spw=False)

Calibrates delays using CASA.

Uses CASA to calibrate delays and write the calibrated visibilities to the corrected_data column of the measurement set.

Parameters:
  • msname (str) – The name of the measurement set. The measurement set msname.ms will be opened.
  • sourcename (str) – The name of the calibrator source. The calibration table will be written to msname_`sourcename`_kcal.
  • refant (str) – The reference antenna to use in calibration. If type str, this is the name of the antenna. If type int, it is the index of the antenna in the measurement set.
  • t (str) – The integration time to use before calibrating, e.g. 'inf' or '60s'. See the CASA documentation for more examples. Defaults to 'inf' (averaging over the entire observation time).
  • combine_spw (boolean) – If True, distinct spws in the same ms will be combined before delay calibration.
Returns:

The number of errors that occured during calibration.

Return type:

int

dsacalib.calib.fill_antenna_gains(gains, flags=None)

Fills in the antenna gains for triple-antenna calibration.

Takes the gains from baseline-based calibration for a trio of antennas and calculates the corresponding antenna gains using products of the baseline gains. Also propagates flag information for the input baseline gains to the antenna gains.

Parameters:
  • gains (narray) – The complex gains matrix, first dimension is baseline. Indices 1, 2 and 4 contain the gains for the cross-correlations. Information in indices 0, 3 and 5 is ignored and overwritten.
  • flags (ndarray) – A boolean array, containing flag information for the gains array. 1 if the data is flagged, 0 otherwise. If None, assumes no flag information available. The first dimension is baseline. Indices 1, 2 and 4 contain the flags for the cross-correlations. Information in indices 0, 3 and 5 is ignored and overwritten.
Returns:

  • gains (ndarray) – The complex gains matrix, first dimension is baseline. Indices 1, 2 and 4 contain the gains for the cross-correlations. Indices 0, 3 and 5 contain the calculated values for the antennas.
  • flags (ndarray) – A boolean array, containing flag information for the gains array. 1 if the data is flagged, 0 otherwise. If None, assumes no flag information available. The first dimension is baseline. Indices 1, 2 and 4 contain the flags for the cross-correlations. Indices 0,3 and 5 contain the calculated values for the antennas.

dsacalib.calib.flag_antenna(msname, antenna, datacolumn='data', pol=None)

Flags an antenna in a measurement set using CASA.

Parameters:
  • msname (str) – The name of the measurement set. The MS msname.ms will be opened.
  • antenna (str) – The antenna to flag. If type str, this is the name of the antenna. If type int, the index of the antenna in the measurement set.
  • datacolumn (str) – The column of the measurement set to flag. Options are 'data', 'model', 'corrected' for the uncalibrated visibilities, the visibility model (used by CASA to calculate calibration solutions), the calibrated visibilities. Defaults to 'data'.
  • pol (str) – The polarization to flag. Must be ‘A’ (which is mapped to polarization ‘XX’ of the CASA measurement set) or ‘B’ (mapped to polarization ‘YY’). Can also be None, for which both polarizations are flagged. Defaults to None.
Returns:

The number of errors that occured during flagging.

Return type:

int

dsacalib.calib.flag_badtimes(msname, times, bad, nant, datacolumn='data', verbose=False)

Flags bad time bins for each antenna in a measurement set using CASA.

Could use some work to select antennas to flag in a smarter way.

Parameters:
  • msname (str) – The name of the measurement set. The MS msname.ms will be opened.
  • times (ndarray) – A 1-D array of times, type float, seconds since MJD=0. Times should be equally spaced and cover the entire time range of the measurement set, but can be coarser than the resolution of the measurement set.
  • bad (ndarray) – A 1-D boolean array with dimensions (len(times), nant). Should have a value of True if the corresponding timebins should be flagged.
  • nant (int) – The number of antennas in the measurement set (includes ones not in the visibilities).
  • datacolumn (str) – The column of the measurement set to flag. Options are 'data', 'model', 'corrected' for the uncalibrated visibilities, the visibility model (used by CASA to calculate calibration solutions), the calibrated visibilities. Defaults to 'data'.
  • verbose (boolean) – If True, will print information about the antenna/time pairs being flagged. Defaults to False.
Returns:

The number of errors that occured during flagging.

Return type:

int

dsacalib.calib.flag_baselines(msname, datacolumn='data', uvrange='2~15m')

Flags an antenna in a measurement set using CASA.

Parameters:
  • msname (str) – The name of the measurement set. The MS msname.ms will be opened.
  • datacolumn (str) – The column of the measurement set to flag. Options are 'data', 'model', 'corrected' for the uncalibrated visibilities, the visibility model (used by CASA to calculate calibration solutions), the calibrated visibilities. Defaults to 'data'.
  • uvrange (str) – The uvrange to flag. Should be CASA-interpretable.
Returns:

The number of errors that occured during flagging.

Return type:

int

dsacalib.calib.flag_manual(msname, key, value, datacolumn='data', pol=None)

Flags a measurement set in CASA using a flagging string.

Parameters:
  • msname (str) – The name of the measurement set. The MS msname.ms will be opened.
  • key (str) – The CASA-interpreted flagging specifier.
  • datacolumn (str) – The column of the measurement set to flag. Options are 'data', 'model', 'corrected' for the uncalibrated visibilities, the visibility model (used by CASA to calculate calibration solutions), the calibrated visibilities. Defaults to 'data'.
  • pol (str) – The polarization to flag. Must be ‘A’ (which is mapped to polarization ‘XX’ of the CASA measurement set) or ‘B’ (mapped to polarization ‘YY’). Can also be None, for which both polarizations are flagged. Defaults to None.
Returns:

The number of errors that occured during flagging.

Return type:

int

dsacalib.calib.flag_zeros(msname, datacolumn='data')

Flags all zeros in a measurement set.

Parameters:
  • msname (str) – The name of the measurement set. The MS msname.ms will be opened.
  • datacolumn (str) – The column of the measurement set to flag. Options are 'data', 'model', 'corrected' for the uncalibrated visibilities, the visibility model (used by CASA to calculate calibration solutions), the calibrated visibilities. Defaults to 'data'.
Returns:

The number of errors that occured during flagging.

Return type:

int

dsacalib.calib.gain_calibration(msname, sourcename, refant, blbased=False, forsystemhealth=False, keepdelays=False, tbeam='30s', interp_thresh=1.5, interp_polyorder=7)

Use CASA to calculate bandpass and complex gain solutions.

Saves solutions to calibration tables and calibrates the measurement set by applying delay, bandpass, and complex gain solutions. Uses baseline-based calibration routines within CASA.

Parameters:
  • msname (str) – The name of the measurement set. The MS msname.ms will be opened.
  • sourcename (str) – The name of the calibrator source. The calibration table will be written to msname_`sourcename`_kcal.
  • refant (str) – The reference antenna to use in calibration. If type str, this is the name of the antenna. If type int, it is the index of the antenna in the measurement set.
  • blbased (boolean) – Set to True if baseline-based calibration desired.
  • forsystemhealth (boolean) – Set to True if gain calibration is for system health monitoring. Delays will be kept at full resolution. If set to False, then at least some of the delay will be incorporated into the bandpass gain table.
  • keepdelays (boolean) – Set to True if you want to update the delays currently set in the system. In this case, delay changes of integer 2 ns will be kept in the delay calibration table, and residual delays will be incorporated into the bandpass gain table. If set to False, all of the delay will be incorporated into the bandpass gain table.
  • tbeam (str) – The integration time to use when measuring gain variations over time, e.g. 'inf' or '60s'. See the CASA documentation for more examples.
  • interp_thresh (float) – Sets flagging of bandpass solutions before interpolating in order to smooth the solutions. After median baselining, any points that deviate by more than interp_thresh*std are flagged.
  • interp_polyorder (int) – The order of the polynomial used to smooth bandpass solutions.
Returns:

The number of errors that occured during calibration.

Return type:

int

dsacalib.calib.get_bad_times(msname, sourcename, refant, tint='59s', combine_spw=False, nspw=1)

Flags bad times in the calibrator data.

Calculates delays on short time periods and compares them to the delay calibration solution. Can only be run after delay calibration.

Parameters:
  • msname (str) – The name of the measurement set. The MS msname.ms will be opened.
  • sourcename (str) – The name of the calibrator source. The calibration table will be written to msname_`sourcename`_kcal.
  • refant (str) – The reference antenna to use in calibration. If type str, the name of the reference antenna, if type int, the index of the antenna in the CASA measurement set. This must be the same as the reference antenna used in the delay calibration, or unexpected errors may occur.
  • tint (str) – The timescale on which to calculate the delay solutions (and evaluate the data quality). Must be a CASA-interpreted string, e.g. 'inf' (average all of the data) or '60s' (average data to 60-second bins before delay calibration). Defaults to '59s'.
  • combine_spw (bool) – Set to True if the spws were combined before delay calibration.
  • nspw (int) – The number of spws in the measurement set.
Returns:

  • bad_times (array) – Booleans, True if the data quality is poor and the time-bin should be flagged, False otherwise. Same dimensions as times.
  • times (array) – Floats, the time (mjd) for each delay solution.
  • error (int) – The number of errors that occured during calibration.

dsacalib.calib.interpolate_bandpass_solutions(msname, calname, thresh=1.5, polyorder=7, mode='ap')

Interpolates bandpass solutions.

Parameters:
  • msname (str) – The measurement set filepath (with the .ms extension omitted).
  • calname (str) – The name of the calibrator source. Calibration tables starting with msname_`calname` will be opened.
  • thresh (float) – Sets flagging of bandpass solutions before interpolating in order to smooth the solutions. After median baselining, any points that deviate by more than interp_thresh*std are flagged.
  • polyorder (int) – The order of the polynomial used to smooth bandpass solutions.
  • mode (str) – The bandpass calibration mode. Must be one of “a”, “p” or “ap”.
dsacalib.calib.reset_flags(msname, datacolumn=None)

Resets all flags in a measurement set, so that all data is unflagged.

Parameters:
  • msname (str) – The name of the measurement set. The MS msname.ms will be opened.
  • datacolumn (str) – The column of the measurement set to flag. Options are 'data', 'model', 'corrected' for the uncalibrated visibilities, the visibility model (used by CASA to calculate calibration solutions), the calibrated visibilities. Defaults to 'data'.
Returns:

The number of errors that occured during flagging.

Return type:

int

dsacalib.constants module

Constants used in the calibration of DSA-110 visibilities.

Author: Dana Simard, dana.simard@astro.caltech.edu, 10/2019

dsacalib.fits_io module

DSACALIB/FITS_IO.PY

Dana Simard, dana.simard@astro.caltech.edu, 10/2019

Modified for python3 from DSA-10 routines written by Vikram Ravi, Harish Vendantham.

Routines to interact w/ fits visibilities recorded by DSA-10.

dsacalib.fits_io.extract_vis_from_psrfits(f, lstmid, seg_len, antenna_order, mjd0, mjd1, quiet=True)

Extracts visibilities from a fits file.

Based on clip.extract_segment from DSA-10 routines.

Parameters:
  • f (pyfits table handle) – The fits file containing the visibilities.
  • lstmid (float) – The LST around which to extract visibilities, in radians.
  • seg_len (float) – The duration (in LST) of visibilities to extract, in radians.
  • antenna_order (list) – The order of the antennas in the correlator.
  • mjd0 (float) – The start time of the file in MJD.
  • mjd1 (float) – The stop time of the file in MJD.
  • quiet (boolean) – If set to False, information on the file will be printed. Defaults True.
Returns:

  • vis (ndarray) – The requested visibilities, dimensions (baselines, time, frequency).
  • lst (array) – The lst of each integration in the visibilities, in radians.
  • mjd (array) – The midpoint mjd of each integration in the visibilities.
  • idxmid (int) – The index along the time axis corresponding to the lstmid. (i.e the index corresponding to the meridian transit of the source.)

dsacalib.fits_io.get_header_info(f, antpos=None, verbose=False, antenna_order=None, dsa10=True)

Extracts important header info from a visibility fits file.

Parameters:
  • f (pyfits table handle) – The visibility data from the correlator.
  • antpos (str) – The path to the text file containing the antenna positions. Defaults dsacalib.constants.PKG_DATA_PATH.
  • verbose (boolean) – If True, information on the fits file is printed to stdout.
  • antenna_order (list) – The order of the antennas in the correlator. Required if dsa10 is set to False. Defaults None.
  • dsa10 (Boolean) – Set to True if the fits file is in dsa10 correlator format, False if the file is in 6-input correlator format.
Returns:

  • nchan (int) – The number of frequency channels.
  • fobs (array) – The midpoint frequency of each channel in GHz.
  • nt (int) – The number of time subintegrations.
  • blen (ndarray) – The ITRF coordinates of the baselines, shape (nbaselines, 3).
  • bname (list) – The station pairs for each baseline (in the same order as blen), shape (nbaselines, 2).
  • tstart (float) – The start time. If dsa10 is set to True, tstart is the start time in MJD. If dsa10 is set to False, tstart is the start time in seconds past the utc start time of the correlator run.
  • tstop (float) – The stop time. If dsa10 is set to True, tstart is the stop time in MJD. If dsa10 is set to False, tstart is the stop time in seconds past the utc start time of the correlator run.
  • tsamp (float) – The sampling time in seconds.
  • aname (list) – The antenna names, in the order they are in in the visibilities.

dsacalib.fits_io.read_psrfits_file(fl, source, dur=<Quantity 50. min>, antenna_order=None, antpos=None, utc_start=None, autocorrs=False, badants=None, quiet=True, dsa10=True)

Reads in the psrfits header and data.

Parameters:
  • fl (str) – The full path to the psrfits file.
  • source (src class instance) – The source to retrieve data for.
  • dur (astropy quantity in minutes or equivalent) – The amount of time to extract around the source meridian passing. Defaults 50*u.min.
  • antenna_order (list) – The order of the antennas in the correlator. Only used if dsa10 is set to False. Defaults None.
  • antpos (str) – The full path of the text file containing the antenna ITRF positions. Defaults dsacalib.constants.PKG_DATA_PATH/antpos_ITRF.txt.
  • utc_start (astropy time object) – The start time of the observation in UTC. Only used if dsa10 is set to False. Defaults None.
  • autocorrs (boolean) – If set to True, both auto and cross correlations will be returned. If set to False, only the cross correlations will be returned. Defaults False.
  • badants (list(int)) – The antennas for which you do not want data to be returned. If set to None, all antennas are returned. Defaults None.
  • quiet (boolean) – If set to True, infromation on the file printed to stdout.
  • dsa10 (boolean) – If set to True, assumes fits file is in dsa10 format, otherwise assumes fits file is in the 3-antenna correlator output format. Defaults True.
Returns:

  • fobs (array) – The frequency of the channels in GHz.
  • blen (array) – The itrf coordinates of the baselines, shape (nbaselines, 3).
  • bname (list) – The station pairs for each baseline (in the same order as blen). Shape (nbaselines, 2).
  • tstart (float) – The start time of the extracted data in MJD.
  • tstop (float) – The stop time of the extracted data in MJD.
  • tsamp (float) – The sampling time in seconds.
  • vis (ndarray) – The requested visibilities, dimensions (baseline, time, frequency, polarization).
  • mjd (array) – The midpoint MJD of each subintegration in the visibilities.
  • lst (array) – The midpoint LST of each subintegration in the visibilities.
  • transit_idx (int) – The index of the meridian passing in the time axis of the visibilities.
  • antenna_order (list) – The antenna indices, in the order that they are in in the visibilities.

dsacalib.fringestopping module

Functions used in fringestopping of DSA-110 visibilities.

Author: Dana Simard, dana.simard@astro.caltech.edu 11/2019

These functions use casatools to build sky models, divide visibilities by sky models, and fringestop visibilities.

dsacalib.fringestopping.amplitude_sky_model(source, ant_ra, pt_dec, fobs, dish_dia=4.65, spind=0.7)

Computes the amplitude sky model due to the primary beam.

Computes the amplitude sky model for a single source due to the primary beam response of an antenna.

Parameters:
  • source (src class instance) – The source to model. The source flux (src.I), right ascension (src.ra) and declination (src.dec) must be specified.
  • ant_ra (ndarray) – The right ascension pointing of the antenna in each time bin of the observation, in radians. If az=0 deg or az=180 deg, this is the lst of each time bin in the observation in radians.
  • pt_dec (float) – The pointing declination of the observation in radians.
  • fobs (array) – The observing frequency of the center of each channel in GHz.
  • dish_dia (float) – The dish diameter in m. Defaults 4.65.
  • spind (float) – The spectral index of the source. Defaults 0.7.
Returns:

The calculated amplitude sky model.

Return type:

ndarray

dsacalib.fringestopping.calc_uvw(blen, tobs, src_epoch, src_lon, src_lat, obs='OVRO_MMA')

Calculates uvw coordinates.

Uses CASA to calculate the u,v,w coordinates of the baselines b towards a source or phase center (specified by src_epoch, src_lon and src_lat) at the specified time and observatory.

Parameters:
  • blen (ndarray) – The ITRF coordinates of the baselines. Type float, shape (nbaselines, 3), units of meters.
  • tobs (ndarray) – An array of floats, the times in MJD for which to calculate the uvw coordinates.
  • src_epoch (str) – The epoch of the source or phase-center, as a CASA-recognized string e.g. 'J2000' or 'HADEC'
  • src_lon (astropy quantity) – The longitude of the source or phase-center, in degrees or an equivalent unit.
  • src_lat (astropy quantity) – The latitude of the source or phase-center, in degrees or an equivalent unit.
  • obs (string) – The name of the observatory in CASA.
Returns:

  • bu (ndarray) – The u-value for each time and baseline, in meters. Shape is (len(b), len(tobs)).
  • bv (ndarray) – The v-value for each time and baseline, in meters. Shape is (len(b), len(tobs)).
  • bw (ndarray) – The w-value for each time and baseline, in meters. Shape is (len(b), len(tobs)).

dsacalib.fringestopping.complex_sky_model(source, ant_ra, pt_dec, fobs, tobs, blen, dish_dia=4.65, spind=0.7, pointing_ra=None)

Computes the complex sky model, taking into account pointing errors.

Use when the pointing error is large enough to introduce a phase error in the visibilities if not properly accounted for.

Parameters:
  • source (src class instance) – The source to model. The source flux (src.I), right ascension (src.ra) and declination (src.dec) must be specified.
  • ant_ra (ndarray) – The right ascension pointing of the antenna in each time bin of the observation, in radians. If az=0 deg or az=180 deg, this is the lst of each time bin in the observation in radians.
  • pt_dec (float) – The pointing declination of the observation in radians.
  • fobs (array) – The observing frequency of the center of each channel in GHz.
  • tobs (array) – The observing time of the center of each timebin in MJD.
  • blen (ndarray) – The ITRF dimensions of each baseline, in m.
  • dish_dia (float) – The dish diameter in m. Defaults 4.65.
  • spind (float) – The spectral index of the source. Defaults 0.7.
  • pt_ra (float) – The pointing (either physically or through fringestopping) right ascension in radians. If None, defaults to the pointing of the antenna, ant_ra. In other words, assumes fringestopping on the meridian.
Returns:

The calculated complex sky model.

Return type:

ndarray

dsacalib.fringestopping.divide_visibility_sky_model(vis, blen, sources, tobs, fobs, lst, pt_dec, return_model=False)

Calculates and applies the sky model visibilities.

Calculates the sky model visibilities on the baselines blen and at times tobs. Divides the input visibilities, vis, by the sky model. vis is modified in-place.

Parameters:
  • vis (ndarray) – The observed complex visibilities, with dimensions (baselines, time, frequency, polarization). vis will be updated in place to the fringe-stopped visibilities
  • blen (ndarray) – The baselines for which to calculate visibilities, shape (nbaselines, 3), units of meters in ITRF coords.
  • sources (list(src class objects)) – The list of sources to include in the sky model.
  • tobs (float or ndarray) – The times for which to calculate the visibility model in MJD.
  • fobs (float or arr(float)) – The frequency for which to calculate the model in GHz.
  • lst (fload or ndarray) – The lsts at which to calculate the visibility model.
  • pt_dec (float) – The pointing declination in radians.
  • return_model (boolean) – If set to True, the visibility model will be returned. Defaults to False.
Returns:

vis_model – The modelled visibilities, dimensions (baselines, time, frequency, polarization). Returned only if return_model is set to True.

Return type:

ndarray

dsacalib.fringestopping.fringestop(vis, blen, source, tobs, fobs, pt_dec, return_model=False)

Fringestops on a source.

Fringestops on a source (or sky position) by dividing the input visibilities by a phase only model. The input visibilities, vis, are modified in place.

Parameters:
  • vis (ndarray) – The visibilities t be fringestopped, with dimensions (baselines, time, freq, pol). vis is modified in place.
  • blen (ndarray) – The ITRF coordinates of the baselines in meters, with dimensions (3, baselines).
  • source (src class instance) – The source to fringestop on.
  • tobs (ndarray) – The observation time (the center of each bin) in MJD.
  • fobs (ndarray) – The observing frequency (the center of each bin) in GHz.
  • pt_dec (float) – The pointing declination of the array, in radians.
  • return_model (boolean) – If True, the fringestopping model is returned. Defaults False.
Returns:

vis_model – The phase-only visibility model by which the visiblities were divided. Returned only if return_model is set to True.

Return type:

ndarray

dsacalib.fringestopping.pb_resp(ant_ra, ant_dec, src_ra, src_dec, freq, dish_dia=4.34)

Computes the primary beam response towards a direction on the sky.

Assumes tapered illumination of the disk. Returns a value between 0 and 1 for each value passed in ant_ra.

Parameters:
  • ant_ra (float or ndarray) – The antenna right ascension pointing in radians. If an array, must be one-dimensional.
  • ant_dec (float) – The antenna declination pointing in radians.
  • src_ra (float) – The source right ascension in radians.
  • src_dec (float) – The source declination in radians.
  • freq (ndarray) – The frequency of each channel in GHz.
  • dish_dia (float) – The dish diameter in meters. Defaults to 4.65.
Returns:

pb – The primary beam response, dimensions (ant_ra, freq) if an array is passed to ant_ra, or (freq) if a float is passed to ant_ra.

Return type:

ndarray

dsacalib.fringestopping.pb_resp_uniform_ill(ant_ra, ant_dec, src_ra, src_dec, freq, dish_dia=4.65)

Computes the primary beam response towards a direction on the sky.

Assumes uniform illumination of the disk. Returns a value between 0 and 1 for each value passed in ant_ra.

Parameters:
  • ant_ra (float or ndarray) – The antenna right ascension pointing in radians. If an array, must be one-dimensional.
  • ant_dec (float) – The antenna declination pointing in radians.
  • src_ra (float) – The source right ascension in radians.
  • src_dec (float) – The source declination in radians.
  • freq (ndarray) – The frequency of each channel in GHz.
  • dish_dia (float) – The dish diameter in meters. Defaults to 4.65.
Returns:

pb – The primary beam response, dimensions (ant_ra, freq).

Return type:

ndarray

dsacalib.fringestopping.set_dimensions(fobs=None, tobs=None, blen=None)

Sets the dimensions of arrays for fringestopping.

Ensures that fobs, tobs and blen are ndarrays with the correct dimensions for fringestopping using jit. Any combination of these arrays may be passed. If no arrays are passed, an empty list is returned

Parameters:
  • fobs (float or ndarray) – The central frequency of each channel in GHz. Defaults None.
  • tobs (float or ndarray) – The central time of each subintegration in MJD. Defaults None.
  • blen (ndarray) – The baselines in ITRF coordinates with dimensions (nbaselines, 3) or (3) if a single baseline. Defaults None.
Returns:

A list of the arrays passed, altered to contain the correct dimensions for fringestopping. The list may contain:

fobs
: ndarray

The central frequency of each channel in GHz with dimensions (channels, 1). Included if fobs is not set to None.

tobs
: ndarray

The central time of each subintegration in MJD with dimensions (time). Included if tobs is not set to None.

b
: ndarray

The baselines in ITRF coordaintes with dimensions (baselines, 3) or (1, 3) if a single baseline. Included if b is not set to None.

Return type:

list

dsacalib.fringestopping.visibility_sky_model(vis_shape, vis_dtype, blen, sources, tobs, fobs, lst, pt_dec)

Calculates the sky model visibilities.

Calculates the sky model visibilities on the baselines b and at times tobs. Ensures that the returned sky model is the same datatype and the same shape as specified by vis_shape and vis_dtype to ensure compatability with jit.

Parameters:
  • vis_shape (tuple) – The shape of the visibilities: (baselines, time, frequency, polarization).
  • vis_dtype (numpy datatype) – The datatype of the visibilities.
  • blen (real array) – The baselines to calculate visibilities for, shape (nbaselines, 3), units of meters in ITRF coords.
  • sources (list(src class instances)) – The sources to include in the sky model.
  • tobs (float or ndarray) – The times at which to calculate the visibility model, in MJD.
  • fobs (float or ndarray) – The frequencies at which to calculate the visibility model, in GHz.
  • lst (ndarray) – The local sidereal time in radians for each time in tobs.
  • pt_dec (float) – The antenna pointing declination in radians.
Returns:

vis_model – The modelled complex visibilities, dimensions (directions, baselines, time, frequency, polarization).

Return type:

ndarray

dsacalib.fringestopping.visibility_sky_model_worker

Builds complex sky models.

This is a worker to contain the for loop in the visibility model calculation using jit. Modifies the input array vis_model in place.

Parameters:
  • vis_model (ndarray) – A placeholder for the output. A complex array initialized to zeros, with the same shape as the array of visibilities you wish to model. Dimensions (baseline, time, freq, polarization).
  • bws (ndarray) – The w component of the baselines towards the phase-center or towards each source in the sky model. Dimensions (sources,baselines).
  • famps (ndarray) – The flux of each source at the reference frequency, in Jy.
  • f0 (float) – The reference frequency, in GHz.
  • spec_idx (float) – The spectral index for the frequency dependence of the source flux.
  • fobs (ndarray) – The central frequency of each channel of the visibilities, in GHz.

dsacalib.hdf5_io module

DSACALIB/HDF5_UTILS.PY

Dana Simard, dana.simard@astro.caltech.edu, 10/2019

Routines to interact w/ hdf5 visibilities recorded by DSA-110.

dsacalib.hdf5_io.initialize_hdf5_file(fhdf, fobs, antenna_order, t0, nbls, nchan, npol, nant)

Initializes the hdf5 file for the fringestopped visibilities.

Parameters:
  • fhdf (hdf5 file handler) – The file to initialize.
  • fobs (array) – The center frequency of each channel in GHz.
  • antenna_order (array) – The order of the antennas in the correlator.
  • t0 (float) – The time of the first subintegration in MJ seconds.
  • nbls (int) – The number of baselines in the visibilities.
  • nchan (int) – The number of channels in the visibilities.
  • npol (int) – The number of polarizations in the visibilities.
  • nant (int) – The number of antennas in the visibilities.
Returns:

  • vis_ds (hdf5 dataset) – The dataset for the visibilities.
  • t_ds (hdf5 dataset) – The dataset for the times.

dsacalib.hdf5_io.read_hdf5_file(fl, source=None, dur=<Quantity 50. min>, autocorrs=True, badants=None, quiet=True)

Reads visibilities from a hdf5 file written by dsa110-fringestopping.

Parameters:
  • fl (str) – Full path to the hdf5 file.
  • source (source instance) – The source to extract from the hdf5 file. If set to None, the entire file is extracted. Defaults None.
  • dur (astropy quantity) – The duration of the observation to extract, in minutes or an equivalent unit. Only used if source is not set to None. Defaults 50*u.min.
  • autocorrs (Boolean) – If set to True, both the autocorrelations and the crosscorrelations are extracted from the hdf5 file. If set to False, only the crosscorrelations are extracted. Defaults True.
  • badants (list) – Antennas that have been flagged as bad or offline. If provied, baselines that include these antennas will not be extracted. If set to None, all baselines in the hdf5 file are extracted. Defaults None.
  • quiet (Boolean) – If set to False, information about the file will be printed to stdout. Defaults True.
Returns:

  • fobs (array) – The observing frequency of the center of each channel in the visibilities, in GHz.
  • blen (ndarray) – The ITRF baseline lengths, dimensions (nbaselines, 3).
  • bname (list(str)) – The name of each baseline.
  • tstart (float) – The start time of the extracted visibilities in MJD. If the data does not contain the specified source, a value of None is returned.
  • tstop (float) – The stop time of the extracted visibilities in MJD. If the data does not contain the specified source, a value of None is returned.
  • vis (ndarray) – The extracted visibilities, dimensions (baselines, time, frequency, polarization).
  • mjd (array) – The time of the center of each timebin in the visibilities, in MJD.
  • transit_idx (int) – The index along the time axis corresponding to the meridian crossing of the source given by source. If source is set to None, a value of None is returned.
  • antenna_order (list) – The antenna names, in the order they are in in the hdf5 visibilities.
  • tsamp (float) – The sampling time in seconds.

dsacalib.ms_io module

DSACALIB/MS_IO.PY

Dana Simard, dana.simard@astro.caltech.edu, 10/2019

Routines to interact with CASA measurement sets and calibration tables.

dsacalib.ms_io.T3_initialize_ms(paramfile, msname, tstart, sourcename, ra, dec)

Initialize a ms to write correlated data from the T3 system to.

Parameters:
  • paramfile (str) – The full path to a yaml parameter file. See package data for a template.
  • msname (str) – The name of the measurement set. Will write to msdir/msname.ms. msdir is defined in paramfile.
  • tstart (astropy.time.Time object) – The start time of the observation.
  • sourcename (str) – The name of the source or field.
  • ra (astropy quantity) – The right ascension of the pointing, units deg or equivalent.
  • dec (astropy quantity) – The declination of the pointing, units deg or equivalent.
dsacalib.ms_io.average_beamformer_solutions(fnames, ttime, outdir, corridxs=None)

Averages written beamformer solutions.

Parameters:
  • fnames (list) –
  • ttime (astropy.time.Time object) – A time to use in the filename of the solutions, indicating when they were written or are useful. E.g. the transit time of the most recent source being averaged over.
  • outdir (str) – The directory in which the beamformer solutions are written, and into which new solutions should be written.
  • corridxs (list) – The correlator nodes for which to average beamformer solutions. Defaults to 1 through 16 inclusive.
Returns:

The names of the written beamformer solutions (one for each correlator node).

Return type:

list

dsacalib.ms_io.caltable_to_etcd(msname, calname, caltime, status, pols=None)

Copies calibration values from delay and gain tables to etcd.

The dictionary passed to etcd should look like: {“ant_num”: <i>, “time”: <d>, “pol”, [<s>, <s>], “gainamp”: [<d>, <d>], “gainphase”: [<d>, <d>], “delay”: [<i>, <i>], “calsource”: <s>, “gaincaltime_offset”: <d>, “delaycaltime_offset”: <d>, ‘sim’: <b>, ‘status’: <i>}

Parameters:
  • msname (str) – The measurement set name, will use solutions created from the measurement set msname.ms.
  • calname (str) – The calibrator name. Will open the calibration tables msname_`calname`_kcal and msname_`calname`_gcal_ant.
  • caltime (float) – The time of calibration transit in mjd.
  • status (int) – The status of the calibration. Decode with dsautils.calstatus.
  • pols (list) – The names of the polarizations. If None, will be set to ['B', 'A']. Defaults None.
dsacalib.ms_io.convert_calibrator_pass_to_ms(cal, date, files, duration, msdir='/mnt/data/dsa110/calibration/', hdf5dir='/mnt/data/dsa110/correlator/')

Converts hdf5 files near a calibrator pass to a CASA ms.

Parameters:
  • cal (dsacalib.utils.src instance) – The calibrator source.
  • date (str) – The date (to day precision) of the calibrator pass. e.g. ‘2020-10-06’.
  • files (list) – The hdf5 filenames corresponding to the calibrator pass. These should be date strings to second precision. e.g. [‘2020-10-06T12:35:04’, ‘2020-10-06T12:50:04’] One ms will be written per filename in files. If the length of files is greater than 1, the mss created will be virtualconcated into a single ms.
  • duration (astropy quantity) – Amount of data to extract, unit minutes or equivalent.
  • msdir (str) – The full path to the directory to place the measurement set in. The ms will be written to msdir/date_`cal.name`.ms
dsacalib.ms_io.convert_to_ms(source, vis, obstm, ofile, bname, antenna_order, tsamp=9.663676416000001, nint=1, antpos=None, model=None, dt=0.00042824074625968933, dsa10=True)

Writes visibilities to an ms.

Uses the casa simulator tool to write the metadata to an ms, then uses the casa ms tool to replace the visibilities with the observed data.

Parameters:
  • source (source class instance) – The calibrator (or position) used for fringestopping.
  • vis (ndarray) – The complex visibilities, dimensions (baseline, time, channel, polarization).
  • obstm (float) – The start time of the observation in MJD.
  • ofile (str) – The name for the created ms. Writes to ofile.ms.
  • bname (list) – The list of baselines names in the form [[ant1, ant2],...].
  • antenna_order (list) – The list of the antennas, in CASA ordering.
  • tsamp (float) – The sampling time of the input visibilities in seconds. Defaults to the value tsamp`*`nint as defined in dsacalib.constants.
  • nint (int) – The number of time bins to integrate by before saving to a measurement set. Defaults 1.
  • antpos (str) – The full path to the text file containing ITRF antenna positions or the csv file containing the station positions in longitude and latitude. Defaults dsacalib.constants.PKG_DATA_PATH/antpos_ITRF.txt.
  • model (ndarray) – The visibility model to write to the measurement set (and against which gain calibration will be done). Must have the same shape as the visibilities vis. If given a value of None, an array of ones will be used as the model. Defaults None.
  • dt (float) – The offset between the CASA start time and the data start time in days. Defaults to the value of casa_time_offset in dsacalib.constants.
  • dsa10 (boolean) – Set to True if the data are from the dsa10 correlator. Defaults True.
dsacalib.ms_io.extract_times(UV, ra, dt)

Extracts data from specified times from an already open UVData instance.

This is an alternative to opening the file with the times specified using pyuvdata.UVData.open().

Parameters:
  • UV (pyuvdata.UVData() instance) – The UVData instance from which to extract data. Modified in-place.
  • ra (float) – The ra of the source around which to extract data, in radians.
  • dt (astropy quantity) – The amount of data to extract, units seconds or equivalent.
dsacalib.ms_io.extract_vis_from_ms(msname, data='data')

Extracts visibilities from a CASA measurement set.

Parameters:
  • msname (str) – The measurement set. Opens msname.ms
  • data (str) – The visibilities to extract. Can be data, model or corrected.
Returns:

  • vals (ndarray) – The visibilities, dimensions (baseline, time, spw, freq, pol).
  • time (array) – The time of each integration in days.
  • fobs (array) – The frequency of each channel in GHz.
  • flags (ndarray) – Flags for the visibilities, same shape as vals. True if flagged.
  • ant1, ant2 (array) – The antenna indices for each baselines in the visibilities.
  • pt_dec (float) – The pointing declination of the array. (Note: Not the phase center, but the physical pointing of the antennas.)

dsacalib.ms_io.get_antenna_gains(gains, ant1, ant2, refant=0)

Calculates antenna gains, g_i, from CASA table of G_ij=g_i g_j*.

Currently does not support baseline-based gains. Refant only used for baseline-based case.

Parameters:
  • gains (ndarray) – The gains read in from the CASA gain table. 0th axis is baseline or antenna.
  • ant2 (ant1,) – The antenna pair for each entry along the 0th axis in gains.
  • refant (int) – The reference antenna index to use to get antenna gains from baseline gains.
Returns:

  • antennas (ndarray) – The antenna indices.
  • antenna_gains (ndarray) – Gains for each antenna in antennas.

dsacalib.ms_io.get_delays(antennas, msname, calname, applied_delays)

Returns the delays to be set in the correlator.

Based on the calibrated delays and the currently applied delays.

Parameters:
  • antennas (list) – The antennas to get delays for.
  • msname (str) – The path to the measurement set containing the calibrator pass.
  • calname (str) – The name of the calibrator. Will open msname_`calname`_kcal.
  • applied_delays (ndarray) – The currently applied delays for every antenna/polarization, in ns. Dimensions (antenna, pol).
Returns:

  • delays (ndarray) – The delays to be applied for every antenna/polarization in ns. Dimensions (antenna, pol).
  • flags (ndarray) – True if that antenna/pol data is flagged in the calibration table. In this case, the delay should be set to 0. Dimensions (antenna, pol).

dsacalib.ms_io.read_caltable(tablename, cparam=False)

Requires that each spw has the same number of frequency channels.

Parameters:
  • tablename (str) – The full path to the calibration table.
  • cparam (bool) – If True, reads the column CPARAM in the calibrtion table. Otherwise reads FPARAM.
Returns:

  • vals (ndarray) – The visibilities, dimensions (baseline, time, spw, freq, pol).
  • time (array) – The time of each integration in days.
  • flags (ndarray) – Flags for the visibilities, same shape as vals. True if flagged.
  • ant1, ant2 (array) – The antenna indices for each baselines in the visibilities.

dsacalib.ms_io.reshape_calibration_data(vals, flags, ant1, ant2, baseline, time, spw)

Reshape calibration or measurement set data.

Reshapes the 0th axis of the input data vals and flags from a combined (baseline-time-spw) axis into 3 axes (baseline, time, spw).

Parameters:
  • vals (ndarray) – The input values, shape (baseline-time-spw, freq, pol).
  • flags (ndarray) – Flag array, same shape as vals.
  • ant2 (ant1,) – The antennas in the baseline, same length as the 0th axis of vals.
  • baseline (array) – The baseline index, same length as the 0th axis of vals.
  • time (array) – The time of each integration, same length as the 0th axis of vals.
  • spw (array) – The spectral window index of each integration, same length as the 0th axis of vals.
Returns:

  • time (array) – Unique times, same length as the time axis of the output vals.
  • vals, flags (ndarray) – The reshaped input arrays, dimensions (baseline, time, spw, freq, pol)
  • ant1, ant2 (array) – ant1 and ant2 for unique baselines, same length as the baseline axis of the output vals.

dsacalib.ms_io.simulate_ms(ofile, tname, anum, xx, yy, zz, diam, mount, pos_obs, spwname, freq, deltafreq, freqresolution, nchannels, integrationtime, obstm, dt, source, stoptime, autocorr, fullpol)

Simulates a measurement set with cross-correlations only.

WARNING: Not simulating autocorrelations correctly regardless of inclusion of autocorr parameter.

Parameters:
  • ofile (str) – The full path to which the measurement set will be written.
  • tname (str) – The telescope name.
  • yy, zz (xx,) – The X, Y and Z ITRF coordinates of the antennas, in meters.
  • diam (float) – The dish diameter in meters.
  • mount (str) – The mount type, e.g. ‘alt-az’.
  • pos_obs (CASA measure instance) – The location of the observatory.
  • spwname (str) – The name of the spectral window, e.g. ‘L-band’.
  • freq (str) – The central frequency, as a CASA-recognized string, e.g. ‘1.4GHz’.
  • deltafreq (str) – The size of each channel, as a CASA-recognized string, e.g. ‘1.24kHz’.
  • freqresolution (str) – The frequency resolution, as a CASA-recognized string, e.g. ‘1.24kHz’.
  • nchannels (int) – The number of frequency channels.
  • integrationtime (str) – The subintegration time, i.e. the width of each time bin, e.g. ‘1.4s’.
  • obstm (float) – The start time of the observation in MJD.
  • dt (float) – The offset between the CASA start time and the true start time in days.
  • source (dsacalib.utils.source instance) – The source observed (or the phase-center).
  • stoptime (float) – The end time of the observation in MJD. DS: should be s?
  • autocorr (boolean) – Set to True if the visibilities include autocorrelations, False if the only include crosscorrelations.
dsacalib.ms_io.uvh5_to_ms(fname, msname, ra=None, dec=None, dt=None, antenna_list=None, flux=None)

Converts a uvh5 data to a uvfits file.

Parameters:
  • fname (str) – The full path to the uvh5 data file.
  • msname (str) – The name of the ms to write. Data will be written to msname.ms
  • ra (astropy quantity) – The RA at which to phase the data. If None, will phase at the meridian of the center of the uvh5 file.
  • dec (astropy quantity) – The DEC at which to phase the data. If None, will phase at the pointing declination.
  • dt (astropy quantity) – Duration of data to extract. Default is to extract the entire file.
  • antenna_list (list) – Antennas for which to extract visibilities from the uvh5 file. Default is to extract all visibilities in the uvh5 file.
  • flux (float) – The flux of the calibrator in Jy. If included, will write a model of the primary beam response to the calibrator source to the model column of the ms. If not included, a model of a constant response over frequency and time will be written instead of the primary beam model.
dsacalib.ms_io.write_beamformer_solutions(msname, calname, caltime, antennas, applied_delays, corr_list=array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), outdir='/home/user/beamformer_weights/', flagged_antennas=None)

Writes beamformer solutions to disk.

Parameters:
  • msname (str) – The name of the measurement set used for calibration.
  • calname (str) – The name of the calibrator source used for calibration. Will open tables that start with msname`_`calname
  • caltime (astropy.time.Time object) – The transit time of the calibrator.
  • antennas (list) – The antenna names for which to write beamformer solutions, in order.
  • applied_delays (ndarray) – The currently applied delays at the time of the calibration, in ns. Dimensions (antenna, pol). The antenna axis should be in the order specified by antennas.
  • corr_list (list) – The indices of the correlator machines to write beamformer weights for. For now, these must be ordered so that the frequencies are contiguous and they are in the same order or the reverse order as in the ms. The bandwidth of each correlator is pulled from dsa110-meridian-fs package data.
  • flagged_antennas (list) – A list of antennas to flag in the beamformer solutions. These antennas will be given beamformer weights of 0, and delays of 0.
  • outdir (str) – The directory to write the beamformer weights in.
Returns:

flags – Dimensions (antennas, pols). True where the data is flagged, and should not be used. Compiled from the ms flags as well as flagged_antennas.

Return type:

ndarray(boolean)

dsacalib.ms_io.write_beamformer_weights(msname, calname, caltime, antennas, outdir, corr_list, antenna_flags)

Writes weights for the beamformer.

Parameters:
  • msname (str) – The prefix of the measurement set. Will open msname.ms
  • calname (str) – The name of the calibrator source.
  • antennas (list) – The names of the antennas to extract solutions for. Order must be the same as the order in the beamformer.
  • outdir (str) – The directory to write the beamformer weights in.
  • corr_list (list) – The indices of the correlator machines to write beamformer weights for. For now, these must be ordered so that the frequencies are contiguous and they are in the same order or the reverse order as in the ms. The bandwidth of each correlator is pulled from dsa110-meridian-fs package data.
  • antenna_flags (ndarray(bool)) – Dimensions (antennas, pols). True where flagged, False otherwise.
Returns:

  • corr_list (list)
  • bu (array) – The length of the baselines in the u direction for each antenna relative to antenna 24.
  • fweights (ndarray) – The frequencies corresponding to the beamformer weights, dimensions (correlator, frequency).
  • filenames (list) – The names of the file containing the beamformer weights.

dsacalib.plotting module

Visibility and calibration solution plotting routines.

Plotting routines to visualize the visibilities and the calibration solutions for DSA-110.

Author: Dana Simard, dana.simard@astro.caltech.edu, 10/2019

dsacalib.plotting.plot_antenna_delays(msname, calname, plabels=None, outname=None, show=True)

Plots antenna delay variations between two delay calibrations.

Compares the antenna delays used in the calibration solution on the timescale of the entire calibrator pass (assumed to be in a CASA table ending in ‘kcal’) to those calculated on a shorter (e.g. 60s) timescale (assumed to be in a CASA table ending in ‘2kcal’).

Parameters:
  • msname (str) – The prefix of the measurement set (msname.ms), used to identify the correct delay calibration tables.
  • calname (str) – The calibrator source name, used to identify the correct delay calibration tables. The tables msname_`calname`_kcal (for a single delay calculated using the entire calibrator pass) and msname_`calname`_2kcal (for delays calculated on a shorter timescale) will be opened.
  • antenna_order (ndarray) – The antenna names in order.
  • outname (string) – The base to use for the name of the png file the plot is saved to. The plot will be saved to outname_antdelays.png. If outname is set to None, the plot is not saved. Defaults None.
  • plabels (list) – The labels along the polarization axis. Defaults to [‘B’, ‘A’].
  • outname – The base to use for the name of the png file the plot is saved to. The plot will be saved to outname`_antdelays.png if an outname is provided. If `outname is None, the image is not saved. Defaults None.
  • show (boolean) – If set to False the plot will be closed after it is generated. Defaults True.
Returns:

  • times (ndarray) – The times at which the antenna delays (on short timescales) were calculated, in MJD.
  • antenna_delays (ndarray) – The delays of the antennas on short timescales, in nanoseconds. Dimensions (polarization, time, antenna).
  • kcorr (ndarray) – The delay correction calculated using the entire observation time, in nanoseconds. Dimensions (polarization, 1, antenna).
  • antenna_order (list) – The antenna indices.

dsacalib.plotting.plot_autocorr(UV)

Plots autocorrelations from UVData object.

Parameters:UV (UVData object) – The UVData object for which to plot autocorrelations.
dsacalib.plotting.plot_bandpass(msname, calname, plabels=None, outname=None, show=True)

Plots the bandpass calibration solutions in the bcal table.

Parameters:
  • msname (str) – The name of the measurement set. Used to identify the calibration table to plot.
  • calname (str) – The name of the calibrator used in calibration. The calibration table msname_`calname`_bcal is opened.
  • plabels (list) – The labels for the polarizations. Defaults ['A', 'B'].
  • outname (str) – The base to use for the name of the png file the plot is saved to. The plot is saved to outname_bandpass.png if an outname is not set to None. If outname is set to None, the plot is not saved. Defaults None.
  • show (boolean) – If set to False, the plot is closed after it is generated.
Returns:

  • bpass (ndarray) – The bandpass solutions, dimensions (antenna or baseline, frequency).
  • fobs (array) – The frequencies at which the bandpass solutions are calculated, in GHz.
  • labels (ndarray) – The antenna or baseline labels along the 0th axis of the bandpass solutions.

dsacalib.plotting.plot_bandpass_phases(filenames, antennas, refant=24, outname=None, show=True, msdir='/mnt/data/dsa110/calibration/')

Plot the bandpass phase observed over multiple calibrators.

filenames
: dict
The details of the calibrator passes to plot.
antennas
: list
The antenna names (as ints) to plot.
refant
: int
The reference antenna to plot phases against.
outname
: str
The base to use for the name of the png file the plot is saved to. The plot is saved to outname_phase.png if outname is not None. If outname is set to None, the plot is not saved. Defaults `None.
show
: boolean
If set to False the plot is closed after being generated.
dsacalib.plotting.plot_calibrated_vis(vis, vis_cal, mjd, fobs, bidx, pol, outname=None, show=True)

Plots the calibrated and uncalibrated visibilities for comparison.

Parameters:
  • vis (ndarray) – The complex, uncalibrated visibilities, with dimensions (baseline, time, freq, pol).
  • vis_cal (ndarray) – The complex calibrated visibilities, with dimensions (baseline, time, freq, pol).
  • mjd (ndarray) – The midpoint time of each subintegration in MJD.
  • fobs (ndarray) – The center frequency of each channel in GHz.
  • bidx (int) – The index along the baseline dimension to plot.
  • pol (int) – The index along the polarization dimension to plot.
  • outname (str) – The base to use for the name of the png file the plot is saved to. The plot will be saved to outname`_cal_vis.png if `outname is provided, otherwise no plot will be saved. Defaults None.
  • show (boolean) – If show is passed False, the plot will be closed after being generated. Otherwise, it is left open. Defaults True.
dsacalib.plotting.plot_current_beamformer_solutions(filenames, calname, date, corrlist=array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), antennas_to_plot=None, antennas=None, outname=None, show=True, gaindir='/home/user/beamformer_weights/', hdf5dir='/mnt/data/dsa110/correlator/')

Plots the phase difference between the two polarizations.

Applies the beamformer weights to the given hdf5 files, and then plots the remaining phase difference between the two polarizations for each antenna.

Parameters:
  • filenames (list) – A list of the hdf5 filenames for which to plot. Each filename should omit the directory and the .hdf5 extension. E.g. [‘2020-10-06T15:32:01’, ‘2020-10-06T15:47:01’] would a valid argument to plot data for 30 minutes starting at 2020-10-06T16:32:01.
  • calname (str) – The name of the source or event that you are plotting. Used in the title of the plot.
  • date (str) – The date of the source or event that you are plotting. Used in the title of the plot. e.g. ‘2020-10-06’
  • corrlist (list(int)) – A list of the correlator indices to plot. Defaults to correlators 01 through 16.
  • antennas_to_plot (array(int)) – The names of the antennas to plot beamformer solutions for. Defaults to antennas 13 through 35, with 21, 22, 23 omitted.
  • antennas (array(int)) – The names of the antennas for which beamformer solutions were generated. Defaults to 24 through 36, 20 through 13 (descending order), then 36 through 74. Must be 64 long.
  • outname (str) – The base to use for the name of the png file the plot is saved to. The plot is saved to outname_beamformerweights.png if outname is not None. f outname is set to None, the plot is not saved. Defaults `None.
  • show (boolean) – If set to False the plot is closed after being generated.
  • gaindir (str) – The full path to the directory in which the beamformer weights are stored.
  • hdf5dir (str) – The full path to the directory in which the correlated hdf5 files are stored. Files were be searched for in hdf5dir/corr??/
dsacalib.plotting.plot_delays(vis_ft, labels, delay_arr, bname, nx=None, outname=None, show=True)

Plots the visibility amplitude against delay.

For a given visibility Fourier transformed along the frequency axis, plots the amplitude against delay and calculates the location of the fringe peak in delay. Returns the peak delay for each visibility, which can be used to calculate the antenna delays.

Parameters:
  • vis_ft (ndarray) – The complex visibilities, dimensions (visibility type, baselines, delay). Note that the visibilities must have been Fourier transformed along the frequency axis and scrunched along the time axis before being passed to plot_delays.
  • labels (list) – The labels of the types of visibilities passed. For example, ['uncalibrated', 'calibrated'].
  • delay_arr (ndarray) – The center of the delay bins in nanoseconds.
  • bname (list) – The baseline labels.
  • nx (int) – The number of plots to tile along the horizontal axis. If nx is given a value of None, this is set to the number of baselines or 5, if there are more than 5 baselines.
  • outname (str) – The base to use for the name of the png file the plot is saved to. The plot will be saved to outname`_delays.png if an outname is provided. If `outname is given a value of None, no plot will be saved. Defaults None.
  • show (boolean) – If show is given a value of False the plot will be closed. Otherwise, the plot will be left open. Defaults True.
Returns:

delays – The peak delay for each visibility, in nanoseconds.

Return type:

ndarray

dsacalib.plotting.plot_dyn_spec(vis, fobs, mjd, bname, normalize=False, outname=None, show=True, nx=None)

Plots the dynamic spectrum of the real part of the visibility.

Parameters:
  • vis (ndarray) – The visibilities to plot. Dimensions (baseline, time, freq, polarization).
  • fobs (ndarray) – The center frequency of each channel in GHz.
  • mjd (ndarray) – The center of each subintegration in MJD.
  • bname (list) – The name of each baseline in the visibilities.
  • normalize (boolean) – If set to True, the visibilities are normalized before plotting. Defaults to False.
  • outname (str) – If provided and not set to None, the plot will be saved to the file outname`_dynspec.png Defaults to ``None`.
  • show (boolean) – If set to False the plot will be closed after rendering. If set to True the plot is left open. Defaults to True.
  • nx (int) – The number of subplots in the horizontal direction of the figure. If not provided, or set to None, nx is set to the minimum of 5 and the number of baselines in the visibilities. Defaults to None.
dsacalib.plotting.plot_gain_calibration(msname, calname, plabels=None, outname=None, show=True)

Plots the gain calibration solutions from the gacal and gpcal tables.

Parameters:
  • msname (str) – The name of the measurement set. Used to identify the gain calibration tables.
  • calname (str) – The calibrator used in gain calibration. Used to identify the gain calibration tables. The tables msname_`calname`_gacal (assumed to contain the gain amplitude soutions) and msname_`calname`_gpcal (assumed to contain the phase amplitude solutions) will be opened.
  • plabels (list) – The names of the polarizations in the calibration solutions. Defaults to ['A', 'B'].
  • outname (str) – The base to use for the name of the png file the plot is saved to. The plot is saved to outname_gaincal.png if outname is not None. If outname is set to None, the plot is not saved.  Defaults ``None.
  • show (boolean) – If set to False the plot is closed after being generated.
Returns:

  • time_days (ndarray) – The times of gain calibration, in days.
  • gain_amp (ndarray) – The gain amplitudes. Dimensions (antenna or baseline, time, pol).
  • gain_phase (ndarray) – The gain phases. Dimensions (antenna or baseline, time, pol).
  • labels (ndarray) – The labels of the antennas or baselines along the 0th axis of the gain solutions.

dsacalib.plotting.plot_image(msname, imtype, sr0, verbose=False, outname=None, show=True, npix=256)

Uses CASA to grid and image visibilities.

Parameters:
  • msname (str) – The prefix of the measurement set name. Opens msname.ms.
  • imtype (str) – The visibilities to image. Can be ‘observed’, ‘corrected’, or ‘model’.
  • sr0 (src instance) – The source to use as the phase center in the image.
  • verbose (boolean) – If True, information about the image, including the location and SNR of the peak, are printed. Default False.
  • outname (str) – The base to use for the name of the png file the plot is saved to. The plot will be saved to outname`_`imtype.png if an outname is provided. If outname is None, the image is not saved. Defaults None.
  • show (boolean) – If show is False, the plot will be closed after being generated. Defaults True.
  • npix (int) – The number of pixels per side to plot in the image. Defaults 256.
dsacalib.plotting.plot_uv_track(bu, bv, outname=None, show=True)

Plots the uv track provided.

Parameters:
  • bu (ndarray) – The u-coordinates of the baselines in meters. Dimensions (baselines, time).
  • bv (ndarray) – The v-coordinates of the baselines in meters. Dimensions (baselines, time).
  • outname (str) – If provided and not set to None, the plot will be saved to the file outname`_dynspec.png Defaults to ``None`.
  • show (boolean) – If set to False the plot will be closed after rendering. If set to True the plot is left open. Defaults to True.
dsacalib.plotting.plot_vis_freq(vis, fobs, bname, outname=None, show=True, nx=None)

Plots visibilities against frequency.

Creates plots of the amplitude and phase of the visibilities vis as a function of frequency fobs. Two separate figures are opened, one for the amplitude and one for the phases. If outname is passed, these are saved as outname_amp_freq.png and outname_phase_freq.png

Parameters:
  • vis (ndarray) – The visibilities to plot. Dimensions (baseline, time, freq, polarization).
  • fobs (ndarray) – The center frequency of each channel in GHz.
  • bname (list) – The name of each baseline in the visibilities.
  • outname (str) – If provided and not set to None, the plots will be saved to the files outname_amp_freq.png and outname_phase_freq.png Defaults to None.
  • show (boolean) – If set to False the plot will be closed after rendering. If set to True the plot is left open. Defaults to True.
  • nx (int) – The number of subplots in the horizontal direction of the figure. If not provided, or set to None, nx is set to the minimum of 5 and the number of baselines in the visibilities. Defaults to None.
dsacalib.plotting.plot_vis_time(vis, mjd, bname, outname=None, show=True, nx=None)

Plots visibilities against time of observation.

Creates plots of the amplitude and phase of the visibilities vis as the time of observation mjd. Two separate figures are opened, one for the amplitude and one for the phases. If outname is passed, these are saved as outname_amp_time.png and outname_phase_time.png

Parameters:
  • vis (ndarray) – The visibilities to plot. Dimensions (baseline, time, freq, polarization).
  • mjd (ndarray) – The center of each subintegration in MJD.
  • bname (list) – The name of each baseline in the visibilities.
  • outname (str) – If provided and not set to None, the plot will be saved to the file outname_dynspec.png Defaults to None.
  • show (boolean) – If set to False the plot will be closed after rendering. If set to True the plot is left open. Defaults to True.
  • nx (int) – The number of subplots in the horizontal direction of the figure. If not provided, or set to None, nx is set to the minimum of 5 and the number of baselines in the visibilities. Defaults to None.
dsacalib.plotting.rebin_vis(arr, nb1, nb2)

Rebins a 2-D array for plotting.

Excess bins along either axis are discarded.

Parameters:
  • arr (ndarray) – The two-dimensional array to rebin.
  • nb1 (int) – The number of bins to rebin by along axis 0.
  • nb2 (int) – The number of bins to rebin by along the axis 1.
Returns:

arr – The rebinned array.

Return type:

ndarray

dsacalib.plotting.summary_plot(msname, calname, npol, plabels, antennas)

Generates a summary plot showing the calibration solutions.

Parameters:
  • msname (str) – The path to the measurement set is msname.ms.
  • calname (str) – The name of the calibrator. Calibration tables starting with msname_``calname`` will be opened.
  • npol (int) – The number of polarization indices. Currently not in use.
  • plabels (list) – The labels of the polarizations.
  • antennas (list) – The antennas to plot.
Returns:

The handle for the generated figure.

Return type:

matplotlib.pyplot.figure

dsacalib.preprocess module

Functions used in preprocessing of hdf5 files.

Prepares hdf5 files written by dsa-meridian-fs for conversion to ms.

dsacalib.preprocess.first_true(iterable, default=False, pred=None)

Returns the first true value in the iterable.

If no true value is found, returns default If pred is not None, returns the first item for which pred(item) is true.

Parameters:
  • iterable (list) – The list for which to find the first True item.
  • default – If not False, then this is returned if no true value is found. Defaults False.
  • pred – If not None, then the first item for which pred(item) is True is returned.
dsacalib.preprocess.fscrunch_file(fname)

Removes outrigger delays before averaging in frequency.

Leaves file untouched if the number of frequency bins is not divisible by the desired number of frequency bins (NFREQ), or is equal to the desired number of frequency bins.

Parameters:fname (str) – The full path to the file to process.
dsacalib.preprocess.rsync_file(rsync_string)

Rsyncs a file from the correlator machines to dsastorage.

Parameters:rsync_string (str) – The correlator machine name and the path to the file to rsync, separated by a space. E.g. ‘corr06 /home/ubuntu/data/2020-06-24T12:32:06.hdf5’

dsacalib.routines module

Calibration routine for DSA-110 calibration with CASA.

Author: Dana Simard, dana.simard@astro.caltech.edu, 2020/06

dsacalib.routines.cal_in_datetime(dt, transit_time, duration=<Quantity 5. min>, filelength=<Quantity 15. min>)

Check to see if a transit is in a given file.

Parameters:
  • dt (str) – The start time of the file, given as a string. E.g. ‘2020-10-06T23:19:02’
  • transit_time (astropy.time.Time instance) – The transit time of the source.
  • duration (astropy quantity) – The amount of time around transit you are interested in, in minutes or seconds.
  • filelength (astropy quantity) – The length of the hdf5 file, in minutes or seconds.
Returns:

True if at least part of the transit is within the file, else False.

Return type:

bool

dsacalib.routines.calculate_sefd(msname, cal, fmin=None, fmax=None, baseline_cal=False, showplots=False, msname_delaycal=None, calname_delaycal=None, halfpower=False, pols=None)

Calculates the SEFD from a measurement set.

The measurement set must have been calibrated against a model of ones and must include autocorrelations.

Parameters:
  • msname (str) – The measurement set name. The measurement set msname.ms will be opened.
  • cal (src class instance) – The calibrator source. Will be used to identify the correct calibration tables. The table msname_`cal.name`_gacal will be opened.
  • fmin (float) – The lowest frequency to consider when calculating the off-source power to use in the SEFD calculation, in GHz. Channels below this frequency will be flagged. Defaults 1.35.
  • fmax (float) – The greatest frequency to consider when calculating the off-source power to use in the SEFD calculation, in GHz. Channels above this frequency will be flagged. Defaults 1.45.
  • baseline_cal (Boolean) – Set to True if the gain tables were derived using baseline-based calibration. Set to False if the gain tables were derived using antenna-based calibration. Defaults True.
  • showplots (Boolean) – If set to True, plots will be generated that show the Gaussian fits to the gains. Defaults False.
  • msname_delaycal (str) – The name of the measurement set from which delay solutions should be applied. Defaults to msname.
  • calname_delaycal (str) – The name of the calibrator source from which delay solutions should be applied. Defaults to calname.
  • halfpower (Boolean) – If True, will calculate the sefd using the half-power point instead of using the off-source power. Defaults False.
  • pols (list) – The labels of the polarization axes. Defaults [‘B’, ‘A’].
Returns:

  • antenna_names (list) – The names of the antennas in their order in sefds.
  • sefds (ndarray) – The SEFD of each antenna/polarization pair, in Jy. Dimensions (antenna, polarization).
  • ant_gains (ndarray) – The antenna gains in 1/Jy. Dimensions (antenna, polarization).
  • ant_transit_time (ndarray) – The meridian transit time of the source as seen by each antenna/ polarization pair, in MJD. Dimensions (antenna, polarization).
  • fref (float) – The reference frequency of the SEFD measurements in GHz.
  • hwhms (float) – The hwhms of the calibrator transits in days.

dsacalib.routines.calibrate_measurement_set(msname, cal, refant, throw_exceptions=True, bad_antennas=None, bad_uvrange='2~27m', keepdelays=False, forsystemhealth=False, interp_thresh=1.5, interp_polyorder=7, blbased=False, manual_flags=None)

Calibrates the measurement set.

Calibration can be done with the aim of monitoring system health (set forsystemhealth=True), obtaining beamformer weights (set forsystemhealth=False and keepdelays=False), or obtaining delays (set forsystemhealth=False and keepdelays=True, new beamformer weights will be generated as well).

Parameters:
  • msname (str) – The name of the measurement set. Will open msname.ms
  • cal (dsacalib.utils.src instance) – The calibration source. Calibration tables will begin with msname_`cal.name`
  • refant (str or int) – The reference antenna name (if str) or index (if int) for calibration.
  • throw_exceptions (bool) – If set to False, exceptions will not be thrown, although they will be logged to syslog. Defaults True.
  • bad_antennas (list(str)) – Antennas (names) to be flagged before calibration.
  • bad_uvrange (str) – Baselines with lengths within bad_uvrange will be flagged before calibration. Must be a casa-understood string with units.
  • keepdelays (bool) – Only used if forsystemhealth is False. If keepdelays is set to False and forsystemhealth is set to False, then delays are integrated into the bandpass solutions and the kcal table is set to all zeros. If keepdelays is set to True and forsystemhealth is set to False, then delays are kept at 2 nanosecond resolution. If forsystemhealth is set to True, delays are kept at full resolution regardless of the keepdelays parameter. Defaults False.
  • forsystemhealth (bool) – Set to True for full-resolution delay and bandpass solutions to use to monitor system health, or to False to generate beamformer weights and delays. Defaults False.
  • interp_thresh (float) – Used if forsystemhealth is False, when smoothing bandpass gains. The gain amplitudes and phases are fit using a polynomial after any points more than interp_thresh*std away from the median-filtered trend are flagged.
  • interp_polyorder (int) – Used if forsystemhealth is False, when smoothing bandpass gains. The gain amplitudes and phases are fit using a polynomial of order interp_polyorder.
  • blbased (boolean) – Set to True for baseline-based calibration, False for antenna-based calibration.
  • manual_flags (list(str)) – Include any additional flags to be done prior to calibration, as CASA-understood strings.
Returns:

A status code. Decode with dsautils.calstatus

Return type:

int

dsacalib.routines.calibration_head(obs_params, ant_params, write_to_etcd=False, throw_exceptions=None, sefd=False)

Controls calibrtion of a dsa10 or dsa110 dataset.

After calibration, results are writen to etcd.

Parameters:
  • obs_params (list) – The observing parameters.
  • ant_params (list) – The antenna configuration.
  • write_to_etcd (boolean) – If set to True, the results of the calibration are pushed to etcd. Defaults False.
  • throw_exceptions (boolean) – If set to False, exceptions are not raised after being logged to syslog. Instead, calibration_head and triple_antenna_cal return the status value. If set to None, throw_exceptions will be set to not write_to_etcd.
  • sefd (boolean) – If set to True, the solutions will be solved against a model of ones in order to allow fitting of the source pass to the antenna gains and 60 minutes will be saved to the measurement set. If set to False, a sky model will be used in calibration and only 10 minutes of data is saved to the measurement set.
Returns:

The status code. Decode with dsautils.calstatus.

Return type:

int

dsacalib.routines.dsa10_cal(fname, msname, cal, pt_dec, antpos, refant, badants=None)

Calibrate dsa10 data.

Parameters:
  • fname (str) – The fits file containing the correlated dsa10 data.
  • msname (str) – The measurement set containing the correlated dsa10 data.
  • cal (dsautils.src instance) – The calibrator source.
  • pt_dec (float) – The pointing declination of the array in radians.
  • antpos (str) – The path to the ITRF file containing the antenna positions.
  • refant (str or int) – The reference antenna name (if str) or index (if int).
  • badants (list(str)) – The naems of antennas that should be flagged before calibration.
dsacalib.routines.flag_antennas_using_delays(antenna_delays, kcorr, msname, kcorr_thresh=0.3)

Flags antennas by comparing the delay on short times to the delay cal.

Parameters:
  • antenna_delays (ndarray) – The antenna delays from the 2kcal calibration file, calculated on short timescales.
  • kcorr (ndarray) – The antenna delays from the kcal calibration file, calculated over the entire calibration pass.
  • msname (str) – The path to the measurement set. Will open msname.ms
  • kcorr_thresh (float) – The tolerance for descrepancies between the antenna_delays and kcorr, in nanoseconds.
dsacalib.routines.flag_pixels(msname, thresh=6.0)

Flags pixels using dsautils.mask_bad_pixels.

Parameters:
  • msname (str) – The path to the measurement set. Opens msname.ms
  • thresh (float) – The RFI threshold in units of standard deviation. Anything above thresh*stddev + mean will be flagged.
dsacalib.routines.get_files_for_cal(caltable, refcorr='01', duration=<Quantity 5. min>, filelength=<Quantity 15. min>, hdf5dir='/mnt/data/dsa110/correlator/', date_specifier='*')

Returns a dictionary containing the filenames for each calibrator pass.

Parameters:
  • caltable (str) – The path to the csv file containing calibrators of interest.
  • refcorr (str) – The reference correlator to search for recent hdf5 files from. Searches the directory hdf5dir/corr`refcorr`/
  • duration (astropy quantity) – The duration around transit which you are interested in extracting, in minutes or seconds.
  • filelength (astropy quantity) – The length of the hdf5 files, in minutes or seconds.
  • hdf5dir (str) – The path to the hdf5 files.
  • date_specifier (str) – A specifier to include to limit the dates for which you are interested in. Should be something interpretable by glob and should be to the second precision. E.g. 2020-10-06*, 2020-10-0[678]* and 2020-10-06T01:03:?? are all valid.
Returns:

A dictionary specifying the hdf5 filenames that correspond to the requested datesand calibrators.

Return type:

dict

dsacalib.routines.plot_solutions(msname, calname, figure_path, show_plots=False)

Plots the antenna delay, gain and bandpass calibration solutions.

Creates separate files for all solutions. To create one plot with all solutions, use plotting.summary_plot.

Parameters:
  • msname (str) – The name of the measurement set. Used to identify the calibration tables.
  • calname (str) – The name of the calibrator. Used to identify the calibration tables.
  • antenna_order (list) – The antenna names, in order.
  • fobs (array) – The central frequency of each channel, in GHz.
  • blbased (boolean) – True of the calibration was baseline-based.
  • figure_dir (str) – The location to save the figures. Defaults ./figures.
  • show_plots (boolean) – If False, plots are closed after being saved. Defaults False.
dsacalib.routines.triple_antenna_cal(obs_params, ant_params, throw_exceptions=True, sefd=False)

Calibrate visibilities from 3 antennas.

Assumes visbilities are stored using dsa-10 or dsa-110 fits format. The caltable_to_etcd function should be able to handle this, but I haven’t tested that yet.

Parameters:
  • obs_params (dict) – Observing parameters
  • ant_params (dict) –
  • show_plots (Boolean) – If set to True, plots of the delay and gain calibration solutions will be shown. Defaults False.
  • throw_exception (Boolean) – If set to True, exceptions will be thrown after being logged in syslog. If set to False, the exceptions will not be thrown, but will still be logged in syslog. Defaults True.
  • sefd (Boolean) – If set to True, enough data (60 minutes) will be included in the measurement set to calculate the off-source power (60 minutes) and the calibration solutions will be solved against a model of ones. If set to False, only 10 minutes will be included in the measurement set and the calibration solutison will be solved against a sky model.
Returns:

  • status (int) – The status code of the pipeline. Decode with dsautils.calstatus.
  • caltime (float) – The meridian crossing time of the source in MJD. If the input file could not be opened, None will be returned.

dsacalib.utils module

DSACALIB/UTILS.PY

Dana Simard, dana.simard@astro.caltech.edu, 10/2019

Modified for python3 from DSA-10 routines written by Vikram Ravi, Harish Vendantham.

Routines to interact w/ fits visibilities recorded by DSA-10, hdf5 visibilities recorded by DSA-110, and visibility in CASA measurement sets.

dsacalib.utils.daz_dha(dec, daz=None, dha=None, lat=0.6498455107238486)

Converts an offset between azimuth and hour angle.

Assumes that the offset in azimuth or hour angle from an azimuth of pi or hour angle of 0 is small. One of daz or dha must be provided, the other is calculated.

Parameters:
  • dec (float) – The pointing declination of the antenna in radians.
  • daz (float) – The azimuth offset in radians. None may also be passed, in which case the azimuth offset is calculated and returned. Defaults to None.
  • dha (float) – The hour angle offset in radians. None may also be passed, in which case the hour angle offset is calculated and returned. Defaults to None.
  • lat (float) – The latitude of the antenna in radians. Defaults to the value of ovro_lat defined in dsacalib.constants.
Returns:

The converted offset. If the value of daz passed was not None, this is the hour angle offset corresponding to the azimuth offset daz. If the value of dha passed was not None, this is the azimuth offset corresonding to the hour angle offset dha.

Return type:

float

Raises:

RuntimeError – If neither daz or `dha is defined.

dsacalib.utils.exception_logger(logger, task, exception, throw)

Logs exception traceback to syslog using the dsa_syslog module.

Parameters:
  • logger (dsa_syslog.DsaSyslogger() instance) – The logger used for within the reduction pipeline.
  • task (str) – A short description of where in the pipeline the error occured.
  • exception (Exception) – The exception that occured.
  • throw (boolean) – If set to True, the exception is raised after the traceback is written to syslogs.
dsacalib.utils.get_antpos_itrf(antpos)

Reads and orders antenna positions from a text or csv file.

Parameters:antpos (str) – The path to the text or csv file containing the antenna positions.
Returns:
  • anum (list(int)) – The antenna numbers, in numerical order.
  • xx, yy, zz (list(float)) – The ITRF coordinates of the antennas, in meters.
dsacalib.utils.get_autobl_indices(nant, casa=False)

Returns a list of the indices containing the autocorrelations.

Can return the index for either correlator-ordered visibilities (casa set to False) or CASA-ordered visibilities (casa set to True).

Parameters:
  • nant (int) – The number of antennas in the visibility set.
  • casa (boolean) – Whether the visibilities follow CASA ordering standards (casa set to True) or DSA-10/DSA-110 correlator ordering standards (casa set to False). Defaults to False, or correlator ordering standards.
Returns:

auto_bls – The list of indices in the visibilities corresponding to autocorrelations.

Return type:

list

dsacalib.utils.mask_bad_bins(vis, axis, thresh=6.0, medfilt=False, nmed=129)

Masks bad channels or time bins in visibility data.

Parameters:
  • vis (ndarray) – The visibility array, with dimensions (baselines, time, frequency, polarization)
  • axis (int) – The axis to flag along. axis set to 1 will flag bad time bins. axis set to 2 will flag bad frequency bins.
  • thresh (float) – The threshold above which to flag data. Anything that deviates from the median by more than thresh multiplied by the standard deviation is flagged.
  • medfilt (Boolean) – Whether to median filter to remove an average trend. If True, will median filter. If False, will subtract the median for the baseline/pol pair.
  • nmed (int) – The size of the median filter to use. Only used in medfilt is True. Must be an odd integer.
Returns:

  • good_bins (ndarray) – Has a value of 1 where the bin is good, and 0 where the bin should be flagged. If axis is 2, the dimensions are (baselines, 1, frequency, polarization). If axis is 1, the dimensions are (baselines, time, 1, polarization).
  • fraction_flagged (ndarray) – The fraction of data flagged for each baseline/polarization pair. Dimensions (baselines, polarization).

dsacalib.utils.mask_bad_pixels(vis, thresh=6.0, mask=None)

Masks pixels with values above a SNR threshold within each visibility.

Parameters:
  • vis (ndarray) – The complex visibilities. Dimensions (baseline, time, frequency, polarization).
  • thresh (float) – The threshold above which to flag data. Data above thresh*the standard deviation in each channel of each visiblity is flagged. Defaults 6.
  • mask (ndarray) – A mask for data that is already flagged. Should be 0 where data has been flagged, 1 otherwise. Same dimensions as vis. Data previously flagged is not used in the calculation of the channel standard deviations.
Returns:

  • good_pixels (ndarray) – Whether a given pixel in vis is good (1 or True) or bad (i.e. above the threshold: 0 or False). Same dimensions as vis.
  • fraction_flagged (array) – The ratio of the flagged data to the total number of pixels for each baseline/polarization.

class dsacalib.utils.src(name, ra, dec, I=1.0, epoch='J2000', pa=None, maj_axis=None, min_axis=None)

Bases: object

Simple class for holding source parameters.

dsacalib.utils.to_deg(string)

Converts a string representation of RA or DEC to degrees.

Parameters:string (str) – RA or DEC in string format e.g. “12h00m19.21s” or “+73d00m45.7s”.
Returns:deg – The angle in degrees.
Return type:astropy quantity

Module contents