Get required modules imported


In [1]:
import copy, glob
import progressbar as PGB
import h5py
import numpy as NP
import numpy.ma as MA
from scipy import interpolate, stats
import matplotlib.pyplot as PLT
import matplotlib.colors as PLTC
import matplotlib.ticker as PLTick
import yaml, argparse, warnings
from astropy.io import ascii
import astropy.units as U
from astropy.stats import sigma_clipped_stats, histogram
from astroutils import DSP_modules as DSP
from astroutils import constants as CNST
from astroutils import mathops as OPS
from astroutils import nonmathops as NMO
from astroutils import lookup_operations as LKP
import astroutils
import prisim
from prisim import interferometry as RI
from prisim import bispectrum_phase as BSP
from prisim import delay_spectrum as DS
from IPython.core.debugger import set_trace
%matplotlib inline

In [2]:
print('AstroUtils git # {0}\nPRISim git # {1}'.format(astroutils.__githash__, prisim.__githash__))


AstroUtils git # 1be75833b358cbc53ff9fd12ec376a5c6335463a
PRISim git # bb083bc1abd3ef44d0b18c094fedfe3dc30ed6ac

Read YAML file containing input parameters


In [44]:
inparmsfile = '/lustre/aoc/users/nthyagar/codes/mine/python/projects/closure/multiday_EQ28XX_data_Fornax_transit_closure_PS_analysis_parms.yaml'
with open(inparmsfile, 'r') as parms_file:
    parms = yaml.safe_load(parms_file)

In [39]:
print(parms)


{'plot': {'1g': {'action': False, 'infile1': 'EQ14new', 'infile2': 'EQ14old', 'avgind': 0, 'obsind': 0}, '1f': {'action': False, 'labels': ['EWs', 'EQ14', 'EQ29'], 'obsind': 0, 'infiles': ['EW14', 'EQ14', 'EQ28'], 'avgind': 0}, '3b': {'action': False}, '1b': {'action': False, 'triad': [0, 23, 25]}, '1': {'action': False}, '2d': {'action': True, 'kbin_min': None, 'kbin_max': None, 'kbintype': 'linear', 'num_kbins': None}, '2c_err': {'action': True, 'other_pserr_file': 'xCPDPS_collapse_axes_123_EQ28XX_HI_21cmfast_FaintGalaxies_fiducial_Fornax_GLEAM_all_FOV_30_ephemeris_HERA61_14.0_arcmin_v2_noisy_errinfo_incoh_diag_avg.hdf5', 'current_lbl': 'Data', 'other_label': 'Model'}, '2f': {'collapseax': [1], 'incohax': [1, 2, 3], 'selection': {'triads': None, 'lst': [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52], 'dlst_range': [1.1], 'days': None}, 'datapool': 'whole', 'antloc_file': '/data4/HERA_Simulations/simulations/hera_layouts/antenna_positions_350.dat', 'cohax': None, 'subselection': {'spw': None, 'day': [[0, 0], [0, 1]], 'lstdiag': [0, 1]}, 'statistic': 'median', 'action': False}, '1a': {'action': False, 'triad': None}, '2e': {'action': False, 'subselection': {'triaddiag': [0], 'spw': [0, 1], 'day': [[0, 1]], 'lstdiag': [0, 1]}}, '3': {'21cm_PS_dir': '/lustre/aoc/users/nthyagar/data/EoR_models/21cmFAST/Andrei_Mesinger/Faint_galaxies_fiducial_1024/PS/21cm_PS/', 'simlabels': ['FG', 'HI'], 'sim_rootdir': '/lustre/aoc/projects/hera/nthyagar/data/HERA/IDR2.1/ClosurePhase/models/visibilities/', 'action': True, 'visdirs': ['Fornax_GLEAM_all_FOV30_ephemeris_HERA61/Fornax_transit_NFbeam_120x10.7sec_1024x97.7kHz/simdata/', 'HI_21cmfast_FaintGalaxies_fiducial/14.0arcmin_v2/Fornax_transit_NFbeam_120x10.7sec_1024x97.7kHz/simdata/'], 'sampling': 'resampled', 'visfile_prfx': 'all-simvis'}, '2': {'incohax': [1, 2, 3], 'selection': {'lstrange': [3.0, 3.6], 'triads': None, 'lst': [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52], 'dlst_range': [1.1], 'days': None}, 'PS_dir': 'PS/', 'xlim': None, 'beaminfo': {'filefmt': 'UVbeam', 'telescope': {'shape': 'dish', 'ocoords': 'altaz', 'orientation': [90.0, 270.0], 'ground_plane': None, 'size': 14.0, 'id': 'hera', 'phased_array': False}, 'nside': 128, 'select_freq': 150000000.0, 'chromatic': True, 'pol': 'X', 'beamfile': 'NF_HERA_antenna_power_pattern_99-201_MHz_nside_128.uvbeam', 'filepathtype': 'default', 'spec_interp': 'cubic'}, 'datapool': ['whole'], 'collapseax_b': [1, 2, 3], 'collapseax_a': [1, 3], 'sampling': 'resampled', 'cohax': None, 'units': 'K', 'infile_pfx_b': 'xCPDPS_collapse_axes_123', 'modelinfo': {'outfile_pfx_b': ['xCPDPS_collapse_axes_123', 'xCPDPS_collapse_axes_123'], 'PS_dir': ['/lustre/aoc/projects/hera/nthyagar/data/HERA/IDR2.1/ClosurePhase/models/bispectrum_phase/PS/', '/lustre/aoc/projects/hera/nthyagar/data/HERA/IDR2.1/ClosurePhase/models/bispectrum_phase/PS/'], 'mdl_day': [[[0, 0], [0, 0]]], 'mdl_cohax': [None, None], 'mdl_ndaybins': [2, 2], 'infile_pfx_a': ['xCPDPS_collapse_axes_13', 'xCPDPS_collapse_axes_13'], 'outfile_pfx_a': ['xCPDPS_collapse_axes_13', 'xCPDPS_collapse_axes_13'], 'infile_pfx_b': ['xCPDPS_collapse_axes_123', 'xCPDPS_collapse_axes_123'], 'mdl_collapax_a': [[1, 3], [1, 3]], 'mdl_collapax_b': [[1, 2, 3], [1, 2, 3]], 'mdl_incohax': [[1, 2, 3], [1, 2, 3]]}, 'statistic': 'median', 'action': True, 'infile_pfx_a': 'xCPDPS_collapse_axes_13', 'subselection': {'triaddiag': [0], 'spw': [0, 1], 'day': [[0, 1]], 'lstdiag': [0, 1]}, 'outfile_pfx_a': 'xCPDPS_collapse_axes_13', 'errtype': ['ssdiff'], 'outfile_pfx_b': 'xCPDPS_collapse_axes_123', 'nsigma': 1.0}, '1e': {'action': False, 'triplet': [25, 26, 39], 'infile': 'EQ14', 'obsind': 0}, '1d': {'selection': {'lstrange': [3.0, 3.7], 'triads': None, 'dayind': 1}, 'applyflags': False, 'action': False, 'datastage': 'prelim', 'statistic': 'median', 'sparseness': 1.0}, '2b': {'action': False}, '2c': {'kprll_min': 0.85, 'action': True, 'diagoffsets_b': [[[0], [1], [0]], [[0], [1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]], [[0], [1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]], [[0], [-1, 0, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]]], 'diagoffsets_a': [[[0], [0]], [[0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]], [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]], [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]]], 'incohax_b': [[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]], 'incohax_a': [[1, 3], [1, 3], [1, 3], [1, 3]]}, '1h': {'action': True, 'selection': {'lstrange': [3.0, 3.7], 'triads': None, 'dayind': 0}, 'freq_bins': [115000000.0, 120000000.0, 125000000.0, 130000000.0, 135000000.0], 'statistic': 'rms'}, '3a': {'action': True, 'bl': [[14.6, 0.0, 0.0], [29.2, 0.0, 0.0]], 'bltol': 0.2, 'lst': None, 'spw': None}, '1c': {'action': False}, '2a': {'action': False}}, 'preProcessing': {'daybinsize': None, 'flagchans': [511], 'band_center': 150000000.0, 'freq_resolution': 97656.25, 'lstbinsize': 60.0, 'flagants': [50], 'appendaxis': 'obsid', 'ndaybins': 2, 'action': True, 'append': False}, 'delaySpectrum': {'bl': [[29.2, 0.0, 0.0], [14.6, 25.287942, 0.0], [-14.6, 25.287942, 0.0]], 'pad': 1.0, 'bltol': 0.1, 'subband': {'shape': 'bhw', 'fftpow': 2.0, 'freq_center': [126500000.0, 163000000.0], 'bw_eff': [10000000.0, 10000000.0]}, 'applyflags': False}, 'dirStruct': {'visfiletype': 'prisim', 'infiles': ['output_bin.npz'], 'projectdir': '/lustre/aoc/projects/hera/nthyagar/data/HERA/IDR2.1/ClosurePhase/Binned_Data/', 'hdf5_infile': 'EQ28XX.hdf5', 'model_hdf5files': ['EQ28XX_Fornax_GLEAM_all_FOV_30_ephemeris_HERA61_noiseless.hdf5', 'EQ28XX_HI_21cmfast_FaintGalaxies_fiducial_Fornax_GLEAM_all_FOV_30_ephemeris_HERA61_14.0_arcmin_v2_noiseless.hdf5'], 'datadir': 'EQ28/XX/', 'model_labels': ['FG', 'FG+HI'], 'visfile': '/lustre/aoc/projects/hera/nthyagar/data/HERA/IDR2.1/ClosurePhase/models/visibilities/Fornax_GLEAM_all_FOV30_ephemeris_HERA61/Fornax_transit_NFbeam_120x10.7sec_1024x97.7kHz/simdata/simvis', 'modeldir': '/lustre/aoc/projects/hera/nthyagar/data/HERA/IDR2.1/ClosurePhase/models/bispectrum_phase/', 'model_npzfiles': ['EQ28XX_Fornax_GLEAM_all_FOV_30_ephemeris_HERA61_noiseless.npz', 'EQ28XX_HI_21cmfast_FaintGalaxies_fiducial_Fornax_GLEAM_all_FOV_30_ephemeris_HERA61_14.0_arcmin_v2_noiseless.npz'], 'figdir': 'figures/'}, 'telescope': {'latitude': -30.7224, 'longitude': 21.4278}}

Parse YAML file and obtain input parameters


In [40]:
projectdir = parms['dirStruct']['projectdir']
datadir = projectdir + parms['dirStruct']['datadir']
figdir = datadir + parms['dirStruct']['figdir']
modelsdir = parms['dirStruct']['modeldir']
infiles = parms['dirStruct']['infiles']
visfile = parms['dirStruct']['visfile']
visfiletype = parms['dirStruct']['visfiletype']
hdf5_infile = parms['dirStruct']['hdf5_infile']
model_hdf5files = parms['dirStruct']['model_hdf5files']
model_labels = parms['dirStruct']['model_labels']

telescope_parms = parms['telescope']
site_latitude = telescope_parms['latitude']
site_longitude = telescope_parms['longitude']

preprocessinfo = parms['preProcessing']
preprocess = preprocessinfo['action']
flagchans = preprocessinfo['flagchans']
if flagchans is not None:
    flagchans = NP.asarray(preprocessinfo['flagchans']).reshape(-1)
flagants = preprocessinfo['flagants']
if flagants is not None:
    flagants = NP.asarray(preprocessinfo['flagants']).reshape(-1)
daybinsize = preprocessinfo['daybinsize']
ndaybins = preprocessinfo['ndaybins']
lstbinsize = preprocessinfo['lstbinsize']
band_center = preprocessinfo['band_center']
freq_resolution = preprocessinfo['freq_resolution']

dspecinfo = parms['delaySpectrum']
subbandinfo = dspecinfo['subband']
freq_window_centers = NP.asarray(subbandinfo['freq_center'])
freq_window_bw = NP.asarray(subbandinfo['bw_eff'])
freq_window_shape = subbandinfo['shape']
freq_window_fftpow = subbandinfo['fftpow']
pad = dspecinfo['pad']
apply_flags = dspecinfo['applyflags']
if apply_flags:
    applyflags_str = 'Y'
else:
    applyflags_str = 'N'

Read and load Reference visibilities for appropriate scaling


In [6]:
bl = NP.asarray(dspecinfo['bl'])
if bl.shape[0] != 3:
    raise ValueError('Input bl must be made of three vectors forming the triad')
bltol = dspecinfo['bltol']

infile = infiles[0]
infile_no_ext = hdf5_infile.split('.hdf5')[0]

# visdata = NP.load(visfile)
if visfile is None:
    visinfo = None
else:
    if visfiletype == 'hdf5':
        visinfo = NMO.load_dict_from_hdf5(visfile+'.hdf5')
        blind, blrefind, dbl = LKP.find_1NN(visinfo['baseline']['blvect'], bl, distance_ULIM=bltol, remove_oob=True)
        if blrefind.size != 3:
            blind_missing = NP.setdiff1d(NP.arange(3), blind, assume_unique=True)
            blind_next, blrefind_next, dbl_next = LKP.find_1NN(visinfo['baseline']['blvect'], -1*bl[blind_missing,:], distance_ULIM=bltol, remove_oob=True)
            if blind_next.size + blind.size != 3:
                raise ValueError('Exactly three baselines were not found in the reference baselines')
            else:
                blind = NP.append(blind, blind_missing[blind_next])
                blrefind = NP.append(blrefind, blrefind_next)
        else:
            blind_missing = []

        vistriad = MA.array(visinfo['vis_real'][blrefind,:,:] + 1j * visinfo['vis_imag'][blrefind,:,:], mask=visinfo['mask'][blrefind,:,:])
        if len(blind_missing) > 0:
            vistriad[-blrefind_next.size:,:,:] = vistriad[-blrefind_next.size:,:,:].conj()
    else:
        visinfo = RI.InterferometerArray(None, None, None, init_file=visfile)

In [7]:
print(visinfo.skyvis_freq.shape)
print(visinfo.lst/15.0) # LST in hours


(1738, 1024, 120)
[3.21168913 3.21466949 3.21764985 3.22063021 3.22361057 3.22659093
 3.22957129 3.23255165 3.23553201 3.23851237 3.24149273 3.24447309
 3.24745345 3.25043381 3.25341417 3.25639453 3.25937489 3.26235525
 3.26533561 3.26831597 3.27129633 3.27427669 3.27725705 3.28023741
 3.28321777 3.28619813 3.28917849 3.29215885 3.29513921 3.29811957
 3.30109993 3.30408029 3.30706065 3.31004101 3.31302137 3.31600173
 3.31898209 3.32196245 3.32494281 3.32792317 3.33090353 3.33388389
 3.33686425 3.33984461 3.34282497 3.34580533 3.34878569 3.35176605
 3.35474641 3.35772677 3.36070713 3.36368749 3.36666785 3.36964821
 3.37262857 3.37560893 3.37858929 3.38156965 3.38455001 3.38753037
 3.39051073 3.39349109 3.39647145 3.39945181 3.40243217 3.40541253
 3.40839289 3.41137325 3.41435361 3.41733397 3.42031433 3.42329469
 3.42627505 3.42925541 3.43223577 3.43521613 3.43819649 3.44117685
 3.44415721 3.44713757 3.45011793 3.45309829 3.45607865 3.45905901
 3.46203937 3.46501973 3.46800009 3.47098045 3.47396081 3.47694117
 3.47992153 3.48290189 3.48588225 3.48886261 3.49184297 3.49482333
 3.49780369 3.50078405 3.50376441 3.50674477 3.50972513 3.51270549
 3.51568585 3.51866621 3.52164657 3.52462693 3.52760729 3.53058765
 3.53356801 3.53654837 3.53952873 3.54250909 3.54548945 3.54846981
 3.55145017 3.55443053 3.55741089 3.56039125 3.56337161 3.56635197]

Load NPZ file containing Closure Phases for basic information


In [8]:
tmpnpzdata = NP.load(datadir+infile)
nchan = tmpnpzdata['flags'].shape[-1]
freqs = band_center + freq_resolution * (NP.arange(nchan) - int(0.5*nchan))

In [9]:
print(tmpnpzdata['last'])


[[64829.11431047 64830.1143047  64832.11430063 ... 64846.11436997
  64847.11437008 64871.11453327]
 [64829.11443509 64830.11442932 64832.11442524 ... 64846.11449458
  64847.11449469 64871.11465789]
 [64829.1145597  64830.11455394 64832.11454986 ... 64846.1146192
  64847.11461931 64871.11478251]
 ...
 [64829.16378299 64830.16377723 64832.16377315 ... 64846.16384249
  64847.1638426  64871.1640058 ]
 [64829.16390761 64830.16390185 64832.16389776 ... 64846.16396711
  64847.16396721 64871.16413041]
 [64829.16403222 64830.16402646 64832.16402238 ... 64846.16409172
  64847.16409183 64871.16425503]]

Initialize instance of class ClosurePhase


In [10]:
cpObj = BSP.ClosurePhase(datadir+hdf5_infile, freqs, infmt='hdf5')

In [11]:
print(cpObj.cpinfo['raw']['lst'].shape)
print(cpObj.cpinfo['raw']['lst'])


(400, 19)
[[2.74345129 2.7433129  2.74321509 ... 2.74487924 2.74488183 2.7487986 ]
 [2.74644207 2.74630368 2.74620587 ... 2.74787003 2.74787261 2.75178938]
 [2.74943285 2.74929446 2.74919665 ... 2.75086081 2.75086339 2.75478016]
 ...
 [3.93079174 3.93065353 3.93055557 ... 3.9322198  3.93222233 3.93613912]
 [3.93378252 3.93364431 3.93354635 ... 3.93521058 3.93521311 3.9391299 ]
 [3.9367733  3.93663509 3.93653714 ... 3.93820137 3.93820389 3.94212069]]

In [12]:
print(cpObj.cpinfo.keys())


[u'raw', 'processed', 'errinfo']

In [13]:
print(cpObj.cpinfo['raw'].keys())
print(cpObj.cpinfo['raw']['triads'].shape)
print(cpObj.cpinfo['raw']['days'].shape)
print(cpObj.cpinfo['raw']['lst-day'].shape)
print(cpObj.cpinfo['raw']['lst'].shape)
print(cpObj.cpinfo['raw']['cphase'].shape)


[u'triads', u'cphase', u'days', u'lst-day', u'lst', u'flags', u'std_triads', u'std_lst', u'dayavg']
(31, 3)
(19,)
(400, 19)
(400, 19)
(400, 19, 31, 1024)

Smooth in LST and days


In [14]:
print('day bin size = '+str(daybinsize), 'ndaybins={0:0d}'.format(ndaybins), 'LST bin size = {0:.1f}s'.format(lstbinsize))
cpObj.smooth_in_tbins(daybinsize=daybinsize, ndaybins=ndaybins, lstbinsize=lstbinsize)


('day bin size = None', 'ndaybins=2', 'LST bin size = 60.0s')
/lustre/aoc/users/nthyagar/src/miniconda2/envs/PRISim-dev/lib/python2.7/site-packages/scipy/stats/_binned_statistic.py:607: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  result = result[core]

In [15]:
print(cpObj.cpinfo['processed'].keys())


['prelim', 'native']

In [16]:
print(cpObj.cpinfo['processed']['prelim'].keys())
print(cpObj.cpinfo['processed']['prelim']['cphase'].keys())
print(cpObj.cpinfo['processed']['prelim']['lstbins'].shape)
print(cpObj.cpinfo['processed']['prelim']['lstbins'])
print(cpObj.cpinfo['processed']['prelim']['daybins'].shape)
print(cpObj.cpinfo['processed']['prelim']['daybins'])
print(cpObj.cpinfo['processed']['prelim']['cphase']['median'].shape)
print(cpObj.cpinfo['processed']['prelim']['eicp']['median'].shape)


['cphase', 'wts', 'eicp', 'dlstbins', 'daybins', 'lstbins', 'diff_dbins']
['rms', 'median', 'mad', 'mean']
(72,)
[2.75178462 2.76845129 2.78511796 2.80178462 2.81845129 2.83511796
 2.85178462 2.86845129 2.88511796 2.90178462 2.91845129 2.93511796
 2.95178462 2.96845129 2.98511796 3.00178462 3.01845129 3.03511796
 3.05178462 3.06845129 3.08511796 3.10178462 3.11845129 3.13511796
 3.15178462 3.16845129 3.18511796 3.20178462 3.21845129 3.23511796
 3.25178462 3.26845129 3.28511796 3.30178462 3.31845129 3.33511796
 3.35178462 3.36845129 3.38511796 3.40178462 3.41845129 3.43511796
 3.45178462 3.46845129 3.48511796 3.50178462 3.51845129 3.53511796
 3.55178462 3.56845129 3.58511796 3.60178462 3.61845129 3.63511796
 3.65178462 3.66845129 3.68511796 3.70178462 3.71845129 3.73511796
 3.75178462 3.76845129 3.78511796 3.80178462 3.81845129 3.83511796
 3.85178462 3.86845129 3.88511796 3.90178462 3.91845129 3.93511796]
(2,)
[2458103.3        2458115.55555556]
(72, 2, 31, 1024)
(72, 2, 31, 1024)

Subtract a model of Closure Phase (optional)

Creates new keys 'submodel' and 'residual' with a key-value structure similar to 'prelim'


In [17]:
cpObj.subtract(NP.zeros(1024))
print(cpObj.cpinfo['processed'].keys())


['prelim', 'residual', 'submodel', 'native']

Create subsample differences to keep track of noise from the noisy data


In [18]:
# ndaybins=4
print('ndaybins={0:0d}'.format(4), 'LST bin size = {0:.1f}s'.format(lstbinsize))
cpObj.subsample_differencing(daybinsize=None, ndaybins=4, lstbinsize=lstbinsize)


('ndaybins=4', 'LST bin size = 60.0s')

In [19]:
print(cpObj.cpinfo['errinfo'].keys())
print(cpObj.cpinfo['errinfo']['daybins'].shape)
print(cpObj.cpinfo['errinfo']['lstbins'].shape)
print(len(cpObj.cpinfo['errinfo']['list_of_pair_of_pairs']))
print(cpObj.cpinfo['errinfo']['list_of_pair_of_pairs'])
print(cpObj.cpinfo['errinfo']['eicp_diff'].keys())
print(cpObj.cpinfo['errinfo']['eicp_diff']['0'].keys())
print(cpObj.cpinfo['errinfo']['eicp_diff']['0']['median'].shape)
print(cpObj.cpinfo['errinfo']['eicp_diff']['1']['median'].shape)


['wts', 'eicp_diff', 'dlstbins', 'daybins', 'lstbins', 'list_of_pair_of_pairs', 'diff_dbins']
(4,)
(72,)
3
[[0, 1, 2, 3], [0, 2, 1, 3], [0, 3, 1, 2]]
['1', '0']
['median', 'mean']
(72, 3, 31, 1024)
(72, 3, 31, 1024)

Create an instance of class ClosurePhaseDelaySpectrum


In [20]:
cpDSobj = BSP.ClosurePhaseDelaySpectrum(cpObj)

Prepare to compute delay spectrum of the ClosurePhaseDelaySpectrum instance


In [21]:
if visinfo is not None:
    if visfiletype == 'hdf5':
        visscaleinfo = {'vis': vistriad, 'lst': visinfo['header']['LST'], 'smoothinfo': {'op_type': 'interp1d', 'interp_kind': 'linear'}}
    else:
        visscaleinfo = {'vis': visinfo, 'bltriplet': bl, 'smoothinfo': {'op_type': 'interp1d', 'interp_kind': 'linear'}}
else:
    visscaleinfo = None

In [22]:
print('freq window centers = ', freq_window_centers)
print('freq window BW eff = ', freq_window_bw)
print('freq window shape = '+freq_window_shape)
print('freq window fftpow = {0:.1f}'.format(freq_window_fftpow))
print('pad = {0:.1f}'.format(pad))


('freq window centers = ', array([1.265e+08, 1.630e+08]))
('freq window BW eff = ', array([10000000., 10000000.]))
freq window shape = bhw
freq window fftpow = 2.0
pad = 1.0

compute delay spectrum of the ClosurePhaseDelaySpectrum instance


In [23]:
cpds = cpDSobj.FT(freq_window_bw, freq_center=freq_window_centers, shape=freq_window_shape, fftpow=freq_window_fftpow, pad=pad, datapool='prelim', visscaleinfo=visscaleinfo, method='fft', resample=True, apply_flags=apply_flags)


/lustre/aoc/users/nthyagar/src/miniconda2/envs/PRISim-dev/lib/python2.7/site-packages/numpy/ma/core.py:2788: ComplexWarning: Casting complex values to real discards the imaginary part
  order=order, subok=True, ndmin=ndmin)
/lustre/aoc/users/nthyagar/src/miniconda2/envs/PRISim-dev/lib/python2.7/site-packages/astroutils/mathops.py:1344: RuntimeWarning: invalid value encountered in less
  mask_out = NP.logical_or(wts_interped.data < eps, NP.isnan(wts_interped.data)) # Mask small, negative, and NaN weights
	Renormalized the shaping window to unit power.
	Renormalized the shaping window to unit power.

Gather info on plots to be made


In [47]:
plot_info = parms['plot']
plots = [key for key in plot_info if plot_info[key]['action']]
print(plots)


['2d', '2c_err', '3', '2', '2c', '1h', '3a']

Plots 1: Inspect closure phase spectra

1a) Plot closure phase spectra and flags/weights for given obsid index and maybe antenna triplet with mean, median and deviation info


In [28]:
if ('1' in plots) or ('1a' in plots) or ('1b' in plots) or ('1c' in plots) or ('1d' in plots):
    triads = map(tuple, cpDSobj.cPhase.cpinfo['raw']['triads'])
    ntriads = len(triads)
    lst = cpDSobj.cPhase.cpinfo['raw']['lst']
    ntimes = lst.size
    tbins = cpDSobj.cPhase.cpinfo['processed']['prelim']['lstbins']
    ntbins = tbins.size
    dlst = lst[1] - lst[0]
    dtbins = cpDSobj.cPhase.cpinfo['processed']['prelim']['dlstbins']
    flags = cpDSobj.cPhase.cpinfo['raw']['flags']
    wts_raw = cpDSobj.cPhase.cpinfo['processed']['native']['wts'].data
    wts_proc = cpDSobj.cPhase.cpinfo['processed']['prelim']['wts'].data
    freq_wts = cpds['freq_wts']
    triad = plot_info['1a']['triad']
    if triad is not None:
        triads_to_plot = tuple(triad)
    else:
        triads_to_plot = triads
    print(triad)
    # triad = (0, 1, 12)
    # triad_ind = triads.index(triad)

In [29]:
print(triads_to_plot)
    # print(triad_ind)
    print(lst) 
    print(dlst*3600) # Difference between adjacent LST (in seconds)
    print(tbins)
    print(wts_raw.shape)
    print(wts_raw[:,0,triad_ind,:].shape)
    print(wts_raw[:,0,triad_ind,620].shape)
    print(dtbins*3.6e3)
    print(wts_proc.shape)
    # print(wts_proc[:,0,triad_ind,:].shape)
    # print(wts_proc[:,0,triad_ind,:].min(), wts_proc[:,0,triad_ind,:].max())
    # print(wts_proc[:,0,triad_ind,620])


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-29-b966d2a4c0b4> in <module>()
----> 1 print(triads_to_plot)
      2 # print(triad_ind)
      3 print(lst)
      4 print(dlst*3600) # Difference between adjacent LST (in seconds)
      5 print(tbins)

NameError: name 'triads_to_plot' is not defined

1a.1) Plot raw weights for a sample triad on a sample day


In [27]:
if '1a' in plots:
        ncol = 3
        nrow = NP.ceil(1.0 * len(triads_to_plot) / ncol).astype(int)
        for irow in range(nrow):
            fig, axs = PLT.subplots(ncols=ncol, figsize=(5*ncol,4))
            for icol in range(ncol):
                triadnum = irow*ncol + icol
                if triadnum < len(triads_to_plot):
                    triplet = triads_to_plot[triadnum]
                    triad_ind = triads.index(triplet)
                    axs[icol].imshow(wts_raw[:,0,triad_ind,:], origin='lower', extent=[1e-6*freqs.min(), 1e-6*freqs.max(), lst.min(), lst.max()+NP.mean(dlst)], vmin=wts_raw.min(), vmax=wts_raw.max(), interpolation='none', cmap='gray')
                    axs[icol].text(0.5, 0.97, '({0[0]:0d}, {0[1]:0d}, {0[2]:0d})'.format(triplet), transform=axs[icol].transAxes, fontsize=12, weight='semibold', ha='center', va='top', color='red')
                    axs[icol].set_xlim(1e-6*freqs.min(), 1e-6*freqs.max())
                    axs[icol].set_ylim(lst.min(), lst.max()+NP.mean(dlst))
                    axs[icol].set_aspect('auto')
                    axs[icol].set_xlabel(r'$f$ [MHz]', fontsize=12, weight='medium')
                    axs[icol].set_ylabel('LST [Hours]', fontsize=12, weight='medium')
                else:
                    axs[icol].spines['top'].set_visible(False)
                    axs[icol].spines['right'].set_visible(False)
                    axs[icol].spines['bottom'].set_visible(False)
                    axs[icol].spines['left'].set_visible(False)
                    axs[icol].set_xticklabels([])
                    axs[icol].set_xticks([])
                    axs[icol].set_yticklabels([])
                    axs[icol].set_yticks([])

            # PLT.savefig(figdir + '{0}_time_frequency_flags_triad_{1[0]:0d}_{1[1]:0d}_{1[2]:0d}.pdf'.format(infile_no_ext, triad), bbox_inches=0)


