original_docstring: r"""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'
      beamformer_name : str
          The title of the beamformer weights.
          e.g. 'J141120+521209_2021-02-19T12:05:51'
      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`.
      antennas : array(int)
          The names of the antennas for which beamformer solutions were
          generated.  Defaults to values in dsautils.cnf
      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??/
      
docstring: r"""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.
docstring_tokens: r " " " 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 .
code: def plot_current_beamformer_solutions(
          filenames, calname, date, beamformer_name, corrlist=np.arange(1, 16+1),
          antennas_to_plot=None, antennas=None, outname=None, show=True,
          gaindir='/home/user/beamformer_weights/',
          hdf5dir='/mnt/data/dsa110/correlator/'
  ):
      r"""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'
      beamformer_name : str
          The title of the beamformer weights.
          e.g. 'J141120+521209_2021-02-19T12:05:51'
      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`.
      antennas : array(int)
          The names of the antennas for which beamformer solutions were
          generated.  Defaults to values in dsautils.cnf
      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??/
      """
      if antennas is None:
          antennas = np.array(list(CONF.get('corr')['antenna_order'].values))
      assert len(antennas) == 64
      if antennas_to_plot is None:
          antennas_to_plot = antennas
      # Should be generalized to different times, baselines
      visdata_corr = np.zeros(
          (len(filenames)*280, 325, 16, 48, 2),
          dtype=np.complex
      )
      for corridx, corr in enumerate(corrlist):
          visdata = np.zeros(
              (len(filenames), 91000, 1, 48, 2),
              dtype=np.complex
          )
          for i, filename in enumerate(filenames):
              files = sorted(glob.glob(
                  '{0}/corr{1:02d}/{2}??.hdf5'.format(
                      hdf5dir,
                      corr,
                      filename[:-2]
                  )
              ))
              if len(files) > 0:
                  with h5py.File(files[0], 'r') as f:
                      visdata[i, ...] = np.array(f['Data']['visdata'][:])
                      ant1 = np.array(f['Header']['ant_1_array'][:])
                      ant2 = np.array(f['Header']['ant_2_array'][:])
          visdata = visdata.reshape((-1, 325, 48, 2))
          ant1 = ant1.reshape(-1, 325)[0, :]
          ant2 = ant2.reshape(-1, 325)[0, :]
          with open(
                  '{0}/beamformer_weights_corr{1:02d}_{2}.dat'.format(
                      gaindir,
                      corr,
                      beamformer_name
                  ),
                  'rb'
          ) as f:
              data = np.fromfile(f, '<f4')
          gains = data[64:].reshape(64, 48, 2, 2)
          gains = gains[..., 0]+1.0j*gains[..., 1]
          my_gains = np.zeros((325, 48, 2), dtype=np.complex)
          for i in range(325):
              idx1 = np.where(antennas == ant1[i]+1)[0][0]
              idx2 = np.where(antennas == ant2[i]+1)[0][0]
              my_gains[i, ...] = np.conjugate(gains[idx1, ...])*gains[idx2, ...]
          visdata_corr[:, :, corridx, ...] = (
              visdata*my_gains[np.newaxis, :, :, :]
          )
      visdata_corr = visdata_corr.reshape((-1, 325, 16*48, 2))
  
      fig, ax = plt.subplots(5, 4, figsize=(25, 12), sharex=True, sharey=True)
      for axi in ax[-1, :]:
          axi.set_xlabel('freq channel')
      for axi in ax[:, 0]:
          axi.set_ylabel('time bin')
      ax = ax.flatten()
      for i, ant in enumerate(antennas_to_plot-1):
          idx = np.where((ant1 == 23) & (ant2 == ant))[0][0]
          ax[i].imshow(
              np.angle(
                  visdata_corr[:, idx, :, 0]/visdata_corr[:, idx, :, 1]
              ),
              aspect='auto',
              origin='lower',
              interpolation='none',
              cmap=plt.get_cmap('RdBu'),
              vmin=-np.pi,
              vmax=np.pi
          )
          ax[i].set_title(
              '24-{0}, {1:.2f}'.format(
                  ant+1,
                  np.angle(
                      np.mean(
                          visdata_corr[:, idx, :, 0]/visdata_corr[:, idx, :, 1]
                      )
                  )
              )
          )
      fig.suptitle('{0} {1}'.format(date, calname))
      if outname is not None:
          plt.savefig('{0}_beamformerweights.png'.format(outname))
      if not show:
          plt.close()
code_tokens: def plot_current_beamformer_solutions ( filenames , calname , date , beamformer_name , corrlist = np . arange ( 1 , 16 + 1 ) , antennas_to_plot = None , antennas = None , outname = None , show = True , gaindir = '/home/user/beamformer_weights/' , hdf5dir = '/mnt/data/dsa110/correlator/' ) : if antennas is None : antennas = np . array ( list ( CONF . get ( 'corr' ) [ 'antenna_order' ] . values ) ) assert len ( antennas ) == 64 if antennas_to_plot is None : antennas_to_plot = antennas visdata_corr = np . zeros ( ( len ( filenames ) * 280 , 325 , 16 , 48 , 2 ) , dtype = np . complex ) for corridx , corr in enumerate ( corrlist ) : visdata = np . zeros ( ( len ( filenames ) , 91000 , 1 , 48 , 2 ) , dtype = np . complex ) for i , filename in enumerate ( filenames ) : files = sorted ( glob . glob ( '{0}/corr{1:02d}/{2}??.hdf5' . format ( hdf5dir , corr , filename [ : - 2 ] ) ) ) if len ( files ) > 0 : with h5py . File ( files [ 0 ] , 'r' ) as f : visdata [ i , ... ] = np . array ( f [ 'Data' ] [ 'visdata' ] [ : ] ) ant1 = np . array ( f [ 'Header' ] [ 'ant_1_array' ] [ : ] ) ant2 = np . array ( f [ 'Header' ] [ 'ant_2_array' ] [ : ] ) visdata = visdata . reshape ( ( - 1 , 325 , 48 , 2 ) ) ant1 = ant1 . reshape ( - 1 , 325 ) [ 0 , : ] ant2 = ant2 . reshape ( - 1 , 325 ) [ 0 , : ] with open ( '{0}/beamformer_weights_corr{1:02d}_{2}.dat' . format ( gaindir , corr , beamformer_name ) , 'rb' ) as f : data = np . fromfile ( f , '<f4' ) gains = data [ 64 : ] . reshape ( 64 , 48 , 2 , 2 ) gains = gains [ ... , 0 ] + 1.0j * gains [ ... , 1 ] my_gains = np . zeros ( ( 325 , 48 , 2 ) , dtype = np . complex ) for i in range ( 325 ) : idx1 = np . where ( antennas == ant1 [ i ] + 1 ) [ 0 ] [ 0 ] idx2 = np . where ( antennas == ant2 [ i ] + 1 ) [ 0 ] [ 0 ] my_gains [ i , ... ] = np . conjugate ( gains [ idx1 , ... ] ) * gains [ idx2 , ... ] visdata_corr [ : , : , corridx , ... ] = ( visdata * my_gains [ np . newaxis , : , : , : ] ) visdata_corr = visdata_corr . reshape ( ( - 1 , 325 , 16 * 48 , 2 ) ) fig , ax = plt . subplots ( 5 , 4 , figsize = ( 25 , 12 ) , sharex = True , sharey = True ) for axi in ax [ - 1 , : ] : axi . set_xlabel ( 'freq channel' ) for axi in ax [ : , 0 ] : axi . set_ylabel ( 'time bin' ) ax = ax . flatten ( ) for i , ant in enumerate ( antennas_to_plot - 1 ) : idx = np . where ( ( ant1 == 23 ) & ( ant2 == ant ) ) [ 0 ] [ 0 ] ax [ i ] . imshow ( np . angle ( visdata_corr [ : , idx , : , 0 ] / visdata_corr [ : , idx , : , 1 ] ) , aspect = 'auto' , origin = 'lower' , interpolation = 'none' , cmap = plt . get_cmap ( 'RdBu' ) , vmin = - np . pi , vmax = np . pi ) ax [ i ] . set_title ( '24-{0}, {1:.2f}' . format ( ant + 1 , np . angle ( np . mean ( visdata_corr [ : , idx , : , 0 ] / visdata_corr [ : , idx , : , 1 ] ) ) ) ) fig . suptitle ( '{0} {1}' . format ( date , calname ) ) if outname is not None : plt . savefig ( '{0}_beamformerweights.png' . format ( outname ) ) if not show : plt . close ( )
short_docstring: r"""Plots the phase difference between the two polarizations.
short_docstring_tokens: r " " " Plots the phase difference between the two polarizations .
comment: r"""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'
      beamformer_name : str
          The title of the beamformer weights.
          e.g. 'J141120+521209_2021-02-19T12:05:51'
      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`.
      antennas : array(int)
          The names of the antennas for which beamformer solutions were
          generated.  Defaults to values in dsautils.cnf
      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??/
      """$SEP$# Should be generalized to different times, baselines