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 = "2459797"
data_path = "/mnt/sn1/2459797"
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-5-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/2459797/zen.2459797.25304.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/2459797/zen.2459797.?????.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 2 ant_metrics files matching glob /mnt/sn1/2459797/zen.2459797.?????.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 2459797
Date 8-5-2022
LST Range 16.451 -- 18.451 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: 33
RF_ok: 11
digital_maintenance: 3
digital_ok: 94
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 66 / 147 (44.9%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 93 / 147 (63.3%)
Redcal Done? ✅
Redcal Flagged Antennas 7 / 147 (4.8%)
Never Flagged Antennas 39 / 147 (26.5%)
A Priori Good Antennas Flagged 58 / 94 total a priori good antennas:
5, 7, 16, 19, 30, 31, 37, 41, 42, 45, 50, 51,
53, 54, 55, 56, 57, 69, 71, 72, 83, 84, 85,
86, 88, 91, 92, 93, 101, 103, 105, 106, 107,
108, 109, 111, 117, 121, 122, 123, 128, 129,
130, 140, 141, 142, 145, 156, 160, 161, 165,
167, 169, 170, 177, 181, 190, 191
A Priori Bad Antennas Not Flagged 3 / 53 total a priori bad antennas:
4, 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_2459797.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 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.365532 -0.536552 -0.531658 -1.014937 -0.975912 -0.848606 -0.588102 -0.125496 0.694137 0.676144 0.439475 3.493481 3.159729
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.289779 3.859215 -0.903627 1.392517 -0.924372 0.114509 0.904674 0.099573 0.708774 0.684505 0.439642 3.938172 3.973150
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.390556 1.077907 -0.535842 4.223932 -1.217270 1.433935 -0.485655 -1.936830 0.722249 0.697745 0.439717 5.263740 5.529027
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.966958 -1.121684 0.062532 -0.166610 0.046445 1.281661 -0.188365 15.302828 0.721876 0.699539 0.431337 4.140483 4.546299
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.119897 13.866241 16.742935 17.353606 18.547004 19.352103 6.113791 4.689642 0.695851 0.666411 0.427529 5.055153 5.271546
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.123386 -0.871088 -0.155275 0.133759 1.851387 2.143498 -0.138388 -0.513766 0.699573 0.676884 0.425198 2.388745 2.276206
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.312424 -1.166555 -0.874878 0.438125 -0.985606 0.200107 2.322578 0.616111 0.677626 0.651064 0.432426 2.108677 2.272358
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.047635 0.986323 1.249858 0.315161 0.033425 0.303713 2.743446 0.484458 0.728343 0.703662 0.435358 1.792452 1.810335
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.391853 -0.905681 -0.772915 -0.247437 -1.004159 -0.889148 2.609872 6.275968 0.736538 0.716196 0.433524 6.295503 10.413262
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.232162 1.072630 0.159495 0.261048 0.021088 -0.147933 1.967080 2.403969 0.737816 0.719907 0.418438 1.643206 1.768897
18 N01 RF_maintenance 100.00% 0.00% 26.88% 0.00% 100.00% 0.00% 2.872036 3.245424 1.149607 0.148314 6.822049 6.883398 252.319593 119.127533 0.710314 0.546250 0.473924 3.810124 2.501034
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.180134 -0.532985 -0.157210 0.026166 -0.210377 0.293617 2.089898 27.905769 0.725382 0.707189 0.420002 4.705424 4.726321
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.989896 0.048198 -0.580337 -0.608235 1.962677 1.650030 -0.221014 -0.801532 0.709823 0.684032 0.417470 2.051598 2.125765
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.110172 -0.275385 0.517590 1.214772 -0.725778 0.621457 1.215373 -1.136775 0.691210 0.665953 0.428833 2.210961 2.316419
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.327565 18.951339 52.013704 52.742226 26.948010 27.364588 19.475998 17.562955 0.042393 0.049095 0.004269 1.234324 1.243711
28 N01 RF_maintenance 100.00% 18.82% 100.00% 0.00% 100.00% 0.00% 10.768333 12.359295 7.041744 9.833952 24.358797 30.706049 18.782746 141.678584 0.509498 0.280689 0.304947 19.138443 4.465113
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.999277 -0.262039 0.344488 -0.589918 -0.703203 -0.716305 -1.129812 0.004013 0.753026 0.736845 0.423609 1.736540 1.767539
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.136787 0.009338 1.533025 -0.702076 1.511308 0.483985 30.144273 1.265172 0.742919 0.730084 0.413486 4.076582 4.686689
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.806624 -0.139991 -1.036567 0.696689 -0.283510 -0.688433 4.512905 5.395812 0.740165 0.718905 0.421364 5.160612 4.801978
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 25.805787 29.727377 2.344962 7.158097 8.142690 8.677666 36.792452 64.624606 0.669482 0.649326 0.233992 9.854810 7.640530
33 N02 RF_maintenance 100.00% 0.00% 26.88% 0.00% 100.00% 0.00% -0.008847 3.243954 -0.191725 0.464917 5.513512 7.107889 95.030282 128.177449 0.702377 0.533431 0.510215 8.515225 3.113682
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.640090 4.822328 -0.054015 0.199542 2.468508 1.329427 0.107861 1.361396 0.691653 0.667448 0.423413 3.819084 3.482033
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.777301 0.536926 -0.138285 -0.434111 -0.245102 -0.462444 0.258526 18.343206 0.713403 0.691931 0.424634 4.744227 5.069645
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.928262 0.055558 -0.815376 -0.644301 2.368369 -0.181180 12.411873 3.302190 0.729994 0.713174 0.424282 4.359332 4.036866
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.157152 -0.729722 -0.149957 -0.621929 2.379193 1.833874 -0.002047 -0.341387 0.750166 0.739167 0.421876 1.644799 1.585638
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.742364 -0.847329 2.183457 1.110611 0.920633 -0.784903 -1.441569 0.117169 0.757990 0.746231 0.422750 6.724449 7.362752
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.193348 0.353536 1.945567 0.911878 -0.518031 -0.549122 -1.351086 -0.374035 0.761834 0.745603 0.432684 4.615129 4.542763
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.435896 0.295123 -0.604994 0.514117 -0.731854 -0.715065 0.204863 22.479626 0.730660 0.705828 0.435590 5.771109 6.238626
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.882499 -0.791655 0.343543 -1.056469 -0.747819 -1.141652 -0.676684 0.245848 0.715043 0.689726 0.445606 1.892491 1.919210
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.240933 1.418846 2.623095 2.770568 8.163651 2.406784 32.276471 -0.809949 0.676245 0.673418 0.388940 5.867028 4.453560
51 N03 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
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.158774 4.379664 -0.347997 -0.290958 -0.378765 -0.809948 3.228693 1.654133 0.734212 0.719372 0.417897 4.746680 4.599954
53 N03 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
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.868713 0.486775 0.969954 0.705277 0.191053 0.697638 1.374059 -0.009422 0.759650 0.748795 0.427472 5.482306 5.612329
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 1.372034 -0.038721 -0.781254 0.640903 1.651154 1.442397 3.534274 -0.306046 0.761622 0.751620 0.429326 4.861457 4.199250
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.732734 0.497613 0.845991 1.432174 1.025249 0.910037 -0.967471 3.976523 0.763449 0.753474 0.426116 3.430320 3.306022
57 N04 digital_ok 100.00% 100.00% 29.57% 0.00% 100.00% 0.00% 17.774270 10.827305 51.751567 6.883884 26.798643 27.247529 14.884450 16.569957 0.051842 0.486079 0.315101 1.204888 3.224117
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.794146 0.061305 0.038209 0.370307 1.133437 0.899792 -0.253441 2.285767 0.705598 0.679476 0.419544 1.639008 1.513493
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.011533 -0.259983 -0.944017 0.377099 0.668883 1.370866 -0.511880 3.167926 0.723075 0.704115 0.411276 1.883071 1.716991
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.203038 -0.395795 0.090632 -0.355028 0.799937 1.335926 1.322960 5.803512 0.740639 0.726118 0.409908 4.555824 5.744702
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.258180 -0.052005 -0.109402 -0.190452 2.331203 2.891647 -0.277007 -0.318428 0.749295 0.738104 0.416682 1.556738 1.672864
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.198370 -0.642105 -0.864320 -0.118504 -0.394840 0.674864 0.098717 2.354583 0.757300 0.750593 0.431684 3.602059 3.614242
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.418835 -1.603546 -0.057650 -1.074551 -0.698972 -0.196679 -0.681136 1.653137 0.764054 0.752974 0.447191 7.865885 7.472277
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.245620 -1.236437 -0.687520 -0.184577 -0.674118 -0.331187 -0.280555 -0.122786 0.764818 0.758833 0.441589 10.858552 8.927115
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.866969 -0.386609 -0.520036 1.459673 0.981869 0.991179 6.456817 -0.987509 0.759280 0.750402 0.452714 4.038043 3.961693
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.330956 2.164802 -0.527047 -0.646904 -0.063984 -0.179651 1.412344 0.138520 0.749996 0.732556 0.468699 1.523034 1.554145
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.421399 2.938090 -0.697309 3.291989 -0.117033 2.626893 1.929182 -0.293086 0.697873 0.671417 0.401909 1.681323 1.515308
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.426288 -0.910536 -0.447039 1.292944 -0.915749 0.224641 -0.957651 -0.335325 0.718185 0.699089 0.409754 10.874545 6.384988
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.593073 2.993346 1.961814 4.363947 0.503891 2.063329 -1.274285 -1.863719 0.737922 0.723806 0.403944 5.418418 5.683323
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.042387 6.182529 -0.158029 1.147040 -0.655922 -0.572183 -0.666975 0.171122 0.080113 0.079679 0.012242 1.184945 1.188104
85 N08 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.205809 0.954748 1.007934 1.936770 -0.206326 -0.033087 -0.189899 -0.018296 0.075124 0.068805 0.008639 1.192845 1.199269
86 N08 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.954356 2.215808 -0.257056 -0.661461 -0.578517 0.443749 -0.672298 0.002047 0.070261 0.064525 0.006224 1.203313 1.198729
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.315852 7.298972 5.974329 0.186678 30.195109 -0.644224 164.352157 -0.765906 0.041947 0.072807 0.007720 1.178038 1.177887
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.947547 17.253321 45.724906 46.705454 27.078816 27.444155 24.628366 18.423334 0.032673 0.032812 0.002100 1.167406 1.172686
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.225180 18.701212 45.607319 46.299684 26.815203 26.989025 14.249666 13.143032 0.031896 0.030812 0.000604 1.222596 1.219119
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.905711 18.073843 45.604810 47.358329 26.948048 27.351225 18.958530 19.126168 0.030878 0.030729 -0.000316 1.238381 1.243577
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.241532 38.601826 9.374454 11.405415 29.703177 30.602846 17.445501 32.824218 0.273888 0.218779 0.101949 2.975159 2.002653
93 N10 digital_ok 0.00% 24.19% 24.19% 75.81% 100.00% 0.00% 0.404061 0.149184 2.746529 -0.885952 0.796443 0.233242 -1.152161 2.357356 0.199999 0.200669 -0.283285 2.132072 1.841736
94 N10 RF_maintenance 100.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.563718 -0.804077 -0.859902 -1.026545 -0.461045 0.750451 7.763227 18.542126 0.538948 0.509691 0.353908 3.239765 2.987905
98 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.287124 1.526583 0.183110 -0.251128 -1.127188 -1.276466 -1.015887 2.825807 0.699572 0.668073 0.404532 7.482462 6.218400
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.848860 0.612690 2.627095 0.153761 1.353266 -0.279090 0.131299 -1.152923 0.716815 0.696730 0.399221 1.740378 1.550101
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.742301 -0.213918 0.231256 -0.211013 -1.417927 -0.282196 0.301379 0.134507 0.734432 0.716904 0.415868 7.149578 6.678998
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.436966 5.975755 3.197787 0.075875 1.300265 -0.785095 2.395448 -0.499360 0.094493 0.083655 0.014624 1.212097 1.219953
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.745011 2.100855 37.524936 9.692096 114.423713 16.906786 1390.501607 203.861030 0.088385 0.056381 0.013204 1.157234 1.177040
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.351152 6.319724 -0.512052 -0.060045 -0.417318 -1.050908 -0.113222 -0.603568 0.063349 0.067284 0.005065 1.195032 1.195301
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.482934 58.619196 0.503785 12.964127 -0.041454 4.004472 1.082731 1.792099 0.066361 0.078739 0.009342 1.199810 1.197177
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.247699 22.375460 45.588167 47.265803 27.012381 27.547273 16.316804 16.680294 0.032748 0.031502 0.000878 1.186316 1.180626
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.544482 19.177033 44.875820 46.766348 26.977933 27.329149 18.000791 15.424733 0.029668 0.028778 0.001194 1.201819 1.188234
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.784483 17.198454 43.972043 44.787515 26.907776 27.142003 17.399402 18.576536 0.029781 0.029440 0.000835 1.226232 1.226204
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.613953 17.359210 45.066183 46.913933 26.871886 27.293002 13.193610 13.838163 0.030846 0.031494 0.001392 1.225726 1.219119
109 N10 digital_ok 0.00% 21.51% 21.51% 0.00% 50.00% 0.00% -1.060372 0.137613 -0.001629 0.502750 -0.714078 0.235868 1.658617 0.878170 0.572795 0.548296 0.378849 2.401618 2.487644
110 N10 RF_maintenance 100.00% 29.57% 21.51% 0.00% 100.00% 0.00% 32.372495 1.488526 3.435285 2.026827 6.715732 -0.743840 1.503693 -1.761151 0.527356 0.538379 0.317144 6.566167 4.833525
111 N10 digital_ok 100.00% 24.19% 24.19% 0.00% 100.00% 0.00% 0.353354 0.770403 -0.278879 1.289080 1.582569 1.907534 0.173335 8.424570 0.548045 0.517478 0.351515 4.879174 4.584409
112 N10 RF_maintenance 0.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.610370 -0.685915 -0.413243 0.782324 -0.233078 -1.098102 -0.120111 -1.458125 0.533761 0.503615 0.345671 4.052719 3.904249
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.262110 1.595973 -0.423266 -0.760208 -0.166810 -0.021088 -0.374010 -0.733578 0.694959 0.671028 0.404070 8.829973 6.908702
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.815363 3.048569 5.051353 5.131485 3.478722 2.375446 -1.743639 -2.111077 0.720319 0.697501 0.418100 7.314958 6.303703
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.064681 0.874073 2.275846 -0.213737 1.088714 1.351858 2.384197 3.020981 0.725813 0.709209 0.418955 1.659116 1.512000
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.886523 1.523783 8.872983 0.325335 8.209710 -0.645503 -1.426055 0.205730 0.739234 0.723467 0.439951 3.670447 3.812246
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.960173 24.217783 9.145390 57.910175 24.506882 28.078447 11.729343 24.668373 0.107805 0.044860 0.057986 1.237161 1.206638
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.365933 3.567499 -0.663286 0.263367 -1.013458 0.428835 54.900817 24.032667 0.073483 0.073634 0.007768 1.206884 1.212994
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.562875 5.109420 1.364764 1.360815 1.338058 0.560962 -0.900503 -0.322014 0.084683 0.085755 0.012055 1.225122 1.219955
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.903700 5.717213 1.188527 -0.108243 0.803722 0.208071 -1.066873 -0.614005 0.109391 0.109770 0.023474 1.232388 1.231963
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.991541 18.254362 46.252825 47.587152 26.949461 27.282380 14.872422 19.958097 0.030386 0.030517 0.000757 1.248837 1.233142
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.754924 18.429951 45.674209 47.859478 27.017673 27.421352 16.591209 19.087915 0.029688 0.030073 0.000757 1.228187 1.228343
127 N10 RF_maintenance 0.00% 18.82% 21.51% 0.00% 100.00% 0.00% -0.458381 -0.583252 0.127141 -0.658473 0.425967 -0.079743 0.295938 1.111829 0.578827 0.553897 0.379125 4.817285 4.202776
128 N10 digital_ok 0.00% 21.51% 21.51% 0.00% 50.00% 0.00% -0.889976 0.924262 -0.287241 1.699214 -0.432103 -0.077601 0.074393 -1.200295 0.571176 0.542149 0.362417 1.836184 1.744827
129 N10 digital_ok 0.00% 21.51% 21.51% 0.00% 50.00% 0.00% -0.193077 -1.440434 -0.531121 -1.135114 0.151647 -0.353520 -0.615164 -0.446339 0.559042 0.532996 0.353184 2.068793 1.985065
130 N10 digital_ok 100.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.012781 0.032771 0.893004 0.614677 0.556058 0.299828 0.415242 8.691021 0.539446 0.510769 0.341687 3.644251 3.819333
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.663067 -0.614778 -1.056953 -0.847256 -1.204990 -1.036752 0.051271 -0.290652 0.629973 0.603013 0.394864 1.867933 1.846999
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.523217 7.560109 -0.481484 0.385357 5.054826 3.599280 4.060083 7.348124 0.637625 0.610172 0.377436 6.033901 8.559028
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.365438 18.863430 44.995293 45.946160 27.084129 27.498812 16.789608 20.586827 0.039802 0.051267 0.004763 1.331271 1.404844
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 22.068219 1.722544 42.438965 -0.693636 27.191137 0.068159 17.576151 -0.668670 0.052575 0.712415 0.521720 1.271587 4.143356
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.819173 16.593159 50.993674 52.821440 26.852637 27.420277 13.772912 14.675334 0.041693 0.045012 0.002781 1.215218 1.218461
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.138087 4.205243 -0.635537 9.702694 1.616947 6.374057 1.849875 20.920661 0.723777 0.703982 0.456137 4.107755 4.508091
142 N13 digital_ok 100.00% 32.26% 100.00% 0.00% 100.00% 0.00% 17.060605 21.440930 8.609828 53.024660 27.050127 27.593659 16.988609 16.913972 0.452128 0.046966 0.288201 9.255456 1.326189
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.312944 -0.429704 1.246430 0.947207 0.609945 0.055845 0.703118 -1.389729 0.735719 0.718127 0.453754 2.430493 2.154574
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.841879 1.138945 1.363908 0.910508 0.114662 0.362670 0.439518 0.296618 0.734819 0.716646 0.458040 2.568791 2.715320
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.612041 18.437218 52.308834 53.435523 26.975439 27.428863 17.488622 20.678585 0.037208 0.039641 -0.000399 1.610136 1.724171
150 N15 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
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.200282 18.569771 51.127749 52.442591 26.922111 27.206022 18.952271 19.164782 0.043290 0.038335 0.002372 1.311094 1.312199
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.916586 0.442312 1.061397 -0.557512 0.624593 -0.406131 5.305286 16.360382 0.636918 0.610967 0.396168 6.473529 6.104431
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.205005 0.640315 0.236961 2.837774 1.974104 0.865749 0.774820 -1.118922 0.640533 0.622005 0.398966 5.314709 5.114651
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.826853 -1.175720 -0.855821 0.001629 -0.479589 0.653897 -0.852250 -0.187441 0.652406 0.631499 0.409718 5.084149 4.705862
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.167039 16.587444 51.762310 52.877399 26.930043 27.363560 17.589065 20.049279 0.046385 0.046891 0.002973 1.200916 1.205382
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.775418 33.276980 -0.464257 3.579253 -0.197224 6.859049 -0.251714 1.530269 0.720294 0.631915 0.408049 4.773713 7.775496
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.499455 0.822055 -0.083836 -0.654638 3.342462 1.938410 0.389366 -0.204351 0.722111 0.706206 0.434022 2.211259 2.617599
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.163214 -0.315841 -0.014717 -0.894816 -0.434446 -1.042698 -0.382658 1.536805 0.732788 0.715880 0.439809 2.681443 2.903906
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.835226 -0.808748 -1.050994 -1.001257 -1.065151 -0.566361 1.165650 1.139867 0.731452 0.713340 0.441843 2.523879 3.515963
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.802998 0.727164 5.647207 -0.859267 3.885195 -1.466435 1.938555 0.939844 0.730895 0.710880 0.441602 7.830698 8.221040
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.030349 1.339872 -0.074410 1.254247 7.898963 1.830401 11.618803 -0.335771 0.712703 0.706050 0.401636 6.429111 7.467853
167 N15 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
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.943778 16.152372 16.983122 19.110685 18.731119 21.659495 4.098201 6.666374 0.678441 0.643305 0.422989 7.801790 8.511543
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.527514 14.887474 18.617333 18.021419 21.046592 20.404989 6.998775 4.843617 0.652417 0.620053 0.421258 6.526363 6.444651
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.645958 13.867038 18.743757 17.411650 21.147401 19.016011 7.417397 4.703762 0.633874 0.608078 0.414464 3.972027 4.312369
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.294032 -0.391499 -0.911963 0.714537 0.707928 0.531082 -0.738836 0.930978 0.612924 0.588771 0.396194 1.543378 1.506248
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.991066 1.299600 0.837415 0.575028 -0.022600 0.085231 2.851359 8.806653 0.621514 0.593900 0.399334 3.895418 4.797074
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.826166 -1.191010 0.895470 -0.874804 -0.629757 -0.775662 0.026045 0.683950 0.632458 0.608864 0.401421 1.393395 1.367058
179 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.735675 -0.011533 -0.970076 -0.394623 2.022146 -0.356868 2.808663 -0.943215 0.639144 0.615352 0.409969 1.414419 1.452317
180 N13 RF_maintenance 100.00% 0.00% 34.95% 0.00% 100.00% 0.00% 0.389717 11.229894 0.539769 47.496135 -0.711614 17.255581 -0.968988 13.271897 0.710462 0.494817 0.506289 25.121915 8.396939
181 N13 digital_ok 100.00% 100.00% 81.18% 0.00% 100.00% 0.00% 18.542038 39.623271 52.452953 5.540502 26.973689 28.434441 16.975065 17.046099 0.051859 0.321688 0.190608 1.204433 2.412046
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.277303 1.739906 16.898747 23.320899 18.566134 19.241942 3.746077 141.167010 0.695889 0.677219 0.441425 4.712504 4.714021
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.268828 -0.689650 -0.253984 -0.777708 -0.772132 -1.857995 -0.429344 3.105149 0.725213 0.706258 0.446157 2.058918 2.496473
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.394280 -0.041868 -0.030715 0.467529 -0.045572 0.108497 0.257387 -0.263849 0.727584 0.708240 0.435292 2.423894 2.613707
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.064245 0.347172 2.101820 1.052211 0.041409 -0.411699 -0.823539 -0.341744 0.724107 0.704589 0.438920 1.974434 1.976148
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.270760 0.469899 3.484878 1.732410 0.807929 0.096670 3.792256 -0.067118 0.710046 0.691796 0.429930 1.977710 2.251397
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.032834 0.372667 0.091012 0.779676 0.038130 -0.756749 1.763724 -1.320399 0.710717 0.692717 0.432258 1.477185 1.690705
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.823553 3.352974 0.437435 -0.504698 -0.531966 -0.620402 0.467074 0.720116 0.674631 0.648932 0.425949 1.879738 1.882217
190 N15 digital_ok 100.00% 10.75% 100.00% 0.00% 100.00% 0.00% 23.410496 20.358483 2.465039 53.395644 11.181476 27.460354 41.747322 19.531586 0.610040 0.053398 0.441667 4.542941 1.480392
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.635088 0.313100 -0.867802 -0.527038 -0.675430 -0.208206 0.006606 27.119333 0.643557 0.606628 0.428444 4.057611 4.223601
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% 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
206 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
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.723365 9.650864 14.146332 12.120262 16.012652 13.401203 19.563355 18.650977 0.653387 0.639480 0.415122 8.115338 10.574607
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% 11.272641 8.774962 inf inf 3385.134989 3385.085555 30020.382752 30021.718025 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.780301 9.613030 7.081815 12.277053 7.517362 10.915674 -0.828359 0.656567 0.663871 0.636773 0.431264 4.744371 4.220028
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.751703 17.573477 20.946383 20.827402 24.067063 23.875692 6.908917 6.335078 0.611820 0.591680 0.406865 3.244718 3.173013
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% 6.323321 9.125842 inf inf 3385.389773 3385.036546 30002.191239 29999.043545 nan nan nan 0.000000 0.000000
320 N03 dish_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
321 N02 not_connected 100.00% 2.69% 59.68% 0.00% 100.00% 0.00% 8.991790 7.305028 11.487492 10.638994 13.358127 11.567343 47.249777 47.526510 0.521458 0.426066 0.328465 0.000000 0.000000
323 N02 not_connected 100.00% 16.13% 65.05% 0.00% 100.00% 0.00% 16.095945 10.068287 2.852683 13.559131 10.190372 12.226495 11.045148 3.009448 0.448032 0.392168 0.270839 0.000000 0.000000
324 N04 not_connected 100.00% 8.06% 59.68% 0.00% 100.00% 0.00% 12.278137 12.986186 15.505770 15.942920 17.450402 17.625624 2.164280 2.363649 0.505177 0.410858 0.332060 0.000000 0.000000
329 N12 dish_maintenance 100.00% 45.70% 70.43% 0.00% 100.00% 0.00% 2.585888 6.452478 4.948130 10.247899 2.387297 10.117015 8.424715 -0.618968 0.422626 0.357880 0.262667 0.000000 0.000000
333 N12 dish_maintenance 100.00% 48.39% 89.25% 0.00% 100.00% 0.00% 0.628019 6.330371 1.249452 9.362933 1.719478 8.194932 7.941780 0.017603 0.403636 0.323262 0.243546 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, 16, 18, 19, 27, 28, 30, 31, 32, 33, 36, 37, 38, 41, 42, 45, 50, 51, 52, 53, 54, 55, 56, 57, 67, 69, 70, 71, 72, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 136, 137, 138, 140, 141, 142, 145, 150, 155, 156, 157, 158, 160, 161, 165, 166, 167, 168, 169, 170, 177, 180, 181, 182, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [9, 10, 15, 17, 20, 21, 29, 40, 46, 65, 66, 68, 73, 81, 99, 118, 135, 143, 144, 162, 163, 164, 176, 178, 179, 183, 184, 185, 186, 187, 189]

golden_ants: [9, 10, 15, 17, 20, 21, 29, 40, 46, 65, 66, 68, 73, 81, 99, 118, 143, 144, 162, 163, 164, 176, 178, 179, 183, 184, 185, 186, 187, 189]
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_2459797.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 [ ]: