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 = "2459846"
data_path = "/mnt/sn1/2459846"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H6C_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: 9-23-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_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/2459846/zen.2459846.14065.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 117 ant_metrics files matching glob /mnt/sn1/2459846/zen.2459846.?????.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 12 ant_metrics files matching glob /mnt/sn1/2459846/zen.2459846.?????.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 2459846
Date 9-23-2022
LST Range 16.967 -- 21.759 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 124
Total Number of Antennas 128
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 1
dish_ok: 1
RF_maintenance: 30
digital_maintenance: 8
digital_ok: 73
not_connected: 15
Commanded Signal Source None
Antennas in Commanded State 0 / 128 (0.0%)
Cross-Polarized Antennas 104, 116, 124
Total Number of Nodes 11
Nodes Registering 0s
Nodes Not Correlating N05
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 39 / 128 (30.5%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 94 / 128 (73.4%)
Redcal Done? ✅
Redcal Flagged Antennas 6 / 128 (4.7%)
Never Flagged Antennas 28 / 128 (21.9%)
A Priori Good Antennas Flagged 48 / 73 total a priori good antennas:
7, 9, 19, 30, 31, 37, 38, 41, 45, 46, 51, 53,
54, 55, 56, 65, 68, 69, 71, 72, 73, 83, 84,
86, 88, 91, 99, 101, 103, 105, 106, 107, 108,
116, 117, 118, 121, 122, 123, 124, 143, 144,
147, 165, 167, 170, 189, 190
A Priori Bad Antennas Not Flagged 3 / 55 total a priori bad antennas:
90, 137, 138
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/H6C_Notebooks/_rtp_summary_/array_health_table_2459846.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% 33.33% 0.00% 3.558579 -0.632615 -0.640534 -0.684342 0.148281 0.097354 -0.548214 0.077237 0.824188 0.668640 0.504347 1.646536 1.415000
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.921320 5.395661 0.443795 -0.402124 1.979577 1.397617 0.358476 -0.463548 0.838035 0.665488 0.504400 4.208553 4.093162
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.385834 0.230467 0.674282 3.014156 -0.578168 1.494616 -0.357837 -0.757349 0.841419 0.679357 0.500215 1.674341 1.499013
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.986230 -0.982748 -0.538319 0.603679 -0.523192 0.160979 0.365094 6.664838 0.835469 0.675744 0.498484 3.058121 3.099226
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.207880 14.694461 22.948974 23.157427 15.799063 16.297801 0.863005 0.579740 0.829436 0.652819 0.507837 2.828434 2.741803
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.365068 -1.083154 -0.817053 0.901398 4.387449 2.006464 -0.292307 -0.602943 0.838241 0.679569 0.499735 3.990922 3.610166
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.230012 -0.866343 0.758440 0.338094 -0.249136 0.806345 0.143336 -0.111791 0.831251 0.662357 0.515867 1.468997 1.349597
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.380635 0.295768 -0.726186 -0.614366 0.987191 1.495074 2.056270 1.051711 0.844762 0.680836 0.493716 1.808496 1.724982
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -0.753744 -0.664870 -0.078324 -0.900401 -0.565960 0.350472 0.979366 0.823748 0.852650 0.684243 0.489366 1.751752 1.491240
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -0.655302 0.237931 1.327208 0.442799 -0.539828 -0.220644 1.162481 0.464404 0.843030 0.687763 0.485904 1.768852 1.559601
18 N01 RF_maintenance 100.00% 0.00% 65.81% 0.00% 100.00% 0.00% 2.998846 9.426321 -0.172019 0.031654 1.067242 2.967116 7.464999 27.627576 0.831688 0.504308 0.536124 2.880477 1.953996
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.200882 -1.826249 -0.956372 0.151811 -0.936588 1.461068 6.236753 8.454585 0.842451 0.686766 0.487667 3.020690 3.271302
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -1.881871 1.480476 -0.324999 -0.767178 1.489484 -0.169550 0.691584 -0.554768 0.843447 0.673899 0.495323 1.513699 1.346942
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.010828 -0.851527 0.133571 -1.011986 -1.024117 -0.279423 0.042435 1.170224 0.837064 0.676689 0.499182 1.520724 1.230459
22 N06 not_connected 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 35.578893 14.096680 4.054215 11.777233 4.402871 3.035083 9.955665 4.594237 0.648258 0.644831 0.381810 0.000000 0.000000
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.004090 25.827178 33.907271 34.969813 21.584638 20.987600 5.503814 4.284333 0.032193 0.036354 0.004288 1.180922 1.168729
28 N01 RF_maintenance 100.00% 0.00% 74.36% 0.00% 100.00% 0.00% 17.755846 33.659504 1.095263 1.669765 23.097415 23.367480 5.858055 23.459054 0.518171 0.256902 0.318144 9.004889 2.923893
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -1.340245 -1.112266 -0.028908 0.517005 -0.511786 -0.662527 -0.593781 1.396740 0.858668 0.693047 0.470608 1.699104 1.596733
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.053829 -0.874056 2.399603 -0.947547 1.618448 -0.197922 4.141222 -0.039770 0.846494 0.692955 0.471396 3.086520 3.173703
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.509124 -0.976767 -0.766017 -0.853974 1.491774 4.655808 -0.325526 0.616158 0.855046 0.692726 0.485873 2.889798 2.839071
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 23.906404 15.135903 1.671592 3.557778 12.661646 11.613998 12.610499 0.068879 0.745793 0.659751 0.332664 3.639624 3.789819
33 N02 RF_maintenance 100.00% 0.00% 42.74% 0.00% 100.00% 0.00% -0.604296 8.220417 0.355489 0.152724 0.575060 1.939649 1.303794 20.864724 0.840375 0.533147 0.563776 3.443825 1.903633
34 N06 not_connected 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 27.416778 6.596305 14.777133 10.385713 21.659479 1.862991 3.587379 -0.443634 0.036927 0.660694 0.510313 0.812346 1.397902
35 N06 not_connected 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.900613 3.045333 0.166639 8.159847 2.408039 5.268061 2.790109 -0.410503 0.801459 0.653715 0.506951 2.766869 1.417140
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.671358 10.122188 0.013667 0.137950 -1.016965 -0.226916 -0.254662 0.386282 0.831701 0.675324 0.506619 3.727564 2.803578
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.517293 0.825671 -0.856609 1.038547 0.204083 0.559222 0.243454 7.753208 0.841050 0.689426 0.489003 3.339501 2.705539
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.113183 -0.407104 0.556215 -0.817161 5.389748 2.329747 3.851333 2.705202 0.847691 0.697614 0.478169 3.063728 2.802405
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.857040 -0.505797 -0.380302 -0.972944 2.721550 0.989581 -0.531726 -0.805518 0.854338 0.695273 0.471439 1.620644 1.496082
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 25.00% -0.357894 -0.544381 3.588112 0.181481 3.587454 -0.507833 -0.449869 -0.791320 0.858993 0.692320 0.468553 2.451020 1.638586
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -1.303603 0.810121 1.960520 0.484628 -0.879827 -0.702632 -0.696223 -0.597901 0.861799 0.695586 0.474098 1.666949 1.419789
43 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.127344 5.163601 33.275061 13.136849 21.574932 5.816819 4.056913 -0.124090 0.026972 0.059046 0.028137 1.192147 1.210466
44 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 13.060742 1.468255 0.373165 -0.599717 6.358430 0.280780 22.630268 2.930634 0.065461 0.048115 0.002475 1.218483 1.211393
45 N05 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.374879 -0.147548 -0.771726 -0.682890 1.231890 1.375134 -0.298789 11.988057 0.052439 0.044169 0.002562 1.215380 1.209432
46 N05 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.712469 26.363011 2.032376 35.009523 2.013114 20.882197 -0.302327 5.104684 0.059145 0.026792 0.035032 1.193450 1.153493
47 N06 not_connected 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.972810 5.354090 9.014502 9.930665 5.248274 2.665419 3.201899 1.934676 0.831543 0.663307 0.508429 5.078319 3.125179
48 N06 not_connected 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.323195 10.686406 16.743820 18.225408 10.055065 9.471941 -0.553845 -1.246931 0.833441 0.662835 0.510042 5.889580 2.806949
49 N06 not_connected 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.110103 10.127262 10.525768 17.653136 5.495598 11.232130 -0.370876 -0.654894 0.820697 0.652079 0.511812 5.534992 2.511837
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.250435 35.473806 -0.728054 3.964019 2.946619 3.655145 0.260494 3.124575 0.830416 0.589252 0.452646 3.968162 3.032696
51 N03 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 46.100427 3.326902 43.394723 0.450174 21.391674 2.512143 12.280990 2.752928 0.038427 0.698887 0.438964 1.156132 2.862393
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.579192 7.999066 -0.213549 -0.302428 2.946932 0.676763 1.478402 -0.431798 0.850744 0.701584 0.466999 3.311625 2.789124
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.245532 2.675333 -0.015419 0.261378 3.263371 0.989566 39.624800 18.438614 0.856157 0.711606 0.466078 3.087452 2.942563
54 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 24.867707 -1.075278 33.721827 -0.007132 21.664346 1.615530 4.256981 -0.512638 0.045941 0.707062 0.478888 1.610311 3.064664
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 66.67% 1.205725 2.174907 -0.660864 0.080104 1.819713 1.962314 1.849244 -0.354257 0.854147 0.701995 0.453254 3.483374 2.857191
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 33.33% -1.157583 0.419743 1.288037 3.378843 -0.476383 1.469939 -0.222014 1.504795 0.857275 0.707508 0.452050 1.663695 1.443799
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 37.333429 0.826479 12.837631 0.811353 8.768892 2.370139 11.437697 0.780392 0.759990 0.698085 0.385731 4.262421 2.870334
58 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.147604 26.377415 33.702278 35.570169 21.706525 21.096693 5.631938 4.846579 0.029524 0.027587 0.003001 1.217586 1.197340
59 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.210792 3.531416 1.010270 1.399444 4.948944 2.089112 4.175592 3.060530 0.052670 0.055542 0.002570 1.169073 1.178312
60 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.348015 26.168524 33.552259 35.272309 21.656050 21.028721 4.061417 3.992793 0.026686 0.026516 0.001050 1.120180 1.119672
61 N06 not_connected 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.469017 4.914879 6.722091 5.456769 3.384881 3.444247 1.239081 4.490981 0.825504 0.648815 0.513185 3.790749 3.444551
62 N06 not_connected 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.679982 9.981952 14.574493 17.614556 8.251354 11.561971 -0.074927 -0.763383 0.835926 0.662395 0.503689 9.189733 4.121884
63 N06 not_connected 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 8.041099 27.025777 14.287448 15.669648 6.091867 20.969139 -0.078713 3.867649 0.808510 0.040676 0.704609 2.819025 1.167914
64 N06 not_connected 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.902269 8.374706 10.417240 15.403964 4.605181 8.784586 0.845489 -0.841843 0.801880 0.627263 0.525451 4.083223 3.226841
65 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.421979 0.284789 -0.843718 0.467823 5.290601 2.424975 0.238694 0.196202 0.835040 0.681049 0.495467 3.646640 3.469256
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 1.030988 1.562907 -0.026830 0.903306 1.263748 0.288532 0.011499 0.996411 0.845984 0.695727 0.472764 1.569642 1.407474
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -0.106886 -0.875627 -0.033973 -0.998090 0.187234 -0.541512 0.653418 2.239154 0.849595 0.707195 0.463156 1.540838 1.354668
68 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 1.668357 49.428107 -0.105368 46.964832 -0.362105 20.767224 0.235791 11.505540 0.852673 0.029221 0.559943 3.184062 1.158829
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 50.00% -0.558906 -1.230180 1.485447 -0.868910 -0.084726 0.753513 -0.246226 0.541132 0.852684 0.711416 0.451167 2.659541 2.222598
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.578967 -1.745728 0.553534 -0.051104 3.132225 2.544959 0.002540 2.639137 0.858617 0.683791 0.456133 14.942183 8.146350
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 66.67% -0.518460 -1.037784 -0.674699 0.257493 -1.122219 -0.616805 -0.603522 -0.498896 0.853594 0.717659 0.446518 11.496152 7.932338
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.740728 -0.843480 0.231330 2.513828 0.256139 0.733640 1.749586 -0.703331 0.855339 0.708115 0.443610 3.560158 2.900062
73 N05 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.030311 -1.035895 33.364030 -0.539875 21.448598 0.380253 5.623196 -0.115973 0.027505 0.061229 0.025553 1.188424 1.214198
74 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.311863 25.608843 34.390047 35.234877 22.010082 20.712446 4.373940 5.779312 0.026134 0.048933 0.013999 1.141582 1.159530
75 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.694334 26.793148 8.911259 35.810377 1.574871 21.226094 8.271986 4.969622 0.039165 0.031446 0.031747 0.967350 0.925661
77 N06 not_connected 100.00% 0.00% 42.74% 0.00% 100.00% 0.00% 23.991533 26.858230 14.175578 11.046340 14.393575 14.793259 7.921027 1.799559 0.760304 0.537635 0.375130 4.573973 2.692753
78 N06 not_connected 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 35.644619 6.379568 10.571478 14.335699 14.940228 7.876759 1.186101 -0.529771 0.637173 0.637062 0.371693 1.572709 1.797315
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.407666 0.049255 0.158836 0.006651 0.600960 -0.141178 0.345239 -0.462297 0.827039 0.663688 0.504531 1.549903 1.482451
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.159681 1.185216 4.368566 4.983391 1.408420 1.412272 0.119836 1.126800 0.837141 0.675086 0.480631 3.725633 3.539333
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.551615 1.171436 4.966292 1.957238 2.324351 1.556854 -0.897180 -0.252425 0.848633 0.700089 0.468191 3.268942 3.306635
84 N08 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 10.730701 46.128872 0.273712 45.387903 -1.183988 20.727381 -0.659062 7.113025 0.857714 0.039418 0.708728 3.568027 1.186962
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.028253 -0.025898 0.443296 0.819595 -0.185583 -0.876291 -0.665843 -0.866190 0.849893 0.705510 0.459305 1.435143 1.344681
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.248034 4.655762 1.211306 1.559942 8.753162 0.909992 0.595343 14.804059 0.854033 0.676515 0.460544 3.160951 2.570973
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.513600 10.322612 3.780124 5.436814 16.771175 2.988278 0.305549 1.970786 0.800654 0.711922 0.396309 2.809987 2.846349
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.814598 4.507033 15.247957 9.793777 7.970674 1.889410 -1.074092 -0.823035 0.852313 0.710322 0.444492 3.324074 2.642431
89 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.000400 0.524591 7.261464 2.002596 -0.135824 0.191066 -0.874323 -0.421131 0.858344 0.690736 0.472363 3.359310 2.589088
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.360168 -0.055084 1.189698 0.002578 -0.775925 -0.455071 -0.142834 2.164960 0.845654 0.688964 0.468927 3.032596 2.390581
91 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.392863 5.534612 13.138549 13.665675 4.593350 5.655042 -0.200778 -0.349421 0.851524 0.690279 0.476128 2.144538 1.766391
98 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.176759 3.067083 0.353906 -0.683303 -0.553929 0.737738 -0.176088 0.977836 0.816981 0.651161 0.505319 1.617979 1.474150
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.650740 0.825917 11.736725 0.552707 5.873634 2.634158 1.780851 -0.631871 0.802771 0.670197 0.482327 2.937043 3.712209
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.473981 -0.398529 -0.911228 0.906301 3.471240 0.688301 0.378743 -0.128771 0.842807 0.679432 0.484140 1.505269 1.497679
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.532143 11.862230 6.958799 2.839199 -0.034064 -0.285205 -0.108121 -0.591264 0.853611 0.698534 0.464132 3.640928 3.260250
102 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 14.106916 27.547818 28.646314 35.663267 7.864275 21.182311 7.650445 7.112148 0.689918 0.037244 0.595822 1.942140 1.306702
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 43.886215 46.013345 38.551211 40.032485 22.180393 21.548044 10.269394 10.110280 0.026537 0.029335 0.002973 1.194735 1.197232
104 N08 RF_maintenance 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 7.836939 83.266690 -0.154961 22.031596 0.182483 2.325466 0.495986 0.802402 0.432699 0.397560 -0.242177 2.182022 2.022954
105 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.677686 2.307573 1.313227 5.131481 2.648671 1.131405 0.137408 -0.305806 0.845226 0.701066 0.459866 2.906655 2.413451
106 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.919831 6.142071 -0.872417 12.992412 2.998140 4.410051 0.509805 -1.160102 0.848956 0.704015 0.453478 2.956756 2.367870
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.507993 8.095801 1.034256 0.782703 0.282405 2.064662 1.439748 2.672538 0.845952 0.688765 0.453383 3.281186 2.374652
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.615865 4.669559 29.905259 0.739301 11.080025 0.133530 2.796807 -0.047002 0.599247 0.686673 0.436564 1.088799 1.774993
116 N07 digital_ok 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 4.173540 0.557674 3.052406 -0.327359 4.079839 0.896951 0.778398 0.401146 0.360810 0.362197 -0.283344 2.378685 2.373066
117 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.055186 28.489655 33.915947 36.343318 21.851918 21.191096 3.828109 4.726425 0.027243 0.028395 0.001274 1.188304 1.191179
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.808995 1.030469 4.178129 1.354162 0.650874 0.569206 -0.005302 -0.312023 0.841643 0.672914 0.490715 3.377856 2.928196
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.462220 1.075507 9.404547 1.332487 3.202215 19.738208 -0.854125 3.074125 0.848980 0.659997 0.496652 3.385852 2.560848
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 3.538631 44.247154 0.364677 45.138528 3.730733 20.954896 -0.332493 10.443445 0.852012 0.036417 0.739449 3.455541 1.222357
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.013751 7.167423 -0.503091 0.273853 -0.691469 0.207263 32.563660 10.361528 0.853189 0.691661 0.487490 3.332172 2.561544
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.873618 10.772426 0.535851 0.353208 1.161838 -0.715829 0.906229 -0.776305 0.853050 0.695999 0.473923 3.397692 2.514401
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.408470 12.813623 3.850362 0.472398 -1.180999 1.193353 -0.800207 -0.457030 0.855061 0.700872 0.478083 3.344816 2.430027
124 N09 digital_ok 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 2.356642 6.703070 4.199548 14.776620 0.787953 7.037446 1.435753 -0.773459 0.422688 0.427168 -0.245402 1.075785 1.214983
125 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.202014 0.789569 -0.545498 3.233795 -0.704235 -0.353081 -0.317289 -0.823952 0.842988 0.692558 0.462678 2.623262 1.987964
126 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 31.613834 2.843783 1.879060 0.344345 4.155497 -0.391658 2.713002 -0.622161 0.782526 0.681347 0.412302 4.027612 5.561768
137 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.717028 -0.457778 1.136046 -0.645827 1.085337 2.519503 1.663688 0.177895 0.830689 0.643689 0.503724 3.220471 2.514525
138 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.783086 0.719264 -0.770470 -0.363511 -0.686454 0.743720 1.812772 -0.979451 0.834660 0.657716 0.504009 3.211723 2.479178
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 66.67% 0.118819 -1.164993 -0.837006 -0.131614 0.797236 2.410393 -0.189471 -0.683139 0.838048 0.687867 0.464040 3.912020 3.553263
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -2.088617 -0.407114 0.308201 0.979163 -0.693941 0.256880 1.423322 18.073244 0.842899 0.681732 0.466215 4.829895 4.208223
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.598044 26.921482 34.110751 35.623202 21.700307 21.054441 4.910120 5.170811 0.030317 0.026220 0.002841 1.105052 1.102850
147 N15 digital_ok 100.00% 25.64% 34.19% 0.00% 100.00% 0.00% 18.099499 7.628266 0.293158 0.582327 59.837402 60.040709 45.031812 -0.626038 0.800836 0.542109 0.512837 4.245052 3.547342
148 N15 RF_maintenance 100.00% 25.64% 34.19% 0.00% 100.00% 0.00% 7.359668 6.708104 0.997587 0.332676 59.480079 60.049559 -0.527660 -0.696425 0.810252 0.537695 0.528638 4.428620 3.424823
149 N15 RF_maintenance 100.00% 25.64% 100.00% 0.00% 100.00% 0.00% 6.674858 28.564584 0.917835 39.798567 59.482302 60.427010 -0.219920 4.626099 0.810085 0.030309 0.630527 4.530593 1.328764
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.821928 26.462408 33.870474 35.406453 21.635094 21.049575 5.333480 4.993361 0.026040 0.027177 0.000061 1.282803 1.265103
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 1.255008 0.109983 0.419487 -0.869708 -0.822403 0.485884 -0.202431 1.642427 0.837289 0.671776 0.491257 1.680339 1.406950
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -0.684111 -1.101526 0.837286 -0.002578 -1.272141 0.786389 0.001935 1.803352 0.835856 0.675443 0.490364 1.857479 1.484431
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.743532 1.307854 7.021879 0.104087 0.015278 -0.475193 -0.289422 -0.399885 0.838923 0.677591 0.488813 3.983954 3.898741
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.871343 14.699557 0.684197 0.968011 6.549962 9.127822 7.136997 0.783860 0.810571 0.593498 0.455478 5.817767 4.344015
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 62.305189 48.607562 4.669849 3.323381 12.424158 8.814488 26.846160 24.781759 0.676873 0.599231 0.344845 3.201487 3.698195
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.057513 3.908429 0.603710 5.968341 0.086005 2.043610 0.074741 -0.484297 0.828471 0.679628 0.501847 4.163545 4.223727
169 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.757009 3.143167 1.597946 1.267917 0.286026 0.067565 -0.829863 -0.001935 0.829973 0.658000 0.519035 1.339640 1.215308
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.113348 1.473106 6.426188 -0.774004 0.398826 -0.644624 1.339633 1.009461 0.825035 0.663003 0.518829 4.350411 4.303622
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -0.333441 -1.336173 0.868488 -0.568646 0.573825 -0.268417 -0.238041 -0.833286 0.829990 0.661137 0.506286 2.083489 1.547236
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -0.456652 -0.579379 0.813639 -0.765152 -0.403107 -0.467929 -0.532771 -0.894398 0.830607 0.664701 0.498739 1.803902 1.478754
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 0.753532 -0.103685 -0.629338 -0.036919 1.290528 -0.388657 0.705068 -0.800124 0.823192 0.664996 0.498775 1.588391 1.497733
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% 1.042534 0.878134 0.077012 -0.119089 -0.358275 -0.804768 1.525157 1.195103 0.825358 0.670408 0.497085 1.379311 1.208199
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.893255 3.185744 0.022831 0.979814 0.147067 1.396093 0.023126 5.004374 0.818690 0.658448 0.514441 4.796044 4.730632
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 66.617416 28.995929 4.519809 35.497001 14.575075 54.975866 44.602103 391.683176 0.615134 0.030887 0.468283 3.757451 1.365257
191 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 33.33% 0.00% -0.816422 -0.010828 -0.982030 -0.335259 1.756592 -0.067565 2.445980 1.135721 0.813361 0.650507 0.527989 1.359761 1.185385
320 N03 dish_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 7.399930 28.736012 14.681595 23.129290 8.852422 20.882745 2.855991 5.061004 0.841647 0.050948 0.588365 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 17.09% 0.00% 100.00% 0.00% 6.005300 5.895377 12.930229 13.763592 8.467315 9.359257 0.813141 0.162129 0.724241 0.456395 0.518757 0.000000 0.000000
322 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 8.323945 11.942828 14.510467 19.818536 8.327456 13.390039 -0.311703 -0.698620 0.063995 0.055125 0.015661 0.000000 0.000000
323 N02 not_connected 100.00% 17.09% 34.19% 0.00% 100.00% 0.00% 30.432884 10.296922 1.228641 18.458518 10.374305 12.871726 4.305911 -0.694339 0.543415 0.433532 0.360841 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 17.09% 0.00% 100.00% 0.00% 8.996056 11.616991 17.130627 18.647242 9.137283 11.614121 -0.013364 -0.764217 0.717587 0.454669 0.498678 0.000000 0.000000
325 N09 dish_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.626219 4.821771 17.307859 10.888887 9.955322 4.044654 -0.364619 -0.592090 0.736885 0.478433 0.523922 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, 17, 18, 19, 20, 21, 22, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 77, 78, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 137, 138, 143, 144, 145, 147, 148, 149, 150, 163, 164, 165, 166, 167, 168, 169, 170, 184, 185, 186, 187, 189, 190, 191, 320, 321, 322, 323, 324, 325]

unflagged_ants: []

golden_ants: []
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/H6C_Notebooks/_rtp_summary_/rtp_summary_table_2459846.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.4.dev8+g8ce4cac
3.1.5.dev74+gf9d2808
In [ ]: