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 = "2459802"
data_path = "/mnt/sn1/2459802"
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-10-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/2459802/zen.2459802.25321.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 600 ant_metrics files matching glob /mnt/sn1/2459802/zen.2459802.?????.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 60 ant_metrics files matching glob /mnt/sn1/2459802/zen.2459802.?????.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 2459802
Date 8-10-2022
LST Range 16.784 -- 20.395 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 600
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 32
RF_ok: 11
digital_maintenance: 3
digital_ok: 95
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 104 / 147 (70.7%)
Cross-Polarized Antennas 93
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N09, N14, N19
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 85 / 147 (57.8%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 104 / 147 (70.7%)
Redcal Done? ✅
Redcal Flagged Antennas 14 / 147 (9.5%)
Never Flagged Antennas 11 / 147 (7.5%)
A Priori Good Antennas Flagged 84 / 95 total a priori good antennas:
5, 7, 9, 16, 17, 19, 20, 29, 30, 37, 38, 40,
41, 42, 45, 53, 54, 55, 56, 65, 66, 67, 68,
69, 71, 72, 73, 83, 84, 86, 88, 91, 93, 94,
98, 99, 101, 103, 105, 106, 107, 108, 109,
111, 112, 117, 118, 121, 122, 123, 127, 128,
129, 130, 140, 141, 142, 143, 144, 156, 157,
158, 160, 161, 162, 163, 164, 165, 167, 169,
170, 176, 177, 178, 179, 181, 183, 184, 185,
186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 0 / 52 total a priori bad antennas:
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_2459802.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% 0.00% 0.00% 1.282998 -0.673323 -0.782116 -0.904891 -0.734321 -0.007785 -0.309165 1.440351 0.737747 0.596572 0.510165 1.976354 1.660766
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.623940 4.791202 -0.765639 1.652720 -0.749956 0.534653 3.033024 0.287287 0.753471 0.602742 0.507671 4.569890 4.935031
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.100539 1.165977 -0.548803 4.545924 -1.129926 1.996130 0.516583 -1.157476 0.762340 0.618578 0.506065 4.312038 4.143135
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.087920 -1.046539 0.348217 -0.325780 -0.469439 -0.403779 1.312986 12.752848 0.760352 0.616757 0.502760 3.374546 3.345843
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.532830 16.422142 21.441238 21.817863 28.770093 29.750944 1.414097 0.620190 0.751093 0.590762 0.509902 3.679777 3.762089
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.33% -0.112583 -1.070612 -0.327095 0.070906 1.797947 1.032105 -0.454538 -0.440638 0.757969 0.605351 0.513571 2.375993 1.812392
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.376453 -1.217224 -0.334862 0.421836 -0.745614 -0.090917 0.296432 0.238435 0.742616 0.582449 0.526289 2.007840 1.681102
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.468378 1.409270 1.353586 0.901957 0.556043 0.381582 -0.066755 0.419252 0.764953 0.616445 0.504086 2.157923 2.045140
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.67% -0.490395 -1.180441 -0.646707 -0.744904 -0.879291 -0.848286 2.477510 2.485450 0.769477 0.634001 0.492682 2.059770 1.810871
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 6.67% 0.313613 0.982592 0.275531 0.767340 0.570319 0.566827 0.837304 1.024792 0.775993 0.642166 0.489026 2.167689 1.945511
18 N01 RF_maintenance 100.00% 0.00% 56.67% 0.00% 100.00% 0.00% 5.343092 5.802329 2.574405 -0.375635 8.743913 10.482491 87.510644 55.645689 0.746988 0.449487 0.530800 3.285861 2.034100
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.544208 -0.772106 0.244161 0.880757 -0.906920 1.911422 11.526018 17.268259 0.768593 0.632366 0.495721 3.922761 3.948541
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 3.33% -1.675214 0.558106 -0.651610 -0.439412 1.793702 0.523372 -0.336542 -0.766451 0.765385 0.615105 0.503988 2.210204 1.980155
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.143811 0.561713 0.664162 1.342374 1.672027 -0.307322 1.637746 -0.517381 0.751831 0.600054 0.518669 2.227773 1.859207
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.097746 24.626860 50.877312 52.079224 41.456772 40.936142 7.047945 5.960645 0.041043 0.045733 0.003602 1.198732 1.201195
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 14.981562 21.482773 3.920030 6.575759 31.921263 39.529456 8.295101 55.571564 0.470210 0.243608 0.283626 17.170426 3.426806
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.33% -0.949647 -0.509240 0.395129 -0.190982 -1.196949 -0.965767 -0.448979 0.352866 0.787132 0.657258 0.485338 2.189938 2.275450
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.945275 -0.136964 -1.100731 -0.484203 -0.541393 -0.651257 11.639585 0.841817 0.779122 0.654139 0.479132 3.992645 4.468693
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.145739 -0.760143 -1.022798 0.529170 -0.664194 0.640483 -0.118958 0.502882 0.781053 0.650308 0.494747 1.975508 1.888134
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 36.080720 34.769691 2.555744 2.388069 11.182892 10.946152 33.185357 38.155715 0.694922 0.588428 0.312953 8.530777 6.600572
33 N02 RF_maintenance 100.00% 0.00% 58.33% 0.00% 100.00% 0.00% -0.963338 5.004390 -0.587282 0.512945 -0.803707 2.921502 3.132488 16.352840 0.755764 0.452640 0.587700 4.934846 2.195161
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.918749 8.008693 0.225416 0.862919 1.462115 0.048158 0.352159 0.844823 0.740986 0.590016 0.510143 3.583993 2.982556
37 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
38 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
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 8.33% 0.138708 -1.115722 -0.297788 -0.335128 1.230390 0.415546 -0.454160 -0.325248 0.781001 0.658138 0.484969 2.385872 2.117944
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 11.67% 0.487570 -1.309484 2.367002 1.508205 1.999830 -0.530244 -0.786513 0.775452 0.787133 0.665491 0.481262 2.535099 2.129820
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 16.67% -0.412942 0.687418 2.173937 1.427372 -0.394247 -0.876242 -0.483491 -0.029426 0.788818 0.666757 0.487320 2.390093 2.060092
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.146552 0.436197 -0.950709 1.255759 -1.003895 0.690020 -0.053119 46.056439 0.772833 0.630508 0.511214 3.285526 2.887912
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.101873 -0.603352 0.750286 -0.863608 -0.652998 -0.754723 -0.281314 2.569487 0.765454 0.610809 0.528983 1.833864 1.672572
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 27.465081 2.325936 3.644796 2.112560 13.487068 8.140099 63.825738 11.129023 0.692957 0.578320 0.436667 3.808681 3.139065
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.701637 2.353797 -0.821733 -0.365868 -0.388726 0.174192 -0.316852 1.391519 0.757571 0.627896 0.499201 1.651969 1.529239
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.267616 7.029078 0.754346 0.153051 -0.556370 -0.992868 0.739936 1.391619 0.772925 0.645260 0.497204 3.466887 3.458496
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.485552 1.578324 -0.644624 0.030480 -0.729646 0.436447 4.028883 8.775873 0.782320 0.667308 0.487110 4.002993 4.002046
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.67% 1.400309 -0.073894 1.371234 1.129635 0.911839 1.205240 0.194075 -0.510721 0.790940 0.674814 0.481692 2.511157 2.274221
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 66.67% 1.115118 0.199752 -0.801658 0.627482 1.449738 1.982325 2.062633 -0.435047 0.790739 0.673535 0.477565 3.985195 3.742975
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.971655 0.509947 1.540236 1.527236 1.245529 1.235104 0.004755 4.241964 0.791536 0.679714 0.478216 4.400274 3.787728
57 N04 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 22.038681 14.006506 48.229045 2.531729 41.346433 37.629294 4.507131 10.495733 0.049593 0.485879 0.249332 1.271944 5.158834
65 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
66 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
67 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
68 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
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.00% -0.320546 -1.054001 -0.292625 0.393317 1.389061 1.614827 -0.342703 1.023383 0.793240 0.685019 0.472738 1.917548 1.605019
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.287154 -1.703552 0.201632 -1.060881 0.660086 -0.908795 -0.024908 0.641585 0.794251 0.681801 0.484066 23.221927 18.644373
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.013333 -1.260036 -0.833408 -0.516446 -0.537223 -0.941876 -0.473694 0.458940 0.797059 0.690240 0.475834 37.629540 44.347496
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 61.67% 3.445866 -0.578410 -0.693292 1.819564 1.683541 1.473810 3.154950 -0.974442 0.787982 0.674160 0.497946 3.760574 3.152079
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 22.618531 2.762408 50.035321 -0.747666 41.353868 0.355326 4.621407 0.520370 0.034218 0.645711 0.364029 1.187418 3.431771
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.000074 2.679928 -0.626574 3.569849 -0.560540 3.048083 2.829628 0.059709 0.748002 0.607357 0.498119 1.590311 1.497493
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.219979 -0.438460 0.503205 1.335279 0.430973 -0.414169 -0.114499 -0.109907 0.765559 0.632268 0.498456 3.745361 3.753955
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.283079 3.709749 2.608153 5.328719 0.509218 3.457006 -0.196619 -1.196296 0.777810 0.664120 0.479473 3.192164 3.494934
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.144616 9.968956 0.154736 1.603687 -0.515840 0.360628 -0.372900 0.181417 0.723310 0.611241 0.443381 4.674092 5.251917
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.598022 1.141767 -0.905740 -0.326083 -1.270517 -1.323085 -0.711614 -0.795709 0.718209 0.608204 0.452166 1.890242 1.664852
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.474007 4.393267 0.839588 -0.529146 1.906955 1.308885 0.194880 0.794855 0.722841 0.595221 0.449286 4.631010 4.358225
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.315522 11.209221 5.440377 1.266143 21.128889 0.313972 39.977895 -0.365906 0.692819 0.613960 0.432434 3.470192 3.148198
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.398168 23.325073 44.134785 45.593993 41.934411 41.282610 10.655425 6.606050 0.033151 0.032254 0.002156 1.182583 1.178773
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.854598 24.284287 44.050382 45.224266 41.375719 40.761559 4.302224 3.432658 0.033842 0.031535 0.001886 1.183460 1.181265
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.953444 23.493821 44.012672 46.234000 41.569607 41.462548 7.347332 6.883258 0.030764 0.031428 0.000489 1.158358 1.155892
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 40.560146 56.934735 6.746482 9.011893 35.999960 42.245918 5.175465 15.308827 0.259214 0.197872 0.099644 0.000000 0.000000
93 N10 digital_ok 0.00% 8.33% 8.33% 91.67% 100.00% 0.00% -0.211360 0.347053 3.466013 -0.775046 2.690427 1.313631 -0.836772 1.547345 0.196657 0.198221 -0.269275 0.000000 0.000000
94 N10 digital_ok 100.00% 8.33% 70.00% 0.00% 100.00% 0.00% -0.603934 -1.525822 -0.534849 -1.085164 -0.329392 1.167818 2.452027 5.922564 0.588976 0.415795 0.418726 0.000000 0.000000
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.036999 3.333192 0.660336 0.367752 0.771668 -0.694258 -0.303867 3.964834 0.751135 0.594362 0.508738 4.730111 3.940138
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.876974 1.282250 3.423544 0.230044 3.692352 1.392772 1.445671 -0.332526 0.761219 0.627147 0.488240 3.863712 4.075818
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.448030 -0.000074 0.424900 0.247759 0.007785 -0.938168 -0.820334 -0.335334 0.776435 0.650744 0.495924 1.666204 1.541346
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.968427 9.504511 4.295845 -0.033684 1.718170 -0.817502 3.978611 0.151585 0.724250 0.604213 0.461057 4.017425 3.704516
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.279482 18.073295 4.006022 2.869621 342.931241 309.332058 7962.618098 7917.307024 0.548878 0.569447 0.396344 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.304981 10.050078 -0.492213 0.122122 -0.150650 -0.291659 -0.022842 -0.149615 0.723023 0.604445 0.458751 3.762681 3.133273
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.857598 83.896244 0.353066 14.749693 0.103447 4.474680 0.917603 0.150577 0.721490 0.589742 0.480188 3.681881 3.071330
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.104500 30.151038 41.547315 43.808541 41.458578 40.978072 5.463334 5.303192 0.034402 0.032451 0.001445 1.193789 1.186267
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.634520 24.973751 43.229552 45.548102 41.437198 41.039103 6.344593 5.071860 0.029708 0.029879 0.001208 1.191870 1.186457
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.704527 22.141997 42.270529 43.557252 41.422050 40.836597 6.083437 6.500879 0.031812 0.030076 0.001453 1.204250 1.202708
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.930288 22.488746 43.443292 45.834631 41.419726 40.926466 3.738703 3.721423 0.031137 0.032254 0.001756 1.082993 1.084965
109 N10 digital_ok 100.00% 8.33% 68.33% 0.00% 100.00% 0.00% -1.168467 -0.003252 0.503540 0.857778 -0.714824 0.814563 4.587303 1.558243 0.608367 0.428495 0.435228 0.000000 0.000000
110 N10 RF_maintenance 100.00% 10.00% 70.00% 0.00% 100.00% 0.00% 28.763745 10.180557 2.160604 0.165212 27.612008 18.828688 17.030390 1.150134 0.559020 0.414722 0.347036 0.000000 0.000000
111 N10 digital_ok 100.00% 8.33% 70.00% 0.00% 100.00% 0.00% 0.561244 1.196111 -0.725347 1.463773 1.278173 0.990235 1.988373 5.609007 0.596512 0.416736 0.419191 0.000000 0.000000
112 N10 digital_ok 0.00% 8.33% 70.00% 0.00% 70.00% 0.00% -1.094315 -0.626951 -0.647217 0.765360 -0.172808 -0.447398 -0.452361 -1.098286 0.581178 0.413006 0.408534 0.000000 0.000000
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.566929 2.606358 -0.240204 -0.529637 0.332435 0.684788 0.946704 -0.710179 0.746768 0.589380 0.507808 1.620244 1.503815
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.424948 3.411258 6.188000 5.850920 4.488872 4.675670 -1.159471 -1.384728 0.767625 0.621300 0.512424 4.640374 4.744524
118 N07 digital_ok 100.00% 0.00% 80.00% 0.00% 100.00% 0.00% 3.193552 0.282744 3.143729 21.464799 2.452089 175.071987 1.475940 26.867867 0.775573 0.163118 0.496775 4.041926 1.211843
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.969779 3.497214 11.031425 0.399127 10.945944 -0.658985 -1.384646 -0.461025 0.788613 0.646697 0.503597 3.736556 3.137917
120 N08 RF_maintenance 100.00% 61.67% 100.00% 0.00% 100.00% 0.00% 21.674146 34.449964 6.014647 57.647873 30.564291 41.198754 3.606566 10.397542 0.416679 0.050763 0.295910 2.950437 1.224428
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.760655 5.680766 -0.636222 0.785133 -0.746549 0.268849 36.423311 16.731843 0.720723 0.595357 0.458898 3.609184 2.816786
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.127487 8.269976 1.917477 1.665193 0.356730 -0.473080 1.978536 3.145582 0.721039 0.585776 0.475482 3.017667 2.438237
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.421653 9.038485 0.483607 -0.018235 -0.474945 0.029018 0.284642 0.564285 0.713093 0.572811 0.486312 3.342972 2.705784
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.762790 23.201785 44.685378 46.556659 41.646044 40.954935 4.706363 7.369262 0.028288 0.029907 0.000695 1.133695 1.134471
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.103838 24.093709 44.131383 46.959264 41.530183 40.982926 6.021256 6.686388 0.028337 0.029599 0.000973 0.847485 0.852452
127 N10 digital_ok 0.00% 8.33% 68.33% 0.00% 68.33% 0.00% -0.347996 -0.491990 0.334189 0.086257 0.949169 0.989516 0.029426 0.580587 0.606702 0.425026 0.435112 0.000000 0.000000
128 N10 digital_ok 0.00% 8.33% 68.33% 0.00% 68.33% 0.00% -1.536567 1.610395 -0.521242 1.595066 -0.651598 0.634845 -0.233886 -0.815246 0.603692 0.423644 0.420637 0.000000 0.000000
129 N10 digital_ok 0.00% 8.33% 68.33% 0.00% 68.33% 0.00% -0.675659 -1.781284 -0.825459 -1.014750 -0.753950 -0.972314 -0.552540 -0.297624 0.595434 0.419765 0.412101 0.000000 0.000000
130 N10 digital_ok 0.00% 8.33% 70.00% 0.00% 70.00% 0.00% 0.060302 0.201887 0.472852 1.366442 0.445833 0.327401 -0.029452 3.607148 0.583949 0.414717 0.405804 0.000000 0.000000
135 N12 digital_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
136 N12 digital_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
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.615990 24.015480 43.383723 44.806479 41.524877 41.000311 5.797155 7.756653 0.034761 0.041276 0.004681 1.221895 1.245146
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 28.704127 2.988565 40.643726 -0.679198 41.430887 0.266414 6.461443 -0.342602 0.048250 0.628591 0.381202 1.248751 2.898363
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.892105 22.259307 49.782285 52.155538 41.451844 41.068836 4.112821 4.339640 0.040825 0.043605 0.001541 1.154732 1.154740
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.889167 3.976154 -0.584888 11.416359 2.297074 3.878376 2.315951 18.335900 0.772114 0.614715 0.514615 3.398784 2.514562
142 N13 digital_ok 100.00% 25.00% 100.00% 0.00% 100.00% 0.00% 24.804589 28.535862 5.508108 52.388373 32.507534 41.057626 7.400578 5.570578 0.442987 0.045569 0.269363 2.201237 1.185136
143 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.496874 -0.840740 1.504905 0.750955 0.438366 0.104086 -0.324478 -1.098691 0.097925 0.100638 0.027400 0.886661 0.888471
144 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.846882 1.373688 0.272755 2.475809 -0.587926 1.388403 1.112883 1.591233 0.084867 0.092514 0.024011 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.475232 24.255248 51.185842 52.822900 41.431554 41.309382 6.229663 7.817995 0.030653 0.032827 -0.000447 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.844275 26.827778 50.980406 53.738294 41.380395 40.852014 7.342647 8.226153 0.051103 0.053840 0.001381 0.000000 0.000000
155 N12 digital_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
156 N12 digital_ok 100.00% 0.00% 1.67% 0.00% 100.00% 0.00% 0.669965 0.288790 1.502981 -0.044418 0.190867 0.340701 3.356492 9.197335 0.698145 0.525428 0.489938 4.802065 4.821695
157 N12 digital_ok 0.00% 0.00% 1.67% 0.00% 1.67% 0.00% 0.223135 1.299344 0.105783 3.014594 0.259605 3.047407 0.306164 -0.347102 0.692021 0.535703 0.476373 2.212463 1.879302
158 N12 digital_ok 0.00% 0.00% 1.67% 0.00% 1.67% 0.00% -0.765571 -1.697804 -0.681358 -0.489936 -0.301650 -0.012738 1.080889 0.784002 0.702609 0.546815 0.479486 2.117864 1.792020
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.568585 21.884695 50.624069 52.220056 41.505592 41.032444 6.507442 7.678024 0.043010 0.045070 0.003549 1.218121 1.216566
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.976537 45.722658 -0.000156 3.764697 -0.320839 10.631353 0.441836 0.537476 0.758170 0.513947 0.485140 4.329856 3.842166
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 8.33% 0.969979 0.916845 -0.202585 -0.843050 1.639825 1.614276 1.738360 0.902558 0.758941 0.598881 0.536247 1.745575 1.643362
163 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.787688 -0.254804 -0.103488 -0.667624 -0.442049 -0.331301 -0.298195 1.699230 0.063798 0.077529 0.011208 1.257566 1.250599
164 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.762720 -1.189072 -0.994217 -0.536071 -0.978533 -0.388343 1.625122 2.616313 0.072388 0.064353 0.006303 1.223538 1.223970
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.503024 1.306000 7.241246 -0.907119 6.058320 -1.226959 3.011314 2.195050 0.070963 0.062703 0.005490 1.296071 1.293037
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.780881 1.732141 -0.142606 1.343744 9.083992 3.289717 38.997473 12.647428 0.098702 0.087777 0.016935 0.000000 0.000000
167 N15 digital_ok 100.00% 1.67% 45.00% 0.00% 100.00% 0.00% 19.262124 21.539089 19.821152 22.245422 29.696265 29.586774 69.260591 38.480088 0.627395 0.489396 0.388707 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.768935 19.550461 21.767019 24.232681 29.145165 33.477211 -0.815368 1.735631 0.718517 0.528125 0.519657 0.000000 0.000000
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.778603 18.056219 23.988320 22.880339 32.966045 31.481436 -0.369649 1.618179 0.709820 0.518861 0.511875 0.000000 0.000000
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.910999 16.304431 24.230091 21.812152 33.664360 29.551992 0.063473 0.830759 0.697593 0.515699 0.504874 0.000000 0.000000
176 N12 digital_ok 0.00% 0.00% 6.67% 0.00% 6.67% 0.00% 0.469151 -0.526662 -0.846726 0.259116 -0.157849 -0.065920 -0.556697 0.638803 0.681421 0.499177 0.490776 2.036867 2.129256
177 N12 digital_ok 100.00% 0.00% 1.67% 0.00% 100.00% 0.00% 1.441459 1.604955 1.103341 1.000504 -0.482088 -0.154143 0.369301 6.019157 0.681753 0.508916 0.481206 6.405713 7.016208
178 N12 digital_ok 0.00% 0.00% 1.67% 0.00% 1.67% 0.00% -1.124005 -1.493571 0.930273 -0.595190 -0.519267 -1.221958 -0.163495 -0.431600 0.683398 0.517591 0.474596 1.946290 1.807233
179 N12 digital_ok 0.00% 0.00% 1.67% 0.00% 1.67% 0.00% -0.461334 0.465198 -1.053958 0.008973 2.071670 -0.655539 3.507908 -0.927199 0.683007 0.518737 0.478894 1.946857 1.905715
180 N13 RF_maintenance 100.00% 0.00% 75.00% 0.00% 100.00% 0.00% 0.435681 16.805973 0.710646 47.905736 -0.560550 29.221226 -0.228430 5.842727 0.748295 0.332993 0.576094 17.093209 3.358828
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.386566 59.831416 51.351563 5.212903 41.508152 39.379247 6.031439 16.338809 0.047776 0.287466 0.144272 1.194673 4.065942
182 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 15.807899 28.481429 21.667377 51.786536 29.094634 40.236207 -1.006527 6.563913 0.731136 0.062006 0.484704 3.718618 1.491556
183 N13 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
184 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.512847 -0.580105 -0.061081 0.793261 -0.055015 -0.226747 2.280222 3.008925 0.072503 0.060508 0.005820 1.301740 1.298860
185 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.608375 -0.059899 0.995846 1.160498 -0.729953 0.439587 1.865535 -0.146628 0.047109 0.055048 0.003901 1.282990 1.287926
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.615641 0.072543 3.992647 2.268212 1.912046 0.702281 3.153894 -0.234105 0.078948 0.076718 0.012440 1.200915 1.204473
187 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.265799 0.724318 -0.008973 0.492212 0.357049 -0.824276 2.369149 1.783440 0.096455 0.098428 0.023592 0.000000 0.000000
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.081672 4.433116 0.350929 1.079116 -0.079865 1.817151 0.662793 6.353466 0.721198 0.541061 0.521539 0.000000 0.000000
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 42.774383 27.145975 3.146374 52.786681 18.763910 40.958740 72.576285 6.828784 0.642445 0.047243 0.456944 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.345010 0.636816 -0.962101 -0.731409 -0.069654 -0.016087 1.251070 6.989605 0.711663 0.523404 0.522516 0.000000 0.000000
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% 12.250591 5.975462 15.517814 -0.366009 18.887980 4.647267 15.164658 26.424837 0.054196 0.043862 0.004663 1.146653 1.154532
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.316759 8.480970 -0.708248 10.674604 10.032657 13.871991 15.742243 16.554655 0.043355 0.051844 0.002405 1.121172 1.121338
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.340037 11.365266 18.203234 14.984312 24.726803 18.999344 5.356102 4.130143 0.058701 0.059859 0.006081 0.000000 0.000000
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% 15.492523 14.884028 inf inf 3168.017685 3740.857418 9973.658446 13679.114954 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.521805 3.952496 9.175457 2.520504 10.942656 4.844131 0.546274 1.277206 0.044821 0.047954 0.002423 0.000000 0.000000
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.424466 21.349772 27.126754 26.540112 38.230138 37.033797 -0.549641 -0.289166 0.064481 0.065736 0.007256 0.000000 0.000000
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% 15.898267 17.139394 120.491111 128.204436 4366.339354 4366.349909 16260.445623 16261.091514 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.031221 27.241202 36.689000 37.263524 41.580699 40.816457 10.124379 6.875295 0.056992 0.051831 0.003923 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 46.67% 0.00% 100.00% 0.00% 9.997166 7.796489 14.443266 12.862402 19.717801 17.119131 28.298601 27.965319 0.638719 0.396987 0.484078 0.000000 0.000000
323 N02 not_connected 100.00% 6.67% 75.00% 0.00% 100.00% 0.00% 20.998204 11.616046 1.555961 16.858198 17.585593 23.578059 4.074560 0.182431 0.520431 0.368402 0.380747 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 60.00% 0.00% 100.00% 0.00% 14.459814 15.258368 19.563857 19.764787 26.019102 26.670665 0.500574 -0.648554 0.634519 0.385504 0.485260 0.000000 0.000000
329 N12 dish_maintenance 100.00% 20.00% 86.67% 0.00% 100.00% 0.00% 3.783570 6.967831 0.462947 12.294548 4.146092 14.033238 6.455842 -0.006598 0.542591 0.329810 0.404944 0.000000 0.000000
333 N12 dish_maintenance 100.00% 21.67% 100.00% 0.00% 100.00% 0.00% 2.406970 6.591038 0.906516 10.992774 5.403871 12.898097 3.075100 -0.064595 0.521169 0.304596 0.387614 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: [4, 5, 7, 8, 9, 16, 17, 18, 19, 20, 27, 28, 29, 30, 32, 33, 36, 37, 38, 40, 41, 42, 45, 50, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 82, 83, 84, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 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, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 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: [3, 10, 15, 21, 31, 46, 51, 81, 85, 100, 116]

golden_ants: [3, 10, 15, 21, 31, 46, 51, 81, 85, 100, 116]
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_2459802.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.3.dev44+g7d4aa18
3.1.4.dev3+g68bd8c3
In [ ]: