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 = "2459788"
data_path = "/mnt/sn1/2459788"
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: 7-27-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/2459788/zen.2459788.25284.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 378 ant_metrics files matching glob /mnt/sn1/2459788/zen.2459788.?????.sum.ant_metrics.hdf5

Load chi^2 info from redcal¶

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

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

        post_redcal_ant_flags_dict[cal] = {ant: np.all(flags[ant]) for ant in flags}
        # check history to distinguish antennas flagged going into redcal from ones flagged during redcal
        tossed_antenna_lines =  hc.history.replace('\n','').split('Throwing out antenna ')[1:]
        flagged_by_redcal_dict[cal] = sorted([int(line.split(' ')[0]) for line in tossed_antenna_lines])
        
    use_redcal = True
else:
    print(f'No files found matching glob {glob_str}. Skipping redcal chisq.')
Found 38 ant_metrics files matching glob /mnt/sn1/2459788/zen.2459788.?????.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 2459788
Date 7-27-2022
LST Range 15.855 -- 18.269 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 377
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 42
RF_ok: 11
digital_maintenance: 1
digital_ok: 87
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 107 / 147 (72.8%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N09, N18
Nodes Not Correlating N10, N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 72 / 147 (49.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 118 / 147 (80.3%)
Redcal Done? ✅
Redcal Flagged Antennas 9 / 147 (6.1%)
Never Flagged Antennas 15 / 147 (10.2%)
A Priori Good Antennas Flagged 76 / 87 total a priori good antennas:
5, 7, 9, 10, 15, 16, 19, 20, 21, 30, 37, 42,
45, 46, 50, 51, 53, 54, 55, 56, 57, 65, 66,
68, 69, 71, 72, 73, 81, 83, 84, 88, 91, 92,
93, 99, 101, 103, 105, 106, 107, 108, 109,
111, 117, 121, 122, 123, 128, 129, 130, 135,
138, 140, 141, 142, 145, 160, 161, 162, 165,
167, 169, 170, 176, 177, 178, 179, 181, 183,
185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 4 / 60 total a priori bad antennas:
3, 4, 100, 116
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_2459788.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 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.220092 -0.460255 0.690047 -0.818109 -0.376090 0.028409 -0.472174 0.678727 0.633721 0.630435 0.401957 7.924936 6.638814
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.152015 3.983802 -0.736591 0.002588 -0.359132 -0.349808 2.787831 0.050603 0.648108 0.639150 0.398216 15.172494 11.683476
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.069626 1.558119 -0.759863 6.290653 -1.148536 5.103948 0.199699 -1.527781 0.655395 0.649152 0.397829 15.199445 15.672508
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.419881 5.775800 12.248748 13.072881 15.252936 14.857632 -1.528059 11.624775 0.644825 0.640265 0.386671 19.859125 18.384280
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.022834 18.638080 24.886648 26.780414 37.106913 38.013828 2.570357 -0.330009 0.621697 0.610829 0.379541 6.177880 6.630814
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.417625 6.203431 1.053564 13.730631 1.563547 16.212481 0.074075 -1.245704 0.622417 0.616054 0.383288 5.535226 5.938715
10 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.498544 16.495916 26.397984 24.891830 40.364229 35.718153 17.147431 15.154015 0.572845 0.571698 0.371614 3.404603 3.750134
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 28.95% 0.017279 1.527546 -0.549702 0.771856 -0.183984 0.168920 -0.504738 0.923285 0.668947 0.660002 0.399707 7.694375 7.354854
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.059436 -1.268600 0.271619 0.040580 -0.066384 0.362082 6.434504 12.884100 0.673273 0.668719 0.390760 30.975369 36.680833
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.211913 0.820588 -0.737092 0.090000 -0.030550 -0.246017 2.579394 3.701650 0.670783 0.669779 0.380747 1.568487 1.774480
18 N01 RF_maintenance 100.00% 0.00% 50.26% 0.00% 100.00% 0.00% 3.921340 4.878704 3.110275 -0.229587 9.935689 11.445146 66.188191 63.279758 0.645783 0.483625 0.423913 19.805917 7.827691
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.272057 15.973536 26.105263 24.145986 39.702463 36.343493 1.287541 1.050315 0.630106 0.635779 0.373136 8.188425 9.726004
20 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.993106 19.384436 15.797595 26.850124 22.351451 39.008087 -1.269653 -0.492458 0.631076 0.600041 0.382292 7.000057 5.710545
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.423342 -0.657076 -0.703159 1.651378 0.649538 0.099319 1.346243 19.048237 0.615838 0.604771 0.377752 5.122110 5.042281
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.347796 28.908571 69.822836 69.550646 52.853891 52.134330 10.527807 7.613470 0.043149 0.048435 0.003739 1.254410 1.269004
28 N01 RF_maintenance 100.00% 42.33% 92.06% 0.00% 100.00% 0.00% 13.514709 18.794021 8.462650 10.135592 47.775643 54.744785 12.500774 57.781391 0.475829 0.270819 0.283387 47.136540 10.832369
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.880983 -0.913621 -0.173108 0.184342 -0.785233 0.047559 -0.160209 0.348729 0.688231 0.686894 0.382538 1.433978 1.523107
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.514287 -0.061699 -0.973708 0.082876 -0.533544 -0.290400 12.980733 1.867718 0.676922 0.677203 0.378070 16.131887 24.515136
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.746451 -1.045494 0.042301 -0.464026 0.707772 0.070590 1.553916 1.642074 0.672207 0.664999 0.377814 1.804145 1.853415
32 N02 RF_maintenance 100.00% 7.94% 0.00% 0.00% 100.00% 0.00% 32.811139 39.559356 3.144783 4.164434 13.847343 15.114589 32.313430 37.416895 0.579425 0.588099 0.196007 10.394370 9.109716
33 N02 RF_maintenance 100.00% 0.00% 52.91% 0.00% 100.00% 0.00% -0.001006 5.013397 1.353271 0.940772 -0.057889 4.348350 3.486642 19.806240 0.627539 0.468276 0.449284 5.793025 3.360108
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.607485 7.997569 0.405167 1.597955 0.958698 0.134226 0.184100 1.453986 0.631555 0.616023 0.378633 5.745456 5.674917
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.670201 0.575689 -0.138290 0.246995 -0.127775 0.260806 -0.161477 14.332053 0.661632 0.650048 0.388449 10.499968 8.862594
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.413632 0.058813 -0.085124 -0.339086 1.519869 0.793826 9.421617 4.691998 0.681119 0.673812 0.396889 10.909561 9.934950
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.844106 -0.010653 0.845488 -0.328713 -0.855458 -0.763631 -0.359156 -0.784424 0.697387 0.696410 0.390083 2.130506 1.958097
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.559195 -0.370537 2.401708 -0.721562 2.278194 -0.472172 -0.754122 -0.670254 0.697172 0.696733 0.377169 1.504906 1.453808
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -1.283946 0.526961 1.969125 1.002842 -0.036100 0.725438 -0.641549 -0.392366 0.700593 0.700626 0.391381 2.122446 1.893785
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.130693 1.222417 0.440335 2.092343 0.131398 0.848664 0.342760 25.300660 0.659888 0.648055 0.389584 9.335058 10.869809
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% -1.428899 -1.277426 -0.358347 -0.947373 -0.686214 -0.416865 -0.115780 3.638344 0.640538 0.632498 0.399156 2.227978 2.392486
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.169415 3.271884 -0.478229 0.796738 0.155155 2.628600 14.975600 16.249848 0.638245 0.626817 0.361195 11.160252 11.110631
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 0.901324 39.273736 3.856458 86.884944 2.408830 52.991707 0.708849 22.771739 0.667717 0.040677 0.400364 14.654463 1.231069
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 12.491013 46.270542 1.004182 87.843637 5.950058 53.063084 9.209835 24.470227 0.648240 0.043246 0.381581 8.767035 1.165408
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.961960 3.233409 5.680194 5.099305 4.335513 3.223797 2.238905 7.737730 0.698614 0.695004 0.383890 14.299307 14.734465
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.075438 3.287923 -0.513620 3.502531 8.249789 20.735130 4.039186 22.354567 0.700771 0.692091 0.357663 47.387636 48.570892
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.531993 -0.001084 -0.653562 0.745527 2.438571 1.891015 10.091537 0.493770 0.702071 0.702315 0.382287 68.710419 57.936434
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.626377 4.531387 13.933136 12.111557 17.642835 14.726825 -1.403992 0.734705 0.704081 0.705864 0.393018 23.935650 19.487293
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 25.712822 -0.904314 66.337346 4.989209 52.570715 8.425123 7.198805 2.279250 0.050223 0.697917 0.429531 1.590031 15.605066
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.637420 0.401400 -0.207745 0.371209 0.243842 0.828748 -0.808142 0.447456 0.645485 0.635444 0.377322 1.326474 1.300794
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.512473 0.945570 0.267814 -0.323465 0.563385 -0.773690 -0.269505 1.852607 0.669977 0.660889 0.371665 1.450786 1.341772
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.169418 -0.755110 -0.499944 -0.778268 -1.089759 0.692920 5.249201 2.815296 0.686268 0.682131 0.367907 8.783113 13.412081
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 15.79% 0.034759 0.010653 -0.830688 1.256942 1.418285 1.616985 -0.076125 -0.363528 0.693601 0.690706 0.373023 2.690731 3.162656
69 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.349535 4.849620 12.008245 11.374945 15.166875 13.854407 -1.035024 0.090236 0.700492 0.705001 0.374527 14.413079 14.786207
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.855025 -1.687145 0.225069 -0.689574 -0.356294 -0.384422 1.118187 1.397297 0.706103 0.703555 0.399016 43.415464 29.782561
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 60.53% 0.302134 -1.001771 0.669097 0.267222 -0.462342 1.059865 0.129569 0.539054 0.702516 0.708396 0.389718 11.267521 12.980385
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.459396 -0.986794 0.763235 2.679338 0.670688 2.061032 5.546618 -0.963001 0.693385 0.700119 0.402873 8.648021 9.631431
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 26.32% 1.057505 0.027517 0.679885 1.290898 1.239938 0.345553 2.926170 0.824429 0.681723 0.675226 0.416917 1.727201 1.888186
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.186522 4.043417 0.000502 5.857195 -0.245176 6.229401 2.385558 0.016547 0.628145 0.620962 0.359002 17.319533 21.939352
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.103483 1.006610 2.137788 -0.315898 2.448386 -0.914360 -0.115809 -0.710979 0.657245 0.651992 0.363911 15.876524 13.347076
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.394241 2.783563 38.846825 5.784950 24.843785 4.889762 4.711633 -1.159191 0.620077 0.677677 0.384662 7.206697 11.900437
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.230457 10.241966 2.398630 2.763130 0.723913 1.857775 -0.663835 -0.687056 0.695933 0.694157 0.364586 12.244127 15.610568
85 N08 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
86 N08 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
87 N08 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
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 39.405324 59.259880 10.612650 13.312654 54.024175 57.044390 9.535531 22.980692 0.076891 0.074631 0.010194 0.000000 0.000000
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.280742 -0.388553 5.834040 1.076966 6.915650 1.223818 -0.740814 2.969477 0.075097 0.075213 -0.012886 0.000000 0.000000
94 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.447380 -1.677080 0.680162 -0.945467 0.355566 1.793382 4.502833 6.497096 0.052986 0.060902 0.006376 0.000000 0.000000
98 N07 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.260750 29.502022 1.917332 2.686639 -0.679955 4.493988 0.468612 5.635312 0.617465 0.593230 0.339103 9.216089 7.125604
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.429768 -0.170732 2.906876 1.367778 4.068157 0.954423 4.409794 0.068517 0.639029 0.636657 0.349249 10.199107 8.755309
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.088550 -0.480644 -0.444607 0.743261 -1.069665 0.682529 -0.050603 -0.252745 0.666863 0.661629 0.367104 18.974258 13.860081
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.684365 17.650987 108.395152 103.444962 3467.881145 3122.694343 18990.835255 16306.213376 nan nan nan 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.390831 9.838791 2.564937 0.548295 1.066941 -0.101583 -0.646678 -0.306039 0.699638 0.696393 0.385040 18.205448 11.969977
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.791187 88.048239 3.097574 19.393534 2.483236 7.900353 0.404597 0.489160 0.693964 0.691529 0.402772 9.671430 8.722649
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
109 N10 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
110 N10 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
111 N10 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
112 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.967584 -0.399573 1.246737 1.564454 1.256995 0.169323 0.273880 -1.304354 0.048580 0.053052 0.003227 0.000000 0.000000
116 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.406112 2.227673 0.090159 -0.318771 0.666452 0.581037 -0.380446 -0.848418 0.603190 0.595842 0.359899 4.757094 5.727201
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.849648 4.308701 9.752530 7.759035 10.879023 6.438818 -1.434227 -1.710854 0.637425 0.632614 0.379761 6.330491 6.229627
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 23.68% 0.00% 3.853312 1.318572 2.419297 1.270661 3.169347 0.858954 1.680560 1.822831 0.643448 0.642555 0.375278 0.702304 0.658234
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.285736 1.814334 10.410020 0.333824 12.398505 0.881541 -1.435443 0.621383 0.662954 0.660156 0.384611 5.399860 5.122270
120 N08 RF_maintenance 100.00% 52.91% 100.00% 0.00% 100.00% 0.00% 20.017095 36.498069 6.265764 77.223738 48.800243 52.941938 5.693276 14.354944 0.441386 0.049326 0.315197 3.097043 1.271773
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.377559 5.115719 -0.078694 1.248530 -0.320022 1.701487 35.743759 19.532938 0.684578 0.685648 0.388372 5.157234 5.215240
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.441894 8.396182 1.312710 0.300601 -0.231616 -0.647114 -0.487241 -0.309276 0.683935 0.682310 0.396425 10.639938 9.811753
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
127 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.211354 -0.684160 -0.664019 0.461073 -0.599359 1.203264 -0.362068 1.017774 0.068340 0.067099 0.015599 0.000000 0.000000
128 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.436448 1.630867 2.845695 4.786393 1.456730 4.458962 -0.363787 0.056384 0.067210 0.066809 0.010441 0.000000 0.000000
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.815638 0.014742 -0.734918 1.132080 -0.815321 -0.393414 -0.735017 -0.859787 0.055433 0.054948 0.004446 0.000000 0.000000
130 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.257793 -0.410418 -0.740896 -0.597457 0.180204 1.498848 0.646197 5.915123 0.054329 0.049954 0.004411 2.667954 3.259983
135 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.742551 -0.748171 0.035522 -0.877898 -0.445517 -0.610383 5.089501 3.521214 0.087389 0.096851 0.020423 1.201814 1.203243
136 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.985879 11.953681 1.116404 0.900192 3.661522 2.730055 3.756166 5.066221 0.073555 0.087682 0.013737 1.158014 1.159858
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.823398 26.806867 60.221979 60.743489 52.895233 52.114902 8.822080 10.578630 0.037546 0.045934 0.004004 1.320421 1.416833
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 30.808216 2.273374 59.883737 -0.442595 52.987043 -0.020720 9.540076 -0.103154 0.047685 0.637292 0.410685 1.210705 7.250101
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.034892 4.961017 -0.176136 -0.228687 1.948004 2.186688 0.803289 0.674916 0.649704 0.645535 0.382062 4.202708 4.288611
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.758766 4.664087 -0.330322 16.358405 1.286040 4.446973 1.244352 16.189798 0.653135 0.634776 0.382773 5.874777 6.386243
142 N13 digital_ok 100.00% 58.20% 100.00% 0.00% 100.00% 0.00% 25.548569 30.904837 10.458281 70.467753 51.079251 52.338324 8.639834 8.171269 0.419878 0.044638 0.224290 10.672191 1.325251
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 15.79% 0.00% -0.179213 -0.415263 -0.002588 1.186115 -0.225730 0.490120 -0.421654 -1.219019 0.665856 0.660626 0.382381 2.057950 2.014917
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 15.79% 0.00% -0.213345 -0.401689 2.089853 -0.809578 0.137603 -0.907954 0.360530 0.706776 0.665335 0.658253 0.396300 2.137468 2.338130
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.441715 26.126929 70.259122 71.094988 52.786505 52.696628 9.358189 11.147197 0.037872 0.039630 -0.000000 1.727354 1.910619
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.399791 28.347879 69.994389 72.248942 52.873129 52.228860 10.504250 10.845820 0.051353 0.053557 0.001544 0.000000 0.000000
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.372945 27.160244 68.593979 69.603805 52.688089 51.768801 10.228741 10.461689 0.040514 0.041567 0.000544 1.158177 1.147919
156 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.450337 19.118742 26.203698 26.876953 39.569244 38.458818 2.668470 5.114113 0.090602 0.093249 0.014647 1.225693 1.231976
157 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.891670 20.190714 25.624708 27.813239 38.708556 40.475294 0.229295 -0.464707 0.087578 0.088858 0.010868 1.306527 1.297994
158 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 13.753884 17.302017 21.666441 25.765679 31.068986 36.586038 -0.871202 -0.723615 0.085331 0.083406 0.012421 1.281643 1.279902
160 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
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.791254 46.320617 -0.910845 5.036741 -0.216940 13.219311 0.132867 0.176967 0.648555 0.560589 0.348031 7.031701 7.486788
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 2.867898 1.076493 -0.325115 -0.197647 2.807739 2.577749 0.590277 -0.485939 0.648923 0.648183 0.377949 2.427456 2.365888
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 0.00% 1.033209 -0.664822 -0.352730 -0.911232 -1.132532 -0.909547 2.020012 0.347141 0.657564 0.654339 0.373535 1.859642 1.918975
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 0.00% -1.268647 -1.047775 -0.254522 -0.340372 -0.028409 -0.909640 0.849565 0.761621 0.653717 0.649841 0.378229 1.864631 1.707224
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.757350 0.376996 7.792204 -0.812148 8.697241 -1.036156 -0.796854 -0.011411 0.651738 0.646215 0.377403 9.674950 10.434113
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.680906 1.830177 0.541298 1.397053 16.375081 5.246154 95.431780 9.040918 0.599331 0.624659 0.351326 0.000000 0.000000
167 N15 digital_ok 100.00% 29.10% 37.04% 0.00% 100.00% 0.00% 18.822244 25.187510 21.264081 25.417080 55.690161 39.544403 41.387864 16.141049 0.526120 0.522200 0.187085 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.179466 21.844344 25.186154 29.389859 37.646485 42.616393 -0.110027 0.001633 0.588556 0.572759 0.371879 0.000000 0.000000
169 N15 digital_ok 100.00% 2.65% 2.65% 0.00% 100.00% 0.00% 20.400594 20.116879 27.804451 27.746507 42.127811 39.859623 0.825706 -0.426962 0.565586 0.557811 0.366982 0.000000 0.000000
170 N15 digital_ok 100.00% 13.23% 2.65% 0.00% 100.00% 0.00% 20.657115 18.575045 28.009363 26.529292 42.725638 37.771607 1.357434 0.130572 0.545323 0.548346 0.363464 0.852784 0.857634
176 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.230691 -0.218646 -0.391435 0.983738 -0.361161 1.024399 -0.558774 -1.028020 0.053034 0.062113 0.005226 0.901752 0.907481
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.873558 1.027242 0.642539 1.004586 -1.010079 0.865819 1.490657 6.155772 0.058772 0.055610 0.005301 0.888440 0.891095
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.009123 -1.675821 -0.865146 -0.466842 -1.837784 -0.498231 -0.654347 -0.904429 0.059568 0.050838 0.007073 1.091296 1.097296
179 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.251302 0.433915 0.126685 0.444224 5.781194 0.802899 7.675548 -0.158018 0.068579 0.059390 0.013551 1.193567 1.192445
180 N13 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
181 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
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.125244 10.422023 25.072140 17.942069 37.580047 40.521319 -0.480332 81.400707 0.619165 0.625891 0.388307 15.840659 19.828322
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.956482 0.708662 1.318639 -0.633404 0.941262 -0.972108 0.046299 6.047701 0.647441 0.637345 0.384974 23.972408 30.274418
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 0.00% 0.376848 -1.166745 1.842031 -0.610844 0.951536 -0.242449 2.398107 0.635583 0.647472 0.640453 0.370607 1.625125 1.911087
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.450711 0.415180 0.353731 5.960716 2.630173 3.086182 4.764463 0.701219 0.649619 0.644029 0.374136 8.446095 9.787337
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.563362 1.379539 27.619236 28.261193 3.814922 3.233630 4.528682 0.802780 0.617260 0.614314 0.356939 3.608202 4.181901
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.850219 19.246786 22.320761 27.133237 32.434995 38.725321 0.364331 -0.608278 0.623799 0.613604 0.366663 0.000000 0.000000
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.960315 4.750409 -0.267345 1.254753 -0.365134 1.754085 0.610708 3.201858 0.593017 0.589464 0.373449 0.000000 0.000000
190 N15 digital_ok 100.00% 42.33% 100.00% 0.00% 100.00% 0.00% 42.601244 29.392307 5.257262 70.982586 26.214180 52.163051 147.056718 9.880063 0.494340 0.049010 0.312247 0.000000 0.000000
191 N15 digital_ok 100.00% 5.29% 2.65% 0.00% 100.00% 0.00% 0.072047 1.177054 0.311509 -0.656049 1.662967 0.555695 2.456614 6.471108 0.561857 0.552159 0.376760 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% 0.00% 0.00% 0.00% 100.00% 0.00% 12.776400 5.879535 18.028342 0.109140 27.034331 8.312422 26.456901 41.090935 0.611389 0.600478 0.364073 4.179811 4.435130
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.582475 9.428949 -0.425824 13.062041 8.539912 19.918092 28.370899 28.583715 0.588976 0.595100 0.354345 2.367255 2.495980
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.293754 17.428804 20.858462 24.470195 31.921647 35.059770 7.591773 8.310237 0.585579 0.581935 0.355210 0.870131 0.857420
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% 12.306399 12.025020 112.120653 112.193818 3723.318692 4384.456815 12806.302130 17705.824183 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.286802 14.100639 10.057551 20.747616 16.113036 28.423850 -0.996385 -1.336583 0.598700 0.590554 0.373362 3.519877 3.642585
224 N19 RF_ok 100.00% 2.65% 0.00% 0.00% 100.00% 0.00% 23.520125 23.898668 31.414737 32.006178 48.155333 46.622124 1.072950 0.116769 0.550907 0.550581 0.352668 1.788038 1.845016
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% 9.509730 13.680563 138.290493 128.436900 5162.217641 5162.029463 21278.327748 21273.075516 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.901748 29.670758 51.738925 51.067075 53.249243 52.092235 14.465860 10.192791 0.066692 0.056691 -0.003368 0.000000 0.000000
321 N02 not_connected 100.00% 29.10% 71.43% 0.00% 100.00% 0.00% 10.692224 9.445737 16.647798 16.144639 26.484826 23.420115 34.926466 34.791569 0.462067 0.407950 0.293892 0.000000 0.000000
323 N02 not_connected 100.00% 44.97% 74.07% 0.00% 100.00% 0.00% 23.226669 13.374410 4.486453 20.378540 21.133534 27.497558 4.187193 0.303018 0.382254 0.383952 0.252865 0.000000 0.000000
324 N04 not_connected 100.00% 39.68% 74.07% 0.00% 100.00% 0.00% 15.672314 17.437580 22.875285 24.303249 33.660798 34.210243 -0.742714 -1.270860 0.444640 0.391146 0.293761 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.074578 8.023176 3.534365 15.752456 2.135848 19.287634 13.127103 -1.177034 0.080144 0.080121 0.027257 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.102664 8.029908 13.288105 13.916882 9.594558 17.630559 4.560089 -0.853018 0.079344 0.079089 0.024397 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 10, 15, 16, 18, 19, 20, 21, 27, 28, 30, 32, 33, 36, 37, 38, 42, 45, 46, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 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: [17, 29, 31, 40, 41]

golden_ants: [17, 29, 31, 40, 41]
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_2459788.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 [ ]: