Second Round of Full Day RFI Flagging¶
by Josh Dillon, last updated October 13, 2024
This notebook is synthesizes information from individual delay_filtered_average_zscore notebooks to find low-level RFI and flag it. That notebook takes smooth_cal
ibrated data, redundantly averages it, performs a high-pass delay filter, and then incoherently averages across baselines, creating a per-polarization z-score. This notebook then takes that whole night of z-scores and finds a new set of flags to both add to the smooth_cal
files, which are updated in place, and to write down as new UVFlag
waterfall-type .h5
files.
Here's a set of links to skip to particular figures and tables:
• Figure 1: Waterfall of Maximum z-Score of Either Polarization Before Round 2 Flagging¶
• Figure 2: Histogram of z-scores¶
• Figure 3: Waterfall of Maximum z-Score of Either Polarization After Round 2 Flagging¶
• Figure 4: Spectra of Time-Averaged z-Scores¶
• Figure 5: Summary of Flags Before and After Round 2 Flagging¶
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 matplotlib.pyplot as plt
import matplotlib
import copy
import warnings
from pyuvdata import UVFlag, UVCal
from hera_cal import utils
from hera_qm import xrfi
from hera_qm.time_series_metrics import true_stretches
from hera_filters import dspec
from IPython.display import display, HTML
%matplotlib inline
display(HTML("<style>.container { width:100% !important; }</style>"))
_ = np.seterr(all='ignore') # get rid of red warnings
%config InlineBackend.figure_format = 'retina'
# get input data file names
SUM_FILE = os.environ.get("SUM_FILE", None)
# SUM_FILE = '/lustre/aoc/projects/hera/h6c-analysis/IDR2/2459861/zen.2459861.25297.sum.uvh5'
SUM_SUFFIX = os.environ.get("SUM_SUFFIX", 'sum.uvh5')
# get input and output suffixes
SMOOTH_CAL_SUFFIX = os.environ.get("SMOOTH_CAL_SUFFIX", 'sum.smooth.calfits')
ZSCORE_SUFFIX = os.environ.get("ZSCORE_SUFFIX", 'sum.red_avg_zscore.h5')
FLAG_WATERFALL2_SUFFIX = os.environ.get("FLAG_WATERFALL2_SUFFIX", 'sum.flag_waterfall_round_2.h5')
OUT_YAML_SUFFIX = os.environ.get("OUT_YAML_SUFFIX", '_aposteriori_flags.yaml')
OUT_YAML_DIR = os.environ.get("OUT_YAML_DIR", None)
# build globs
sum_glob = '.'.join(SUM_FILE.split('.')[:-3]) + '.*.' + SUM_SUFFIX
cal_files_glob = sum_glob.replace(SUM_SUFFIX, SMOOTH_CAL_SUFFIX)
zscore_glob = sum_glob.replace(SUM_SUFFIX, ZSCORE_SUFFIX)
# build out yaml file
if OUT_YAML_DIR is None:
OUT_YAML_DIR = os.path.dirname(SUM_FILE)
out_yaml_file = os.path.join(OUT_YAML_DIR, SUM_FILE.split('.')[-4] + OUT_YAML_SUFFIX)
# get flagging parameters
Z_THRESH = float(os.environ.get("Z_THRESH", 4))
WS_Z_THRESH = float(os.environ.get("WS_Z_THRESH", 2))
AVG_Z_THRESH = float(os.environ.get("AVG_Z_THRESH", 1))
MAX_FREQ_FLAG_FRAC = float(os.environ.get("MAX_FREQ_FLAG_FRAC", .25))
MAX_TIME_FLAG_FRAC = float(os.environ.get("MAX_TIME_FLAG_FRAC", .1))
AVG_SPECTRUM_FILTER_DELAY = float(os.environ.get("AVG_SPECTRUM_FILTER_DELAY", 250)) # in ns
EIGENVAL_CUTOFF = float(os.environ.get("EIGENVAL_CUTOFF", 1e-12))
TIME_AVG_DELAY_FILT_SNR_THRESH = float(os.environ.get("TIME_AVG_DELAY_FILT_SNR_THRESH", 4.0))
TIME_AVG_DELAY_FILT_SNR_DYNAMIC_RANGE = float(os.environ.get("TIME_AVG_DELAY_FILT_SNR_DYNAMIC_RANGE", 1.5))
for setting in ['Z_THRESH', 'WS_Z_THRESH', 'AVG_Z_THRESH', 'MAX_FREQ_FLAG_FRAC', 'MAX_TIME_FLAG_FRAC', 'AVG_SPECTRUM_FILTER_DELAY',
'EIGENVAL_CUTOFF', 'TIME_AVG_DELAY_FILT_SNR_THRESH', 'TIME_AVG_DELAY_FILT_SNR_DYNAMIC_RANGE']:
print(f'{setting} = {eval(setting)}')
Z_THRESH = 4.0 WS_Z_THRESH = 2.0 AVG_Z_THRESH = 1.0 MAX_FREQ_FLAG_FRAC = 0.25 MAX_TIME_FLAG_FRAC = 0.1 AVG_SPECTRUM_FILTER_DELAY = 250.0 EIGENVAL_CUTOFF = 1e-12 TIME_AVG_DELAY_FILT_SNR_THRESH = 4.0 TIME_AVG_DELAY_FILT_SNR_DYNAMIC_RANGE = 1.5
Load z-scores¶
# load z-scores
zscore_files = sorted(glob.glob(zscore_glob))
print(f'Found {len(zscore_files)} *.{ZSCORE_SUFFIX} files starting with {zscore_files[0]}.')
uvf = UVFlag(zscore_files, use_future_array_shapes=True)
Found 1851 *.sum.red_avg_zscore.h5 files starting with /mnt/sn1/data1/2460695/zen.2460695.25238.sum.red_avg_zscore.h5.
# get calibration solution files
cal_files = sorted(glob.glob(cal_files_glob))
print(f'Found {len(cal_files)} *.{SMOOTH_CAL_SUFFIX} files starting with {cal_files[0]}.')
Found 1851 *.sum.smooth.calfits files starting with /mnt/sn1/data1/2460695/zen.2460695.25238.sum.smooth.calfits.
assert len(zscore_files) == len(cal_files)
# extract z-scores and correct by a single number per polarization to account for biases created by filtering
zscore = {pol: uvf.metric_array[:, :, np.argwhere(uvf.polarization_array == utils.polstr2num(pol, x_orientation=uvf.x_orientation))[0][0]] for pol in ['ee', 'nn']}
zscore = {pol: zscore[pol] - np.nanmedian(zscore[pol]) for pol in zscore}
freqs = uvf.freq_array
times = uvf.time_array
extent = [freqs[0] / 1e6, freqs[-1] / 1e6, times[-1] - int(times[0]), times[0] - int(times[0])]
def plot_max_z_score(zscore, flags=None, vmin=-5, vmax=5):
if flags is None:
flags = np.any(~np.isfinite(list(zscore.values())), axis=0)
plt.figure(figsize=(14,10), dpi=100)
plt.imshow(np.where(flags, np.nan, np.nanmax([zscore['ee'], zscore['nn']], axis=0)), aspect='auto',
cmap='coolwarm', interpolation='none', vmin=vmin, vmax=vmax, extent=extent)
plt.colorbar(location='top', label='Max z-score of either polarization', extend='both', aspect=40, pad=.02)
plt.xlabel('Frequency (MHz)')
plt.ylabel(f'JD - {int(times[0])}')
plt.tight_layout()
Figure 1: Waterfall of Maximum z-Score of Either Polarization Before Round 2 Flagging¶
Shows the worse of the two results from delay_filtered_average_zscore from either polarization. Dips near flagged channels are expected, due to overfitting of noise. Positive-going excursions are problematic and likely evidence of RFI.
plot_max_z_score(zscore)
All-NaN axis encountered
def plot_histogram():
plt.figure(figsize=(14,4), dpi=100)
bins = np.arange(-50, 100, .1)
hist_ee = plt.hist(np.ravel(zscore['ee']), bins=bins, density=True, label='ee-polarized z-scores', alpha=.5)
hist_nn = plt.hist(np.ravel(zscore['nn']), bins=bins, density=True, label='nn-polarized z-scores', alpha=.5)
plt.plot(bins, (2*np.pi)**-.5 * np.exp(-bins**2 / 2), 'k:', label='Gaussian approximate\nnoise-only distribution')
plt.axvline(WS_Z_THRESH, c='r', ls='--', label='Watershed z-score')
plt.axvline(Z_THRESH, c='r', ls='-', label='Threshold z-score')
plt.yscale('log')
all_densities = np.concatenate([hist_ee[0][hist_ee[0] > 0], hist_nn[0][hist_nn[0] > 0]])
plt.ylim(np.min(all_densities) / 2, np.max(all_densities) * 2)
plt.xlim([-50, 100])
plt.legend()
plt.xlabel('z-score')
plt.ylabel('Density')
plt.tight_layout()
Figure 2: Histogram of z-scores¶
Shows a comparison of the histogram of z-scores in this file (one per polarization) to a Gaussian approximation of what one might expect from thermal noise. Without filtering, the actual distribution is a weighted sum of Rayleigh distributions. Filtering further complicates this. To make the z-scores more reliable, a single per-polarization median is subtracted from each waterfall, which allows us to flag low-level outliers with more confidence. Any points beyond the solid red line are flagged. Any points neighboring a flag beyond the dashed red line are also flagged. Finally, flagging is performed for low-level outliers in whole times or channels.
plot_histogram()
Perform flagging¶
def iteratively_flag_on_averaged_zscore(flags, zscore, avg_func=np.nanmean, avg_z_thresh=AVG_Z_THRESH, verbose=True):
'''Flag whole integrations or channels based on average z-score. This is done
iteratively to prevent bad times affecting channel averages or vice versa.'''
flagged_chan_count = 0
flagged_int_count = 0
while True:
zspec = avg_func(np.where(flags, np.nan, zscore), axis=0)
ztseries = avg_func(np.where(flags, np.nan, zscore), axis=1)
if (np.nanmax(zspec) < avg_z_thresh) and (np.nanmax(ztseries) < avg_z_thresh):
break
if np.nanmax(zspec) >= np.nanmax(ztseries):
flagged_chan_count += np.sum((zspec >= np.nanmax(ztseries)) & (zspec >= avg_z_thresh))
flags[:, (zspec >= np.nanmax(ztseries)) & (zspec >= avg_z_thresh)] = True
else:
flagged_int_count += np.sum((ztseries >= np.nanmax(zspec)) & (ztseries >= avg_z_thresh))
flags[(ztseries >= np.nanmax(zspec)) & (ztseries >= avg_z_thresh), :] = True
if verbose:
print(f'\tFlagging an additional {flagged_int_count} integrations and {flagged_chan_count} channels.')
def impose_max_chan_flag_frac(flags, max_flag_frac=MAX_FREQ_FLAG_FRAC, verbose=True):
'''Flag channels already flagged more than max_flag_frac (excluding completely flagged times).'''
unflagged_times = ~np.all(flags, axis=1)
frequently_flagged_chans = np.mean(flags[unflagged_times, :], axis=0) >= max_flag_frac
if verbose:
print(f'\tFlagging {np.sum(frequently_flagged_chans) - np.sum(np.all(flags, axis=0))} channels previously flagged {max_flag_frac:.2%} or more.')
flags[:, frequently_flagged_chans] = True
def impose_max_time_flag_frac(flags, max_flag_frac=MAX_TIME_FLAG_FRAC, verbose=True):
'''Flag times already flagged more than max_flag_frac (excluding completely flagged channels).'''
unflagged_chans = ~np.all(flags, axis=0)
frequently_flagged_times = np.mean(flags[:, unflagged_chans], axis=1) >= max_flag_frac
if verbose:
print(f'\tFlagging {np.sum(frequently_flagged_times) - np.sum(np.all(flags, axis=1))} times previously flagged {max_flag_frac:.2%} or more.')
flags[frequently_flagged_times, :] = True
def time_avg_zscore_dly_filt_SNRs(flags, filter_delay=AVG_SPECTRUM_FILTER_DELAY, eigenval_cutoff=EIGENVAL_CUTOFF):
"""Produces SNRs after time-averaging z-scores and delay filtering, accounting for flagging's effect on the filter."""
# figure out high and low band based on FM gap at 100 MHz
flagged_stretches = true_stretches(np.all(flags, axis=0))
FM_gap = [fs for fs in flagged_stretches if fs.start <= np.argmin(np.abs(freqs - 100e6)) < fs.stop][0]
low_band = slice((0 if flagged_stretches[0].start != 0 else flagged_stretches[0].stop), FM_gap.start)
high_band = slice(FM_gap.stop, (len(freqs) if flagged_stretches[-1].stop != len(freqs) else flagged_stretches[-1].start))
filt_SNR = {}
for pol in zscore:
# calculate timeavg_SNR and filter
noise_prediction = 1.0 / np.sum(~flags, axis=0)**.5
timeavg_SNR = np.nanmean(np.where(flags, np.nan, zscore[pol] / noise_prediction), axis=0)
wgts = np.where(np.isfinite(timeavg_SNR), 1, 0)
model = np.zeros_like(timeavg_SNR)
for band in [low_band, high_band]:
model[band], _, _ = dspec.fourier_filter(freqs[band], np.where(np.isfinite(timeavg_SNR[band]), timeavg_SNR[band], 0),
wgts[band], [0], [AVG_SPECTRUM_FILTER_DELAY / 1e9], mode="dpss_solve",
eigenval_cutoff=[EIGENVAL_CUTOFF], suppression_factors=[EIGENVAL_CUTOFF])
filt_SNR[pol] = timeavg_SNR - model
# correct for impact of filter
correction_factors = np.ones_like(wgts) * np.nan
for band in [low_band, high_band]:
X = dspec.dpss_operator(freqs[band], [0], filter_half_widths=[AVG_SPECTRUM_FILTER_DELAY / 1e9], eigenval_cutoff=[EIGENVAL_CUTOFF])[0]
W = wgts[band]
leverage = np.diag(X @ np.linalg.pinv(np.dot(X.T * W, X)) @ (X.T * W))
correction_factors[band] = np.where(leverage > 0, (1 - leverage)**.5, np.nan) # because the underlying data should be gaussian
filt_SNR[pol] /= correction_factors
return filt_SNR
def iteratively_flag_on_delay_filtered_time_avg_zscore(flags, thresh=TIME_AVG_DELAY_FILT_SNR_THRESH, dynamic_range=TIME_AVG_DELAY_FILT_SNR_DYNAMIC_RANGE,
filter_delay=AVG_SPECTRUM_FILTER_DELAY, eigenval_cutoff=EIGENVAL_CUTOFF):
"""Flag whole channels based on their outlierness after delay-filterd time-averaged zscores.
This is done iteratively since the delay filter can be unduly influenced by large outliers."""
filt_SNR = time_avg_zscore_dly_filt_SNRs(flags, filter_delay=AVG_SPECTRUM_FILTER_DELAY, eigenval_cutoff=EIGENVAL_CUTOFF)
while True:
largest_SNR = np.nanmax(list(filt_SNR.values()))
if largest_SNR < thresh:
break
#
cut = np.max([thresh, largest_SNR / dynamic_range])
for pol in filt_SNR:
flags[:, filt_SNR[pol] > cut] = True
filt_SNR = time_avg_zscore_dly_filt_SNRs(flags, filter_delay=AVG_SPECTRUM_FILTER_DELAY, eigenval_cutoff=EIGENVAL_CUTOFF)
flags = np.any(~np.isfinite(list(zscore.values())), axis=0)
print(f'{np.mean(flags):.3%} of waterfall flagged to start.')
# flag whole integrations or channels using outliers in median
while True:
nflags = np.sum(flags)
for pol in ['ee', 'nn']:
iteratively_flag_on_averaged_zscore(flags, zscore[pol], avg_func=np.nanmedian, avg_z_thresh=AVG_Z_THRESH, verbose=True)
impose_max_chan_flag_frac(flags, max_flag_frac=MAX_FREQ_FLAG_FRAC, verbose=True)
impose_max_time_flag_frac(flags, max_flag_frac=MAX_TIME_FLAG_FRAC, verbose=True)
if np.sum(flags) == nflags:
break
print(f'{np.mean(flags):.3%} of waterfall flagged after flagging whole times and channels with median z > {AVG_Z_THRESH}.')
# flag largest outliers
for pol in ['ee', 'nn']:
flags |= (zscore[pol] > Z_THRESH)
print(f'{np.mean(flags):.3%} of waterfall flagged after flagging z > {Z_THRESH} outliers.')
# watershed flagging
while True:
nflags = np.sum(flags)
for pol in ['ee', 'nn']:
flags |= xrfi._ws_flag_waterfall(zscore[pol], flags, WS_Z_THRESH)
if np.sum(flags) == nflags:
break
print(f'{np.mean(flags):.3%} of waterfall flagged after watershed flagging on z > {WS_Z_THRESH} neighbors of prior flags.')
# flag whole integrations or channels using outliers in mean
while True:
nflags = np.sum(flags)
for pol in ['ee', 'nn']:
iteratively_flag_on_averaged_zscore(flags, zscore[pol], avg_func=np.nanmean, avg_z_thresh=AVG_Z_THRESH, verbose=True)
impose_max_chan_flag_frac(flags, max_flag_frac=MAX_FREQ_FLAG_FRAC, verbose=True)
impose_max_time_flag_frac(flags, max_flag_frac=MAX_TIME_FLAG_FRAC, verbose=True)
if np.sum(flags) == nflags:
break
print(f'{np.mean(flags):.3%} of waterfall flagged after flagging whole times and channels with average z > {AVG_Z_THRESH}.')
# flag channels based on delay filter
iteratively_flag_on_delay_filtered_time_avg_zscore(flags, thresh=TIME_AVG_DELAY_FILT_SNR_THRESH, dynamic_range=TIME_AVG_DELAY_FILT_SNR_DYNAMIC_RANGE,
filter_delay=AVG_SPECTRUM_FILTER_DELAY, eigenval_cutoff=EIGENVAL_CUTOFF)
print(f'{np.mean(flags):.3%} of flagging channels that are {TIME_AVG_DELAY_FILT_SNR_THRESH}σ outliers after delay filtering the time average.')
# watershed flagging again
while True:
nflags = np.sum(flags)
for pol in ['ee', 'nn']:
flags |= xrfi._ws_flag_waterfall(zscore[pol], flags, WS_Z_THRESH)
if np.sum(flags) == nflags:
break
print(f'{np.mean(flags):.3%} of waterfall flagged after another round of watershed flagging on z > {WS_Z_THRESH} neighbors of prior flags.')
22.961% of waterfall flagged to start.
All-NaN slice encountered
Flagging an additional 0 integrations and 14 channels. Flagging 0 channels previously flagged 25.00% or more. Flagging 1 times previously flagged 10.00% or more.
Flagging an additional 1 integrations and 83 channels. Flagging 0 channels previously flagged 25.00% or more. Flagging 1 times previously flagged 10.00% or more.
Flagging an additional 0 integrations and 0 channels. Flagging 0 channels previously flagged 25.00% or more. Flagging 0 times previously flagged 10.00% or more.
Flagging an additional 0 integrations and 0 channels. Flagging 0 channels previously flagged 25.00% or more. Flagging 0 times previously flagged 10.00% or more. 28.664% of waterfall flagged after flagging whole times and channels with median z > 1.0. 29.512% of waterfall flagged after flagging z > 4.0 outliers.
33.242% of waterfall flagged after watershed flagging on z > 2.0 neighbors of prior flags. Flagging an additional 0 integrations and 0 channels. Flagging 106 channels previously flagged 25.00% or more. Flagging 351 times previously flagged 10.00% or more.
Mean of empty slice Mean of empty slice
Flagging an additional 0 integrations and 0 channels. Flagging 2 channels previously flagged 25.00% or more. Flagging 0 times previously flagged 10.00% or more. Flagging an additional 0 integrations and 0 channels. Flagging 0 channels previously flagged 25.00% or more.
Flagging 0 times previously flagged 10.00% or more. Flagging an additional 0 integrations and 0 channels. Flagging 0 channels previously flagged 25.00% or more. Flagging 0 times previously flagged 10.00% or more. 43.575% of waterfall flagged after flagging whole times and channels with average z > 1.0.
Mean of empty slice Casting complex values to real discards the imaginary part Casting complex values to real discards the imaginary part
46.676% of flagging channels that are 4.0σ outliers after delay filtering the time average.
47.439% of waterfall flagged after another round of watershed flagging on z > 2.0 neighbors of prior flags.
Show results of flagging¶
Figure 3: Waterfall of Maximum z-Score of Either Polarization After Round 2 Flagging¶
The same as Figure 1, but after the flagging performed in this notebook.
plot_max_z_score(zscore, flags=flags)
All-NaN axis encountered
def zscore_spectra(ylim=[-3, 3], flags=flags):
fig, axes = plt.subplots(2, 1, figsize=(14,6), dpi=100, sharex=True, sharey=True, gridspec_kw={'hspace': 0})
for ax, pol in zip(axes, ['ee', 'nn']):
ax.plot(freqs / 1e6, np.nanmean(zscore[pol], axis=0),'r', label=f'{pol}-Polarization Before Round 2 Flagging', lw=.5)
ax.plot(freqs / 1e6, np.nanmean(np.where(flags, np.nan, zscore[pol]), axis=0), label=f'{pol}-Polarization After Round 2 Flagging')
ax.legend(loc='lower right')
ax.set_ylabel('Time-Averged Z-Score\n(Excluding Flags)')
ax.set_ylim(ylim)
axes[1].set_xlabel('Frequency (MHz)')
plt.tight_layout()
Figure 4: Spectra of Time-Averaged z-Scores¶
The average along the time axis of Figures 1 and 3 (though now separated per-polarization). This plot is useful for showing channels with repeated low-level RFI.
zscore_spectra()
Mean of empty slice Mean of empty slice
def summarize_flagging(flags=flags):
plt.figure(figsize=(14,10), dpi=100)
cmap = matplotlib.colors.ListedColormap(((0, 0, 0),) + matplotlib.cm.get_cmap("Set2").colors[0:2])
plt.imshow(np.where(np.any(~np.isfinite(list(zscore.values())), axis=0), 1, np.where(flags, 2, 0)),
aspect='auto', cmap=cmap, interpolation='none', extent=extent)
plt.clim([-.5, 2.5])
cbar = plt.colorbar(location='top', aspect=40, pad=.02)
cbar.set_ticks([0, 1, 2])
cbar.set_ticklabels(['Unflagged', 'Previously Flagged', 'Flagged Here Using Delayed Filtered z-Scores'])
plt.xlabel('Frequency (MHz)')
plt.ylabel(f'JD - {int(times[0])}')
plt.tight_layout()
Figure 5: Summary of Flags Before and After Round 2 Flagging¶
This plot shows which times and frequencies were flagged before and after this notebook. It is directly comparable to Figure 5 of the first round full_day_rfi notebook.
summarize_flagging()
The get_cmap function was deprecated in Matplotlib 3.7 and will be removed two minor releases later. Use ``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap(obj)`` instead.
Save results¶
add_to_history = 'by full_day_rfi_round_2 notebook with the following environment:\n' + '=' * 65 + '\n' + os.popen('conda env export').read() + '=' * 65
tind = 0
always_flagged_ants = set()
ever_unflagged_ants = set()
for cal_file in cal_files:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
# update cal_file
uvc = UVCal()
uvc.read(cal_file, use_future_array_shapes=True)
uvc.flag_array |= (flags[tind:tind + len(uvc.time_array), :].T)[None, :, :, None]
uvc.history += 'Modified ' + add_to_history
uvc.write_calfits(cal_file, clobber=True)
# keep track of flagged antennas
for antnum in uvc.ant_array:
for antpol in ['Jee', 'Jnn']:
if np.all(uvc.get_flags(antnum, antpol)):
if (antnum, antpol) not in ever_unflagged_ants:
always_flagged_ants.add((antnum, antpol))
else:
ever_unflagged_ants.add((antnum, antpol))
always_flagged_ants.discard((antnum, antpol))
# Create new flag object
uvf_out = UVFlag(uvc, waterfall=True, mode='flag')
uvf_out.flag_array |= flags[tind:tind + len(uvc.time_array), :, None]
uvf_out.history += 'Produced ' + add_to_history
uvf_out.write(cal_file.replace(SMOOTH_CAL_SUFFIX, FLAG_WATERFALL2_SUFFIX), clobber=True)
# increment time index
tind += len(uvc.time_array)
print(f'Saved {len(cal_files)} *.{FLAG_WATERFALL2_SUFFIX} files starting with {cal_files[0].replace(SMOOTH_CAL_SUFFIX, FLAG_WATERFALL2_SUFFIX)}.')
Saved 1851 *.sum.flag_waterfall_round_2.h5 files starting with /mnt/sn1/data1/2460695/zen.2460695.25238.sum.flag_waterfall_round_2.h5.
# write summary of entirely flagged times/freqs/ants to yaml
all_flagged_times = np.all(flags, axis=1)
all_flagged_freqs = np.all(flags, axis=0)
all_flagged_ants = sorted(always_flagged_ants)
dt = np.median(np.diff(times))
out_yml_str = 'JD_flags: ' + str([[times[flag_stretch][0] - dt / 2, times[flag_stretch][-1] + dt / 2]
for flag_stretch in true_stretches(all_flagged_times)])
df = np.median(np.diff(freqs))
out_yml_str += '\n\nfreq_flags: ' + str([[freqs[flag_stretch][0] - df / 2, freqs[flag_stretch][-1] + df / 2]
for flag_stretch in true_stretches(all_flagged_freqs)])
out_yml_str += '\n\nex_ants: ' + str(all_flagged_ants).replace("'", "").replace('(', '[').replace(')', ']')
print(f'Writing the following to {out_yaml_file}\n' + '-' * (25 + len(out_yaml_file)))
print(out_yml_str)
with open(out_yaml_file, 'w') as outfile:
outfile.writelines(out_yml_str)
Writing the following to /mnt/sn1/data1/2460695/2460695_aposteriori_flags.yaml ------------------------------------------------------------------------------ JD_flags: [[2460695.2537196823, 2460695.2539433786], [2460695.254390771, 2460695.2546144673], [2460695.254838163, 2460695.2550618593], [2460695.2561803404, 2460695.2562921885], [2460695.2564040367, 2460695.256627733], [2460695.258640999, 2460695.258864695], [2460695.2605424165, 2460695.2607661127], [2460695.2613253533, 2460695.2614372014], [2460695.26210829, 2460695.2623319863], [2460695.2634504675, 2460695.2636741637], [2460695.2660229737, 2460695.26624667], [2460695.2706087464, 2460695.270944291], [2460695.2729575564, 2460695.2731812526], [2460695.2740760376, 2460695.2741878857], [2460695.2749708225, 2460695.2751945187], [2460695.275418215, 2460695.275530063], [2460695.2760893037, 2460695.276313], [2460695.2769840886, 2460695.2770959367], [2460695.2774314806, 2460695.2775433287], [2460695.279780291, 2460695.2801158354], [2460695.2802276835, 2460695.2804513797], [2460695.2864911775, 2460695.2867148737], [2460695.293313912, 2460695.293985001], [2460695.2940968485, 2460695.294432393], [2460695.296333811, 2460695.296445659], [2460695.2971167476, 2460695.2972285957], [2460695.2991300137, 2460695.299465558], [2460695.299801102, 2460695.300024798], [2460695.304610571, 2460695.304834267], [2460695.305281659, 2460695.305952748], [2460695.306959381, 2460695.307071229], [2460695.307294925, 2460695.3074067733], [2460695.310762217, 2460695.3110977607], [2460695.313222875, 2460695.313446571], [2460695.315236141, 2460695.3155716853], [2460695.316578318, 2460695.3169138622], [2460695.3172494066, 2460695.317584951], [2460695.3179204953, 2460695.3182560396], [2460695.3183678878, 2460695.3190389764], [2460695.3191508246, 2460695.319374521], [2460695.319486369, 2460695.3201574576], [2460695.3202693057, 2460695.320493002], [2460695.320716698, 2460695.3208285463], [2460695.3220588756, 2460695.3226181157], [2460695.327986825, 2460695.328322369], [2460695.331901509, 2460695.332013357], [2460695.335256952, 2460695.335592496], [2460695.336151737, 2460695.336375433], [2460695.3376057623, 2460695.3379413066], [2460695.349797206, 2460695.3502445985], [2460695.366462574, 2460695.366574422], [2460695.36668627, 2460695.3671336626], [2460695.3693706244, 2460695.3694824725], [2460695.371943131, 2460695.372054979], [2460695.3739563967, 2460695.3745156373], [2460695.3766407515, 2460695.3784303213], [2460695.379325106, 2460695.37966065], [2460695.3797724983, 2460695.3798843464], [2460695.3799961945, 2460695.380443587], [2460695.3808909794, 2460695.381338372], [2460695.38145022, 2460695.3817857644], [2460695.382233157, 2460695.382456853], [2460695.3826805493, 2460695.3837990304], [2460695.3839108786, 2460695.384134575], [2460695.3842464224, 2460695.3843582706], [2460695.384581967, 2460695.384693815], [2460695.384805663, 2460695.3863715366], [2460695.386707081, 2460695.386930777], [2460695.3871544735, 2460695.387490018], [2460695.387713714, 2460695.3880492584], [2460695.3881611065, 2460695.3882729546], [2460695.3883848027, 2460695.388608499], [2460695.3889440433, 2460695.3890558914], [2460695.3891677395, 2460695.3892795877], [2460695.3897269797, 2460695.389838828], [2460695.3903980684, 2460695.3905099165], [2460695.390957309, 2460695.391181005], [2460695.3914047014, 2460695.391963942], [2460695.3926350307, 2460695.393082423], [2460695.3945364486, 2460695.3946482968], [2460695.394760145, 2460695.395431233], [2460695.395543081, 2460695.3956549293], [2460695.3958786256, 2460695.396102322], [2460695.396437866, 2460695.3966615624], [2460695.3968852586, 2460695.397220803], [2460695.3976681954, 2460695.3977800435], [2460695.39800374, 2460695.3987866766], [2460695.3988985247, 2460695.3997933096], [2460695.400128854, 2460695.40035255], [2460695.4005762464, 2460695.4007999427], [2460695.4009117903, 2460695.4012473347], [2460695.401471031, 2460695.401582879], [2460695.4018065752, 2460695.4020302715], [2460695.4021421196, 2460695.4028132083], [2460695.4029250564, 2460695.4030369045], [2460695.4031487526, 2460695.403596145], [2460695.403707993, 2460695.4038198413], [2460695.4040435376, 2460695.404267234], [2460695.40449093, 2460695.405497563], [2460695.405609411, 2460695.4058331074], [2460695.4060568037, 2460695.4061686518], [2460695.406392348, 2460695.406504196], [2460695.40683974, 2460695.406951588], [2460695.4073989806, 2460695.407622677], [2460695.4084056136, 2460695.4085174617], [2460695.40862931, 2460695.408741158], [2460695.408853006, 2460695.4091885504], [2460695.409635943, 2460695.409747791], [2460695.410754424, 2460695.4109781203], [2460695.4110899684, 2460695.4113136646], [2460695.4119847533, 2460695.4120966014], [2460695.412208449, 2460695.412320297], [2460695.412879538, 2460695.413103234], [2460695.413215082, 2460695.4137743227], [2460695.413998019, 2460695.414109867], [2460695.415004652, 2460695.4151165], [2460695.415228348, 2460695.4153401963], [2460695.416123133, 2460695.4162349813], [2460695.4164586775, 2460695.417017918], [2460695.4173534624, 2460695.4174653105], [2460695.417800855, 2460695.4180245507], [2460695.418360095, 2460695.4188074875], [2460695.4189193356, 2460695.4190311837], [2460695.41925488, 2460695.4197022724], [2460695.4207089054, 2460695.421156298], [2460695.421268146, 2460695.421379994], [2460695.422162931, 2460695.422386627], [2460695.4227221715, 2460695.4228340196], [2460695.4229458678, 2460695.423057716], [2460695.423616956, 2460695.423728804], [2460695.424511741, 2460695.424623589], [2460695.4249591334, 2460695.4250709815], [2460695.4251828296, 2460695.4252946777], [2460695.42574207, 2460695.4258539183], [2460695.426301311, 2460695.426413159], [2460695.4268605513, 2460695.4269723995], [2460695.42753164, 2460695.427643488], [2460695.428314577, 2460695.428426425], [2460695.429097513, 2460695.4293212094], [2460695.4295449057, 2460695.429768602], [2460695.42988045, 2460695.429992298], [2460695.4305515387, 2460695.430663387], [2460695.4312226274, 2460695.432005564], [2460695.4321174123, 2460695.4323411086], [2460695.432676653, 2460695.432900349], [2460695.4332358935, 2460695.4333477416], [2460695.4334595897, 2460695.433683286], [2460695.433795134, 2460695.433906982], [2460695.4348017666, 2460695.4354728553], [2460695.4355847035, 2460695.4356965516], [2460695.436032096, 2460695.4364794884], [2460695.4367031846, 2460695.437038729], [2460695.4377098177, 2460695.437821666], [2460695.437933514, 2460695.4384927545], [2460695.438828299, 2460695.438940147], [2460695.439051995, 2460695.439834932], [2460695.440058628, 2460695.441177109], [2460695.441512653, 2460695.4419600456], [2460695.445091793, 2460695.445203641], [2460695.446657666, 2460695.4468813622], [2460695.447552451, 2460695.447664299], [2460695.4481116915, 2460695.4482235396], [2460695.4551581223, 2460695.4552699705], [2460695.4584017172, 2460695.4585135654], [2460695.459296502, 2460695.4594083503], [2460695.4606386796, 2460695.460974224], [2460695.4675732623, 2460695.4677969585], [2460695.468244351, 2460695.468356199], [2460695.468803591, 2460695.4692509836], [2460695.4756263257, 2460695.47596187], [2460695.477975136, 2460695.4783106805], [2460695.5011276943, 2460695.5014632386], [2460695.503252808, 2460695.5037002005], [2460695.50727934, 2460695.5075030364], [2460695.508621517, 2460695.5088452133], [2460695.5120888087, 2460695.512312505], [2460695.519135239, 2460695.5193589353], [2460695.5196944796, 2460695.5198063278], [2460695.53680724, 2460695.536919088], [2460695.5381494174, 2460695.5382612655], [2460695.5454195444, 2460695.5456432407], [2460695.5540318484, 2460695.5542555447], [2460695.576513318, 2460695.576625166], [2460695.5778554953, 2460695.5780791915], [2460695.579645065, 2460695.5798687614], [2460695.5807635463, 2460695.58109909], [2460695.5813227864, 2460695.5814346345], [2460695.583000508, 2460695.5833360525], [2460695.586579648, 2460695.586691496], [2460695.5874744323, 2460695.587921825], [2460695.5887047616, 2460695.589040306], [2460695.5898232427, 2460695.590046939], [2460695.590829876, 2460695.59116542], [2460695.5929549895, 2460695.593402382], [2460695.595415648, 2460695.5957511924], [2460695.599777724, 2460695.5998895722], [2460695.6001132685, 2460695.6003369647], [2460695.600784357, 2460695.6008962053], [2460695.604922737, 2460695.605146433], [2460695.6107388386, 2460695.610962535], [2460695.6117454716, 2460695.6118573197], [2460695.614094282, 2460695.6144298264], [2460695.615324611, 2460695.615548307], [2460695.617561573, 2460695.6177852694], [2460695.6181208137, 2460695.618232662], [2460695.622818434, 2460695.6229302823], [2460695.626062029, 2460695.6262857253], [2460695.6265094215, 2460695.6267331177], [2460695.6294174725, 2460695.6295293206], [2460695.64138522, 2460695.641608916], [2460695.6452999036, 2460695.6455236], [2460695.6470894734, 2460695.6473131697], [2460695.6483198027, 2460695.648431651], [2460695.649885676, 2460695.650892309], [2460695.6512278533, 2460695.6513397014], [2460695.652793727, 2460695.652905575], [2460695.653129271, 2460695.6532411193], [2460695.6559254737, 2460695.656261018], [2460695.661517879, 2460695.661741575], [2460695.662300816, 2460695.662412664], [2460695.6631956007, 2460695.6663273475]] freq_flags: [[49911499.0234375, 50155639.6484375], [62118530.2734375, 62728881.8359375], [69931030.2734375, 70053100.5859375], [87387084.9609375, 108139038.0859375], [109970092.7734375, 110092163.0859375], [112167358.3984375, 112411499.0234375], [112655639.6484375, 113021850.5859375], [113265991.2109375, 113510131.8359375], [113632202.1484375, 113754272.4609375], [116073608.3984375, 116195678.7109375], [116317749.0234375, 116928100.5859375], [124008178.7109375, 124130249.0234375], [124740600.5859375, 125228881.8359375], [127304077.1484375, 127914428.7109375], [129989624.0234375, 130111694.3359375], [134994506.8359375, 135116577.1484375], [136337280.2734375, 136459350.5859375], [136825561.5234375, 138168334.9609375], [138656616.2109375, 138778686.5234375], [141464233.3984375, 141586303.7109375], [141708374.0234375, 141830444.3359375], [141952514.6484375, 142318725.5859375], [142684936.5234375, 143417358.3984375], [143539428.7109375, 143661499.0234375], [143783569.3359375, 144027709.9609375], [144638061.5234375, 145004272.4609375], [145492553.7109375, 145614624.0234375], [147079467.7734375, 147323608.3984375], [147445678.7109375, 147567749.0234375], [148178100.5859375, 148544311.5234375], [149154663.0859375, 149276733.3984375], [149887084.9609375, 150009155.2734375], [151840209.9609375, 151962280.2734375], [153915405.2734375, 154037475.5859375], [154159545.8984375, 154403686.5234375], [155014038.0859375, 155380249.0234375], [156356811.5234375, 156478881.8359375], [156967163.0859375, 157089233.3984375], [157577514.6484375, 157699584.9609375], [158187866.2109375, 158432006.8359375], [158676147.4609375, 158798217.7734375], [159164428.7109375, 159286499.0234375], [161239624.0234375, 161483764.6484375], [168807983.3984375, 168930053.7109375], [169906616.2109375, 170150756.8359375], [170272827.1484375, 170394897.4609375], [170516967.7734375, 170639038.0859375], [170883178.7109375, 171005249.0234375], [171249389.6484375, 171371459.9609375], [171737670.8984375, 171859741.2109375], [175155639.6484375, 175399780.2734375], [175521850.5859375, 175643920.8984375], [177108764.6484375, 177230834.9609375], [179916381.8359375, 180160522.4609375], [180282592.7734375, 180648803.7109375], [181137084.9609375, 181381225.5859375], [182479858.3984375, 182601928.7109375], [182968139.6484375, 183944702.1484375], [184555053.7109375, 184677124.0234375], [186141967.7734375, 187118530.2734375], [187362670.8984375, 187728881.8359375], [189559936.5234375, 189804077.1484375], [189926147.4609375, 192611694.3359375], [192855834.9609375, 194076538.0859375], [194320678.7109375, 198837280.2734375], [198959350.5859375, 199447631.8359375], [199935913.0859375, 200424194.3359375], [200546264.6484375, 202133178.7109375], [202377319.3359375, 202499389.6484375], [203231811.5234375, 203475952.1484375], [203842163.0859375, 204696655.2734375], [204818725.5859375, 205551147.4609375], [206039428.7109375, 206161499.0234375], [206649780.2734375, 209335327.1484375], [209823608.3984375, 210189819.3359375], [210433959.9609375, 210678100.5859375], [211288452.1484375, 211410522.4609375], [211532592.7734375, 211898803.7109375], [212020874.0234375, 212387084.9609375], [213363647.4609375, 213851928.7109375], [214950561.5234375, 215438842.7734375], [216049194.3359375, 216171264.6484375], [216537475.5859375, 216781616.2109375], [219711303.7109375, 219955444.3359375], [220321655.2734375, 220443725.5859375], [220565795.8984375, 220809936.5234375], [220932006.8359375, 221054077.1484375], [221176147.4609375, 221298217.7734375], [221664428.7109375, 221786499.0234375], [222640991.2109375, 223861694.3359375], [225692749.0234375, 225814819.3359375], [226425170.8984375, 228134155.2734375], [228988647.4609375, 234359741.2109375]] ex_ants: [[7, Jee], [9, Jee], [15, Jnn], [16, Jee], [17, Jnn], [18, Jnn], [21, Jee], [22, Jee], [22, Jnn], [27, Jee], [27, Jnn], [28, Jee], [28, Jnn], [31, Jnn], [32, Jnn], [33, Jnn], [34, Jee], [34, Jnn], [35, Jee], [35, Jnn], [37, Jnn], [40, Jee], [40, Jnn], [41, Jee], [41, Jnn], [42, Jee], [42, Jnn], [45, Jee], [46, Jee], [47, Jee], [47, Jnn], [48, Jee], [48, Jnn], [49, Jee], [49, Jnn], [51, Jee], [54, Jee], [54, Jnn], [55, Jee], [55, Jnn], [56, Jee], [56, Jnn], [57, Jee], [57, Jnn], [61, Jee], [61, Jnn], [62, Jee], [62, Jnn], [63, Jee], [63, Jnn], [64, Jee], [64, Jnn], [68, Jee], [68, Jnn], [69, Jee], [69, Jnn], [70, Jee], [70, Jnn], [71, Jee], [71, Jnn], [72, Jee], [72, Jnn], [73, Jee], [77, Jee], [77, Jnn], [78, Jee], [78, Jnn], [83, Jnn], [84, Jee], [84, Jnn], [86, Jee], [86, Jnn], [87, Jee], [88, Jee], [88, Jnn], [89, Jee], [89, Jnn], [90, Jee], [90, Jnn], [92, Jee], [93, Jee], [95, Jee], [97, Jnn], [98, Jnn], [100, Jnn], [103, Jnn], [104, Jee], [104, Jnn], [107, Jee], [107, Jnn], [108, Jnn], [109, Jnn], [114, Jee], [114, Jnn], [117, Jee], [120, Jee], [120, Jnn], [121, Jee], [121, Jnn], [124, Jee], [125, Jee], [125, Jnn], [127, Jee], [127, Jnn], [130, Jee], [130, Jnn], [134, Jee], [135, Jee], [136, Jnn], [140, Jee], [142, Jnn], [143, Jee], [143, Jnn], [144, Jee], [144, Jnn], [145, Jee], [145, Jnn], [146, Jee], [146, Jnn], [155, Jee], [161, Jee], [161, Jnn], [163, Jee], [163, Jnn], [164, Jee], [164, Jnn], [165, Jee], [165, Jnn], [166, Jee], [166, Jnn], [170, Jee], [171, Jnn], [179, Jee], [179, Jnn], [180, Jnn], [182, Jee], [182, Jnn], [184, Jee], [184, Jnn], [185, Jee], [185, Jnn], [186, Jee], [186, Jnn], [187, Jee], [187, Jnn], [188, Jnn], [198, Jnn], [199, Jee], [199, Jnn], [200, Jee], [200, Jnn], [201, Jnn], [202, Jnn], [204, Jee], [207, Jnn], [208, Jee], [209, Jnn], [212, Jnn], [213, Jee], [215, Jee], [215, Jnn], [216, Jee], [218, Jee], [218, Jnn], [221, Jee], [226, Jnn], [232, Jee], [235, Jnn], [240, Jee], [240, Jnn], [241, Jee], [241, Jnn], [242, Jee], [242, Jnn], [243, Jee], [243, Jnn], [245, Jnn], [246, Jee], [250, Jee], [251, Jee], [253, Jnn], [255, Jnn], [262, Jee], [262, Jnn], [268, Jnn], [320, Jee], [320, Jnn], [321, Jee], [321, Jnn], [323, Jee], [323, Jnn], [324, Jee], [324, Jnn], [325, Jee], [325, Jnn], [326, Jee], [326, Jnn], [327, Jee], [327, Jnn], [328, Jee], [328, Jnn], [329, Jee], [329, Jnn], [331, Jee], [331, Jnn], [332, Jee], [332, Jnn], [333, Jee], [333, Jnn], [336, Jee], [336, Jnn], [340, Jee], [340, Jnn]]
Metadata¶
for repo in ['hera_cal', 'hera_qm', 'hera_filters', 'hera_notebook_templates', 'pyuvdata']:
exec(f'from {repo} import __version__')
print(f'{repo}: {__version__}')
hera_cal: 3.6.2.dev110+g0529798 hera_qm: 2.2.0 hera_filters: 0.1.6.dev1+g297dcce
hera_notebook_templates: 0.1.dev936+gdc93cad pyuvdata: 3.0.1.dev70+g283dda3
print(f'Finished execution in {(time.time() - tstart) / 60:.2f} minutes.')
Finished execution in 44.23 minutes.