import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import glob
import os
from astropy import units
from copy import deepcopy
from pyuvdata import UVFlag
from SSINS import INS
from SSINS import version as SSINS_ver
import matplotlib.colors as colors
from matplotlib import cm
from IPython.display import display, HTML
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
display(HTML("<style>.container { width:100% !important; }</style>"))
# Use environment variables to figure out path to data
JD = os.environ['JULIANDATE']
data_path = os.environ['DATA_PATH']
print(f'JD = {JD}')
print(f'data_path = "{data_path}"')
JD = int(JD)
JD = 2459868 data_path = "/mnt/sn1/2459868"
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 10-15-2022
uvf = UVFlag(f'{data_path}/zen.{JD}.total_stage_1_threshold_flags.h5')
plt.figure(figsize=(16,12))
plt.imshow(uvf.flag_array[:,:,0], aspect='auto', interpolation='none',
extent=[uvf.freq_array[0] / 1e6, uvf.freq_array[-1] / 1e6,
uvf.time_array[-1] - JD, uvf.time_array[0] - JD])
plt.xlabel('Frequency (MHz)')
plt.ylabel(f'JD - {JD}')
ax2 = plt.gca().twinx()
ax2.set_ylim([uvf.lst_array[0] * 12 / np.pi, uvf.lst_array[-1] * 12 / np.pi])
ax2.invert_yaxis()
ax2.set_ylabel('LST (hours)')
ax3 = plt.gca().twiny()
ax3.set_xlim([0, uvf.Nfreqs - 1])
ax3.set_xlabel('Channel');
Yellow is flagged. Blue is unflagged.
ssins_dirs_sorted = sorted(glob.glob(f"{data_path}/zen.{JD}*.SSINS"))
init_ssins_path = glob.glob(f"{ssins_dirs_sorted[0]}/*flags.h5")
ssins_uvf = UVFlag(init_ssins_path)
for path in ssins_dirs_sorted[1:]:
new_path = glob.glob(f"{path}/*flags.h5")[0]
ssins_uvf += UVFlag(new_path)
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) Cell In [6], line 3 1 ssins_dirs_sorted = sorted(glob.glob(f"{data_path}/zen.{JD}*.SSINS")) 2 init_ssins_path = glob.glob(f"{ssins_dirs_sorted[0]}/*flags.h5") ----> 3 ssins_uvf = UVFlag(init_ssins_path) 4 for path in ssins_dirs_sorted[1:]: 5 new_path = glob.glob(f"{path}/*flags.h5")[0] File ~/mambaforge/envs/RTP/lib/python3.10/site-packages/pyuvdata/uvflag/uvflag.py:521, in UVFlag.__init__(self, indata, mode, copy_flags, waterfall, history, label, use_future_array_shapes, run_check, check_extra, run_check_acceptability) 518 self.label = "" # Added to at the end 519 if isinstance(indata, (list, tuple)): 520 self.__init__( --> 521 indata[0], 522 mode=mode, 523 copy_flags=copy_flags, 524 waterfall=waterfall, 525 history=history, 526 label=label, 527 use_future_array_shapes=use_future_array_shapes, 528 run_check=run_check, 529 check_extra=check_extra, 530 run_check_acceptability=run_check_acceptability, 531 ) 532 if len(indata) > 1: 533 for i in indata[1:]: IndexError: list index out of range
plt.figure(figsize=(16,12))
plt.imshow(ssins_uvf.flag_array[:,:,0], aspect='auto', interpolation='none',
extent=[ssins_uvf.freq_array[0] / 1e6, ssins_uvf.freq_array[-1] / 1e6,
ssins_uvf.time_array[-1] - JD, ssins_uvf.time_array[0] - JD])
plt.xlabel('Frequency (MHz)')
plt.ylabel(f'JD - {JD}')
ax2 = plt.gca().twinx()
ax2.set_ylim([ssins_uvf.lst_array[0] * 12 / np.pi, ssins_uvf.lst_array[-1] * 12 / np.pi])
ax2.invert_yaxis()
ax2.set_ylabel('LST (hours)')
ax3 = plt.gca().twiny()
ax3.set_xlim([0, ssins_uvf.Nfreqs - 1])
ax3.set_xlabel('Channel');
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In [7], line 2 1 plt.figure(figsize=(16,12)) ----> 2 plt.imshow(ssins_uvf.flag_array[:,:,0], aspect='auto', interpolation='none', 3 extent=[ssins_uvf.freq_array[0] / 1e6, ssins_uvf.freq_array[-1] / 1e6, 4 ssins_uvf.time_array[-1] - JD, ssins_uvf.time_array[0] - JD]) 5 plt.xlabel('Frequency (MHz)') 6 plt.ylabel(f'JD - {JD}') NameError: name 'ssins_uvf' is not defined
<Figure size 1600x1200 with 0 Axes>
FM is manually flagged at the beginning.
plt.figure(figsize=(16,12))
flag_table = np.zeros_like(uvf.flag_array[:, :, 0]).astype(float)
flag_table[np.logical_and(ssins_uvf.flag_array[:, :, 0], uvf.flag_array[:, :, 0])] = 0.75
flag_table[np.logical_and(ssins_uvf.flag_array[:, :, 0], np.logical_not(uvf.flag_array[:, :, 0]))] = 0.5
flag_table[np.logical_and(np.logical_not(ssins_uvf.flag_array[:, :, 0]), uvf.flag_array[:, :, 0])] = 0.25
# Prepare a colormap.
cmap = plt.cm.colors.ListedColormap(
["slategray", "darkturquoise", "plum", "lemonchiffon"]
)
print(cmap.__dict__)
cax = plt.imshow(flag_table, aspect='auto', interpolation='none',
extent=[uvf.freq_array[0] / 1e6, uvf.freq_array[-1] / 1e6,
uvf.time_array[-1] - JD, uvf.time_array[0] - JD],
cmap=cmap,
vmin=0, vmax=1)
plt.xlabel('Frequency (MHz)')
plt.ylabel(f'JD - {JD}')
ax2 = plt.gca().twinx()
ax2.set_ylim([ssins_uvf.lst_array[0] * 12 / np.pi, ssins_uvf.lst_array[-1] * 12 / np.pi])
ax2.invert_yaxis()
ax2.set_ylabel('LST (hours)')
ax3 = plt.gca().twiny()
ax3.set_xlim([0, ssins_uvf.Nfreqs - 1])
ax3.set_xlabel('Channel');
cbar_ticklabels = ["Flagged in Neither", "Flagged in XRFI", "Flagged in SSINS", "Flagged in Both"]
# Configure the colorbar so that labels are at the center of each section.
cbar = plt.colorbar(cax)
cbar_ticks = np.arange(0.125, 1.125, 0.25)
cbar.set_ticks(cbar_ticks)
cbar.set_ticklabels(cbar_ticklabels);
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In [8], line 3 1 plt.figure(figsize=(16,12)) 2 flag_table = np.zeros_like(uvf.flag_array[:, :, 0]).astype(float) ----> 3 flag_table[np.logical_and(ssins_uvf.flag_array[:, :, 0], uvf.flag_array[:, :, 0])] = 0.75 4 flag_table[np.logical_and(ssins_uvf.flag_array[:, :, 0], np.logical_not(uvf.flag_array[:, :, 0]))] = 0.5 5 flag_table[np.logical_and(np.logical_not(ssins_uvf.flag_array[:, :, 0]), uvf.flag_array[:, :, 0])] = 0.25 NameError: name 'ssins_uvf' is not defined
<Figure size 1600x1200 with 0 Axes>
xrfi_dirs = sorted(glob.glob(f'{data_path}/zen.{JD}.?????.stage_1_xrfi'))
print(f'Found {len(xrfi_dirs)} directories containing XRFI intermediate data products.')
files1 = [glob.glob(f'{d}/*combined_metrics1.h5')[0] for d in xrfi_dirs]
print(f'Found {len(files1)} combined round 1 XRFI metrics files.')
files2 = [glob.glob(f'{d}/*combined_metrics2.h5')[0] for d in xrfi_dirs]
print(f'Found {len(files2)} combined round 2 XRFI metrics files.')
uvf1 = UVFlag(files1)
uvf2 = UVFlag(files2)
uvf2.metric_array = np.where(np.isinf(uvf2.metric_array), uvf1.metric_array,
uvf2.metric_array)
Found 1862 directories containing XRFI intermediate data products. Found 1862 combined round 1 XRFI metrics files. Found 1862 combined round 2 XRFI metrics files.
plt.figure(figsize=(16,12))
max_abs = 100
if np.max(uvf2.metric_array) > max_abs:
extend = 'max'
if np.min(uvf2.metric_array) < -max_abs:
extend = 'both'
elif np.min(uvf2.metric_array) < -max_abs:
extend = 'min'
else:
extend = 'neither'
plt.imshow(uvf2.metric_array[:,:,0], aspect='auto', cmap='RdBu_r', interpolation='none',
norm=colors.SymLogNorm(linthresh=1,vmin=-max_abs, vmax=max_abs),
extent=[uvf.freq_array[0] / 1e6, uvf.freq_array[-1] / 1e6,
uvf.time_array[-1] - JD, uvf.time_array[0] - JD])
plt.colorbar(pad=.07, extend=extend,
label='RFI Detection Significance ($\sigma$s)')
plt.title('Combined XRFI Metrics')
plt.xlabel('Frequency (MHz)')
plt.ylabel(f'JD - {JD}')
ax2 = plt.gca().twinx()
ax2.set_ylim([uvf.lst_array[0] * 12 / np.pi, uvf.lst_array[-1] * 12 / np.pi])
ax2.invert_yaxis()
ax2.set_ylabel('LST (hours)')
ax3 = plt.gca().twiny()
ax3.set_xlim([0, uvf.Nfreqs - 1])
ax3.set_xlabel('Channel');