In [1]:
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
import matplotlib.patches as mpatches
import matplotlib.gridspec as gridspec
import numpy as np
from pyuvdata import UVCal, UVData, UVFlag
import pyuvdata
import os
import sys
import glob
import uvtools as uvt
from astropy.time import Time
from astropy.coordinates import EarthLocation, SkyCoord, AltAz, Angle
import pandas
import warnings 
import copy
from hera_notebook_templates import utils
import hera_qm
from hera_mc import cm_hookup
import h5py
import importlib
from scipy import stats
import scipy
import pandas as pd
from IPython.display import display, HTML
#warnings.filterwarnings('ignore')

%matplotlib inline
%config InlineBackend.figure_format = 'retina'
In [2]:
#get data location
JD = os.environ['JULIANDATE']
data_path = os.environ['DATA_PATH']
nb_outdir = os.environ['NB_OUTDIR']
utc = Time(JD, format='jd').datetime
print(f'JD = {JD}')
print(f'Date = {utc.month}-{utc.day}-{utc.year}')
print(f'data_path = "{data_path}"')
JD = 2459771
Date = 7-10-2022
data_path = "/mnt/sn1/2459771"
In [3]:
# Load in data
HHfiles, difffiles, uvdx, uvdy = utils.load_data_ds(data_path,JD)
    
uvd = UVData()
uvd_diff = UVData()
uvd.read(HHfiles[0])
use_ants = [int(ant) for ant in uvd.get_ants()]
bls = [(ant, ant) for ant in use_ants]
uvd.read(HHfiles[::10], skip_bad_files=True, bls=bls)
uvd_diff.read(difffiles[::10], skip_bad_files=True, bls=bls)
lsts = uvd.lst_array

flagfile = glob.glob(os.path.join(HHfiles[0].split('zen')[0],'zen.{}*total_stage_1_threshold_flags.h5'.format(JD)))
uvf = UVFlag()
uvf.read(flagfile)
bls = [(ant, ant) for ant in uvd.get_ants()]
times_uvf = np.unique(uvf.time_array)
times_uvd = np.unique(uvd.time_array)
idx_times = [np.where(time_uvd == times_uvf)[0][0] for time_uvd in times_uvd]
uvd.flag_array[:,0,:,:] = np.repeat(uvf.flag_array[idx_times], len(bls), axis=0)
1862 sum files found between JDs 2459771.25308 and 2459771.66938
1862 diff files found between JDs 2459771.25308 and 2459771.66938

LST Coverage¶

Shows the LSTs (in hours) and JDs for which data is collected. Green represents data, red means no data.

In [4]:
utils.plot_lst_coverage(uvd)

Delay spectrum¶

Delay spectrum CLEANed using uvtools.dspec.high_pass_fourier_filter with 7th-order Blackman-Harris window function. Odd/even visibilities are used to remove noise bias.

In [5]:
_data_cleaned_sq, d_even, d_odd = utils.clean_ds(bls, uvd, uvd_diff, N_threads=14)

Waterfalls of delay spectra for autocorrelation¶

These plots show autocorrelation delay spectrum waterfalls of each antenna that is active and whose status qualifies for this notebook. For nn/ee polarization, the autocorrelation delay spectrum is normalized by the max of the delay spectrum. For ne polarization, the autocorrelation delay spectrum is normalized by max(sqrt(|nn| |ee|)). ne and en are the same for autocorrelations, and thus only ne is shown here. The delay spectra are presented in dB with 10log10($|\tilde{V}|$).

For each node, antennas are ordered by SNAP number, and within that by SNAP input number. The antenna number label color corresponds to the a priori status of that antenna.

nn polarization¶

In [6]:
utils.plot_wfds(uvd, _data_cleaned_sq, 0)

ee polarization¶

In [7]:
utils.plot_wfds(uvd, _data_cleaned_sq, 1)

ne polarization¶

In [8]:
utils.plot_wfds(uvd, _data_cleaned_sq, 2)

Analysis of 2700ns features in delay spectra¶

This plot shows the relative amplitude at 2700 ns feature. The relative amplitude is calculated in dB with the mean amplitude at 2500-3000 ns compared to the mean amplitude at 2000-2500 ns. Larger values of relative feature amplitude indicate higher probability of detecting the peak at 2700 ns. Antennas in the same node are grouped by the shaded region.

In [9]:
utils.plot_antFeatureMap_2700ns(uvd, _data_cleaned_sq, JD, pol='nn')
In [10]:
utils.plot_antFeatureMap_2700ns(uvd, _data_cleaned_sq, JD, pol='ee')

This plot shows a matrix representing the 2700ns feature correlation of each baseline. The color bar indicates the amplitude of 2700ns (mean amplitude of 2500-3000ns delay spectrum) in dB which is the same as that in the above plot.

In [11]:
# utils.CorrMatrix_2700ns(uvd, HHfiles, difffiles, flagfile, JD, N_threads=14)

Analysis of noise floor in delay spectra¶

This plot shows the ratio of delay spectrum to noise floor (averaged over 1000-4000ns). Near 1 indicates the delay spectrum reaches to the noise floor, which may mean good.

In [12]:
utils.plot_antFeatureMap_noise(uvd_diff, d_even, d_odd, JD, pol='nn')
In [13]:
utils.plot_antFeatureMap_noise(uvd_diff, d_even, d_odd, JD, pol='ee')
In [14]:
# get the ratio of delay spectum to noise for different freqeuncy bands and pols
ds_noise_ratio = utils.get_ds_noise_ratio(uvd, uvd_diff, bls)

nodes, antDict, inclNodes = utils.generate_nodeDict(uvd)
ants = uvd.get_ants()
# build dataframe
to_show = {'Ant': ants, 'Node': [int(antDict[ant]['node']) for ant in ants], 'Snap': [int(antDict[ant]['snapLocs'][0]) for ant in ants]}
df = pd.DataFrame(to_show)
 
cols_ratio = []
for key in ds_noise_ratio.keys():
    if(key[0] == 40):
        col = r'Full '
    else:
        col = r'{}-{} MHz '.format(key[0], key[1])
    col += key[2]
    df[col] = ds_noise_ratio[key]
    cols_ratio.append(col)
    

# sort by node number and then by antenna number within nodes
df.sort_values(['Node', 'Ant'], ascending=True)

ratio_cut = 3
# style dataframe
table = df.style.hide_index() \
          .applymap(lambda val: 'color: red' if val > ratio_cut else '', subset=cols_ratio) \
          .set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])])

This table shows the ratio of the delay spectrum to the noise level from diff files for different frequency bands and pols. The ratio > 3 is colored in red