1a.2) Plot processed weights for a sample triad on a sample day


In [28]:
for dayind in range(ndaybins):
            for irow in range(nrow):
                fig, axs = PLT.subplots(ncols=ncol, figsize=(5*ncol,4))
                for icol in range(ncol):
                    triadnum = irow*ncol + icol
                    if triadnum < len(triads_to_plot):
                        triplet = triads_to_plot[triadnum]
                        triad_ind = triads.index(triplet)
                        wtsimg = axs[icol].imshow(wts_proc[:,dayind,triad_ind,:], origin='lower', extent=[1e-6*freqs.min(), 1e-6*freqs.max(), tbins.min(), tbins.max()+NP.mean(dtbins)], vmin=wts_proc.min(), vmax=wts_proc.max(), interpolation='none', cmap='gray')
                        axs[icol].text(0.5, 0.97, '({0[0]:0d}, {0[1]:0d}, {0[2]:0d})'.format(triplet), transform=axs[icol].transAxes, fontsize=12, weight='semibold', ha='center', va='top', color='red')
                        axs[icol].set_xlim(1e-6*freqs.min(), 1e-6*freqs.max())
                        axs[icol].set_ylim(tbins.min(), tbins.max()+NP.mean(dtbins))
                        axs[icol].set_aspect('auto')
                        axs[icol].set_xlabel(r'$f$ [MHz]', fontsize=12, weight='medium')
                        axs[icol].set_ylabel('LST [Hours]', fontsize=12, weight='medium')
                    else:
                        axs[icol].spines['top'].set_visible(False)
                        axs[icol].spines['right'].set_visible(False)
                        axs[icol].spines['bottom'].set_visible(False)
                        axs[icol].spines['left'].set_visible(False)
                        axs[icol].set_xticklabels([])
                        axs[icol].set_xticks([])
                        axs[icol].set_yticklabels([])
                        axs[icol].set_yticks([])

#         fig = PLT.figure(figsize=(6,5))
#         ax = fig.add_subplot(111)
#         wtsimg = ax.imshow(wts_proc[:,0,triad_ind,:], origin='lower', extent=[1e-6*freqs.min(), 1e-6*freqs.max(), tbins.min(), tbins.max()+NP.mean(dtbins)], vmin=wts_proc.min(), vmax=wts_proc.max(), interpolation='none', cmap='gray')
#         ax.text(0.5, 0.97, '({0[0]:0d}, {0[1]:0d}, {0[2]:0d})'.format(triad), transform=ax.transAxes, fontsize=12, weight='semibold', ha='center', va='top', color='red')
#         ax.set_xlim(1e-6*freqs.min(), 1e-6*freqs.max())
#         ax.set_ylim(tbins.min(), tbins.max()+NP.mean(dtbins))
#         ax.set_aspect('auto')
#         ax.set_xlabel(r'$f$ [MHz]', fontsize=12, weight='medium')
#         ax.set_ylabel('LST [hours]', fontsize=12, weight='medium')
#         cbax = fig.add_axes([0.86, 0.2, 0.02, 0.75])
#         cbar = fig.colorbar(wtsimg, cax=cbax, orientation='vertical')
#         cbax.yaxis.tick_right()
#         # cbax.yaxis.set_label_position('right')
            
#         fig.subplots_adjust(top=0.95)
#         fig.subplots_adjust(left=0.2)
#         fig.subplots_adjust(bottom=0.2)
#         fig.subplots_adjust(right=0.85)
#         # PLT.savefig(figdir + '{0}_time_frequency_wts_triad_{1[0]:0d}_{1[1]:0d}_{1[2]:0d}.pdf'.format(infile_no_ext, triad), bbox_inches=0)


/lustre/aoc/users/nthyagar/src/miniconda2/envs/PRISim-dev/lib/python2.7/site-packages/matplotlib/pyplot.py:522: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)