Calibration Smoothing¶
by Josh Dillon, last updated March 29, 2023
This notebook runs calibration smoothing to the gains coming out of file_calibration notebook. It removes any flags founds on by that notebook and replaces them with flags generated from full_day_rfi and full_day_antenna_flagging. It also plots the results for a couple of antennas.
Here's a set of links to skip to particular figures and tables:
• Figure 1: Full-Day Gain Amplitudes Before and After smooth_cal
¶
• Figure 2: Full-Day Gain Phases Before and After smooth_cal
¶
• Figure 3: Full-Day $\chi^2$ / DoF Waterfall from Redundant-Baseline Calibration¶
• Figure 4: Average $\chi^2$ per Antenna vs. Time and Frequency¶
import time
tstart = time.time()
import os
os.environ['HDF5_USE_FILE_LOCKING'] = 'FALSE'
import h5py
import hdf5plugin # REQUIRED to have the compression plugins available
import numpy as np
import glob
import copy
import warnings
import matplotlib
import matplotlib.pyplot as plt
from hera_cal import io, utils, smooth_cal
from hera_qm.time_series_metrics import true_stretches
%matplotlib inline
from IPython.display import display, HTML
Parse inputs¶
# get files
SUM_FILE = os.environ.get("SUM_FILE", None)
# SUM_FILE = '/users/jsdillon/lustre/H6C/abscal/2459853/zen.2459853.25518.sum.uvh5'
SUM_SUFFIX = os.environ.get("SUM_SUFFIX", 'sum.uvh5')
CAL_SUFFIX = os.environ.get("CAL_SUFFIX", 'sum.omni.calfits')
SMOOTH_CAL_SUFFIX = os.environ.get("SMOOTH_CAL_SUFFIX", 'sum.smooth.calfits')
ANT_FLAG_SUFFIX = os.environ.get("ANT_FLAG_SUFFIX", 'sum.antenna_flags.h5')
RFI_FLAG_SUFFIX = os.environ.get("RFI_FLAG_SUFFIX", 'sum.flag_waterfall.h5')
FREQ_SMOOTHING_SCALE = float(os.environ.get("FREQ_SMOOTHING_SCALE", 10.0)) # MHz
TIME_SMOOTHING_SCALE = float(os.environ.get("TIME_SMOOTHING_SCALE", 6e5)) # seconds
EIGENVAL_CUTOFF = float(os.environ.get("EIGENVAL_CUTOFF", 1e-12))
for setting in ['SUM_FILE', 'SUM_SUFFIX', 'CAL_SUFFIX', 'SMOOTH_CAL_SUFFIX', 'ANT_FLAG_SUFFIX',
'RFI_FLAG_SUFFIX', 'FREQ_SMOOTHING_SCALE', 'TIME_SMOOTHING_SCALE', 'EIGENVAL_CUTOFF']:
print(f'{setting} = {eval(setting)}')
SUM_FILE = /mnt/sn1/data1/2460455/zen.2460455.16876.sum.uvh5 SUM_SUFFIX = sum.uvh5 CAL_SUFFIX = sum.omni.calfits SMOOTH_CAL_SUFFIX = sum.smooth.calfits ANT_FLAG_SUFFIX = sum.antenna_flags.h5 RFI_FLAG_SUFFIX = sum.flag_waterfall.h5 FREQ_SMOOTHING_SCALE = 10.0 TIME_SMOOTHING_SCALE = 600000.0 EIGENVAL_CUTOFF = 1e-12
Load files¶
sum_glob = '.'.join(SUM_FILE.split('.')[:-3]) + '.*.' + SUM_SUFFIX
cal_files_glob = sum_glob.replace(SUM_SUFFIX, CAL_SUFFIX)
cal_files = sorted(glob.glob(cal_files_glob))
print(f'Found {len(cal_files)} *.{CAL_SUFFIX} files starting with {cal_files[0]}.')
Found 1572 *.sum.omni.calfits files starting with /mnt/sn1/data1/2460455/zen.2460455.16876.sum.omni.calfits.
rfi_flag_files_glob = sum_glob.replace(SUM_SUFFIX, RFI_FLAG_SUFFIX)
rfi_flag_files = sorted(glob.glob(rfi_flag_files_glob))
print(f'Found {len(rfi_flag_files)} *.{RFI_FLAG_SUFFIX} files starting with {rfi_flag_files[0]}.')
Found 1572 *.sum.flag_waterfall.h5 files starting with /mnt/sn1/data1/2460455/zen.2460455.16876.sum.flag_waterfall.h5.
ant_flag_files_glob = sum_glob.replace(SUM_SUFFIX, ANT_FLAG_SUFFIX)
ant_flag_files = sorted(glob.glob(ant_flag_files_glob))
print(f'Found {len(ant_flag_files)} *.{ANT_FLAG_SUFFIX} files starting with {ant_flag_files[0]}.')
Found 1572 *.sum.antenna_flags.h5 files starting with /mnt/sn1/data1/2460455/zen.2460455.16876.sum.antenna_flags.h5.
cs = smooth_cal.CalibrationSmoother(cal_files, flag_file_list=(ant_flag_files + rfi_flag_files), ignore_calflags=True,
pick_refant=True, propagate_refant_flags=True, load_chisq=True, load_cspa=True)
for pol in cs.refant:
print(f'Reference antenna {cs.refant[pol][0]} selected for {pol}.')
Mean of empty slice
Reference antenna 94 selected for Jnn. Reference antenna 147 selected for Jee.
# duplicate a small number of abscal gains for plotting
antnums = set([ant[0] for ant in cs.ants])
flags_per_antnum = [np.sum(cs.flag_grids[ant, 'Jnn']) + np.sum(cs.flag_grids[ant, 'Jee']) for ant in antnums]
refant_nums = [ant[0] for ant in cs.refant.values()]
candidate_ants = [ant for ant, nflags in zip(antnums, flags_per_antnum) if (ant not in refant_nums) and (nflags <= np.percentile(flags_per_antnum, 25))
and not np.all(cs.flag_grids[ant, 'Jee']) and not np.all(cs.flag_grids[ant, 'Jnn'])]
ants_to_plot = [func(candidate_ants) for func in (np.min, np.max)]
abscal_gains = {(ant, pol): np.array(cs.gain_grids[(ant, pol)]) for ant in ants_to_plot for pol in ['Jee', 'Jnn']}
Perform smoothing¶
cs.time_freq_2D_filter(freq_scale=FREQ_SMOOTHING_SCALE, time_scale=TIME_SMOOTHING_SCALE, eigenval_cutoff=EIGENVAL_CUTOFF,
method='DPSS', fit_method='lu_solve', fix_phase_flips=True, flag_phase_flip_ints=True)
49 phase flips detected on antenna (189, 'Jnn'). A total of 127 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
2 phase flips detected on antenna (57, 'Jnn'). A total of 1 integrations were phase-flipped relative to the 0th integration between 2460455.506424625 and 2460455.506424625.
41 phase flips detected on antenna (295, 'Jnn'). A total of 235 integrations were phase-flipped relative to the 0th integration between 2460455.4830483687 and 2460455.5202937913.
28 phase flips detected on antenna (87, 'Jnn'). A total of 143 integrations were phase-flipped relative to the 0th integration between 2460455.4896474076 and 2460455.518056829.
67 phase flips detected on antenna (285, 'Jnn'). A total of 146 integrations were phase-flipped relative to the 0th integration between 2460455.4846142423 and 2460455.5202937913.
2 phase flips detected on antenna (108, 'Jnn'). A total of 1 integrations were phase-flipped relative to the 0th integration between 2460455.506424625 and 2460455.506424625.
65 phase flips detected on antenna (143, 'Jnn'). A total of 133 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
1 phase flips detected on antenna (155, 'Jee'). A total of 334 integrations were phase-flipped relative to the 0th integration between 2460455.4830483687 and 2460455.5202937913.
13 phase flips detected on antenna (147, 'Jnn'). A total of 212 integrations were phase-flipped relative to the 0th integration between 2460455.489871104 and 2460455.5202937913.
1 phase flips detected on antenna (116, 'Jee'). A total of 334 integrations were phase-flipped relative to the 0th integration between 2460455.4830483687 and 2460455.5202937913.
65 phase flips detected on antenna (85, 'Jnn'). A total of 144 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
1 phase flips detected on antenna (30, 'Jnn'). A total of 124 integrations were phase-flipped relative to the 0th integration between 2460455.506536473 and 2460455.5202937913.
9 phase flips detected on antenna (19, 'Jnn'). A total of 68 integrations were phase-flipped relative to the 0th integration between 2460455.4962464464 and 2460455.5202937913.
2 phase flips detected on antenna (72, 'Jnn'). A total of 1 integrations were phase-flipped relative to the 0th integration between 2460455.506424625 and 2460455.506424625.
66 phase flips detected on antenna (222, 'Jnn'). A total of 151 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
18 phase flips detected on antenna (211, 'Jnn'). A total of 90 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5087734354.
64 phase flips detected on antenna (123, 'Jnn'). A total of 118 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
3 phase flips detected on antenna (16, 'Jnn'). A total of 165 integrations were phase-flipped relative to the 0th integration between 2460455.501838852 and 2460455.5202937913.
71 phase flips detected on antenna (65, 'Jnn'). A total of 121 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
65 phase flips detected on antenna (53, 'Jnn'). A total of 129 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
71 phase flips detected on antenna (122, 'Jnn'). A total of 107 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
76 phase flips detected on antenna (101, 'Jnn'). A total of 123 integrations were phase-flipped relative to the 0th integration between 2460455.4906540406 and 2460455.519846399.
81 phase flips detected on antenna (50, 'Jnn'). A total of 128 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
10 phase flips detected on antenna (55, 'Jnn'). A total of 50 integrations were phase-flipped relative to the 0th integration between 2460455.4896474076 and 2460455.506424625.
5 phase flips detected on antenna (41, 'Jnn'). A total of 166 integrations were phase-flipped relative to the 0th integration between 2460455.489871104 and 2460455.5202937913.
88 phase flips detected on antenna (187, 'Jnn'). A total of 108 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
68 phase flips detected on antenna (240, 'Jnn'). A total of 155 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
72 phase flips detected on antenna (102, 'Jnn'). A total of 127 integrations were phase-flipped relative to the 0th integration between 2460455.4906540406 and 2460455.519846399.
31 phase flips detected on antenna (184, 'Jnn'). A total of 176 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
5 phase flips detected on antenna (169, 'Jnn'). A total of 260 integrations were phase-flipped relative to the 0th integration between 2460455.491101433 and 2460455.5202937913.
2 phase flips detected on antenna (56, 'Jnn'). A total of 1 integrations were phase-flipped relative to the 0th integration between 2460455.506424625 and 2460455.506424625.
6 phase flips detected on antenna (191, 'Jnn'). A total of 6 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.4914369774.
64 phase flips detected on antenna (38, 'Jnn'). A total of 133 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
21 phase flips detected on antenna (224, 'Jnn'). A total of 187 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
31 phase flips detected on antenna (168, 'Jnn'). A total of 162 integrations were phase-flipped relative to the 0th integration between 2460455.4895355594 and 2460455.5202937913.
65 phase flips detected on antenna (239, 'Jnn'). A total of 184 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
76 phase flips detected on antenna (121, 'Jnn'). A total of 143 integrations were phase-flipped relative to the 0th integration between 2460455.4906540406 and 2460455.519846399.
77 phase flips detected on antenna (228, 'Jnn'). A total of 123 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
2 phase flips detected on antenna (91, 'Jnn'). A total of 1 integrations were phase-flipped relative to the 0th integration between 2460455.506424625 and 2460455.506424625.
71 phase flips detected on antenna (52, 'Jnn'). A total of 126 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
3 phase flips detected on antenna (4, 'Jnn'). A total of 165 integrations were phase-flipped relative to the 0th integration between 2460455.501838852 and 2460455.5202937913.
75 phase flips detected on antenna (142, 'Jnn'). A total of 116 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
77 phase flips detected on antenna (140, 'Jnn'). A total of 149 integrations were phase-flipped relative to the 0th integration between 2460455.4906540406 and 2460455.5202937913.
40 phase flips detected on antenna (124, 'Jnn'). A total of 103 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.518056829.
80 phase flips detected on antenna (66, 'Jnn'). A total of 111 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.519846399.
3 phase flips detected on antenna (15, 'Jnn'). A total of 165 integrations were phase-flipped relative to the 0th integration between 2460455.501838852 and 2460455.5202937913.
1 phase flips detected on antenna (5, 'Jnn'). A total of 124 integrations were phase-flipped relative to the 0th integration between 2460455.506536473 and 2460455.5202937913.
3 phase flips detected on antenna (89, 'Jnn'). A total of 125 integrations were phase-flipped relative to the 0th integration between 2460455.506312777 and 2460455.5202937913.
48 phase flips detected on antenna (283, 'Jnn'). A total of 189 integrations were phase-flipped relative to the 0th integration between 2460455.4830483687 and 2460455.5197345507.
80 phase flips detected on antenna (141, 'Jnn'). A total of 113 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.519846399.
65 phase flips detected on antenna (181, 'Jnn'). A total of 180 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
5 phase flips detected on antenna (71, 'Jnn'). A total of 126 integrations were phase-flipped relative to the 0th integration between 2460455.489871104 and 2460455.5202937913.
58 phase flips detected on antenna (221, 'Jnn'). A total of 98 integrations were phase-flipped relative to the 0th integration between 2460455.489982952 and 2460455.520181943.
15 phase flips detected on antenna (106, 'Jnn'). A total of 177 integrations were phase-flipped relative to the 0th integration between 2460455.4896474076 and 2460455.5202937913.
11 phase flips detected on antenna (126, 'Jnn'). A total of 268 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
74 phase flips detected on antenna (179, 'Jnn'). A total of 156 integrations were phase-flipped relative to the 0th integration between 2460455.488193382 and 2460455.519846399.
72 phase flips detected on antenna (237, 'Jnn'). A total of 126 integrations were phase-flipped relative to the 0th integration between 2460455.488193382 and 2460455.519846399.
37 phase flips detected on antenna (266, 'Jnn'). A total of 188 integrations were phase-flipped relative to the 0th integration between 2460455.4830483687 and 2460455.5202937913.
60 phase flips detected on antenna (139, 'Jnn'). A total of 89 integrations were phase-flipped relative to the 0th integration between 2460455.491996218 and 2460455.5197345507.
2 phase flips detected on antenna (135, 'Jee'). A total of 1 integrations were phase-flipped relative to the 0th integration between 2460455.4829365206 and 2460455.4829365206.
70 phase flips detected on antenna (155, 'Jnn'). A total of 131 integrations were phase-flipped relative to the 0th integration between 2460455.488193382 and 2460455.5197345507.
71 phase flips detected on antenna (51, 'Jnn'). A total of 169 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
57 phase flips detected on antenna (201, 'Jnn'). A total of 88 integrations were phase-flipped relative to the 0th integration between 2460455.4906540406 and 2460455.5202937913.
32 phase flips detected on antenna (20, 'Jnn'). A total of 135 integrations were phase-flipped relative to the 0th integration between 2460455.489871104 and 2460455.518056829.
24 phase flips detected on antenna (33, 'Jnn'). A total of 172 integrations were phase-flipped relative to the 0th integration between 2460455.489871104 and 2460455.518056829.
62 phase flips detected on antenna (160, 'Jnn'). A total of 125 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
12 phase flips detected on antenna (185, 'Jnn'). A total of 94 integrations were phase-flipped relative to the 0th integration between 2460455.4896474076 and 2460455.5087734354.
19 phase flips detected on antenna (125, 'Jnn'). A total of 257 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
34 phase flips detected on antenna (281, 'Jnn'). A total of 112 integrations were phase-flipped relative to the 0th integration between 2460455.4830483687 and 2460455.5197345507.
66 phase flips detected on antenna (235, 'Jnn'). A total of 160 integrations were phase-flipped relative to the 0th integration between 2460455.4846142423 and 2460455.519846399.
61 phase flips detected on antenna (167, 'Jnn'). A total of 151 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
67 phase flips detected on antenna (217, 'Jnn'). A total of 191 integrations were phase-flipped relative to the 0th integration between 2460455.488193382 and 2460455.5202937913.
71 phase flips detected on antenna (21, 'Jnn'). A total of 163 integrations were phase-flipped relative to the 0th integration between 2460455.4896474076 and 2460455.5202937913.
53 phase flips detected on antenna (98, 'Jnn'). A total of 202 integrations were phase-flipped relative to the 0th integration between 2460455.483272065 and 2460455.5202937913.
65 phase flips detected on antenna (269, 'Jnn'). A total of 135 integrations were phase-flipped relative to the 0th integration between 2460455.488193382 and 2460455.5202937913.
40 phase flips detected on antenna (137, 'Jnn'). A total of 76 integrations were phase-flipped relative to the 0th integration between 2460455.490877737 and 2460455.519846399.
63 phase flips detected on antenna (159, 'Jnn'). A total of 163 integrations were phase-flipped relative to the 0th integration between 2460455.488193382 and 2460455.5202937913.
85 phase flips detected on antenna (208, 'Jnn'). A total of 96 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
69 phase flips detected on antenna (67, 'Jnn'). A total of 172 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
22 phase flips detected on antenna (105, 'Jnn'). A total of 87 integrations were phase-flipped relative to the 0th integration between 2460455.4917725218 and 2460455.518056829.
59 phase flips detected on antenna (207, 'Jnn'). A total of 124 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.5202937913.
61 phase flips detected on antenna (216, 'Jnn'). A total of 151 integrations were phase-flipped relative to the 0th integration between 2460455.488193382 and 2460455.5202937913.
16 phase flips detected on antenna (205, 'Jnn'). A total of 99 integrations were phase-flipped relative to the 0th integration between 2460455.4895355594 and 2460455.5087734354.
34 phase flips detected on antenna (162, 'Jnn'). A total of 125 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
40 phase flips detected on antenna (182, 'Jnn'). A total of 130 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
20 phase flips detected on antenna (7, 'Jnn'). A total of 166 integrations were phase-flipped relative to the 0th integration between 2460455.4906540406 and 2460455.518056829.
42 phase flips detected on antenna (250, 'Jnn'). A total of 155 integrations were phase-flipped relative to the 0th integration between 2460455.483272065 and 2460455.5197345507.
43 phase flips detected on antenna (251, 'Jnn'). A total of 168 integrations were phase-flipped relative to the 0th integration between 2460455.483272065 and 2460455.5202937913.
38 phase flips detected on antenna (118, 'Jnn'). A total of 149 integrations were phase-flipped relative to the 0th integration between 2460455.4917725218 and 2460455.5197345507.
36 phase flips detected on antenna (246, 'Jnn'). A total of 84 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
26 phase flips detected on antenna (227, 'Jnn'). A total of 106 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.520181943.
12 phase flips detected on antenna (36, 'Jnn'). A total of 15 integrations were phase-flipped relative to the 0th integration between 2460455.4904303444 and 2460455.5038521183.
2 phase flips detected on antenna (238, 'Jnn'). A total of 22 integrations were phase-flipped relative to the 0th integration between 2460455.488193382 and 2460455.4905421925.
6 phase flips detected on antenna (163, 'Jnn'). A total of 3 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.489871104.
12 phase flips detected on antenna (145, 'Jnn'). A total of 11 integrations were phase-flipped relative to the 0th integration between 2460455.4894237113 and 2460455.49188437.
2 phase flips detected on antenna (135, 'Jnn'). A total of 12 integrations were phase-flipped relative to the 0th integration between 2460455.483272065 and 2460455.484502394.
71 phase flips detected on antenna (198, 'Jnn'). A total of 144 integrations were phase-flipped relative to the 0th integration between 2460455.488193382 and 2460455.5202937913.
12 phase flips detected on antenna (46, 'Jnn'). A total of 37 integrations were phase-flipped relative to the 0th integration between 2460455.3238884998 and 2460455.4673896325.
3 phase flips detected on antenna (42, 'Jnn'). A total of 165 integrations were phase-flipped relative to the 0th integration between 2460455.501838852 and 2460455.5202937913.
7 phase flips detected on antenna (234, 'Jnn'). A total of 294 integrations were phase-flipped relative to the 0th integration between 2460455.483272065 and 2460455.5202937913.
53 phase flips detected on antenna (8, 'Jnn'). A total of 134 integrations were phase-flipped relative to the 0th integration between 2460455.4895355594 and 2460455.5202937913.
Plot results¶
lst_grid = utils.JD2LST(cs.time_grid) * 12 / np.pi
lst_grid[lst_grid > lst_grid[-1]] -= 24
def amplitude_plot(ant_to_plot):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
# Pick vmax to not saturate 90% of the abscal gains
vmax = np.max([np.percentile(np.abs(cs.gain_grids[ant_to_plot, pol][~cs.flag_grids[ant_to_plot, pol]]), 99) for pol in ['Jee', 'Jnn']])
display(HTML(f'<h2>Antenna {ant_to_plot} Amplitude Waterfalls</h2>'))
# Plot abscal gain amplitude waterfalls for a single antenna
fig, axes = plt.subplots(4, 2, figsize=(14,14), gridspec_kw={'height_ratios': [1, 1, .4, .4]})
for ax, pol in zip(axes[0], ['Jee', 'Jnn']):
ant = (ant_to_plot, pol)
extent=[cs.freqs[0]/1e6, cs.freqs[-1]/1e6, lst_grid[-1], lst_grid[0]]
im = ax.imshow(np.where(cs.flag_grids[ant], np.nan, np.abs(cs.gain_grids[ant])), aspect='auto', cmap='inferno',
interpolation='nearest', vmin=0, vmax=vmax, extent=extent)
ax.set_title(f'Smoothcal Gain Amplitude of Antenna {ant[0]}: {pol[-1]}-polarized' )
ax.set_xlabel('Frequency (MHz)')
ax.set_ylabel('LST (Hours)')
ax.set_xlim([cs.freqs[0]/1e6, cs.freqs[-1]/1e6])
ax.set_yticklabels(ax.get_yticks() % 24)
plt.colorbar(im, ax=ax, orientation='horizontal', pad=.15)
# Now flagged plot abscal waterfall
for ax, pol in zip(axes[1], ['Jee', 'Jnn']):
ant = (ant_to_plot, pol)
extent=[cs.freqs[0]/1e6, cs.freqs[-1]/1e6, lst_grid[-1], lst_grid[0]]
im = ax.imshow(np.where(cs.flag_grids[ant], np.nan, np.abs(abscal_gains[ant])), aspect='auto', cmap='inferno',
interpolation='nearest', vmin=0, vmax=vmax, extent=extent)
ax.set_title(f'Abscal Gain Amplitude of Antenna {ant[0]}: {pol[-1]}-polarized' )
ax.set_xlabel('Frequency (MHz)')
ax.set_ylabel('LST (Hours)')
ax.set_xlim([cs.freqs[0]/1e6, cs.freqs[-1]/1e6])
ax.set_yticklabels(ax.get_yticks() % 24)
plt.colorbar(im, ax=ax, orientation='horizontal', pad=.15)
# Now plot mean gain spectra
for ax, pol in zip(axes[2], ['Jee', 'Jnn']):
ant = (ant_to_plot, pol)
nflags_spectrum = np.sum(cs.flag_grids[ant], axis=0)
to_plot = nflags_spectrum <= np.percentile(nflags_spectrum, 75)
ax.plot(cs.freqs[to_plot] / 1e6, np.nanmean(np.where(cs.flag_grids[ant], np.nan, np.abs(abscal_gains[ant])), axis=0)[to_plot], 'r.', label='Abscal')
ax.plot(cs.freqs[to_plot] / 1e6, np.nanmean(np.where(cs.flag_grids[ant], np.nan, np.abs(cs.gain_grids[ant])), axis=0)[to_plot], 'k.', ms=2, label='Smoothed')
ax.set_ylim([0, vmax])
ax.set_xlim([cs.freqs[0]/1e6, cs.freqs[-1]/1e6])
ax.set_xlabel('Frequency (MHz)')
ax.set_ylabel('|g| (unitless)')
ax.set_title(f'Mean Infrequently-Flagged Gain Amplitude of Antenna {ant[0]}: {pol[-1]}-polarized')
ax.legend(loc='upper left')
# Now plot mean gain time series
for ax, pol in zip(axes[3], ['Jee', 'Jnn']):
ant = (ant_to_plot, pol)
nflags_series = np.sum(cs.flag_grids[ant], axis=1)
to_plot = nflags_series <= np.percentile(nflags_series, 75)
ax.plot(lst_grid[to_plot], np.nanmean(np.where(cs.flag_grids[ant], np.nan, np.abs(abscal_gains[ant])), axis=1)[to_plot], 'r.', label='Abscal')
ax.plot(lst_grid[to_plot], np.nanmean(np.where(cs.flag_grids[ant], np.nan, np.abs(cs.gain_grids[ant])), axis=1)[to_plot], 'k.', ms=2, label='Smoothed')
ax.set_ylim([0, vmax])
ax.set_xlabel('LST (hours)')
ax.set_ylabel('|g| (unitless)')
ax.set_title(f'Mean Infrequently-Flagged Gain Amplitude of Antenna {ant[0]}: {pol[-1]}-polarized')
ax.set_xticklabels(ax.get_xticks() % 24)
ax.legend(loc='upper left')
plt.tight_layout()
plt.show()
def phase_plot(ant_to_plot):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
display(HTML(f'<h2>Antenna {ant_to_plot} Phase Waterfalls</h2>'))
fig, axes = plt.subplots(4, 2, figsize=(14,14), gridspec_kw={'height_ratios': [1, 1, .4, .4]})
# Plot phase waterfalls for a single antenna
for ax, pol in zip(axes[0], ['Jee', 'Jnn']):
ant = (ant_to_plot, pol)
extent=[cs.freqs[0]/1e6, cs.freqs[-1]/1e6, lst_grid[-1], lst_grid[0]]
im = ax.imshow(np.where(cs.flag_grids[ant], np.nan, np.angle(cs.gain_grids[ant])), aspect='auto', cmap='inferno',
interpolation='nearest', vmin=-np.pi, vmax=np.pi, extent=extent)
ax.set_title(f'Smoothcal Gain Phase of Ant {ant[0]} / Ant {cs.refant[pol][0]}: {pol[-1]}-polarized')
ax.set_xlabel('Frequency (MHz)')
ax.set_ylabel('LST (Hours)')
ax.set_xlim([cs.freqs[0]/1e6, cs.freqs[-1]/1e6])
ax.set_yticklabels(ax.get_yticks() % 24)
plt.colorbar(im, ax=ax, orientation='horizontal', pad=.15)
# Now plot abscal phase waterfall
for ax, pol in zip(axes[1], ['Jee', 'Jnn']):
ant = (ant_to_plot, pol)
extent=[cs.freqs[0]/1e6, cs.freqs[-1]/1e6, lst_grid[-1], lst_grid[0]]
im = ax.imshow(np.where(cs.flag_grids[ant], np.nan, np.angle(abscal_gains[ant])), aspect='auto', cmap='inferno',
interpolation='nearest', vmin=-np.pi, vmax=np.pi, extent=extent)
ax.set_title(f'Abscal Gain Phase of Ant {ant[0]} / Ant {cs.refant[pol][0]}: {pol[-1]}-polarized')
ax.set_xlabel('Frequency (MHz)')
ax.set_ylabel('LST (Hours)')
ax.set_xlim([cs.freqs[0]/1e6, cs.freqs[-1]/1e6])
ax.set_yticklabels(ax.get_yticks() % 24)
plt.colorbar(im, ax=ax, orientation='horizontal', pad=.15)
# Now plot median gain spectra
for ax, pol in zip(axes[2], ['Jee', 'Jnn']):
ant = (ant_to_plot, pol)
nflags_spectrum = np.sum(cs.flag_grids[ant], axis=0)
to_plot = nflags_spectrum <= np.percentile(nflags_spectrum, 75)
ax.plot(cs.freqs[to_plot] / 1e6, np.nanmedian(np.where(cs.flag_grids[ant], np.nan, np.angle(abscal_gains[ant])), axis=0)[to_plot], 'r.', label='Abscal')
ax.plot(cs.freqs[to_plot] / 1e6, np.nanmedian(np.where(cs.flag_grids[ant], np.nan, np.angle(cs.gain_grids[ant])), axis=0)[to_plot], 'k.', ms=2, label='Smoothed')
ax.set_ylim([-np.pi, np.pi])
ax.set_xlim([cs.freqs[0]/1e6, cs.freqs[-1]/1e6])
ax.set_xlabel('Frequency (MHz)')
ax.set_ylabel(f'Phase of g$_{{{ant[0]}}}$ / g$_{{{cs.refant[pol][0]}}}$')
ax.set_title(f'Median Infrequently-Flagged Gain Phase of Ant {ant[0]} / Ant {cs.refant[pol][0]}: {pol[-1]}-polarized')
ax.legend(loc='upper left')
# # Now plot median gain time series
for ax, pol in zip(axes[3], ['Jee', 'Jnn']):
ant = (ant_to_plot, pol)
nflags_series = np.sum(cs.flag_grids[ant], axis=1)
to_plot = nflags_series <= np.percentile(nflags_series, 75)
ax.plot(lst_grid[to_plot], np.nanmean(np.where(cs.flag_grids[ant], np.nan, np.angle(abscal_gains[ant])), axis=1)[to_plot], 'r.', label='Abscal')
ax.plot(lst_grid[to_plot], np.nanmean(np.where(cs.flag_grids[ant], np.nan, np.angle(cs.gain_grids[ant])), axis=1)[to_plot], 'k.', ms=2, label='Smoothed')
ax.set_ylim([-np.pi, np.pi])
ax.set_xlabel('LST (hours)')
ax.set_ylabel(f'Phase of g$_{{{ant[0]}}}$ / g$_{{{cs.refant[pol][0]}}}$')
ax.set_title(f'Mean Infrequently-Flagged Gain Phase of Ant {ant[0]} / Ant {cs.refant[pol][0]}: {pol[-1]}-polarized')
ax.set_xticklabels(ax.get_xticks() % 24)
ax.legend(loc='upper left')
plt.tight_layout()
plt.show()
Figure 1: Full-Day Gain Amplitudes Before and After smooth_cal
¶
Here we plot abscal
and smooth_cal
gain amplitudes for both of the sample antennas. We also show means across time/frequency, excluding frequencies/times that are frequently flagged.
for ant_to_plot in ants_to_plot:
amplitude_plot(ant_to_plot)
Antenna 4 Amplitude Waterfalls
Antenna 295 Amplitude Waterfalls
Figure 2: Full-Day Gain Phases Before and After smooth_cal
¶
Here we plot abscal
and smooth_cal
phases relative to each polarization's reference antenna for both of the sample antennas. We also show medians across time/frequency, excluding frequencies/times that are frequently flagged.
for ant_to_plot in ants_to_plot:
phase_plot(ant_to_plot)
Antenna 4 Phase Waterfalls
Antenna 295 Phase Waterfalls
Examine $\chi^2$¶
def chisq_plot():
fig, axes = plt.subplots(1, 2, figsize=(14, 10), sharex=True, sharey=True)
extent = [cs.freqs[0]/1e6, cs.freqs[-1]/1e6, lst_grid[-1], lst_grid[0]]
for ax, pol in zip(axes, ['Jee', 'Jnn']):
im = ax.imshow(np.where(cs.flag_grids[cs.refant[pol]], np.nan, cs.chisq_grids[pol]), vmin=1, vmax=5,
aspect='auto', cmap='turbo', interpolation='none', extent=extent)
ax.set_yticklabels(ax.get_yticks() % 24)
ax.set_title(f'{pol[1:]}-Polarized $\\chi^2$ / DoF')
ax.set_xlabel('Frequency (MHz)')
axes[0].set_ylabel('LST (hours)')
plt.tight_layout()
fig.colorbar(im, ax=axes, pad=.07, label='$\\chi^2$ / DoF', orientation='horizontal', extend='both', aspect=50)
Figure 3: Full-Day $\chi^2$ / DoF Waterfall from Redundant-Baseline Calibration¶
Here we plot $\chi^2$ per degree of freedom from redundant-baseline calibration for both polarizations separately. While this plot is a little out of place, as it was not produced by this notebook, it is a convenient place where all the necessary components are readily available. If the array were perfectly redundant and any non-redundancies in the calibrated visibilities were explicable by thermal noise alone, this waterfall should be all 1.
chisq_plot()
set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator. set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.