In [15]:
HTML(table.render())
Out[15]:
Ant Node Snap Full nn Full ee 50-85 MHz nn 50-85 MHz ee 120-155 MHz nn 120-155 MHz ee 155-190 MHz nn 155-190 MHz ee 190-225 MHz nn 190-225 MHz ee
3 1 2 1.625378 1.467785 2.151565 2.394280 2.009180 1.931792 2.748020 2.203149 2.646565 2.723818
4 1 2 1.472256 1.848215 3.401173 2.390186 1.945380 1.927356 1.792707 2.022930 5.290098 5.516019
5 1 2 1.250416 1.684706 2.681713 2.304843 1.970967 1.849556 2.246618 2.424780 10.972490 15.075388
7 2 0 1.486725 1.289571 2.209247 2.029135 1.956431 1.873470 1.764439 1.784328 3.519977 3.471347
8 2 0 1.363368 1.411992 2.797908 2.900337 1.985319 2.147496 1.983573 1.909901 3.520815 3.773684
9 2 0 1.253816 1.397895 2.521487 2.187013 1.814703 2.029616 2.516534 2.591579 4.097887 4.143533
10 2 1 1.281729 1.371576 2.950523 4.093267 1.787029 2.033757 2.023408 2.463744 3.756876 5.243217
15 1 3 1.647004 1.619385 2.764270 2.301408 2.113888 2.496495 2.364489 2.121257 7.934437 10.734060
16 1 3 1.699069 1.764189 2.443531 2.049903 2.325984 2.952098 2.033450 3.054653 20.904741 27.614503
17 1 3 1.781163 1.596450 2.086311 1.835062 2.035983 1.877265 2.102833 1.595020 2.295170 4.263965
18 1 0 60.602080 45.481847 1.898925 2.271397 283.041582 223.520994 1.529833 1.796651 3.434894 2.470971
19 2 1 1.385786 1.514716 2.366076 2.416914 1.685633 1.998441 2.434918 2.867198 13.215511 15.078501
20 2 1 1.178314 1.341665 2.466047 1.699049 1.763163 1.740637 1.839568 1.744768 3.188512 3.069398
21 2 2 1.269585 1.183649 2.253568 1.619054 1.725866 1.674399 1.857134 1.670642 3.349689 3.660912
27 1 0 5.194001 5.200792 12.320711 15.974590 15.858935 10.790944 5.122873 2.525445 5.157795 1.842114
28 1 0 213.420094 1.293513 3.291959 3.510713 1018.879009 2.099266 2.218256 2.240103 3.731572 4.671169
29 1 1 1.742893 1.657686 3.088266 2.197749 1.814382 1.897334 3.221696 3.264862 6.162193 5.949784
30 1 1 1.651475 1.503911 3.147670 1.826301 2.445256 1.846691 4.398277 5.482190 5.586876 5.540051
31 2 2 1.479104 1.736164 2.044548 1.851420 2.168799 2.247331 3.727057 7.659413 6.218616 16.790058
32 2 2 1.920619 2.738687 1.916297 3.015457 1.908320 2.820978 4.218450 9.062010 5.561523 7.580917
33 2 3 40.867045 1.310747 2.426521 2.089040 208.761267 1.842028 1.597240 1.941606 3.970589 3.895743
36 3 3 2.033002 1.943072 2.512788 2.293836 1.917439 1.788936 2.131069 1.817561 3.925549 3.850978
37 3 1 1.342408 1.411227 7.227801 4.414074 2.779316 2.243051 2.352424 2.452342 10.678685 8.894326
38 3 1 1.206998 1.611340 2.676043 2.367415 1.901001 2.111524 3.097920 3.003911 3.099938 4.075166
40 4 1 1.330570 1.374201 2.567129 2.295637 1.718937 1.933252 1.911606 2.021460 3.516897 3.530686
41 4 3 1.341462 1.518971 2.408295 2.600774 1.792173 1.841057 1.840929 1.630643 2.863498 3.071584
42 4 0 1.383473 1.256535 2.562652 1.927652 2.302917 1.794212 1.936813 1.720819 8.564657 12.105804
45 5 0 1.625324 1.407038 5.659891 1.664103 3.641929 1.697954 3.457224 1.845001 5.000208 2.715713
46 5 0 1.699132 1.563088 3.232133 2.651700 2.972975 2.513389 1.828727 2.095355 3.545278 3.198639
50 3 3 1.799931 1.347634 2.436381 2.051388 2.174450 1.874932 2.022373 2.028317 2.767731 3.265888
51 3 2 7.604667 1.483947 21.056263 2.424845 7.736531 2.173117 6.870903 2.222270 9.801586 8.146942
52 3 3 9.008864 1.685081 24.803457 2.081475 6.054974 2.258879 5.544689 2.437035 6.137546 6.815006
53 3 2 1.373147 1.499441 4.156750 3.232267 2.546311 2.715196 2.413346 2.731583 7.116223 6.800611
54 4 0 1.504620 1.275662 2.529697 2.276879 2.659889 2.586100 2.064856 2.083207 4.681420 5.877495
55 4 2 0.986402 1.626450 2.472203 1.283075 1.743055 2.062070 2.124968 1.796905 5.084964 2.290769
56 4 1 1.495582 1.709628 2.086433 2.443609 1.910629 2.223978 1.771139 1.909797 3.794392 4.905067
57 4 3 1.394160 1.450722 3.679858 2.823353 2.534545 1.865476 2.231971 1.558788 3.457367 2.995578
65 3 0 1.718015 1.498113 3.641137 3.257570 2.825727 1.770549 2.300118 1.780469 3.878342 3.600438
66 3 0 2.418868 2.145252 6.600648 2.272571 4.723233 3.689273 3.257852 1.884757 7.903479 4.917356
67 3 0 1.715047 1.499099 2.395855 2.393199 1.965994 1.854636 1.695878 1.814395 3.104801 3.164470
68 3 1 1.274802 1.116919 2.466206 2.111984 1.825222 1.778010 1.744030 1.942468 2.493034 3.248236
69 4 1 1.500372 1.723504 2.515107 3.555365 1.764113 2.045725 2.071897 2.182068 2.952174 3.192899
70 4 2 2.270955 1.973727 3.153081 2.174196 4.867585 2.204571 3.888147 2.775928 3.070927 4.699513
71 4 2 1.234286 1.956209 2.488177 2.486335 1.714881 1.890211 1.934156 1.657131 2.583432 2.877531
72 4 0 1.641771 1.845830 2.598363 2.343313 2.477406 3.038016 1.783184 2.629289 4.880702 7.626929
73 5 0 1.607790 1.623939 2.695617 2.322988 2.079300 2.523596 2.072828 2.079447 6.492031 6.043753
81 7 0 1.439348 1.455887 2.344434 1.658623 1.592850 1.718436 1.906658 1.894460 6.555934 8.978643
82 7 0 1.475183 1.361378 1.956898 2.263120 1.621891 2.182678 1.715673 1.849235 3.362237 4.115581
83 7 0 1.235441 1.294126 2.430408 2.570078 2.089355 1.797928 2.213594 1.847305 3.294263 4.169031
88 9 0 7.718501 31.989029 34.726685 51.175938 12.037503 43.430770 6.595524 6.414857 9.716874 5.121999
89 9 2 nan nan nan nan nan nan nan nan nan nan
90 9 0 5.165614 2.982813 2.857807 2.762343 8.840895 5.114629 24.559990 10.086203 41.872981 14.218376
91 9 1 4.767442 9.045606 20.735774 16.986048 7.774141 20.394340 8.598173 6.491743 12.892393 3.799665
92 10 0 1.666673 1.620081 2.461225 3.030786 2.051076 1.997179 1.806629 1.892460 2.505669 2.047722
93 10 0 6.201036 1.671966 24.605009 2.868097 7.626066 1.807868 4.361232 1.726970 4.000449 3.448080
94 10 0 1.326379 1.619038 2.049069 3.708158 1.785846 2.779778 2.011670 3.213889 4.061923 6.543512
98 7 2 4.913304 1.134798 3.368956 2.411455 11.609263 1.853244 22.580245 2.574142 71.372218 4.730231
99 7 2 1.434694 1.153734 2.137168 1.878450 1.933163 1.741550 1.759547 1.666383 4.276169 5.897339
100 7 1 1.322839 1.090455 2.389965 3.608722 1.764175 2.193420 1.612169 1.855044 3.720938 3.700885
105 9 1 3.974643 3.654163 28.113268 11.621171 5.338059 8.767634 7.673920 2.675612 15.637389 3.523265
106 9 3 2.096145 2.038045 2.384888 2.219386 4.165466 3.429244 3.212884 4.777826 4.143771 3.685899
107 9 0 12.929373 46.110054 53.373890 262.311899 14.842576 29.191935 13.669126 104.277405 6.606673 2.070864
108 9 1 1.560244 1.250319 2.924520 1.856299 2.112590 1.765047 1.851304 1.839665 4.663015 3.976365
109 10 1 2.076567 2.258658 3.482764 2.359217 3.678764 3.519865 1.937750 2.002538 3.185024 2.874192
110 10 1 1.061979 3.498746 2.325704 3.078877 2.063840 4.104397 1.832352 2.880077 2.556394 2.665896
111 10 1 1.408668 1.292381 2.635939 2.064494 2.266282 1.525794 1.751091 1.753786 1.978557 1.754965
112 10 2 1.596219 1.301889 6.507190 2.438365 2.726769 1.740176 2.362584 1.831164 4.038424 2.981312
116 7 2 1.090955 1.054361 2.165560 1.835061 2.213554 1.620690 1.948217 1.607271 5.831546 3.499104
117 7 3 1.350464 1.512290 2.214318 2.087323 1.941718 1.933886 2.166601 2.560444 8.781527 12.026557
118 7 3 1.476979 1.477936 2.255910 1.952108 2.243022 1.993383 2.352863 2.441935 5.798142 7.689157
119 7 1 1.193970 1.087180 2.600057 2.133502 2.192523 1.759437 2.149503 1.690149 7.355800 3.721117
124 9 2 nan nan nan nan nan nan nan nan nan nan
125 9 3 5.862863 3.978267 55.114151 17.731826 14.454263 8.578249 4.188154 2.557978 7.483316 2.674462
126 9 3 6.111628 3.877985 51.652707 14.220632 10.484154 12.168503 7.935587 7.404698 9.208365 5.866177
127 10 2 2.047427 2.786398 3.583447 2.265853 4.028102 5.980062 4.178820 6.425714 7.059014 9.267551
128 10 2 1.210775 1.466931 2.734018 2.557953 2.082912 1.830642 2.018782 1.998331 4.446695 3.985965
129 10 3 1.502321 1.346913 2.361312 1.734250 1.754229 1.705834 1.788241 1.645072 2.664340 3.004305
130 10 3 1.337490 2.368302 3.390181 19.981965 2.266326 1.897500 2.572772 2.096668 5.819801 2.255021
135 12 2 1.402730 1.308093 2.785984 1.901097 2.323129 1.927938 2.752870 1.963281 2.521444 3.561887
136 12 2 1.644177 1.599406 12.735011 1.909907 2.411104 1.819239 6.355355 3.650161 4.256661 3.095534
137 7 3 5.913899 3.481089 14.277357 16.660553 6.625209 3.929952 4.143172 1.734168 5.553085 1.946272
138 7 1 1.569433 6.220374 1.973027 6.007353 1.785233 5.027774 2.440087 2.236832 12.425101 3.202195
140 13 2 1.558862 1.479257 1.981308 1.931509 2.010822 2.248668 2.446829 2.142831 2.796412 3.839092
141 13 2 11.618174 1.523882 19.275133 2.028479 41.144197 2.523396 30.456618 2.325449 26.649263 5.575492
142 13 2 3.898511 2.840167 9.296460 4.464198 8.275737 3.985836 3.472631 1.779076 5.414807 3.188840
143 14 2 nan nan nan nan nan nan nan nan nan nan
144 14 3 3.938706 1.644956 2.026550 1.781986 5.613382 2.462747 2.215775 1.915324 2.298355 5.126754
145 14 3 6.798083 4.656529 21.492008 28.496328 18.094297 15.838122 3.763633 1.842634 3.446584 1.843761
150 15 1 7.639577 9.544477 31.545817 57.406121 13.640817 14.176138 4.873238 10.249336 3.864560 2.102162
155 12 2 4.104919 4.773096 13.958208 26.926095 5.026986 6.783379 4.457612 10.978757 4.725388 2.719800
156 12 3 1.664076 1.528049 2.541485 1.791162 2.500320 2.462938 2.608497 2.378111 1.893916 2.277768
157 12 3 1.550689 1.486471 2.124820 1.943424 2.235558 2.254631 1.783848 2.248433 2.548874 3.678251
158 12 3 2.109781 1.441562 5.783319 1.798209 4.646731 2.541128 3.596650 2.368880 6.602670 13.993475
160 13 3 nan nan nan nan nan nan nan nan nan nan
161 13 0 6.388988 1.825361 4.482719 1.900363 9.684525 3.076746 4.164969 2.509302 3.754028 7.905636
162 13 0 1.531890 1.415294 2.415020 2.510024 2.292696 2.480534 1.858612 2.349581 4.497426 7.763624
163 14 2 nan nan nan nan nan nan nan nan nan nan
164 14 2 nan nan nan nan nan nan nan nan nan nan
165 14 0 nan nan nan nan nan nan nan nan nan nan
166 14 0 nan nan nan nan nan nan nan nan nan nan
167 15 1 2.566797 4.046720 3.292430 2.181637 2.949674 3.314504 4.609168 3.022531 3.226487 2.453277
168 15 2 1.907765 1.621361 3.660197 2.145777 2.515088 2.027974 10.559703 8.382444 15.427781 20.467670
169 15 2 1.635061 1.558068 2.535887 2.431135 2.115069 2.147149 3.951868 6.351233 8.776397 8.589207
170 15 2 1.967368 1.610748 2.913794 2.999537 3.540676 3.387142 5.353589 6.683576 7.741219 9.947392
176 12 0 1.221085 1.147616 2.289378 2.228279 1.858951 1.938246 2.689326 2.424089 5.014434 4.916040
177 12 0 1.213360 1.449861 2.191938 2.169529 2.047704 2.144456 1.812324 1.860942 3.519801 3.183809
178 12 0 1.281619 1.195308 2.439141 2.147909 1.927861 1.962884 1.813180 2.078640 3.680315 3.351652
179 12 1 2.176478 1.163832 2.505538 2.082464 2.367315 1.831265 11.382848 2.377777 5.904388 3.929213
180 13 3 nan nan nan nan nan nan nan nan nan nan
181 13 3 nan nan nan nan nan nan nan nan nan nan
182 13 0 1.780488 2.076374 2.645124 2.481287 2.784633 4.791928 2.607785 2.051193 4.106378 5.713734
183 13 1 1.583376 1.540390 2.582561 2.602430 2.567953 2.400042 2.227698 2.076398 7.607545 6.579749
184 14 0 nan nan nan nan nan nan nan nan nan nan
185 14 1 1.675790 2.240393 2.726490 2.947768 2.167280 2.748688 3.913926 5.803963 6.819686 16.471468
186 14 1 1.514104 1.303636 2.383545 2.159213 1.754766 1.902950 1.985631 2.436392 4.260341 6.460955
187 14 1 1.816782 1.604222 6.901726 3.691085 4.040340 2.977423 4.882263 4.272751 26.991129 50.390558
189 15 3 1.230852 1.284891 2.111215 2.079096 1.594031 1.748902 1.648408 1.645283 1.903123 2.472963
190 15 3 5.785790 3.876921 14.611733 1.676672 3.935406 3.280343 4.557611 2.074099 5.129933 5.925129
191 15 3 1.427914 1.655568 2.426754 1.976629 2.336651 2.604428 2.351866 1.869120 2.793608 3.214193
220 18 2 nan nan nan nan nan nan nan nan nan nan
221 18 2 nan nan nan nan nan nan nan nan nan nan
222 18 2 nan nan nan nan nan nan nan nan nan nan
320 3 2 6.513958 6.986341 15.296612 36.535352 5.420874 6.134188 8.622369 6.325301 7.130463 2.251468
321 2 3 2.246561 1.760277 2.047233 2.519075 2.110595 2.149674 1.758407 1.759764 2.008573 2.249820
323 2 3 1.126929 4.884009 3.345847 5.594575 1.673679 4.740360 1.885115 1.967567 1.963605 4.123890
324 4 3 1.287965 1.837692 2.169243 2.006619 1.594510 1.589443 1.707104 1.557798 1.644860 1.765514
329 12 1 1.080435 1.063764 3.139237 6.834076 1.700128 1.897441 1.685425 1.638789 2.368493 2.569232
333 12 1 1.390209 1.594934 3.072019 2.003815 2.177090 2.746532 2.083767 1.720802 2.416532 2.351584
In [16]:
csv_file = os.path.join(nb_outdir, 'ds_noise_ratio_{}.csv'.format(JD))
df.to_csv(csv_file, index=False)

Delay spectrum and autocorrelation plot per baseline per polarization for a given frequency (sub-)band¶

Left panel: time averaged delay spectum of autocorrelation in dB with 10*log10($|\tilde{V}|$) (blue) and noise from diff file representing the expected variance of the delay spectrum (red). The time-averaging is performed by 1. binning three time integrations of each even and odd visibility, 2. Fouier transform the binned even and odd visibilities, and 3. multiply the even and odd delay spectra at alternating time bin and average the squared delay spectrum along the time axis. This helps to reduce the noise bias. Both autocorrelation delay spectrum and diff delay spectrum are averaged in the same way

Right panel: time averaged autocorrelations w/o (orange) and w/ xRFI flags (blue). Flagged one is shifted from the unflagged one for clarity

In [17]:
utils.interactive_plots_dspec(bls, uvd, uvd_diff, JD)
In [ ]: