Calibration

class ehtim.caltable.Caltable(ra, dec, rf, bw, datadict, tarr, source='SgrA', mjd=51544, timetype='UTC')[source]
source

The source name

Type

str

ra

The source Right Ascension in fractional hours

Type

float

dec

The source declination in fractional degrees

Type

float

mjd

The integer MJD of the observation

Type

int

rf

The observation frequency in Hz

Type

float

bw

The observation bandwidth in Hz

Type

float

timetype

How to interpret tstart and tstop; either ‘GMST’ or ‘UTC’

Type

str

tarr

The array of telescope data with datatype DTARR

Type

numpy.recarray

tkey

A dictionary of rows in the tarr for each site name

Type

dict

data

keys are sites in tarr, entries are calibration data tables of type DTCAL

Type

dict

applycal(obs, interp='linear', extrapolate=None, force_singlepol=False, copy_closure_tables=True)[source]

Apply the calibration table to an observation.

Parameters
  • obs (Obsdata) – The observation with data to be calibrated

  • interp (str) – Interpolation method (‘linear’,’nearest’,’cubic’)

  • extrapolate (bool) – If True, points outside interpolation range will be extrapolated.

  • force_singlepol (str) – If ‘L’ or ‘R’, will set opposite polarization gains equal to chosen polarization

Returns

the calibrated Obsdata object

Return type

(Obsdata)

copy()[source]

Copy the observation object.

Args:

Returns

a copy of the Caltable object.

Return type

(Caltable)

enforce_positive(method='median', min_gain=0.9, sites=[], verbose=True)[source]

Enforce that caltable gains are not low (e.g., that sites are not significantly more sensitive than estimated). By rescaling the entire gain curve to enforce a specified minimum site gain.

Parameters
  • caltab (Caltable) – Input Caltable with station gains

  • method (str) – ‘median’, ‘mean’, or ‘min’

  • min_gain (float) – Site gains above this value are not modified.

  • sites (list) – List of sites to check and adjust. For sites=[], all sites are fixed.

  • verbose (bool) – If True, print corrections.

Returns

Axes object with the plot

Return type

(Caltable)

merge(caltablelist, interp='linear', extrapolate=1)[source]

Merge the calibration table with a list of other calibration tables

Parameters
  • caltablelist (list) – The list of caltables to be merged

  • interp (str) – Interpolation method (‘linear’,’nearest’,’cubic’)

  • extrapolate (bool) – If True, points outside interpolation range will be extrapolated.

Returns

the merged Caltable object

Return type

(Caltable)

pad_scans(maxdiff=60, padtype='median')[source]

Pad data points around scans.

Parameters
  • maxdiff (float) – “scan” separation length (seconds)

  • padtype (str) – padding type, ‘endval’ or ‘median’

Returns

a padded caltable object

Return type

(Caltable)

plot_dterms(sites='all', label=None, legend=True, clist=[0.11764705882352941, 0.5647058823529412, 1.0, 1.0, 0.38823529411764707, 0.2784313725490196, 0.5411764705882353, 0.16862745098039217, 0.8862745098039215, 0.4196078431372549, 0.5568627450980392, 0.13725490196078433, 1.0, 0.6470588235294118, 0.0, 0.5450980392156862, 0.27058823529411763, 0.07450980392156863, 0.0, 0.0, 0.803921568627451, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.39215686274509803, 0.0, 0.8235294117647058, 0.7058823529411765, 0.5490196078431373, 0.0, 0.0, 0.0], rangex=False, rangey=False, markersize=6, show=True, grid=True, export_pdf='')[source]

Make a plot of the D-terms.

Parameters
  • sites (list) – list of sites to plot

  • label (str) – title for plot

  • legend (bool) – add telescope legend or not

  • clist (list) – list of colors for different stations

  • rangex (list) – lower and upper x-axis limits

  • rangey (list) – lower and upper y-axis limits

  • markersize (float) – marker size

  • show (bool) – display the plot or not

  • grid (bool) – add a grid to the plot or not

  • export_pdf (str) – save a pdf file to this path

Returns

matplotlib.axes

plot_gains(sites, gain_type='amp', pol='R', label=None, ang_unit='deg', timetype=False, yscale='log', legend=True, clist=[0.11764705882352941, 0.5647058823529412, 1.0, 1.0, 0.38823529411764707, 0.2784313725490196, 0.5411764705882353, 0.16862745098039217, 0.8862745098039215, 0.4196078431372549, 0.5568627450980392, 0.13725490196078433, 1.0, 0.6470588235294118, 0.0, 0.5450980392156862, 0.27058823529411763, 0.07450980392156863, 0.0, 0.0, 0.803921568627451, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.39215686274509803, 0.0, 0.8235294117647058, 0.7058823529411765, 0.5490196078431373, 0.0, 0.0, 0.0], rangex=False, rangey=False, markersize=[3], show=True, grid=False, axislabels=True, axis=False, export_pdf='')[source]

Plot gains on multiple sites vs time. :param sites: a list of site names for which to plot gains. Empty list is all sites. :type sites: list :param gain_type: ‘amp’ or ‘phase’ :type gain_type: str :param pol str: ‘R’ or ‘L’ :type pol str: str :param ang_unit: phase unit ‘deg’ or ‘rad’ :type ang_unit: str :param timetype: ‘GMST’ or ‘UTC’ :type timetype: str :param yscale: ‘log’ or ‘lin’, :type yscale: str :param clist: list of colors for the plot :type clist: list :param label: base label for legend :type label: str :param rangex: [xmin, xmax] x-axis (time) limits :type rangex: list :param rangey: [ymin, ymax] y-axis (gain) limits :type rangey: list :param legend: Plot legend if True :type legend: bool :param grid: Plot gridlines if True :type grid: bool :param axislabels: Show axis labels if True :type axislabels: bool :param show: Display the plot if true :type show: bool :param axis: add plot to this axis :type axis: matplotlib.axes.Axes :param markersize: size of plot markers :type markersize: int :param export_pdf: path to pdf file to save figure :type export_pdf: str

Returns

Axes object with the plot

Return type

(matplotlib.axes.Axes)

save_txt(obs, datadir='.', sqrt_gains=False)[source]

Saves a Caltable object to text files in the given directory :param obs: The observation object associated with the Caltable :type obs: Obsdata :param datadir: directory to save caltable in :type datadir: str :param sqrt_gains: If True, we square gains before saving. :type sqrt_gains: bool

Returns:

scan_avg(obs, incoherent=True)[source]

average the gains across scans.

Parameters
  • obs (ehtim.Obsdata) – input observation

  • incoherent (bool) – True to average gain amps, False to average amps+phase

Returns

the averaged Caltable object

Return type

(Caltable)

ehtim.caltable.load_caltable(obs, datadir, sqrt_gains=False)[source]

Load apriori Caltable object from text files in the given directory :param obs: The observation object associated with the Caltable :type obs: Obsdata :param datadir: directory to save caltable in :type datadir: str :param sqrt_gains: If True, we take the sqrt of table gains before loading. :type sqrt_gains: bool

Returns

a caltable object

Return type

(Caltable)

ehtim.caltable.make_caltable(obs, gains, sites, times)[source]

Create a Caltable object for an observation :param obs: The observation object associated with the Caltable :type obs: Obsdata :param gains: list of gains (?? format ??) :type gains: list :param sites: list of sites :type sites: list :param times: list of times :type times: list

Returns

a caltable object

Return type

(Caltable)

ehtim.caltable.save_caltable(caltable, obs, datadir='.', sqrt_gains=False)[source]

Saves a Caltable object to text files in the given directory :param obs: The observation object associated with the Caltable :type obs: Obsdata :param datadir: directory to save caltable in :type datadir: str :param sqrt_gains: If True, we square gains before saving. :type sqrt_gains: bool

Returns:

ehtim.calibrating.self_cal.self_cal(obs, im, sites=[], pol='I', apply_singlepol=False, method='both', minimizer_method='BFGS', pad_amp=0.0, gain_tol=0.2, solution_interval=0.0, scan_solutions=False, ttype='direct', fft_pad_factor=2, caltable=False, debias=True, apply_dterms=False, copy_closure_tables=False, processes=- 1, show_solution=False, msgtype='bar', use_grad=False)[source]

Self-calibrate a dataset to an image.

Parameters
  • obs (Obsdata) – The observation to be calibrated

  • im (Image) – the image to be calibrated to

  • sites (list) – list of sites to include in the self calibration. empty list calibrates all sites

  • pol (str) – which image polarization to self-calibrate visibilities to

  • apply_singlepol (str) – if calibrating to pol=’RR’ or pol=’LL’, apply solution only to the single polarization

  • method (str) – chooses what to calibrate, ‘amp’, ‘phase’, or ‘both’

  • minimizer_method (str) – Method for scipy.optimize.minimize (e.g., ‘CG’, ‘BFGS’)

  • pad_amp (float) – adds fractional uncertainty to amplitude sigmas in quadrature

  • gain_tol (float or list) – gains that exceed this value will be disfavored by the prior for asymmetric gain_tol for corrections below/above unity, pass a 2-element list

  • solution_interval (float) – solution interval in seconds; If 0., determine solution for each unique time

  • scan_solutions (bool) – If True, determine one gain per site per scan (supersedes solution_interval)

  • caltable (bool) – if True, returns a Caltable instead of an Obsdata

  • processes (int) – number of cores to use in multiprocessing

  • ttype (str) – if “fast” or “nfft” use FFT to produce visibilities. Else “direct” for DTFT

  • fft_pad_factor (float) – zero pad the image to fft_pad_factor * image size in FFT

  • debias (bool) – If True, debias the amplitudes

  • apply_dterms (bool) – if True, apply dterms (in obs.tarr) to clean data before calibrating

  • show_solution (bool) – if True, display the solution as it is calculated

  • msgtype (str) – type of progress message to be printed, default is ‘bar’

  • use_grad (bool) – if True, use gradients in minimizer

Returns

the calibrated observation, if caltable==False (Caltable): the derived calibration table, if caltable==True

Return type

(Obsdata)

