Nightly Per-Antenna Quality Summary Notebook¶

Josh Dillon, Last Revised February 2021

This notebooks brings together as much information as possible from ant_metrics, auto_metrics and redcal to help figure out which antennas are working properly and summarizes it in a single giant table. It is meant to be lightweight and re-run as often as necessary over the night, so it can be run when any of those is done and then be updated when another one completes.

Contents:¶

  • Table 1: Overall Array Health
  • Table 2: RTP Per-Antenna Metrics Summary Table
  • Figure 1: Array Plot of Flags and A Priori Statuses
In [1]:
import os
os.environ['HDF5_USE_FILE_LOCKING'] = 'FALSE'
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import pandas as pd
pd.set_option('display.max_rows', 1000)
from hera_qm.metrics_io import load_metric_file
from hera_cal import utils, io, redcal
import glob
import h5py
from copy import deepcopy
from IPython.display import display, HTML
from hera_notebook_templates.utils import status_colors
from hera_mc import mc
from pyuvdata import UVData

%matplotlib inline
%config InlineBackend.figure_format = 'retina'
display(HTML("<style>.container { width:100% !important; }</style>"))
In [2]:
# If you want to run this notebook locally, copy the output of the next cell into the first few lines of this cell.

# JD = "2459122"
# data_path = '/lustre/aoc/projects/hera/H4C/2459122'
# ant_metrics_ext = ".ant_metrics.hdf5"
# redcal_ext = ".maybe_good.omni.calfits"
# nb_outdir = '/lustre/aoc/projects/hera/H4C/h4c_software/H4C_Notebooks/_rtp_summary_'
# good_statuses = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
# os.environ["JULIANDATE"] = JD
# os.environ["DATA_PATH"] = data_path
# os.environ["ANT_METRICS_EXT"] = ant_metrics_ext
# os.environ["REDCAL_EXT"] = redcal_ext
# os.environ["NB_OUTDIR"] = nb_outdir
# os.environ["GOOD_STATUSES"] = good_statuses
In [3]:
# Use environment variables to figure out path to data
JD = os.environ['JULIANDATE']
data_path = os.environ['DATA_PATH']
ant_metrics_ext = os.environ['ANT_METRICS_EXT']
redcal_ext = os.environ['REDCAL_EXT']
nb_outdir = os.environ['NB_OUTDIR']
good_statuses = os.environ['GOOD_STATUSES']
print(f'JD = "{JD}"')
print(f'data_path = "{data_path}"')
print(f'ant_metrics_ext = "{ant_metrics_ext}"')
print(f'redcal_ext = "{redcal_ext}"')
print(f'nb_outdir = "{nb_outdir}"')
print(f'good_statuses = "{good_statuses}"')
JD = "2459798"
data_path = "/mnt/sn1/2459798"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H5C_Notebooks/_rtp_summary_"
good_statuses = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
In [4]:
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 8-6-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H5C_Notebooks/blob/main/antenna_report/antenna_{ant}_report.html'

Load Auto Metrics¶

In [6]:
use_auto_metrics = False

# find the auto_metrics file
glob_str = os.path.join(data_path, f'zen.{JD}*.auto_metrics.h5')
auto_metrics_file = sorted(glob.glob(glob_str))

# if it exists, load and extract relevant information
if len(auto_metrics_file) > 0:
    auto_metrics_file = auto_metrics_file[0]
    print(f'Found auto_metrics results file at {auto_metrics_file}.')
    
    auto_metrics = load_metric_file(auto_metrics_file)
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
    auto_ex_ants = auto_metrics['ex_ants']['r2_ex_ants']
    
    use_auto_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping auto_metrics.')
Found auto_metrics results file at /mnt/sn1/2459798/zen.2459798.25320.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

# get a list of all ant_metrics files
glob_str = os.path.join(data_path, f'zen.{JD}.?????.sum{ant_metrics_ext}')
ant_metrics_files = sorted(glob.glob(glob_str))

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 372 ant_metrics files matching glob /mnt/sn1/2459798/zen.2459798.?????.sum.ant_metrics.hdf5

Load chi^2 info from redcal¶

In [8]:
use_redcal = False
glob_str = os.path.join(data_path, f'zen.{JD}.?????.sum{redcal_ext}')

redcal_files = sorted(glob.glob(glob_str))
if len(redcal_files) > 0:
    print(f'Found {len(redcal_files)} ant_metrics files matching glob {glob_str}')
    post_redcal_ant_flags_dict = {}
    flagged_by_redcal_dict = {}
    cspa_med_dict = {}
    for cal in redcal_files:
        hc = io.HERACal(cal)
        _, flags, cspa, chisq = hc.read()
        cspa_med_dict[cal] = {ant: np.nanmedian(cspa[ant], axis=1) for ant in cspa}

        post_redcal_ant_flags_dict[cal] = {ant: np.all(flags[ant]) for ant in flags}
        # check history to distinguish antennas flagged going into redcal from ones flagged during redcal
        tossed_antenna_lines =  hc.history.replace('\n','').split('Throwing out antenna ')[1:]
        flagged_by_redcal_dict[cal] = sorted([int(line.split(' ')[0]) for line in tossed_antenna_lines])
        
    use_redcal = True
else:
    print(f'No files found matching glob {glob_str}. Skipping redcal chisq.')
Found 38 ant_metrics files matching glob /mnt/sn1/2459798/zen.2459798.?????.sum.known_good.omni.calfits

Figure out some general properties¶

In [9]:
# Parse some general array properties, taking into account the fact that we might be missing some of the metrics
ants = []
pols = []
antpol_pairs = []

if use_auto_metrics:
    ants = sorted(set(bl[0] for bl in auto_metrics['modzs']['r2_shape_modzs']))
    pols = sorted(set(bl[2] for bl in auto_metrics['modzs']['r2_shape_modzs']))
if use_ant_metrics:
    antpol_pairs = sorted(set([antpol for dms in ant_metrics_dead_metrics.values() for antpol in dms.keys()]))
    antpols = sorted(set(antpol[1] for antpol in antpol_pairs))
    ants = sorted(set(antpol[0] for antpol in antpol_pairs) | set(ants))
    pols = sorted(set(utils.join_pol(ap, ap) for ap in antpols) | set(pols))
if use_redcal:
    antpol_pairs = sorted(set([ant for cspa in cspa_med_dict.values() for ant in cspa.keys()]) | set(antpol_pairs))
    antpols = sorted(set(antpol[1] for antpol in antpol_pairs))
    ants = sorted(set(antpol[0] for antpol in antpol_pairs) | set(ants))
    pols = sorted(set(utils.join_pol(ap, ap) for ap in antpols) | set(pols))

# Figure out remaining antennas not in data and also LST range
data_files = sorted(glob.glob(os.path.join(data_path, 'zen.*.sum.uvh5')))
hd = io.HERAData(data_files[0])
unused_ants = [ant for ant in hd.antpos if ant not in ants]    
hd_last = io.HERAData(data_files[-1])

Load a priori antenna statuses and node numbers¶

In [10]:
# try to load a priori antenna statusesm but fail gracefully if this doesn't work.
a_priori_statuses = {ant: 'Not Found' for ant in ants}
nodes = {ant: np.nan for ant in ants + unused_ants}
try:
    from hera_mc import cm_hookup

    # get node numbers
    hookup = cm_hookup.get_hookup('default')
    for ant_name in hookup:
        ant = int("".join(filter(str.isdigit, ant_name)))
        if ant in nodes:
            if hookup[ant_name].get_part_from_type('node')['E<ground'] is not None:
                nodes[ant] = int(hookup[ant_name].get_part_from_type('node')['E<ground'][1:])
    
    # get apriori antenna status
    for ant_name, data in hookup.items():
        ant = int("".join(filter(str.isdigit, ant_name)))
        if ant in a_priori_statuses:
            a_priori_statuses[ant] = data.apriori

except Exception as err:
    print(f'Could not load node numbers and a priori antenna statuses.\nEncountered {type(err)} with message: {err}')

Summarize auto metrics¶

In [11]:
if use_auto_metrics:
    # Parse modzs
    modzs_to_check = {'Shape': 'r2_shape_modzs', 'Power': 'r2_power_modzs', 
                      'Temporal Variability': 'r2_temp_var_modzs', 'Temporal Discontinuties': 'r2_temp_diff_modzs'}
    worst_metrics = []
    worst_zs = []
    all_modzs = {}
    binary_flags = {rationale: [] for rationale in modzs_to_check}

    for ant in ants:
        # parse modzs and figure out flag counts
        modzs = {f'{pol} {rationale}': auto_metrics['modzs'][dict_name][(ant, ant, pol)] 
                 for rationale, dict_name in modzs_to_check.items() for pol in pols}
        for pol in pols:
            for rationale, dict_name in modzs_to_check.items():
                binary_flags[rationale].append(auto_metrics['modzs'][dict_name][(ant, ant, pol)] > mean_round_modz_cut)

        # parse out all metrics for dataframe
        for k in modzs:
            col_label = k + ' Modified Z-Score'
            if col_label in all_modzs:
                all_modzs[col_label].append(modzs[k])
            else:
                all_modzs[col_label] = [modzs[k]]
                
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
else:
    mean_round_modz_cut = 0

Summarize ant metrics¶

In [12]:
if use_ant_metrics:
    a_priori_flag_frac = {ant: np.mean([ant in apxa for apxa in ant_metrics_apriori_exants.values()]) for ant in ants}
    dead_ant_frac = {ap: {ant: np.mean([(ant, ap) in das for das in ant_metrics_dead_ants_dict.values()])
                                 for ant in ants} for ap in antpols}
    crossed_ant_frac = {ant: np.mean([np.any([(ant, ap) in cas for ap in antpols])
                                      for cas in ant_metrics_crossed_ants_dict.values()]) for ant in ants}
    ant_metrics_xants_frac_by_antpol = {antpol: np.mean([antpol in amx for amx in ant_metrics_xants_dict.values()]) for antpol in antpol_pairs}
    ant_metrics_xants_frac_by_ant = {ant: np.mean([np.any([(ant, ap) in amx for ap in antpols])
                                     for amx in ant_metrics_xants_dict.values()]) for ant in ants}
    average_dead_metrics = {ap: {ant: np.nanmean([dm.get((ant, ap), np.nan) for dm in ant_metrics_dead_metrics.values()]) 
                                 for ant in ants} for ap in antpols}
    average_crossed_metrics = {ant: np.nanmean([cm.get((ant, ap), np.nan) for ap in antpols 
                                                for cm in ant_metrics_crossed_metrics.values()]) for ant in ants}
else:
    dead_cut = 0.4
    crossed_cut = 0.0

Summarize redcal chi^2 metrics¶

In [13]:
if use_redcal:
    cspa = {ant: np.nanmedian(np.hstack([cspa_med_dict[cal][ant] for cal in redcal_files])) for ant in antpol_pairs}
    redcal_prior_flag_frac = {ant: np.mean([np.any([afd[ant, ap] and not ant in flagged_by_redcal_dict[cal] for ap in antpols])
                                            for cal, afd in post_redcal_ant_flags_dict.items()]) for ant in ants}
    redcal_flagged_frac = {ant: np.mean([ant in fbr for fbr in flagged_by_redcal_dict.values()]) for ant in ants}

Get FEM switch states¶

In [14]:
HHautos = sorted(glob.glob(f"{data_path}/zen.{JD}.*.sum.autos.uvh5"))
diffautos = sorted(glob.glob(f"{data_path}/zen.{JD}.*.diff.autos.uvh5"))

try:
    db = mc.connect_to_mc_db(None)
    session = db.sessionmaker()
    startJD = float(HHautos[0].split('zen.')[1].split('.sum')[0])
    stopJD = float(HHautos[-1].split('zen.')[1].split('.sum')[0])
    startTime = Time(startJD,format='jd')
    stopTime = Time(stopJD,format='jd')
    res = session.get_antenna_status(starttime=startTime, stoptime=stopTime)
    fem_switches = {}
    if len(res) == 0:
        femState = None
    else:
        for antpol in res:
            fem_switches[(antpol.antenna_number, antpol.antenna_feed_pol)] = antpol.fem_switch
    femState = (max(set(list(fem_switches.values())), key = list(fem_switches.values()).count)) 
except Exception as e:
    print(e)
    femState = None

Find X-engine Failures¶

In [15]:
read_inds = [1, len(HHautos)//2, -2]
x_status = [1,1,1,1,1,1,1,1]
s = UVData()
s.read(HHautos[1])

nants = len(s.get_ants())
freqs = s.freq_array[0]*1e-6
nfreqs = len(freqs)

antCon = {a: None for a in ants}
rightAnts = []
for i in read_inds:
    s = UVData()
    d = UVData()
    s.read(HHautos[i])
    d.read(diffautos[i])
    for pol in [0,1]:
        sm = np.abs(s.data_array[:,0,:,pol])
        df = np.abs(d.data_array[:,0,:,pol])
        sm = np.r_[sm, np.nan + np.zeros((-len(sm) % nants,len(freqs)))]
        sm = np.nanmean(sm.reshape(-1,nants,nfreqs),axis=1)
        df = np.r_[df, np.nan + np.zeros((-len(df) % nants,len(freqs)))]
        df = np.nanmean(df.reshape(-1,nants,nfreqs),axis=1)

        evens = (sm + df)/2
        odds = (sm - df)/2
        rat = np.divide(evens,odds)
        rat = np.nan_to_num(rat)
        for xbox in range(0,8):
            xavg = np.nanmean(rat[:,xbox*192:(xbox+1)*192],axis=1)
            if np.nanmax(xavg)>1.5 or np.nanmin(xavg)<0.5:
                x_status[xbox] = 0
    for ant in ants:
        for pol in ["xx", "yy"]:
            if antCon[ant] is False:
                continue
            spectrum = s.get_data(ant, ant, pol)
            stdev = np.std(spectrum)
            med = np.median(np.abs(spectrum))
            if (femState == "load" or femState == 'noise') and 80000 < stdev <= 4000000 and antCon[ant] is not False:
                antCon[ant] = True
            elif femState == "antenna" and stdev > 500000 and med > 950000 and antCon[ant] is not False:
                antCon[ant] = True
            else:
                antCon[ant] = False
            if np.min(np.abs(spectrum)) < 100000:
                antCon[ant] = False
for ant in ants:
    if antCon[ant] is True:
        rightAnts.append(ant)
            
x_status_str = ''
for i,x in enumerate(x_status):
    if x==0:
        x_status_str += '\u274C '
    else:
        x_status_str += '\u2705 '

Build Overall Health DataFrame¶

In [16]:
def comma_sep_paragraph(vals, chars_per_line=40):
    outstrs = []
    for val in vals:
        if (len(outstrs) == 0) or (len(outstrs[-1]) > chars_per_line):
            outstrs.append(str(val))
        else:
            outstrs[-1] += ', ' + str(val)
    return ',<br>'.join(outstrs)
In [17]:
# Time data
to_show = {'JD': [JD]}
to_show['Date'] = f'{utc.month}-{utc.day}-{utc.year}'
to_show['LST Range'] = f'{hd.lsts[0] * 12 / np.pi:.3f} -- {hd_last.lsts[-1] * 12 / np.pi:.3f} hours'

# X-engine status
to_show['X-Engine Status'] = x_status_str

# Files
to_show['Number of Files'] = len(data_files)

# Antenna Calculations
to_show['Total Number of Antennas'] = len(ants)

to_show[' '] = ''
to_show['OPERATIONAL STATUS SUMMARY'] = ''

status_count = {status: 0 for status in status_colors}
for ant, status in a_priori_statuses.items():
    if status in status_count:
        status_count[status] = status_count[status] + 1
    else:
        status_count[status] = 1
to_show['Antenna A Priori Status Count'] = '<br>'.join([f'{status}: {status_count[status]}' for status in status_colors if status in status_count and status_count[status] > 0])

to_show['Commanded Signal Source'] = femState
to_show['Antennas in Commanded State'] = f'{len(rightAnts)} / {len(ants)} ({len(rightAnts) / len(ants):.1%})'

if use_ant_metrics:
    to_show['Cross-Polarized Antennas'] = ', '.join([str(ant) for ant in ants if (np.max([dead_ant_frac[ap][ant] for ap in antpols]) + crossed_ant_frac[ant] == 1) 
                                                                                 and (crossed_ant_frac[ant] > .5)])

# Node calculations
nodes_used = set([nodes[ant] for ant in ants if np.isfinite(nodes[ant])])
to_show['Total Number of Nodes'] = len(nodes_used)
if use_ant_metrics:
    node_off = {node: True for node in nodes_used}
    not_correlating = {node: True for node in nodes_used}
    for ant in ants:
        for ap in antpols:
            if np.isfinite(nodes[ant]):
                if np.isfinite(average_dead_metrics[ap][ant]):
                    node_off[nodes[ant]] = False
                if dead_ant_frac[ap][ant] < 1:
                    not_correlating[nodes[ant]] = False
    to_show['Nodes Registering 0s'] = ', '.join([f'N{n:02}' for n in sorted([node for node in node_off if node_off[node]])])
    to_show['Nodes Not Correlating'] = ', '.join([f'N{n:02}' for n in sorted([node for node in not_correlating if not_correlating[node] and not node_off[node]])])

# Pipeline calculations    
to_show['  '] = ''
to_show['NIGHTLY ANALYSIS SUMMARY'] = ''
    
all_flagged_ants = []
if use_ant_metrics:
    to_show['Ant Metrics Done?'] = '\u2705'
    ant_metrics_flagged_ants = [ant for ant in ants if ant_metrics_xants_frac_by_ant[ant] > 0]
    all_flagged_ants.extend(ant_metrics_flagged_ants)
    to_show['Ant Metrics Flagged Antennas'] = f'{len(ant_metrics_flagged_ants)} / {len(ants)} ({len(ant_metrics_flagged_ants) / len(ants):.1%})' 
else:
    to_show['Ant Metrics Done?'] = '\u274C'
if use_auto_metrics:
    to_show['Auto Metrics Done?'] = '\u2705'
    auto_metrics_flagged_ants = [ant for ant in ants if ant in auto_ex_ants]
    all_flagged_ants.extend(auto_metrics_flagged_ants)    
    to_show['Auto Metrics Flagged Antennas'] = f'{len(auto_metrics_flagged_ants)} / {len(ants)} ({len(auto_metrics_flagged_ants) / len(ants):.1%})' 
else:
    to_show['Auto Metrics Done?'] = '\u274C'
if use_redcal:
    to_show['Redcal Done?'] = '\u2705'    
    redcal_flagged_ants = [ant for ant in ants if redcal_flagged_frac[ant] > 0]
    all_flagged_ants.extend(redcal_flagged_ants)    
    to_show['Redcal Flagged Antennas'] = f'{len(redcal_flagged_ants)} / {len(ants)} ({len(redcal_flagged_ants) / len(ants):.1%})' 
else:
    to_show['Redcal Done?'] = '\u274C' 
to_show['Never Flagged Antennas'] = f'{len(ants) - len(set(all_flagged_ants))} / {len(ants)} ({(len(ants) - len(set(all_flagged_ants))) / len(ants):.1%})'

# Count bad antennas with good statuses and vice versa
n_apriori_good = len([ant for ant in ants if a_priori_statuses[ant] in good_statuses.split(',')])
apriori_good_flagged = []
aprior_bad_unflagged = []
for ant in ants:
    if ant in set(all_flagged_ants) and a_priori_statuses[ant] in good_statuses.split(','):
        apriori_good_flagged.append(ant)
    elif ant not in set(all_flagged_ants) and a_priori_statuses[ant] not in good_statuses.split(','):
        aprior_bad_unflagged.append(ant)
to_show['A Priori Good Antennas Flagged'] = f'{len(apriori_good_flagged)} / {n_apriori_good} total a priori good antennas:<br>' + \
                                            comma_sep_paragraph(apriori_good_flagged)
to_show['A Priori Bad Antennas Not Flagged'] = f'{len(aprior_bad_unflagged)} / {len(ants) - n_apriori_good} total a priori bad antennas:<br>' + \
                                            comma_sep_paragraph(aprior_bad_unflagged)

# Apply Styling
df = pd.DataFrame(to_show)
divider_cols = [df.columns.get_loc(col) for col in ['NIGHTLY ANALYSIS SUMMARY', 'OPERATIONAL STATUS SUMMARY']]
try:
    to_red_columns = [df.columns.get_loc(col) for col in ['Cross-Polarized Antennas', 'Nodes Registering 0s', 
                                                          'Nodes Not Correlating', 'A Priori Good Antennas Flagged']]
except:
    to_red_columns = []
def red_specific_cells(x):
    df1 = pd.DataFrame('', index=x.index, columns=x.columns)
    for col in to_red_columns:
        df1.iloc[col] = 'color: red'
    return df1

df = df.T
table = df.style.hide_columns().apply(red_specific_cells, axis=None)
for col in divider_cols:
    table = table.set_table_styles([{"selector":f"tr:nth-child({col+1})", "props": [("background-color", "black"), ("color", "white")]}], overwrite=False)

Table 1: Overall Array Health¶

In [18]:
HTML(table.render())
Out[18]:
JD 2459798
Date 8-6-2022
LST Range 16.521 -- 18.521 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 372
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 31
RF_ok: 11
digital_maintenance: 3
digital_ok: 96
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 111 / 147 (75.5%)
Cross-Polarized Antennas 93
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N08, N09
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 65 / 147 (44.2%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 96 / 147 (65.3%)
Redcal Done? ✅
Redcal Flagged Antennas 17 / 147 (11.6%)
Never Flagged Antennas 28 / 147 (19.0%)
A Priori Good Antennas Flagged 71 / 96 total a priori good antennas:
3, 5, 7, 9, 16, 19, 20, 29, 30, 37, 40, 41,
42, 45, 50, 53, 54, 55, 56, 57, 69, 71, 72,
73, 83, 84, 85, 86, 88, 91, 93, 94, 98, 101,
103, 105, 106, 107, 108, 109, 111, 112, 117,
118, 121, 122, 123, 127, 128, 129, 130, 140,
141, 142, 143, 145, 156, 157, 160, 161, 165,
167, 169, 170, 177, 178, 181, 186, 187, 189,
190
A Priori Bad Antennas Not Flagged 3 / 51 total a priori bad antennas:
67, 82, 135
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/array_health_table_2459798.csv

Build DataFrame¶

In [20]:
# build dataframe
to_show = {'Ant': [f'<a href="{ant_to_report_url(ant)}" target="_blank">{ant}</a>' for ant in ants],
           'Node': [f'N{nodes[ant]:02}' for ant in ants], 
           'A Priori Status': [a_priori_statuses[ant] for ant in ants]}
           #'Worst Metric': worst_metrics, 'Worst Modified Z-Score': worst_zs}
df = pd.DataFrame(to_show)

# create bar chart columns for flagging percentages:
bar_cols = {}
if use_auto_metrics:
    bar_cols['Auto Metrics Flags'] = [float(ant in auto_ex_ants) for ant in ants]
if use_ant_metrics:
    if np.sum(list(a_priori_flag_frac.values())) > 0:  # only include this col if there are any a priori flags
        bar_cols['A Priori Flag Fraction in Ant Metrics'] = [a_priori_flag_frac[ant] for ant in ants]
    for ap in antpols:
        bar_cols[f'Dead Fraction in Ant Metrics ({ap})'] = [dead_ant_frac[ap][ant] for ant in ants]
    bar_cols['Crossed Fraction in Ant Metrics'] = [crossed_ant_frac[ant] for ant in ants]
if use_redcal:
    bar_cols['Flag Fraction Before Redcal'] = [redcal_prior_flag_frac[ant] for ant in ants]
    bar_cols['Flagged By Redcal chi^2 Fraction'] = [redcal_flagged_frac[ant] for ant in ants]  
for col in bar_cols:
    df[col] = bar_cols[col]

# add auto_metrics
if use_auto_metrics:
    for label, modz in all_modzs.items():
        df[label] = modz
z_score_cols = [col for col in df.columns if 'Modified Z-Score' in col]        
        
# add ant_metrics
ant_metrics_cols = {}
if use_ant_metrics:
    for ap in antpols:
        ant_metrics_cols[f'Average Dead Ant Metric ({ap})'] = [average_dead_metrics[ap][ant] for ant in ants]
    ant_metrics_cols['Average Crossed Ant Metric'] = [average_crossed_metrics[ant] for ant in ants]
    for col in ant_metrics_cols:
        df[col] = ant_metrics_cols[col]   

# add redcal chisq
redcal_cols = []
if use_redcal:
    for ap in antpols:
        col_title = f'Median chi^2 Per Antenna ({ap})'
        df[col_title] = [cspa[ant, ap] for ant in ants]
        redcal_cols.append(col_title)

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

# style dataframe
table = df.style.hide_index()\
          .applymap(lambda val: f'background-color: {status_colors[val]}' if val in status_colors else '', subset=['A Priori Status']) \
          .background_gradient(cmap='viridis', vmax=mean_round_modz_cut * 3, vmin=0, axis=None, subset=z_score_cols) \
          .background_gradient(cmap='bwr_r', vmin=dead_cut-.25, vmax=dead_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .background_gradient(cmap='bwr_r', vmin=crossed_cut-.25, vmax=crossed_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .background_gradient(cmap='plasma', vmax=4, vmin=1, axis=None, subset=redcal_cols) \
          .applymap(lambda val: 'font-weight: bold' if val < dead_cut else '', subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val < crossed_cut else '', subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .applymap(lambda val: 'color: red' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .bar(subset=list(bar_cols.keys()), vmin=0, vmax=1) \
          .format({col: '{:,.4f}'.format for col in z_score_cols}) \
          .format({col: '{:,.4f}'.format for col in ant_metrics_cols}) \
          .format({col: '{:,.2%}'.format for col in bar_cols}) \
          .applymap(lambda val: 'font-weight: bold', subset=['Ant']) \
          .set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])]) \

Table 2: RTP Per-Antenna Metrics Summary Table¶

This admittedly very busy table incorporates summary information about all antennas in the array. Its columns depend on what information is available when the notebook is run (i.e. whether auto_metrics, ant_metrics, and/or redcal is done). These can be divided into 5 sections:

Basic Antenna Info: antenna number, node, and its a priori status.

Flag Fractions: Fraction of the night that an antenna was flagged for various reasons. Note that auto_metrics flags antennas for the whole night, so it'll be 0% or 100%.

auto_metrics Details: If auto_metrics is included, this section shows the modified Z-score signifying how much of an outlier each antenna and polarization is in each of four categories: bandpass shape, overall power, temporal variability, and temporal discontinuities. Bold red text indicates that this is a reason for flagging the antenna. It is reproduced from the auto_metrics_inspect.ipynb nightly notebook, so check that out for more details on the precise metrics.

ant_metrics Details: If ant_metrics is included, this section shows the average correlation-based metrics for antennas over the whole night. Low "dead ant" metrics (nominally below 0.4) indicate antennas not correlating with the rest of the array. Negative "crossed ant" metrics indicate antennas that show stronger correlations in their cross-pols than their same-pols, indicating that the two polarizations are probably swapped. Bold text indicates that the average is below the threshold for flagging.

redcal chi^2 Details: If redcal is included, this shows the median chi^2 per antenna. This would be 1 in an ideal array. Antennas are thrown out when they they are outliers in their median chi^2, usually greater than 4-sigma outliers in modified Z-score.

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
4 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
5 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.962364 -0.834852 -0.190092 -0.210290 0.577298 0.155252 2.556685 17.202613 0.717779 0.691775 0.439578 3.765623 3.808035
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.634029 16.250257 17.396500 17.926943 14.237960 15.042319 3.738884 3.014729 0.692523 0.658903 0.434114 3.992687 4.232798
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 28.95% -0.036273 -0.715570 -0.170970 -0.037011 1.872001 1.738799 -0.146343 1.783171 0.696154 0.668970 0.430758 3.493797 3.239773
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.908559 -1.150417 -1.069725 0.248189 -0.963474 0.421547 3.301668 0.803455 0.674970 0.644240 0.439387 2.323765 2.284737
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.311856 1.171142 1.477517 0.963963 -0.024983 0.506098 0.198949 0.458100 0.723630 0.695259 0.455143 2.363691 2.000159
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.058703 -0.744682 -0.217442 -0.852425 -0.304283 -1.245535 4.320495 11.500240 0.731636 0.708679 0.453038 5.628737 6.885229
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.292918 1.414192 0.673374 0.776137 -0.167724 -0.195856 3.164888 3.418327 0.734649 0.713889 0.437576 2.464062 2.318248
18 N01 RF_maintenance 100.00% 0.00% 21.51% 0.00% 100.00% 0.00% 3.154476 2.023938 2.354062 -0.597531 2.015168 3.336619 15.210773 50.733282 0.718030 0.545537 0.494223 3.999272 2.420189
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.502203 -0.773533 -0.201979 0.564913 -0.706788 0.626370 3.506775 10.448001 0.722310 0.700949 0.429991 5.572115 4.850475
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -1.076291 0.201359 -0.298351 -0.690238 1.170271 1.450387 0.177257 -0.536605 0.707322 0.677501 0.424464 2.397347 2.454652
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.099290 1.501927 0.999503 0.792721 -0.908910 -0.358700 1.248194 -0.648939 0.689369 0.659619 0.434776 2.427035 2.339062
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.976100 23.923379 53.184248 53.865099 20.951702 21.489800 14.826683 13.196226 0.040837 0.045772 0.002411 1.215000 1.216253
28 N01 RF_maintenance 100.00% 21.51% 100.00% 0.00% 100.00% 0.00% 12.915680 13.820654 7.763380 9.528180 18.742239 22.203239 17.459504 55.000621 0.495570 0.271771 0.312794 12.925205 3.605252
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 7.89% -0.939154 -0.026202 0.069709 -0.400063 -0.845422 -0.790296 -0.890450 0.056241 0.749958 0.730942 0.437214 2.245558 2.290213
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.453272 0.021799 1.763831 -0.664413 1.637281 -0.455246 17.297328 0.857505 0.741458 0.725790 0.429276 4.183816 4.912055
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.557477 -0.104020 -1.008516 0.107085 -0.971713 -0.071438 1.962237 3.634938 0.739531 0.715289 0.433818 2.056590 2.062584
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 29.860404 33.963796 2.329945 7.727515 6.562776 7.003971 30.305351 51.200176 0.669701 0.643765 0.242877 10.827113 10.042868
33 N02 RF_maintenance 100.00% 0.00% 26.88% 0.00% 100.00% 0.00% -0.249718 3.151921 -0.576874 0.552224 4.025233 5.371354 69.450094 93.681562 0.704447 0.530114 0.519773 5.630339 3.061237
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.672303 5.919146 -0.137447 0.718215 1.479729 0.636156 -0.454068 0.694404 0.691266 0.664335 0.424158 5.454358 5.204332
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.890416 0.824937 0.608387 0.045974 -0.058671 0.204614 0.510739 16.526491 0.712810 0.688306 0.423708 4.522755 4.948266
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.067414 -0.034978 -0.844636 -0.938452 2.152369 0.393145 11.542474 1.416024 0.729725 0.709820 0.424806 3.507489 3.295309
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% 0.016571 -0.474343 -0.045697 -0.379394 2.449984 2.116312 -0.376953 -0.289924 0.749455 0.735469 0.427213 2.657882 2.464059
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 34.21% 0.416006 -0.207051 1.532719 1.670041 -0.036968 -0.370217 -1.172915 -0.246472 0.757193 0.743581 0.430226 2.697342 2.275315
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.306011 0.675690 1.473216 1.243020 -0.789341 -0.651528 -0.901980 -0.345462 0.761961 0.743657 0.443624 4.724013 4.601054
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.268807 0.729845 -0.660611 0.984093 -0.991033 -0.368522 -0.015153 13.497737 0.731916 0.704238 0.446347 4.364737 4.403046
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.739574 -0.347013 0.643383 -0.880272 -0.048583 -0.768613 -0.912896 1.320167 0.715704 0.687331 0.454868 2.019362 1.826982
50 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% 1.214251 2.625822 -0.803323 2.361328 0.669799 1.909470 0.459721 -1.327141 0.698537 0.669508 0.405020 3.055038 2.952591
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.268076 1.289209 -0.693341 -0.413164 0.296271 0.123315 -0.586643 0.667801 0.717639 0.697745 0.413089 2.463053 2.427595
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.319161 5.396352 -0.337942 -0.076353 -0.627758 -0.477329 0.134386 1.687411 0.735141 0.717152 0.414927 4.844319 4.590865
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.164325 1.348556 -0.789463 -0.097873 -0.982935 -0.117911 4.341438 10.578316 0.751724 0.736648 0.422547 4.473561 4.737169
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.783800 1.355356 2.056110 1.076270 0.673692 0.889597 1.886008 -0.266043 0.758194 0.747281 0.413060 4.995025 4.781324
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 1.597051 0.009160 -0.362631 0.360061 0.024983 1.256160 3.667170 -0.461391 0.763727 0.751296 0.436890 5.098892 4.351792
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.463636 0.748369 0.792802 1.347131 0.925193 1.067713 -0.971336 0.322639 0.765166 0.754229 0.436058 3.514166 3.082541
57 N04 digital_ok 100.00% 100.00% 26.88% 0.00% 100.00% 0.00% 21.353058 12.293114 53.013890 1.254014 20.814144 21.298850 11.725740 13.409401 0.049157 0.485326 0.323712 1.301660 3.636545
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.014911 0.093981 0.068071 0.791543 1.362305 1.177749 -0.318808 0.523101 0.705870 0.676593 0.419718 2.895173 2.789774
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.275179 -0.239424 -0.356516 0.714009 1.516117 0.679182 -0.135473 3.176822 0.723483 0.701880 0.408764 3.330938 2.645861
67 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.184584 -0.572447 0.095189 -0.809140 0.610777 0.893279 0.536319 1.472563 0.742600 0.724949 0.408713 5.862301 6.060475
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.137813 0.110790 -0.295456 -0.164549 1.277364 1.858090 -0.746753 -0.649974 0.751277 0.737966 0.415341 2.170697 2.202663
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.216900 -0.602911 -0.721658 0.085927 -1.079203 -0.184570 -0.567704 -0.341426 0.760785 0.751106 0.433598 3.837686 4.001045
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.724823 -1.773923 0.335472 -1.091944 -0.530308 -1.092915 0.946905 2.619182 0.767391 0.754993 0.454610 25.430590 21.753467
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.009600 -0.894806 -0.261636 -0.407952 -0.508662 -0.247950 0.286076 3.370952 0.768411 0.760149 0.445406 37.817829 29.866812
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.033918 0.110950 -0.504566 1.548948 0.543008 1.185908 4.577594 -1.131797 0.762908 0.752423 0.458888 3.942278 3.904936
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 42.11% 2.738266 2.526202 -0.360255 -0.620304 -0.468139 0.152642 2.712952 -0.067432 0.753317 0.733566 0.478063 2.450880 2.110702
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.475000 2.871759 -0.277842 2.913015 -0.169537 1.772087 0.410663 -1.446993 0.698169 0.669125 0.403769 2.459368 2.445768
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.841219 -0.812944 -0.699454 1.641213 0.249815 0.096552 -0.234925 -0.659973 0.718888 0.697382 0.407394 7.532736 5.579768
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.897146 3.337693 1.704420 4.357857 0.443159 1.776290 -1.055099 -1.677387 0.740036 0.723935 0.403863 4.076449 4.155582
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.491548 7.680990 -0.093748 1.476859 -0.632911 -0.503717 -0.671579 0.338359 0.074534 0.073910 0.012973 1.188869 1.186646
85 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
86 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.056351 8.611685 5.407465 0.072868 22.214774 0.494602 102.784084 -0.891823 0.042223 0.056313 0.005942 1.185686 1.185377
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.713259 20.852432 46.818179 47.909286 21.313589 21.786206 19.066600 14.007909 0.032545 0.031245 0.001782 1.180300 1.175517
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.171821 21.466832 46.619035 47.495836 20.847650 21.416795 10.862003 10.088576 0.031919 0.029849 0.000641 1.211616 1.214308
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.670762 21.416821 46.712818 48.579075 20.956175 21.641258 14.861227 14.404672 0.030423 0.030472 -0.000021 1.250775 1.247389
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.805304 43.411968 9.987511 12.813467 22.971632 23.888627 12.692491 22.030306 0.263503 0.210164 0.097044 3.338594 2.759310
93 N10 digital_ok 0.00% 24.19% 24.19% 75.81% 100.00% 0.00% 0.645676 0.138338 2.649140 -0.909863 0.428176 0.334864 -1.099250 1.005121 0.194648 0.196012 -0.291975 3.221467 2.972986
94 N10 digital_ok 100.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.290651 -0.290356 -0.511672 -1.012496 -0.046930 1.057070 6.277233 7.123184 0.538457 0.506324 0.360223 3.794196 3.397152
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.061754 19.079836 0.124615 1.384184 -0.255225 3.063481 -0.156997 12.703577 0.700489 0.653359 0.397810 6.572956 7.660270
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.986515 0.931986 2.513402 0.367669 0.969301 -0.551294 0.216365 -0.697847 0.717400 0.695781 0.405287 2.124814 1.930522
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.673292 0.000492 -0.503163 0.217878 -0.918161 -0.834509 0.615461 -0.056241 0.736826 0.717069 0.420362 2.055538 1.918447
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.560040 7.369716 3.326781 -0.104712 1.374101 -0.590543 2.237325 -0.379767 0.082132 0.073424 0.016921 1.205699 1.204804
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.475209 15.030065 80.854394 77.536473 1779.670127 1612.378871 20198.939465 17104.620860 nan nan nan 0.000000 0.000000
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.986623 7.571269 -0.519709 0.099623 0.151155 -0.139256 0.371933 0.075082 0.059141 0.054497 0.003047 1.186996 1.190957
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.409855 69.210867 0.291826 14.101204 -0.493562 2.851295 0.109996 0.941607 0.056482 0.066395 0.005574 1.194462 1.192651
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.116184 26.571798 44.364791 46.223084 20.958405 21.611711 12.668648 13.056726 0.033719 0.031644 0.001158 1.168192 1.163758
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.924904 20.370784 47.311582 48.205835 20.862267 21.277848 12.899618 14.370389 0.029035 0.028882 0.001303 1.194090 1.191957
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.123741 20.588514 46.160570 48.142195 20.839896 21.402648 10.362966 10.545566 0.030581 0.031304 0.001378 1.221501 1.219278
109 N10 digital_ok 0.00% 18.82% 18.82% 0.00% 18.42% 0.00% -0.718051 0.195336 -0.059117 0.842453 -0.780907 0.100554 1.142255 2.353017 0.572821 0.546557 0.385355 1.996075 1.898015
110 N10 RF_maintenance 100.00% 26.88% 18.82% 0.00% 100.00% 0.00% 37.403770 1.500210 3.442702 1.677488 5.305085 -0.707734 0.954240 -1.612193 0.529985 0.537410 0.322874 13.660757 5.135909
111 N10 digital_ok 100.00% 24.19% 24.19% 0.00% 100.00% 0.00% 0.487813 0.931129 -0.258581 1.119582 1.166164 2.276876 -0.154145 7.063487 0.549876 0.516701 0.358698 4.434750 4.601410
112 N10 digital_ok 0.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.591058 -0.616395 -0.278125 0.251237 0.816666 -1.043690 1.146537 -0.725151 0.535979 0.503786 0.353287 4.012037 3.704359
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.821642 2.013811 -0.793480 -0.423465 -0.639289 0.055203 -0.681181 -0.839368 0.695684 0.668684 0.410349 2.344663 2.298630
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.901580 3.331446 4.767734 4.895306 1.931876 1.404588 -1.618247 -1.976311 0.722283 0.696684 0.424964 6.037405 5.935787
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.430944 1.180757 2.340690 0.579247 0.715884 1.252802 1.567186 4.905076 0.729233 0.709996 0.426508 5.574064 4.377522
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.367616 3.069363 7.378107 0.293336 4.802568 -0.509002 -1.130866 1.411136 0.744912 0.725151 0.447880 5.031774 4.403024
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.823771 28.703710 9.841443 59.456209 19.460135 22.057168 9.867368 19.630533 0.086817 0.040796 0.054666 1.237136 1.196425
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.522498 4.272446 -0.704282 0.556419 -0.552908 -0.024258 41.953592 22.165049 0.058452 0.051122 0.003150 1.200309 1.201859
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.165614 5.964665 1.436301 1.014567 1.626631 -0.199735 -0.622262 -0.810845 0.067378 0.061838 0.004870 1.229068 1.234174
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.052378 7.177227 0.899279 -0.074401 0.200632 0.770396 -0.965919 -0.778285 0.076829 0.067235 0.010036 1.237272 1.233549
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
127 N10 digital_ok 0.00% 16.13% 18.82% 0.00% 100.00% 0.00% -0.144932 -0.411167 0.606371 -0.150131 1.328456 0.625447 0.063601 0.087956 0.581762 0.555060 0.385232 6.285036 5.684808
128 N10 digital_ok 0.00% 18.82% 18.82% 0.00% 18.42% 0.00% -0.988588 1.137749 -0.293439 1.120483 -0.635796 -0.547410 -0.436436 -1.197672 0.575218 0.544883 0.369658 1.583441 1.482887
129 N10 digital_ok 0.00% 18.82% 18.82% 0.00% 18.42% 0.00% -0.223237 -1.559515 -0.567030 -1.131276 -0.178957 -0.474046 -0.686394 -0.450192 0.563713 0.535550 0.361390 1.684349 1.578891
130 N10 digital_ok 100.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.049749 0.367892 1.061301 1.153189 0.126492 0.405021 0.384757 5.815026 0.543352 0.513126 0.350920 4.236504 3.848071
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.817453 -0.763203 -1.010916 -0.925347 -0.930158 -0.706555 1.290589 0.090055 0.629448 0.600734 0.401824 4.913422 4.410142
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.917840 10.428409 -0.400142 0.421821 4.202192 3.538475 1.218940 3.370369 0.637834 0.608117 0.383362 5.705209 5.510434
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.055601 21.010576 46.127306 47.175117 20.999910 21.493014 13.141490 15.472335 0.037382 0.044759 0.003501 1.231945 1.248874
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 26.160390 2.255057 45.856911 1.795658 21.081154 0.174025 13.646779 0.250502 0.046406 0.713719 0.535582 1.256765 4.593192
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.994383 21.385434 52.120739 54.099343 20.870704 21.505731 10.633635 11.196163 0.039897 0.040701 0.001010 1.205457 1.207248
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.669159 5.401037 -0.634414 10.619496 2.150643 4.168932 1.339414 14.912665 0.729784 0.705889 0.460604 4.898907 4.518029
142 N13 digital_ok 100.00% 29.57% 100.00% 0.00% 100.00% 0.00% 20.852261 25.322523 9.664071 54.358790 17.864971 21.645904 10.748614 12.932282 0.451423 0.042680 0.294889 9.159832 1.295347
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 26.32% 0.175962 -0.817318 1.701691 0.450846 1.872934 0.476201 0.418523 -1.457504 0.741377 0.720673 0.462487 2.961599 2.362576
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 23.68% 0.00% 0.836111 1.288300 -0.595768 -0.247485 0.770512 -0.725219 2.100778 1.249164 0.743159 0.721254 0.465019 2.253482 2.127189
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.270636 22.047093 53.535447 54.738709 20.949757 21.460269 13.447465 15.865704 0.035011 0.038397 0.000136 1.591236 1.710345
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.139610 24.034219 53.311681 55.656354 20.982495 21.537325 14.562296 15.534824 0.056900 0.059231 0.001745 1.313758 1.319944
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.657127 21.274462 52.273534 53.726048 20.879841 21.363345 14.423662 15.132524 0.042079 0.039544 0.001322 1.284950 1.277280
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.956921 0.697706 0.964700 0.049129 0.467418 0.214718 3.018996 11.550891 0.637283 0.609172 0.404418 5.678834 5.346601
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.139729 2.156363 0.262252 2.681472 0.711530 0.818788 0.841522 1.984138 0.643007 0.620495 0.408868 3.121320 2.904722
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.800558 -1.420109 -0.910181 -0.742653 -0.803475 0.126244 -0.744914 1.292389 0.654447 0.630886 0.418463 2.648615 2.754191
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.472256 19.171508 52.968201 54.229605 20.908036 21.516853 13.307195 15.575435 0.044761 0.043437 0.001874 1.181744 1.182824
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.640197 39.126353 -0.596729 3.646082 -0.407663 5.521955 -0.339438 0.837639 0.727216 0.634483 0.417242 4.825127 9.569554
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.216416 0.925027 -0.575757 -0.883769 1.684472 1.058506 -0.464100 -0.451614 0.730739 0.711173 0.443846 2.467646 2.316667
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.456572 -0.209247 0.298613 -0.609608 -0.042440 -0.875053 1.873028 0.431370 0.740457 0.721185 0.447357 2.638088 2.586778
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.067959 -1.122661 -1.097764 -0.551583 -0.520571 0.173939 1.870967 2.731521 0.741823 0.720584 0.447645 2.325720 2.495685
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.856356 0.791041 6.080160 -0.926871 3.109257 -1.210704 -0.979046 -0.736798 0.741168 0.719745 0.443504 4.362939 5.120873
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.104910 1.503794 -0.145228 1.123994 11.223241 1.520592 13.355268 3.939336 0.722624 0.714681 0.405009 9.577594 8.331720
167 N15 digital_ok 100.00% 0.00% 5.38% 0.00% 100.00% 0.00% 17.435378 21.071867 16.769633 17.228779 20.086154 16.900798 96.375653 31.096634 0.670835 0.625655 0.303941 9.403723 7.546454
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.457721 19.039278 17.593193 19.817991 14.151682 16.940022 2.524976 3.886202 0.689313 0.651806 0.433319 7.152009 5.688406
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.464044 17.537017 19.401202 18.688755 16.237896 15.919640 3.420884 3.008229 0.664173 0.629143 0.427550 5.517330 4.233542
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.588376 16.240598 19.531016 18.007262 16.236474 14.737014 3.962038 3.315293 0.644122 0.614511 0.425718 4.188973 3.740824
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.012383 -0.226125 -1.009376 0.319618 0.867792 0.134794 -0.559262 -0.351033 0.612723 0.586346 0.404448 2.408478 2.579208
177 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 1.330485 1.415690 0.799226 0.339880 -0.398767 -0.416158 -0.583725 2.930752 0.621422 0.591847 0.406782 2.929244 3.113868
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.998273 -1.189684 1.051769 -0.771210 -0.520753 -0.862381 -0.405088 -0.433175 0.633469 0.606972 0.410381 2.573353 2.656294
179 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.743637 0.036147 -1.043771 0.037011 0.747618 -0.167020 3.579365 -0.941896 0.642393 0.614888 0.419794 1.968911 2.074975
180 N13 RF_maintenance 100.00% 0.00% 35.48% 0.00% 100.00% 0.00% 0.429822 13.320661 -0.053819 48.635817 -0.868902 13.225017 -0.895915 9.513069 0.718852 0.499223 0.523259 209.473793 53.307868
181 N13 digital_ok 100.00% 100.00% 89.25% 0.00% 100.00% 0.00% 22.347247 46.848140 53.686735 6.050213 20.954387 22.688220 13.319240 16.860385 0.047516 0.317280 0.193283 1.187366 4.075348
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.868523 1.142873 17.617212 -0.436244 14.183830 0.354105 2.071407 89.317275 0.707056 0.704822 0.458625 4.794938 4.695601
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.400970 -0.853040 0.205784 -1.073811 -0.460883 -1.018322 -0.553536 2.397795 0.734988 0.713168 0.453968 2.346208 2.278311
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.314809 -0.000492 0.273994 0.675607 1.064605 0.406943 0.443294 -0.510516 0.738277 0.716726 0.441434 2.235187 2.124190
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.011791 0.455485 1.723457 1.259202 -0.397363 -0.266104 -0.448948 -0.642584 0.735444 0.713542 0.439553 2.139410 1.958290
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.587677 0.861479 4.397236 2.292607 0.770837 0.180542 3.820604 -0.129955 0.722411 0.701720 0.429468 3.762515 3.805707
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.05% 1.070219 0.318934 0.322747 0.411084 -0.367616 -1.118471 3.314891 -0.715592 0.722767 0.702423 0.431230 2.673176 2.250843
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.783500 4.306743 0.499393 0.493444 -0.700206 -0.290323 0.325754 13.248244 0.685172 0.657212 0.430711 5.596072 4.730544
190 N15 digital_ok 100.00% 5.38% 100.00% 0.00% 100.00% 0.00% 30.853087 24.192282 3.300218 54.762383 16.146521 21.581853 50.176213 14.867043 0.616739 0.046639 0.446916 5.107039 1.526337
191 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 18.42% 0.00% -0.248592 1.591028 -0.768296 1.255530 -0.730761 0.092915 -0.179809 1.168008 0.651372 0.610419 0.439663 1.191053 1.071838
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.793169 13.394783 12.695113 14.844798 10.717032 12.896050 27.181267 30.220921 0.690059 0.665921 0.423811 4.025382 3.707107
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.958242 8.320616 -0.666467 8.998091 4.836233 7.451181 30.471492 28.915784 0.672020 0.655768 0.408429 3.831754 3.842468
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.902816 11.186781 14.680800 12.311447 11.747782 9.389074 9.132382 4.036286 0.666020 0.650228 0.414410 6.326331 6.234163
220 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
221 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
222 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.858014 10.141330 82.823094 80.608678 1956.730930 1962.460110 13963.766807 14116.914082 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.308102 2.800169 7.527501 -0.639556 5.813731 1.477334 -0.853712 16.805941 0.675707 0.641552 0.432705 4.144877 3.429542
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.116891 20.710068 21.806500 21.620730 18.557071 18.702378 4.972281 4.617152 0.624804 0.602086 0.407322 3.893654 3.679495
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.572457 4.294236 102.077062 109.562985 2704.644926 2704.736942 22905.960644 22908.507112 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.476268 24.523945 39.580971 39.808014 21.196111 21.472983 18.867103 14.520267 0.062474 0.060951 -0.002802 0.000000 0.000000
321 N02 not_connected 100.00% 2.69% 62.37% 0.00% 100.00% 0.00% 10.212409 8.345565 11.721676 10.828834 10.028772 9.298859 31.485414 31.222802 0.517081 0.416109 0.334456 0.000000 0.000000
323 N02 not_connected 100.00% 10.75% 65.05% 0.00% 100.00% 0.00% 19.051280 11.563220 2.686866 13.862473 8.102564 10.271375 10.744543 2.279096 0.444098 0.380843 0.275629 0.000000 0.000000
324 N04 not_connected 100.00% 2.69% 62.37% 0.00% 100.00% 0.00% 14.497356 15.038891 15.988892 16.336120 13.130337 13.709476 1.440860 1.442527 0.500764 0.400445 0.337634 0.000000 0.000000
329 N12 dish_maintenance 100.00% 48.39% 73.12% 0.00% 100.00% 0.00% 2.509844 6.968718 2.262862 10.197680 1.593242 7.773312 7.095316 -0.744243 0.422490 0.347865 0.272103 0.000000 0.000000
333 N12 dish_maintenance 100.00% 56.45% 94.62% 0.00% 100.00% 0.00% 1.161098 7.123348 1.814933 9.444448 0.922129 6.060246 4.352902 -0.664845 0.395817 0.311630 0.245440 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 16, 18, 19, 20, 27, 28, 29, 30, 32, 33, 36, 37, 38, 40, 41, 42, 45, 50, 52, 53, 54, 55, 56, 57, 67, 69, 70, 71, 72, 73, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 160, 161, 165, 166, 167, 168, 169, 170, 177, 178, 180, 181, 182, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [10, 15, 17, 21, 31, 46, 51, 65, 66, 68, 81, 99, 100, 116, 158, 162, 163, 164, 176, 179, 183, 184, 185]

golden_ants: [10, 15, 17, 21, 31, 46, 51, 65, 66, 68, 81, 99, 100, 116, 158, 162, 163, 164, 176, 179, 183, 184, 185]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/rtp_summary_table_2459798.csv
In [24]:
# Load antenna positions
data_list = sorted(glob.glob(os.path.join(data_path, f'zen.{JD}.?????.sum.uvh5')))
hd = io.HERAData(data_list[len(data_list) // 2])

# Figure out where to draw the nodes
node_centers = {}
for node in sorted(set(list(nodes.values()))):
    if np.isfinite(node):
        this_node_ants = [ant for ant in ants + unused_ants if nodes[ant] == node]
        if len(this_node_ants) == 1:
            # put the node label just to the west of the lone antenna 
            node_centers[node] = hd.antpos[ant][node] + np.array([-14.6 / 2, 0, 0])
        else:
            # put the node label between the two antennas closest to the node center
            node_centers[node] = np.mean([hd.antpos[ant] for ant in this_node_ants], axis=0)
            closest_two_pos = sorted([hd.antpos[ant] for ant in this_node_ants], 
                                     key=lambda pos: np.linalg.norm(pos - node_centers[node]))[0:2]
            node_centers[node] = np.mean(closest_two_pos, axis=0)
In [25]:
def Plot_Array(ants, unused_ants, outriggers):
    plt.figure(figsize=(16,16))
    
    plt.scatter(np.array([hd.antpos[ant][0] for ant in hd.data_ants if ant in ants]), 
                np.array([hd.antpos[ant][1] for ant in hd.data_ants if ant in ants]), c='w', s=0)

    # connect every antenna to their node
    for ant in ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', zorder=0)

    rc_color = '#0000ff'
    antm_color = '#ffa500'
    autom_color = '#ff1493'

    # Plot 
    unflagged_ants = []
    for i, ant in enumerate(ants):
        ant_has_flag = False
        # plot large blue annuli for redcal flags
        if use_redcal:
            if redcal_flagged_frac[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=7 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=rc_color, alpha=redcal_flagged_frac[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot medium green annuli for ant_metrics flags
        if use_ant_metrics: 
            if ant_metrics_xants_frac_by_ant[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=antm_color, alpha=ant_metrics_xants_frac_by_ant[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot small red annuli for auto_metrics
        if use_auto_metrics:
            if ant in auto_ex_ants:
                ant_has_flag = True                
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, lw=0, color=autom_color)) 
        
        # plot black/white circles with black outlines for antennas
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4 * (2 - 1 * float(not outriggers)), fill=True, color=['w', 'k'][ant_has_flag], ec='k'))
        if not ant_has_flag:
            unflagged_ants.append(ant)

        # label antennas, using apriori statuses if available
        try:
            bgc = matplotlib.colors.to_rgb(status_colors[a_priori_statuses[ant]])
            c = 'black' if (bgc[0]*0.299 + bgc[1]*0.587 + bgc[2]*0.114) > 186 / 256 else 'white'
        except:
            c = 'k'
            bgc='white'
        plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color=c, backgroundcolor=bgc)

    # label nodes
    for node in sorted(set(list(nodes.values()))):
        if not np.isnan(node) and not np.all(np.isnan(node_centers[node])):
            plt.text(node_centers[node][0], node_centers[node][1], str(node), va='center', ha='center', bbox={'color': 'w', 'ec': 'k'})
    
    # build legend 
    legend_objs = []
    legend_labels = []
    
    # use circles for annuli 
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgecolor='k', markerfacecolor='w', markersize=13))
    legend_labels.append(f'{len(unflagged_ants)} / {len(ants)} Total {["Core", "Outrigger"][outriggers]} Antennas Never Flagged')
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='k', markersize=15))
    legend_labels.append(f'{len(ants) - len(unflagged_ants)} Antennas {["Core", "Outrigger"][outriggers]} Flagged for Any Reason')

    if use_auto_metrics:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=autom_color, markersize=15))
        legend_labels.append(f'{len([ant for ant in auto_ex_ants if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas Flagged by Auto Metrics')
    if use_ant_metrics: 
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=antm_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum([frac for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants]), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Ant Metrics\n(alpha indicates fraction of time)')        
    if use_redcal:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=rc_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum(list(redcal_flagged_frac.values())), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in redcal_flagged_frac.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Redcal\n(alpha indicates fraction of time)')

    # use rectangular patches for a priori statuses that appear in the array
    for aps in sorted(list(set(list(a_priori_statuses.values())))):
        if aps != 'Not Found':
            legend_objs.append(plt.Circle((0, 0), radius=7, fill=True, color=status_colors[aps]))
            legend_labels.append(f'A Priori Status:\n{aps} ({[status for ant, status in a_priori_statuses.items() if ant in ants].count(aps)} {["Core", "Outrigger"][outriggers]} Antennas)')

    # label nodes as a white box with black outline
    if len(node_centers) > 0:
        legend_objs.append(matplotlib.patches.Patch(facecolor='w', edgecolor='k'))
        legend_labels.append('Node Number')

    if len(unused_ants) > 0:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='grey', markersize=15, alpha=.2))
        legend_labels.append(f'Anntenna Not In Data')
        
    
    plt.legend(legend_objs, legend_labels, ncol=2, fontsize='large', framealpha=1)
    
    if outriggers:
        pass
    else:
        plt.xlim([-200, 150])
        plt.ylim([-150, 150])        
       
    # set axis equal and label everything
    plt.axis('equal')
    plt.tight_layout()
    plt.title(f'Summary of {["Core", "Outrigger"][outriggers]} Antenna Statuses and Metrics on {JD}', size=20)    
    plt.xlabel("Antenna East-West Position (meters)", size=12)
    plt.ylabel("Antenna North-South Position (meters)", size=12)
    plt.xticks(fontsize=12)
    plt.yticks(fontsize=12)
    xlim = plt.gca().get_xlim()
    ylim = plt.gca().get_ylim()    
        
    # plot unused antennas
    plt.autoscale(False)    
    for ant in unused_ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', alpha=.2, zorder=0)
        
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='w', ec=None, alpha=1, zorder=0))
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='grey', ec=None, alpha=.2, zorder=0))
        if hd.antpos[ant][0] < xlim[1] and hd.antpos[ant][0] > xlim[0]:
            if hd.antpos[ant][1] < ylim[1] and hd.antpos[ant][1] > ylim[0]:
                plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color='k', alpha=.2) 

Figure 1: Array Plot of Flags and A Priori Statuses¶

This plot shows all antennas, which nodes they are connected to, and their a priori statuses (as the highlight text of their antenna numbers). It may also show (depending on what is finished running):

  • Whether they were flagged by auto_metrics (red circle) for bandpass shape, overall power, temporal variability, or temporal discontinuities. This is done in a binary fashion for the whole night.
  • Whether they were flagged by ant_metrics (green circle) as either dead (on either polarization) or crossed, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.
  • Whether they were flagged by redcal (blue circle) for high chi^2, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.

Note that the last fraction does not include antennas that were flagged before going into redcal due to their a priori status, for example.

In [26]:
core_ants = [ant for ant in ants if ant < 320]
outrigger_ants = [ant for ant in ants if ant >= 320]
Plot_Array(ants=core_ants, unused_ants=unused_ants, outriggers=False)
if len(outrigger_ants) > 0:
    Plot_Array(ants=outrigger_ants, unused_ants=sorted(set(unused_ants + core_ants)), outriggers=True)

Metadata¶

In [27]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.2
3.1.1.dev2+g1b5039f
In [ ]: