original_docstring: r"""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 : str
          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 : 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 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.
      
docstring: r"""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  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.
  
  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.
docstring_tokens: r " " " 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 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 . 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 .
code: def plot_antenna_delays(msname, calname, plabels=None, outname=None, show=True):
      r"""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 : str
          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 : 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 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.
      """
      if plabels is None:
          plabels = ['B', 'A']
  
      ccyc = plt.rcParams['axes.prop_cycle'].by_key()['color']
  
      # Pull the solutions for the entire timerange and the
      # 60-s data from the measurement set tables
      antenna_delays, times, _flags, _ant1, _ant2 = \
          read_caltable('{0}_{1}_2kcal'.format(msname, calname), cparam=False)
      npol = antenna_delays.shape[-1]
      kcorr, _tkcorr, _flags, antenna_order, _ant2 = \
          read_caltable('{0}_{1}_kcal'.format(msname, calname), cparam=False)
      nant = len(antenna_order)
  
      val_to_plot = (antenna_delays - kcorr).squeeze(axis=3).mean(axis=2)
      mean_along_time = np.abs(val_to_plot.reshape(nant, -1, npol).mean(1))
      idx_to_plot = np.where(
          (mean_along_time[..., 0] > 1e-10) |
          (mean_along_time[..., 1] > 1e-10))[0]
      tplot = (times-times[0])*ct.SECONDS_PER_DAY/60.
      ny = max(len(idx_to_plot)//10+1, 2)
      _, ax = plt.subplots(ny, 1, figsize=(10, 8*ny))
      lcyc = ['.', 'x']
      for i, bidx in enumerate(idx_to_plot):
          for j in range(npol):
              ax[i//10].plot(
                  tplot,
                  val_to_plot[bidx, :, j],
                  marker=lcyc[j%len(lcyc)],
                  label='{0} {1}'.format(antenna_order[bidx]+1, plabels[j]),
                  alpha=0.5,
                  color=ccyc[i%len(ccyc)]
              )
      for i in range(ny):
          ax[i].set_ylim(-5, 5)
          ax[i].set_ylabel('delay (ns)')
          ax[i].legend(
              ncol=len(idx_to_plot)//15+1,
              fontsize='small',
              bbox_to_anchor=(1.05, 1),
              loc='upper left'
          )
          ax[i].set_xlabel('time (min)')
          ax[i].axhline(1.5)
          ax[i].axhline(-1.5)
      if outname is not None:
          plt.savefig('{0}_antdelays.png'.format(outname), bbox_inches='tight')
      if not show:
          plt.close()
  
      return times, antenna_delays, kcorr, antenna_order
code_tokens: def plot_antenna_delays ( msname , calname , plabels = None , outname = None , show = True ) : if plabels is None : plabels = [ 'B' , 'A' ] ccyc = plt . rcParams [ 'axes.prop_cycle' ] . by_key ( ) [ 'color' ] antenna_delays , times , _flags , _ant1 , _ant2 = read_caltable ( '{0}_{1}_2kcal' . format ( msname , calname ) , cparam = False ) npol = antenna_delays . shape [ - 1 ] kcorr , _tkcorr , _flags , antenna_order , _ant2 = read_caltable ( '{0}_{1}_kcal' . format ( msname , calname ) , cparam = False ) nant = len ( antenna_order ) val_to_plot = ( antenna_delays - kcorr ) . squeeze ( axis = 3 ) . mean ( axis = 2 ) mean_along_time = np . abs ( val_to_plot . reshape ( nant , - 1 , npol ) . mean ( 1 ) ) idx_to_plot = np . where ( ( mean_along_time [ ... , 0 ] > 1e-10 ) | ( mean_along_time [ ... , 1 ] > 1e-10 ) ) [ 0 ] tplot = ( times - times [ 0 ] ) * ct . SECONDS_PER_DAY / 60. ny = max ( len ( idx_to_plot ) // 10 + 1 , 2 ) _ , ax = plt . subplots ( ny , 1 , figsize = ( 10 , 8 * ny ) ) lcyc = [ '.' , 'x' ] for i , bidx in enumerate ( idx_to_plot ) : for j in range ( npol ) : ax [ i // 10 ] . plot ( tplot , val_to_plot [ bidx , : , j ] , marker = lcyc [ j % len ( lcyc ) ] , label = '{0} {1}' . format ( antenna_order [ bidx ] + 1 , plabels [ j ] ) , alpha = 0.5 , color = ccyc [ i % len ( ccyc ) ] ) for i in range ( ny ) : ax [ i ] . set_ylim ( - 5 , 5 ) ax [ i ] . set_ylabel ( 'delay (ns)' ) ax [ i ] . legend ( ncol = len ( idx_to_plot ) // 15 + 1 , fontsize = 'small' , bbox_to_anchor = ( 1.05 , 1 ) , loc = 'upper left' ) ax [ i ] . set_xlabel ( 'time (min)' ) ax [ i ] . axhline ( 1.5 ) ax [ i ] . axhline ( - 1.5 ) if outname is not None : plt . savefig ( '{0}_antdelays.png' . format ( outname ) , bbox_inches = 'tight' ) if not show : plt . close ( ) return times , antenna_delays , kcorr , antenna_order
short_docstring: r"""Plots antenna delay variations between two delay calibrations.
short_docstring_tokens: r " " " Plots antenna delay variations between two delay calibrations .
comment: r"""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 : str
          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 : 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 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.
      """$SEP$# Pull the solutions for the entire timerange and the$SEP$# 60-s data from the measurement set tables