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 = "2459815"
data_path = "/mnt/sn1/2459815"
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: 8-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/2459815/zen.2459815.25319.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

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

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 372 ant_metrics files matching glob /mnt/sn1/2459815/zen.2459815.?????.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/2459815/zen.2459815.?????.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 2459815
Date 8-23-2022
LST Range 17.638 -- 19.638 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 372
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 32
RF_ok: 11
digital_maintenance: 3
digital_ok: 95
not_connected: 3
Commanded Signal Source None
Antennas in Commanded State 0 / 147 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N10
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 53 / 147 (36.1%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 101 / 147 (68.7%)
Redcal Done? ✅
Redcal Flagged Antennas 15 / 147 (10.2%)
Never Flagged Antennas 25 / 147 (17.0%)
A Priori Good Antennas Flagged 73 / 95 total a priori good antennas:
3, 5, 7, 9, 17, 19, 30, 37, 38, 40, 41, 42,
45, 51, 53, 54, 55, 56, 67, 68, 69, 71, 72,
73, 81, 83, 84, 85, 86, 88, 91, 93, 94, 98,
99, 101, 103, 105, 106, 107, 108, 109, 111,
112, 117, 118, 121, 122, 123, 127, 128, 129,
130, 140, 141, 142, 144, 156, 158, 160, 161,
165, 167, 169, 170, 177, 179, 181, 186, 187,
189, 190, 191
A Priori Bad Antennas Not Flagged 3 / 52 total a priori bad antennas:
82, 90, 135
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H6C_Notebooks/_rtp_summary_/array_health_table_2459815.csv

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
4 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
5 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.849538 -1.133814 -0.057536 -0.077464 -0.997266 0.578301 1.387095 11.788509 0.787738 0.644611 0.530517 3.648068 3.332572
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.529131 15.376366 18.797550 19.211019 33.402555 34.686216 4.647580 0.304685 0.773695 0.608777 0.535590 3.487289 3.589427
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 26.32% -0.722878 -1.534154 -0.020255 -0.487287 0.599682 -0.045855 -0.147221 0.349153 0.781673 0.620902 0.537825 2.561571 2.016228
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.535116 -0.674818 -1.090450 -0.165912 -0.449308 -0.609965 3.356802 0.519143 0.770009 0.604496 0.543798 1.882574 1.735115
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.513661 1.028076 -0.903242 -0.967872 -1.150224 -0.164079 -0.354755 0.367564 0.793809 0.643640 0.534396 2.330361 2.262183
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.190125 -1.207350 -0.329792 -1.158658 -1.034274 -1.346651 3.129830 1.394306 0.796595 0.659372 0.528708 2.394434 2.140082
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 7.89% 0.098425 1.149227 0.563917 0.680574 0.935486 0.749757 2.463632 1.871267 0.801325 0.662779 0.519951 2.400132 2.296515
18 N01 RF_maintenance 100.00% 0.00% 54.30% 0.00% 100.00% 0.00% 4.518201 4.123712 2.962983 -0.560859 5.668644 5.881605 19.700082 65.160655 0.787783 0.481489 0.587862 3.759527 2.121328
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.892833 10.437208 -1.145258 14.712814 -0.631522 24.068558 11.610078 2.212559 0.798973 0.655005 0.524495 3.946545 3.701515
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.727968 0.658773 -0.251001 -0.668408 -0.413518 1.355635 2.112524 1.336944 0.791443 0.635745 0.521283 1.992171 1.900335
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.085226 1.794464 1.058119 0.978280 -0.646748 2.228470 1.665242 0.322324 0.781496 0.619790 0.541036 2.085372 1.896170
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.860942 24.576314 47.088315 47.840239 47.677754 48.107964 12.413623 10.978550 0.038977 0.044390 0.003094 1.195399 1.204022
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 13.985578 16.305540 4.190103 5.705753 42.888180 47.652189 17.307397 54.497215 0.492987 0.252464 0.334038 17.645247 3.186473
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.864405 0.276897 -0.079984 -0.533033 -1.091927 -0.711156 -0.644913 0.924475 0.815316 0.684887 0.515705 2.329289 2.417322
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.472592 -0.128359 0.307634 -1.010720 0.924300 1.454898 8.258613 1.551020 0.810700 0.682759 0.509147 4.410142 4.682017
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.513806 -0.947110 -1.127263 -0.537534 1.903547 2.156308 2.411232 3.623885 0.811685 0.674005 0.524169 2.076089 1.965279
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 36.414833 30.598530 2.588430 2.009225 10.960552 12.446353 33.521336 42.781157 0.744004 0.607634 0.350865 8.593179 7.380487
33 N02 RF_maintenance 100.00% 0.00% 51.61% 0.00% 100.00% 0.00% 0.653517 3.916170 0.900670 -0.583486 16.867358 16.309160 138.636285 147.395397 0.788296 0.492275 0.617813 4.633252 2.180501
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.678501 6.336392 0.215336 -0.103265 1.558218 0.607199 0.003176 0.996903 0.787422 0.646723 0.523233 3.275533 2.780819
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.453756 0.924714 -1.008295 -0.684787 -0.834673 -1.031410 0.122985 17.181785 0.799744 0.663178 0.516271 3.139440 2.997296
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.721426 -0.249628 -0.928753 -1.112368 1.078228 0.404074 11.868679 3.426192 0.806136 0.681716 0.508249 3.286512 2.950392
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.592134 -0.292103 -0.123588 -0.281731 1.085330 0.144075 -0.259128 0.147601 0.812667 0.695108 0.493619 2.485538 2.143542
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.006053 -0.805317 1.384193 1.374784 2.417811 -0.464571 -0.446046 1.231316 0.820957 0.702093 0.497806 2.446475 2.096539
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 23.68% -0.831144 0.248914 1.417907 1.036181 -0.153947 -0.395628 -1.079795 -0.011804 0.821359 0.699246 0.507323 2.480222 2.153053
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.200291 0.405767 -1.112803 0.640592 -0.858784 -0.729421 0.183824 11.516964 0.804999 0.660617 0.532724 3.453919 2.859153
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.913187 -0.471808 0.591265 -0.918381 -1.107928 -0.480856 -0.690895 3.315403 0.797404 0.641653 0.550659 1.854552 1.612947
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.824706 7.166827 -0.605997 0.864071 -0.507698 6.347831 0.655110 9.739649 0.786255 0.615094 0.484205 3.591886 2.965662
51 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.819192 2.132550 -0.959660 -0.118302 2.117951 0.649659 0.533906 4.909612 0.804076 0.684243 0.497702 3.729318 3.357534
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.374297 5.974706 -0.200005 -0.097487 1.162073 0.327081 1.793406 2.600394 0.816562 0.697683 0.493236 3.621074 3.210298
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.398025 1.400413 -0.940438 -0.058122 -0.216182 0.782434 4.675129 12.384381 0.822496 0.717283 0.487760 3.817203 3.957941
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 15.79% 0.907491 -0.279332 1.684638 0.884186 0.885119 0.856075 0.955164 -0.233047 0.827657 0.717576 0.489225 2.264774 2.076999
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 2.516680 0.102842 0.815914 0.647839 0.924670 0.256813 0.407786 -0.398321 0.834678 0.724018 0.499259 4.549346 5.171850
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 84.21% -0.921469 0.671826 1.076408 1.546889 1.639803 0.605793 -0.823460 0.023783 0.830420 0.720316 0.492276 3.911494 3.510190
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 27.131631 -1.638879 18.472531 0.265281 16.974436 0.702329 18.125497 1.340584 0.707050 0.704178 0.370941 5.266770 3.043185
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.502299 0.311024 -0.055417 0.956659 0.228638 0.399638 -0.527083 1.119844 0.798001 0.657472 0.515604 1.650544 1.447447
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.390019 -0.242433 -0.403591 0.335547 1.696799 1.313180 -0.334758 2.702845 0.809046 0.693571 0.492072 1.664877 1.424915
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.964566 -0.502344 -0.746088 -0.786784 0.944286 0.965096 1.555155 6.945844 0.822038 0.716433 0.476339 4.890460 6.771755
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 7.89% 0.938687 0.637395 0.198746 -0.536887 0.641127 1.480487 -0.418399 -0.362734 0.827371 0.731825 0.464825 2.003624 1.864972
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 81.58% 0.697577 -0.366405 -0.106298 0.223352 -0.333193 1.768103 -0.529502 1.722094 0.837165 0.735097 0.483976 4.930755 4.817696
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.706013 -1.510710 0.930838 -1.051218 -0.109787 -0.831083 -0.574194 1.136299 0.833252 0.729324 0.487450 27.932917 30.260263
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.769695 -1.063788 -0.257856 -0.767497 0.325083 -0.797740 -0.303506 0.295587 0.833828 0.735456 0.473747 39.477257 22.351573
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 57.89% 2.455962 -0.823916 -0.847435 1.503651 1.016628 1.342223 3.891432 -1.152500 0.825329 0.713420 0.495579 3.180371 2.697083
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 21.974665 0.379776 46.318158 -0.409018 47.499492 0.392475 8.381601 2.695237 0.033554 0.693242 0.402368 1.183698 2.968552
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.262832 2.700046 -0.379715 3.116586 0.025175 5.108778 1.166067 0.404472 0.791194 0.652298 0.500835 3.847112 3.683272
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.048616 -0.248756 0.512301 0.291736 2.310887 -0.601431 0.663509 -0.486092 0.809623 0.683638 0.501935 4.101606 3.314940
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.160645 3.117079 2.078628 4.478247 1.030457 3.320691 -1.152183 -1.411663 0.820112 0.712735 0.476723 3.587119 3.852336
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.321450 9.109864 -0.076577 0.978449 -0.658873 0.913709 -0.558162 2.278572 0.831594 0.728084 0.457752 4.648080 4.731117
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 42.11% 0.538403 0.361197 -0.975091 -0.688764 -1.223639 -1.628758 -0.860117 -0.666073 0.836261 0.737021 0.477621 1.868253 1.691892
86 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 76.32% 2.606289 2.565753 1.423244 -0.740439 0.136116 1.195632 -1.093265 -0.805310 0.832949 0.717456 0.475018 3.625878 2.817382
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 33.367754 11.189604 2.322309 1.198971 13.779631 0.978215 5.090625 2.363882 0.753658 0.731191 0.399912 4.214129 3.203934
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 19.135062 16.683558 22.600004 20.267679 41.503560 36.379278 7.580792 0.839155 0.790542 0.698959 0.501817 2.958694 2.835388
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.116285 -0.161870 1.111160 0.745176 0.346979 -0.737192 -0.353719 -0.211704 0.811386 0.676708 0.535120 3.525619 3.031470
91 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.753017 17.838880 20.582688 21.217959 37.001820 38.686814 2.668652 2.255512 0.776435 0.630632 0.556655 3.020291 2.626721
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 35.563098 48.452344 6.823200 8.658047 45.669338 52.084385 9.438175 21.076138 0.105638 0.099725 0.013872 12.746385 4.334269
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.717108 -0.907083 3.013896 0.294161 3.512655 -0.770688 5.627091 -0.834835 0.079787 0.091242 0.011700 0.944238 0.945807
94 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.236784 -0.206881 -0.647617 -1.052641 -0.517516 2.021268 4.128146 8.468923 0.087554 0.094645 0.013655 0.000000 0.000000
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.584473 3.400186 -0.444969 3.993078 9.096844 0.421178 393.177359 3.162789 0.795192 0.640834 0.516787 3.970356 3.486497
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.938268 0.577570 3.153737 0.629725 5.121202 -0.239017 1.745497 -0.181148 0.808547 0.678416 0.501271 4.207499 4.360713
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.631198 -0.247945 -0.333098 -0.193142 -0.512159 -0.441975 0.374441 0.062785 0.821104 0.700226 0.498836 1.854439 1.583773
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.163362 8.859319 3.305663 -0.126906 1.728236 -0.741914 3.602172 0.355829 0.832973 0.719509 0.483308 3.916850 3.608046
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.829338 5.552004 28.092986 28.284872 152.629665 166.212545 1090.108155 1150.229354 0.739624 0.647099 0.462067 2.546013 2.759016
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.914787 9.365810 -0.577414 0.130530 -0.275381 -0.569039 -0.315643 -0.287522 0.831458 0.729551 0.480883 3.432757 3.266843
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.968738 74.670059 -0.147165 13.581321 1.043753 6.193939 0.167395 0.459771 0.834602 0.722356 0.506208 3.779575 3.424646
105 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.899158 8.683949 7.657850 12.508548 10.153940 19.566413 -0.657611 -1.505717 0.827444 0.713187 0.506010 3.669672 3.285104
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% 25.752522 26.423453 3.450275 47.280624 44.500087 48.139328 12.924111 9.821614 0.241504 0.046440 0.111746 1.924711 1.215197
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.275801 4.277181 3.165362 1.419716 1.070968 0.558477 0.252833 0.007967 0.794640 0.664070 0.534780 3.914345 3.351348
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.721976 0.417380 0.020255 0.983664 -1.093266 1.162364 -0.804363 0.011804 0.081889 0.079230 0.014874 1.407782 1.405488
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 44.466769 1.594769 3.707334 1.362512 8.229055 -0.859494 0.540230 -0.170315 0.092097 0.073561 0.006923 0.000000 0.000000
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.040584 0.747905 -0.394170 0.652280 0.389494 2.023717 -0.264026 1.954130 0.063254 0.074283 0.005501 1.196668 1.200077
112 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.674690 -0.093858 -0.568554 0.125450 -0.141303 -1.397788 -0.575744 -1.016663 0.074613 0.082351 0.010808 1.454408 1.453262
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.773452 1.813659 0.402587 -0.779504 -0.900169 -0.061026 1.772941 -0.496083 0.793429 0.650133 0.518049 1.893688 1.571437
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.575080 1.625580 4.506063 3.781480 5.184006 3.775781 -1.242848 -1.124100 0.806048 0.669883 0.515836 5.083047 5.274326
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 3.101329 25.153446 2.568122 42.247765 1.947453 48.235579 -0.514039 7.100405 0.817424 0.049920 0.591430 5.196134 1.238075
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.940758 1.351282 9.038917 0.545751 12.811115 -0.471450 -1.991336 -0.869508 0.828017 0.699586 0.510753 3.823138 3.395657
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 18.216808 31.134251 6.035245 53.161023 40.322042 48.805830 5.769161 18.083269 0.521957 0.057392 0.413694 2.835997 1.198748
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.906043 5.590731 -0.783711 0.317560 -0.575916 1.441923 54.182765 27.450252 0.828582 0.718383 0.482738 3.575354 3.430057
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.515087 7.327675 1.446847 0.980544 0.005883 -0.062579 0.110202 0.427404 0.826708 0.714021 0.489731 4.475268 4.007532
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.322012 8.284675 -0.255363 -0.141082 -1.329526 -1.102115 0.879971 1.804947 0.824093 0.713459 0.498659 6.638338 5.536469
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
127 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.060847 0.035110 0.628872 -0.055618 0.639524 1.103584 0.089581 0.725200 0.093676 0.091983 0.017986 1.354813 1.336793
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.014746 1.445049 -0.455150 0.706598 0.137481 0.357866 -0.516537 -0.749442 0.083467 0.070440 0.010405 1.454787 1.459798
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.249800 -1.088104 0.816056 0.940531 -0.415694 -0.611183 -1.202429 -0.682908 0.064555 0.076304 0.008243 1.462996 1.462802
130 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.726572 0.585766 0.769792 1.574264 0.894724 1.249338 0.208697 6.302616 0.090531 0.085085 0.013141 1.345843 1.326520
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.774894 -0.157807 -1.127003 -1.055108 -1.142892 -1.524181 2.097582 0.299673 0.789299 0.637601 0.533452 4.830366 3.942608
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.516931 11.230132 -0.697190 0.256519 2.423366 3.337942 2.460718 3.709576 0.797619 0.640370 0.510575 6.349600 5.789601
137 N07 RF_maintenance 100.00% 54.30% 100.00% 0.00% 100.00% 0.00% 20.196463 29.462108 21.680279 40.867496 45.356908 48.390769 6.691674 13.923821 0.441521 0.055825 0.271986 3.512073 1.292756
138 N07 RF_maintenance 100.00% 100.00% 51.61% 0.00% 100.00% 0.00% 24.055695 16.854924 37.957484 0.835555 48.043612 48.654400 11.602949 11.565582 0.047724 0.456845 0.279089 1.287841 3.657963
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.991770 20.716518 46.099745 48.078683 47.514231 48.012702 7.733368 8.477660 0.040700 0.042931 0.000523 1.167177 1.156142
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.943898 5.489737 -0.577549 9.436945 0.479744 4.501106 1.400733 27.127667 0.816587 0.688493 0.500551 7.050746 5.855479
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 22.157926 26.482324 5.151574 48.312660 45.356013 48.191162 8.957006 10.893870 0.510998 0.042626 0.325904 13.768105 1.390612
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.117660 -1.457066 1.591755 0.415509 1.212045 0.156415 -0.158918 -1.127915 0.809990 0.698141 0.501417 1.577629 1.238277
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.227241 -0.741000 1.448922 -0.752287 -0.952240 -0.182320 1.196145 8.946302 0.805970 0.685646 0.509863 15.492003 11.525141
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.204027 22.718451 47.408158 48.682536 47.690563 47.853808 10.631553 14.565946 0.034917 0.036923 -0.000267 1.492571 1.496470
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.149763 24.473655 47.242131 49.574645 47.987564 48.384092 12.243501 13.937395 0.043558 0.044716 0.001357 1.130002 1.130839
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.617334 22.381697 46.219540 47.700309 47.464703 47.607568 11.453277 13.797554 0.043894 0.043566 0.001132 1.306944 1.310199
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.694582 1.494820 0.892947 0.169721 -0.493406 0.329905 6.593569 15.884047 0.795015 0.634799 0.532035 5.385873 5.048526
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.241415 0.712567 -0.337809 2.710010 0.120091 1.502206 0.365129 -1.018535 0.799145 0.659762 0.529918 1.620873 1.342006
158 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.071502 -1.058962 -1.005434 -1.092765 -0.033663 -0.297204 1.975175 5.673784 0.801471 0.662051 0.521942 4.184682 4.787668
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.456407 20.274497 46.893999 48.133877 47.672105 48.031407 11.402206 14.064979 0.041966 0.043034 0.000946 1.206402 1.206572
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.449172 42.200971 -0.601028 3.448751 -0.694312 11.988252 0.340821 4.510820 0.798608 0.604266 0.456965 3.557594 5.005712
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.665125 0.335256 -0.997278 -0.748307 1.015074 0.045855 2.987881 1.517403 0.799728 0.673818 0.507137 2.103498 1.947709
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.253947 -0.306894 -0.028162 -0.293744 -0.494246 -0.715435 -0.085276 2.316710 0.800053 0.680186 0.504250 2.224198 2.052190
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.296362 -1.268657 -1.209108 -0.442444 -1.350061 -0.359713 -0.093713 1.259115 0.798511 0.674725 0.513554 2.286386 2.171537
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.608348 1.809280 6.511281 -0.908342 7.356672 -1.722675 1.208993 0.147044 0.794554 0.668141 0.509430 4.716936 6.134356
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.411679 2.346895 -0.170019 1.477604 11.650244 4.174514 107.355495 9.002086 0.764816 0.652095 0.473199 6.748523 5.394765
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.222447 20.103678 15.321920 18.922541 37.038386 38.647922 9.070658 5.889027 0.673150 0.536957 0.349146 4.120304 2.905525
168 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
170 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.089380 -0.674291 -1.026684 0.373720 -0.155130 -0.097269 -0.661615 -0.647945 0.788040 0.617725 0.549817 1.688523 1.327031
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.683024 1.241895 0.911357 0.166583 -0.581248 -0.028042 1.489737 7.664620 0.784202 0.627098 0.536586 5.893454 6.830163
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.094546 -1.718239 0.837612 -0.856043 0.447253 -0.479872 -0.349193 -0.850308 0.789287 0.644001 0.530031 1.515157 1.390313
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.385011 0.014002 -0.761165 -0.044224 4.543640 -0.069163 6.629410 -0.303116 0.789554 0.652306 0.529977 3.157788 3.126359
180 N13 RF_maintenance 100.00% 0.00% 59.68% 0.00% 100.00% 0.00% 0.611940 14.980339 -0.039082 43.874762 -0.576999 32.928818 -0.523747 9.906970 0.791576 0.430263 0.600310 28.230084 5.226160
181 N13 digital_ok 100.00% 100.00% 67.74% 0.00% 100.00% 0.00% 22.445403 50.190764 47.555119 4.445810 47.704914 50.461144 10.839774 13.808556 0.045800 0.345497 0.192833 1.198052 2.695592
182 N13 RF_maintenance 100.00% 0.00% 65.05% 0.00% 100.00% 0.00% 14.701544 21.257362 19.086652 45.458950 33.629448 39.355068 2.277924 10.472590 0.778997 0.351574 0.575302 4.090111 1.742145
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.689415 -0.966766 0.222064 -1.070037 -0.679495 -2.256553 -0.456369 2.438038 0.795671 0.666623 0.517391 2.074439 1.942595
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.858994 0.006053 0.302605 0.551833 -0.311206 0.669486 1.741462 -0.333954 0.795064 0.670552 0.509684 2.257748 1.977867
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.746553 0.491522 0.980881 0.996544 -0.079801 0.646272 2.917438 -0.529572 0.793554 0.662240 0.516445 2.146286 1.839843
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.782075 0.145414 4.729947 2.602949 1.634614 0.539728 2.521961 0.066166 0.780267 0.646389 0.511093 3.571600 3.643232
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 47.37% 0.605913 0.958179 0.418816 0.399341 -0.117494 -1.534025 1.727269 1.024652 0.775536 0.643239 0.511480 0.788450 0.769167
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.780898 4.268780 0.428453 1.764857 0.300785 1.043468 1.433694 20.554176 0.755248 0.592599 0.537122 4.873546 3.757913
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 41.071773 25.125147 3.929624 48.688937 19.088373 48.155475 12.763033 13.215234 0.633063 0.041509 0.456419 2.466737 0.969552
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.514412 2.435013 -0.723633 9.062581 0.237968 4.012886 0.101451 11.109548 0.742328 0.551944 0.558362 3.292216 2.470246
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% 21.878702 20.282514 12.260355 0.701693 23.396880 7.354664 37.000830 43.231521 0.764800 0.598962 0.522896 5.022010 3.909223
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.859239 19.406050 2.652168 8.600024 9.263705 16.900467 35.904957 39.077260 0.752265 0.607919 0.520490 2.898272 2.942432
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 24.081011 21.233487 14.682765 11.682687 28.918780 22.542756 15.801420 16.099447 0.740357 0.592922 0.518809 6.155521 4.667084
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% 39.485871 39.738021 inf inf 3309.073217 3899.209702 15613.183532 21208.882312 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.847416 18.556090 7.456217 7.101463 13.668889 12.033236 0.143735 4.432160 0.755659 0.599475 0.531784 3.619625 3.021642
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 30.745597 30.808636 22.603195 22.235513 43.437906 42.925476 2.433762 1.261764 0.705887 0.551011 0.510970 2.792786 2.621117
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% 39.006964 39.242074 inf inf 4554.766296 4554.500720 25177.921936 25179.314191 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.033786 25.348053 34.119726 34.432579 47.798244 47.865286 17.179873 12.400096 0.058266 0.054866 -0.000211 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 53.76% 0.00% 100.00% 0.00% 9.005730 7.094535 12.592213 11.528141 22.662342 20.181137 43.392374 43.747550 0.646694 0.408136 0.488789 0.000000 0.000000
323 N02 not_connected 100.00% 0.00% 64.52% 0.00% 100.00% 0.00% 19.008928 10.518897 1.269312 15.002133 17.922835 24.798699 5.624210 0.781966 0.528184 0.370459 0.392165 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 53.76% 0.00% 100.00% 0.00% 12.729166 8.040191 16.207891 10.364802 29.083933 17.668878 -0.676393 -1.110901 0.653549 0.415530 0.500206 0.000000 0.000000
329 N12 dish_maintenance 100.00% 0.00% 56.45% 0.00% 100.00% 0.00% 2.708597 6.177977 2.116012 10.351583 7.361038 16.722130 7.795138 -0.305573 0.614255 0.403122 0.460901 0.000000 0.000000
333 N12 dish_maintenance 100.00% 0.00% 64.52% 0.00% 100.00% 0.00% 2.427937 5.908735 1.159980 9.653368 5.457638 15.128737 3.514852 -0.787395 0.591410 0.369754 0.447091 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, 17, 18, 19, 27, 28, 30, 32, 33, 36, 37, 38, 40, 41, 42, 45, 50, 51, 52, 53, 54, 55, 56, 57, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 144, 145, 150, 155, 156, 158, 160, 161, 165, 166, 167, 168, 169, 170, 177, 179, 180, 181, 182, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [10, 15, 16, 20, 21, 29, 31, 46, 65, 66, 100, 116, 143, 157, 162, 163, 164, 176, 178, 183, 184, 185]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Metadata¶

In [27]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.3.dev44+g7d4aa18
3.1.4.dev3+g68bd8c3
In [ ]: