Reference complex gain calibration refers to determining the "system" amplitude and phase with high precision as a function of IF band (i.e. integrated over each 500 MHz IF band). A typical reference calibration would cover 34 bands, 2 polarizations, and 13 antennas. The routines (on pipeline machine) to retrieve and analyze the data are in the module refcal_anal.py. Start from a time range during which the reference calibration observation occurred (check the phasecal results to see which 1-hr scan had stable phases)

import refcal_anal as ra
from util import Time
#example time range of the refcal scan that took place BEFORE the observation
trange=Time(['2017-04-08T14:00','2017-04-08T15:00'])

Now read the data from that timerange

out=ra.rd_refcal(trange)

Note that there are optional arguments that can be given, such as projid='PHASECAL' (the default) and srcid='1229+060', but these are generally not needed.

To correct for differential feed rotation (for refcal data after 05:00 UT on 2017-Jul-01), you can use:

out_corr = ra.unrot_refcal(out)

Take a look at the phases (averaged over each band):

ra.graph(out_corr)

By default it displays only bands 5, 11, 17, 23 and polarization XX. To change the bands and polarization to display, use the "bandplt" and 'pol' parameters (better to check more bands).

ra.graph(out_corr, bandplt=[5,13,19,25], pol=1)

Observations within this time range will be used for averaging to get the reference phases/amplitudes. Data will be flagged if the SNR is less than minsnr, which can be supplied. The default minsnr is set to 1.0. We can further determine a finer selection of time range within this scan that has clean and stable phases if needed, by setting the new timerange in "trange" below.

refcal=ra.refcal_anal(out_corr,timerange=trange,scanidx=[0])

It will generate four plots. First and second are phases and amplitudes of the data similar as those produced by ra.graph(), but with the selected time range for averaging highlighted (one can use "bandplt" and "pol" to choose bands and polarization to display as well). The 3rd plot is the averaged phase vs. frequency and the 4th is the averaged amplitude vs. frequency. Those data will be our "analyzed" reference calibration data saved in the returned dictionary (named "refcal" here). The dictionary contains the actual complex values (refcal['refcal']), a flag array with the same shape (refcal['flag']), and some timestamps, e.g., refcal['t_mid'] is the middle of the time range used for averaging. Both refcal['refcal'] and refcal['flag'] have a shape of (15, 2, 34) -- which corresponds to # of antennas, # of polarizations, and # of bands.

If you determine some antenna, band, polarization need to be flagged/unflagged, they have to be manually changed in the returned refcal['flag'] array. In this example, Antenna 12 was not tracking, and the algorithm did not pick up all of them, so we have to do this manually -- setting refcal['flag'][11, :, :]=1

refcal['flag'][11]=1

If satisfied with the results (by looking at the plots), we can go ahead and send them to the SQL database

import cal_header as ch
ch.refcal2sql(refcal)

To retrieve the refcal data back from SQL database based on, e.g., a solar data one wish to calibrate. We can provide a time:

t=Time('2017-04-07T19:40')
refcal=ra.sql2refcal(t)

The resulted refcal have three keys: 'amp' (15 x 2 x 34 array), 'pha' (15 x 2 x 34 array), and 'timestamp' (in jd). The refcal data found will be the closest one PRIOR to the supplied observation time.

Updating the Reference Calibrations Table

The table below lists the known good reference calibrations. To facilitate adding entries to this table, do the following, where the time is after the desired refcal, but before any later refcal:

t=Time('2017-06-23T19:40') # retrieves the refcal at 13:07 UT on that day
refcal=ra.sql2refcal(t)
ra.graph_results(refcal, savefigs=True)

This will create summary plots of the amplitude and phase, will write the two corresponding *.png files into the /common/webplots/refcal folder, and will print as a text string the lines needed to add an entry. Just cut from the terminal and paste into the wiki editor at the appropriate place to preserve time order.