ehtim.calibrating.self_cal.self_cal_scan(scan, im, V_scan=[], sites=[], polrep='stokes', pol='I', apply_singlepol=False, method='both', minimizer_method='BFGS', show_solution=False, pad_amp=0.0, gain_tol=0.2, debias=True, caltable=False, use_grad=False)[source]

Self-calibrate a scan to an image.

Parameters
  • scan (np.recarray) – data array of type DTPOL_STOKES or DTPOL_CIRC

  • im (Image) – the image to be calibrated to

  • sites (list) – list of sites to include in the self calibration. empty list calibrates all sites

  • V_scan (list) – precomputed scan visibilities

  • polrep (str) – ‘stokes’ or ‘circ’ to specify the polarization products in scan

  • pol (str) – which image polarization to self-calibrate visibilities to

  • apply_singlepol (str) – if calibrating to pol=’RR’ or pol=’LL’, apply solution only to the single polarization

  • method (str) – chooses what to calibrate, ‘amp’, ‘phase’, or ‘both’

  • minimizer_method (str) – Method for scipy.optimize.minimize (e.g., ‘CG’, ‘BFGS’, ‘Nelder-Mead’, etc.)

  • pad_amp (float) – adds fractional uncertainty to amplitude sigmas in quadrature

  • gain_tol (float or list) – gains that exceed this value will be disfavored by the prior for asymmetric gain_tol for corrections below/above unity, pass a 2-element list

  • debias (bool) – If True, debias the amplitudes

  • caltable (bool) – if True, returns a Caltable instead of an Obsdata

  • show_solution (bool) – if True, display the solution as it is calculated

  • use_grad (bool) – if True, use gradients in minimizer

Returns

the calibrated observation, if caltable==False (Caltable): the derived calibration table, if caltable==True

Return type

(Obsdata)

ehtim.calibrating.network_cal.network_cal(obs, zbl, sites=[], zbl_uvdist_max=10000000.0, method='amp', minimizer_method='BFGS', pol='I', pad_amp=0.0, gain_tol=0.2, solution_interval=0.0, scan_solutions=False, caltable=False, processes=- 1, show_solution=False, debias=True, msgtype='bar')[source]

Network-calibrate a dataset with zero baseline constraints.

Parameters
  • obs (Obsdata) – The observation to be calibrated

  • zbl (float or function) – constant zero baseline flux in Jy, or a function of UT hour.

  • sites (list) – list of sites to include in the network calibration. empty list calibrates all sites

  • zbl_uvdist_max (float) – maximum uv-distance considered a zero baseline

  • method (str) – chooses what to calibrate, ‘amp’, ‘phase’, or ‘both’.

  • minimizer_method (str) – Method for scipy.optimize.minimize (e.g., ‘CG’, ‘BFGS’)

  • pol (str) – which visibility to compute gains for

  • pad_amp (float) – adds fractional uncertainty to amplitude sigmas in quadrature

  • gain_tol (float) – gains that exceed this value will be disfavored by the prior

  • solution_interval (float) – solution interval in seconds; one gain is derived for each interval. If 0.0, a solution is determined for each unique time

  • scan_solutions (bool) – If True, determine one gain per site per scan. Supersedes solution_interval

  • debias (bool) – If True, debias the amplitudes

  • caltable (bool) – if True, returns a Caltable instead of an Obsdata

  • processes (int) – number of cores to use in multiprocessing

  • show_solution (bool) – if True, display the solution as it is calculated

  • msgtype (str) – type of progress message to be printed, default is ‘bar’

Returns

the calibrated observation, if caltable==False (Caltable): the derived calibration table, if caltable==True

Return type

(Obsdata)

ehtim.calibrating.network_cal.network_cal_scan(scan, zbl, sites, clustered_sites, polrep='stokes', pol='I', zbl_uvidst_max=10000000.0, method='both', minimizer_method='BFGS', show_solution=False, pad_amp=0.0, gain_tol=0.2, caltable=False, debias=True)[source]

Network-calibrate a scan with zero baseline constraints.

Parameters
  • obs (Obsdata) – The observation to be calibrated

  • zbl (float or function) – constant zero baseline flux in Jy, or a function of UT hour.

  • sites (list) – list of sites to include in the network calibration. empty list calibrates all sites

  • clustered_sites (tuple) – information on clustered sites, returned by make_cluster_data

  • polrep (str) – ‘stokes’ or ‘circ’ to specify the polarization products in scan

  • pol (str) – which image polarization to self-calibrate visibilities to

  • zbl_uvdist_max (float) – maximum uv-distance considered a zero baseline

  • method (str) – chooses what to calibrate, ‘amp’, ‘phase’, or ‘both’

  • pad_amp (float) – adds fractional uncertainty to amplitude sigmas in quadrature

  • gain_tol (float) – gains that exceed this value will be disfavored by the prior

  • debias (bool) – If True, debias the amplitudes

  • caltable (bool) – if True, returns a Caltable instead of an Obsdata

  • show_solution (bool) – if True, display the solution as it is calculated

Returns

the calibrated scan, if caltable==False (Caltable): the derived calibration table, if caltable==True

Return type

(Obsdata)