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 = "2459800"
data_path = "/mnt/sn1/2459800"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H5C_Notebooks/_rtp_summary_"
good_statuses = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
In [4]:
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 8-8-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H5C_Notebooks/blob/main/antenna_report/antenna_{ant}_report.html'

Load Auto Metrics¶

In [6]:
use_auto_metrics = False

# find the auto_metrics file
glob_str = os.path.join(data_path, f'zen.{JD}*.auto_metrics.h5')
auto_metrics_file = sorted(glob.glob(glob_str))

# if it exists, load and extract relevant information
if len(auto_metrics_file) > 0:
    auto_metrics_file = auto_metrics_file[0]
    print(f'Found auto_metrics results file at {auto_metrics_file}.')
    
    auto_metrics = load_metric_file(auto_metrics_file)
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
    auto_ex_ants = auto_metrics['ex_ants']['r2_ex_ants']
    
    use_auto_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping auto_metrics.')
Found auto_metrics results file at /mnt/sn1/2459800/zen.2459800.25309.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/2459800/zen.2459800.?????.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/2459800/zen.2459800.?????.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 2459800
Date 8-8-2022
LST Range 16.650 -- 18.650 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: 31
RF_ok: 11
digital_maintenance: 3
digital_ok: 96
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 109 / 147 (74.1%)
Cross-Polarized Antennas 93
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N08, N09, N19
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 75 / 147 (51.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 104 / 147 (70.7%)
Redcal Done? ✅
Redcal Flagged Antennas 15 / 147 (10.2%)
Never Flagged Antennas 21 / 147 (14.3%)
A Priori Good Antennas Flagged 76 / 96 total a priori good antennas:
5, 7, 10, 16, 19, 20, 29, 30, 37, 40, 42, 45,
50, 53, 54, 55, 56, 57, 66, 68, 69, 71, 72,
73, 83, 84, 85, 86, 88, 91, 93, 94, 98, 99,
101, 103, 105, 106, 107, 108, 109, 111, 112,
117, 121, 122, 123, 127, 128, 129, 130, 140,
141, 142, 143, 144, 145, 156, 160, 161, 162,
165, 167, 169, 170, 176, 177, 179, 181, 183,
184, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 1 / 51 total a priori bad antennas:
135
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/array_health_table_2459800.csv

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.427221 -0.593920 -0.700146 -1.098408 -0.970779 -0.373702 -0.543888 0.867414 0.715531 0.692634 0.447278 1.754339 1.568193
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.281841 4.107845 -1.172232 1.426949 -0.951764 0.220673 -0.165320 0.084191 0.728874 0.699936 0.444883 7.483682 6.297547
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.195023 1.336145 -0.938073 3.866851 -1.354178 1.001205 -0.212206 -2.147890 0.740842 0.710587 0.447157 6.455790 6.273214
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.242707 -1.225529 -0.216518 -0.427764 0.097460 1.389291 -0.269630 16.737742 0.737035 0.708247 0.446638 5.040409 4.901889
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.206838 17.092424 16.594802 17.176150 16.510387 17.571773 7.254505 5.480241 0.710311 0.672600 0.449650 4.324471 4.979867
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.029890 -1.105050 0.093944 -0.393222 2.925412 2.603213 0.118403 0.306719 0.712113 0.681605 0.450484 1.708625 1.583020
10 N02 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
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.490448 1.246235 1.489541 0.334458 0.590210 0.832307 0.754220 1.032507 0.749066 0.719850 0.436774 2.075109 1.936542
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.031511 -0.899477 -0.716087 -0.551793 -0.880730 -0.991717 11.499663 14.056726 0.755067 0.730721 0.435641 6.879489 8.173737
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.676803 1.637593 0.344912 0.406004 -0.370137 0.022220 0.192738 0.684428 0.756661 0.733732 0.432514 1.996931 1.917735
18 N01 RF_maintenance 100.00% 0.00% 19.35% 0.00% 100.00% 0.00% 2.921431 3.635069 0.199811 0.257009 9.821961 6.723481 300.076519 121.851420 0.719674 0.557070 0.489329 4.740127 2.874863
19 N02 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
20 N02 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
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.222575 1.065324 0.467951 0.956523 -0.145596 0.516039 1.996664 -1.562833 0.702844 0.670477 0.454293 1.839279 1.734379
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.643343 23.294454 53.611419 54.396289 24.110374 25.096950 22.318321 20.896708 0.043725 0.048001 0.002564 1.228637 1.232481
28 N01 RF_maintenance 100.00% 5.38% 100.00% 0.00% 100.00% 0.00% 13.040269 15.368684 7.381515 10.912265 21.389430 27.374470 22.256823 137.046479 0.529225 0.294397 0.322011 20.171991 4.436072
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% -1.284790 -0.224135 -0.001596 -0.503931 -0.917133 -0.534061 -0.862338 0.191998 0.770567 0.750874 0.428737 2.142139 2.134395
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.488951 0.033914 -0.507893 -0.688384 0.817261 0.689250 20.068174 0.486210 0.759979 0.742122 0.428444 5.364395 6.351843
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.779579 -0.145109 -1.166349 0.675327 -0.404755 -0.064872 1.351257 1.255541 0.754010 0.729436 0.441222 1.747784 1.743041
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 31.834233 31.768228 2.258330 2.425059 8.933147 8.003661 41.004247 41.176994 0.683632 0.662247 0.256012 12.582978 11.341114
33 N02 RF_maintenance 100.00% 0.00% 22.04% 0.00% 100.00% 0.00% -0.200432 3.328903 0.046509 0.460452 5.591643 6.522199 102.292318 125.797308 0.717248 0.540961 0.539196 8.147410 3.494732
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.181770 6.079821 -0.286608 0.382354 2.143011 0.581159 0.798751 1.910492 0.716155 0.689269 0.424986 5.686624 5.121163
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.508331 0.807676 -0.128487 -0.093184 0.487254 0.284682 0.856235 23.531744 0.738210 0.713198 0.421249 5.899114 6.955052
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.147741 -0.212134 -0.825312 -1.175507 3.077614 0.383441 11.225483 5.000918 0.754096 0.733838 0.417841 5.512276 5.053978
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 15.79% 0.347601 -0.397056 0.192396 -0.361374 2.868686 1.783145 0.347450 -0.424680 0.772518 0.758533 0.418023 2.481197 2.349293
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.682801 -0.782411 1.706996 1.194929 0.020045 -0.499332 -1.176952 1.952490 0.777555 0.764167 0.423002 2.067637 1.916091
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 89.47% -0.335002 0.462233 1.582443 1.055519 -0.702791 -0.631971 -1.515090 -0.340047 0.779141 0.760716 0.437862 5.675986 5.916763
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.433704 0.616729 -0.652324 0.606591 -0.862721 -0.232690 0.502282 12.681032 0.743842 0.715784 0.452912 5.182381 4.844579
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.254730 -0.586873 0.182040 -1.038137 -0.425752 -1.406863 -0.576232 -0.348668 0.729296 0.698854 0.467183 1.851215 1.663362
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 20.081902 1.732301 4.188219 2.194380 9.423808 1.848377 61.817051 -0.363394 0.688313 0.694854 0.374335 8.127892 6.965864
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.286087 1.448096 -0.804006 -0.933029 0.123613 -0.881513 0.032241 0.252072 0.742820 0.722649 0.410872 1.941919 1.889292
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.995975 5.371192 -0.526845 -0.273332 0.071494 -0.401241 3.144448 3.369968 0.758786 0.740826 0.409775 5.286508 5.439985
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.753596 1.157040 -0.909819 -0.409000 -1.450636 -0.339082 6.462061 13.205170 0.772871 0.759339 0.415248 5.514015 6.244458
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.476225 0.966294 1.359060 0.887322 2.258978 1.742059 11.753138 3.265624 0.781899 0.768718 0.418668 7.690007 7.215979
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.400908 -0.192732 -0.974683 0.261431 1.832909 1.876370 4.284965 -0.119264 0.781634 0.769411 0.432128 5.964858 5.472144
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 76.32% -0.842349 -0.050886 0.453138 0.784168 0.333148 -0.023400 -0.914521 -0.813743 0.780533 0.769650 0.436934 4.867624 4.216888
57 N04 digital_ok 100.00% 100.00% 21.51% 0.00% 100.00% 0.00% 22.308596 12.793141 53.375538 2.273433 24.037143 24.536246 18.153549 21.105732 0.049410 0.497909 0.291488 1.390614 3.711613
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.308655 0.019905 0.345608 0.687975 1.564749 2.799582 0.090339 2.679567 0.732544 0.702678 0.423373 1.732845 1.651731
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.088636 -0.305391 -1.088218 0.629197 0.396676 0.618595 -0.112900 4.377329 0.748707 0.726748 0.407860 6.321570 6.811801
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.591555 -0.560470 -0.233174 -0.827881 0.966592 2.057144 1.846579 6.129639 0.765682 0.748322 0.404598 5.588171 7.569690
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.385170 -0.052656 -0.427379 -0.177629 2.564931 2.891690 -0.023862 -0.379141 0.772523 0.759981 0.409221 2.110657 2.263359
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 92.11% 0.075208 -0.655187 -1.121521 0.037815 -0.338836 0.782528 0.316906 2.339743 0.777615 0.768257 0.426203 4.782466 5.094057
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.939507 -1.670893 -0.345053 -0.944495 -0.961317 -0.441518 -0.235114 1.522125 0.780615 0.769762 0.452067 35.476201 24.176976
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.139147 -1.258737 -0.606426 -0.750695 -0.586313 -0.723804 -0.137014 -0.133626 0.783666 0.775747 0.439085 42.918797 38.244349
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.288368 -0.379972 -0.350911 0.984204 1.059770 0.382483 11.663904 -1.554007 0.772564 0.761652 0.459226 4.562484 4.292276
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 23.559792 3.020672 52.736377 -0.789953 24.006864 0.063853 17.534310 0.080537 0.037236 0.742078 0.462216 1.237466 3.952136
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.687107 3.214611 -0.501427 2.773274 0.609502 2.273321 1.132724 -1.336476 0.726296 0.697426 0.408493 1.882457 1.882455
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.832036 -0.931737 -0.479653 1.398023 0.220622 0.332644 4.862034 -0.068871 0.748150 0.724634 0.415375 7.139414 6.040039
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.705168 3.803615 1.476186 4.210106 0.064192 1.586757 -1.082644 -2.195187 0.763302 0.746632 0.404038 5.397887 5.514469
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.469397 7.588484 -0.291703 1.507273 -0.886186 -0.189296 -0.628739 0.482135 0.088367 0.086287 0.013131 1.194244 1.196912
85 N08 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.105136 0.780515 -1.028910 -0.460595 -1.592997 -1.164965 -0.416153 -0.748677 0.075465 0.075766 0.008039 1.213309 1.213503
86 N08 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.446711 2.766734 -0.757509 -0.891170 -0.499278 0.123489 -0.672718 -0.598401 0.070658 0.076407 0.006697 1.220849 1.220187
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.175430 8.656655 4.899537 0.920860 4.358311 -0.191721 7.280933 0.102710 0.085540 0.073038 0.010954 1.196421 1.196364
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.966369 21.162630 47.184131 48.225269 24.261464 25.206369 28.722147 21.648750 0.032050 0.031338 0.002092 1.185193 1.183338
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.308584 22.491245 47.067086 47.836851 24.068995 24.926022 17.273455 16.025876 0.031887 0.029848 0.001018 1.189101 1.190079
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.066491 21.984857 47.059417 48.869485 24.196702 25.394527 22.757259 22.216313 0.030544 0.030871 0.000245 1.204491 1.204227
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 32.320180 46.457640 10.061669 12.416654 26.442583 28.394779 20.591103 40.700854 0.273109 0.221545 0.100987 4.911511 3.629641
93 N10 digital_ok 0.00% 13.44% 13.44% 86.56% 100.00% 0.00% 0.537361 0.527263 2.459266 -0.922490 1.220063 0.726807 -1.373586 1.320783 0.207464 0.210414 -0.280317 5.212787 5.520414
94 N10 digital_ok 100.00% 13.44% 22.04% 0.00% 100.00% 0.00% -0.400458 -1.208121 -0.148885 -1.047566 -0.474866 -0.376571 4.879139 4.949426 0.549616 0.510530 0.356718 5.955638 4.930635
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.477569 8.268749 -0.270667 -0.007654 -1.082873 -1.130337 -0.359180 6.125649 0.728263 0.690596 0.410857 10.385980 8.108891
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.182056 0.647081 2.234078 -0.587534 3.436055 -0.003167 7.265883 -0.596658 0.743113 0.720411 0.402824 6.885085 6.680736
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.534101 0.079399 -0.130030 0.129193 -1.505320 -0.692338 -1.277480 -0.134587 0.758788 0.738628 0.420729 1.855453 1.890258
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.553091 7.645729 2.945406 -0.266345 1.333509 -0.715062 7.332090 0.323047 0.099407 0.083464 0.014328 1.212831 1.215057
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.870778 2.114081 24.096118 2.460000 50.897380 3.515942 659.890665 60.258015 0.051269 0.072258 0.007519 1.228020 1.229009
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.047277 7.800903 -0.498192 -0.343221 -0.128751 -1.210448 0.429284 -0.144430 0.069190 0.068218 0.004704 1.230373 1.231511
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.269695 72.206508 0.713055 13.557011 -0.098907 4.070571 1.920934 1.927226 0.086079 0.093608 0.012576 1.203222 1.203514
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.729690 27.414474 47.034290 48.800502 24.235307 25.392491 19.338927 19.278672 0.032706 0.031403 0.000909 1.183549 1.181279
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.654913 23.238035 46.310438 48.218921 24.143600 25.151868 21.480228 18.148021 0.029511 0.029057 0.001035 1.209770 1.208411
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.654208 21.026898 45.383085 46.259353 24.118096 24.922694 20.354112 22.321940 0.029776 0.030573 0.000952 1.241305 1.243129
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.709664 21.234409 46.501328 48.442130 24.053109 25.080480 16.268594 16.741393 0.030596 0.031049 0.001172 1.147512 1.133566
109 N10 digital_ok 0.00% 13.44% 19.35% 0.00% 21.05% 0.00% -0.678191 0.138169 -0.234714 0.378854 -0.572865 0.173752 0.188903 1.096491 0.585377 0.550377 0.385641 2.067100 2.106886
110 N10 RF_maintenance 100.00% 18.82% 22.04% 0.00% 100.00% 0.00% 27.711704 3.864560 1.962276 0.303094 25.129306 16.797775 86.428851 16.867433 0.541257 0.528519 0.303236 19.988624 8.723921
111 N10 digital_ok 0.00% 13.44% 22.04% 0.00% 23.68% 5.26% 0.529648 0.868225 -0.155833 0.682179 1.513954 0.360822 -0.153810 1.113488 0.558604 0.515774 0.352023 1.715395 2.164151
112 N10 digital_ok 0.00% 13.44% 22.04% 0.00% 23.68% 0.00% -0.767958 -0.474941 -0.512594 0.456366 -0.025088 -0.107617 -0.109107 -1.685342 0.540823 0.501194 0.344216 1.779257 2.048243
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.873383 1.730319 -0.058499 -0.673654 -0.194914 0.053836 -0.043239 -0.902403 0.721913 0.692454 0.414964 1.994583 2.029073
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.926086 3.968525 4.597515 4.821917 2.533811 1.997234 -1.824554 -2.510896 0.745575 0.718317 0.428336 7.910223 9.753416
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.820622 1.247545 1.788160 0.231447 1.225116 1.511334 1.655244 3.328372 0.749783 0.730229 0.425436 1.881803 1.888509
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.311705 0.346289 8.602413 0.381362 7.174768 -0.774168 -1.195331 1.317276 0.760502 0.742135 0.448664 5.548541 5.442696
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.034375 29.675012 9.447293 59.720839 21.301978 25.932086 14.225213 28.929218 0.116603 0.046163 0.063561 1.245400 1.204065
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.443464 4.525441 -0.826751 0.432513 -0.616186 -0.011467 54.432146 29.960483 0.081760 0.069992 0.006655 1.217464 1.217170
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.943902 6.454466 0.964903 1.125255 1.309624 -0.264284 -0.087046 -0.537851 0.102266 0.104500 0.015552 1.254456 1.258520
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.723503 7.665363 0.146646 -0.170825 0.057203 0.413367 -0.616906 -0.718032 0.124580 0.112052 0.025025 1.242143 1.246322
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.375766 22.341454 47.707606 49.124224 24.164049 25.078188 17.929771 23.975612 0.030147 0.029957 0.000897 1.226921 1.220913
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.792210 21.676674 47.154212 49.434856 24.218867 25.233362 19.966904 22.542376 0.029277 0.030293 0.000920 1.208202 1.211105
127 N10 digital_ok 0.00% 13.44% 19.35% 0.00% 21.05% 0.00% -0.277892 -0.350969 0.127052 -0.441185 0.366019 -0.224296 0.676264 0.945880 0.590205 0.555817 0.385430 2.053031 2.101986
128 N10 digital_ok 0.00% 13.44% 19.35% 0.00% 21.05% 10.53% -0.875212 0.998123 -0.194999 1.266323 -0.646675 0.298827 0.377473 -1.406081 0.580444 0.541521 0.364539 2.576099 2.533326
129 N10 digital_ok 0.00% 13.44% 19.35% 0.00% 21.05% 0.00% -0.355970 -0.860871 0.001596 0.524218 0.007228 -0.007228 -0.628544 -0.467609 0.566510 0.528649 0.350112 2.076286 2.021749
130 N10 digital_ok 100.00% 13.44% 22.04% 0.00% 100.00% 0.00% -0.073184 0.291722 0.997034 0.846683 -0.227801 0.298897 0.623198 9.425242 0.545775 0.506148 0.338499 5.213454 5.363217
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.986508 -0.510923 -1.140742 -1.076678 -0.791325 -1.123627 -0.434473 -0.644650 0.656987 0.623925 0.410496 6.390742 5.864667
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.220078 9.753526 -0.650531 0.193909 5.879243 4.794101 5.005347 12.130121 0.660908 0.630575 0.387538 8.471472 9.144053
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.551216 21.573991 46.497770 47.502272 24.214813 25.135077 20.359071 23.825609 0.037969 0.045491 0.003182 1.371567 1.495075
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 27.031594 2.277901 43.808316 -0.751356 24.404427 0.157950 20.868669 -0.808617 0.048864 0.728158 0.491069 1.369938 7.402368
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.039429 20.907233 52.561221 54.490544 24.049088 25.187099 16.757286 17.520938 0.040536 0.040448 0.001202 1.198329 1.197088
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.030179 5.914243 -0.658398 10.767684 1.811581 4.138407 1.475281 23.722292 0.740481 0.716025 0.467381 3.883943 4.133669
142 N13 digital_ok 100.00% 24.19% 100.00% 0.00% 100.00% 0.00% 20.874614 26.154453 8.791929 54.699024 21.210738 25.359536 16.433728 19.927270 0.456546 0.042330 0.270128 7.739442 1.236789
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 47.37% -0.091636 -0.720168 1.252850 0.587429 0.923181 0.585513 0.126482 -1.809259 0.749938 0.726488 0.470094 3.430618 2.979131
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 63.16% 0.900224 1.655773 -0.803064 0.884036 -1.261917 1.167798 -0.285781 0.295330 0.746643 0.722722 0.474313 3.559902 3.276283
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.614677 21.864469 53.910126 55.094200 24.137083 25.198119 20.693305 24.085586 0.035771 0.037346 -0.000382 1.429076 1.438763
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.940492 25.297078 53.669564 55.938025 24.127759 25.052046 22.193330 23.667840 0.060409 0.065917 0.004164 1.309712 1.323371
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.321817 22.582358 52.707360 54.097477 24.084940 24.948061 22.323478 23.215436 0.042963 0.038838 0.002624 1.318473 1.320790
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.173717 1.033843 0.671563 -0.403498 1.239320 0.658950 4.417386 16.665770 0.654884 0.622234 0.405157 5.908728 5.693588
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.186371 1.654447 0.189852 2.473848 1.297846 1.223449 0.831956 -0.306726 0.658066 0.632877 0.408151 2.040286 1.850639
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.440174 -1.114877 -0.865017 -0.418491 0.192663 0.962218 2.566761 0.318405 0.669162 0.641826 0.417273 2.117671 2.012748
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.916634 41.201998 -0.863620 3.507828 -0.583222 7.373943 0.012754 1.412361 0.735780 0.641837 0.419116 6.515464 7.941761
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.05% 1.761635 1.073932 -0.487601 -0.916684 3.349635 1.732779 0.778782 -0.327023 0.738059 0.715527 0.451699 2.311020 2.194740
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.714850 -0.280841 0.118628 -1.079910 -0.428655 -0.958486 -0.053444 1.167633 0.744754 0.721971 0.459003 1.934214 1.851361
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.151619 -0.739827 -1.261702 -0.904678 -1.095858 -0.757030 0.073695 0.935047 0.741641 0.716296 0.465618 1.719556 1.718076
165 N14 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
166 N14 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
167 N15 digital_ok 100.00% 2.69% 5.38% 0.00% 100.00% 0.00% 17.580315 22.537561 15.059857 16.010275 18.172099 19.227030 10.495611 12.494858 0.644304 0.606120 0.294168 5.354103 4.448383
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.305996 19.926549 16.883165 18.975120 16.834091 19.877541 4.652473 6.967936 0.683162 0.640180 0.431016 5.397810 4.191336
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 19.188390 18.368793 18.506751 17.864452 18.812738 18.687541 6.625177 5.951946 0.658761 0.616815 0.423178 5.056407 4.120798
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 19.304466 17.036260 18.680282 17.277570 18.982269 17.693659 7.067866 5.452472 0.641037 0.602156 0.416122 3.888794 3.262948
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.081011 -0.347073 -1.155075 0.101868 0.604666 0.150181 0.249563 -0.563715 0.629917 0.598303 0.405715 2.004819 2.090072
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.128597 1.448931 0.420556 -0.562576 -0.696912 -0.178846 1.847852 10.116095 0.637767 0.603062 0.407070 9.247866 10.615045
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.672178 -1.293094 1.072713 -0.813205 -0.318472 -1.068925 0.023862 -1.131332 0.648435 0.616735 0.408652 2.107287 1.939489
179 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 15.79% -0.414346 0.387994 -1.010616 -0.229426 1.528470 -0.211673 2.226892 -1.137254 0.654461 0.623897 0.419377 2.056085 2.094988
180 N13 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
182 N13 RF_maintenance 100.00% 0.00% 3.23% 0.00% 100.00% 0.00% 16.493126 1.341596 16.765035 22.584522 16.506166 128.797751 5.188292 210.092791 0.710110 0.661428 0.463813 5.587402 5.010047
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.420421 -0.825219 -0.193318 -1.144553 -0.537820 -1.913993 0.086012 6.024741 0.735946 0.708703 0.464051 6.610897 5.834709
184 N14 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
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.019905 0.756847 1.285225 1.040241 0.962847 -0.490874 -1.249368 -0.584878 0.727715 0.700121 0.462884 1.782339 1.734485
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.722419 0.851902 3.662878 1.842350 0.475115 0.156385 5.867434 0.522586 0.713749 0.686313 0.451474 4.581308 4.530309
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 55.26% 1.184260 0.621354 0.003657 0.335509 -0.656644 -1.288391 1.977122 1.341582 0.715659 0.688947 0.448230 3.781044 3.285864
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.925818 4.452930 0.458092 -0.654819 -0.966852 -0.889688 1.154636 4.316059 0.680516 0.643836 0.435358 5.434583 4.429635
190 N15 digital_ok 100.00% 2.69% 100.00% 0.00% 100.00% 0.00% 31.911788 24.963224 2.620496 55.073558 14.194252 25.242814 111.709248 23.131713 0.599507 0.051426 0.419521 3.792119 1.219710
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.389005 0.275870 -1.014191 -0.870779 -1.436036 -1.231518 0.024819 10.881877 0.652406 0.603799 0.431270 2.685650 2.600505
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.366124 6.020737 12.125465 -0.514829 13.162183 3.981563 40.681713 60.728623 0.064270 0.051688 0.007491 1.299335 1.307137
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.467008 8.755645 -0.051180 8.477940 5.766538 9.657894 45.506167 42.718474 0.053206 0.062287 0.003688 1.376545 1.372893
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.511892 12.044655 14.014888 11.936042 14.383616 12.055209 15.390113 12.196290 0.066765 0.063530 0.007296 1.168812 1.163681
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% 10.108531 7.089456 83.179467 84.663105 2624.672669 2987.728671 20101.238170 26399.746884 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.368873 13.153575 6.879922 13.260907 6.774962 12.884206 -0.578025 1.359725 0.063282 0.072162 0.005597 1.221825 1.221557
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.000597 21.612284 20.862860 20.695131 21.370280 21.761544 8.576084 8.382177 0.074766 0.075979 0.006123 1.301590 1.308342
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.912344 12.425341 102.781058 97.027558 3632.537598 3632.303933 33128.646518 33125.759723 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.326548 25.313746 40.082283 40.256265 24.514380 25.135082 29.113755 22.937727 0.065732 0.062842 -0.003067 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 56.99% 0.00% 100.00% 0.00% 10.951229 8.933706 11.256782 10.393273 12.662199 11.484181 47.553025 46.608533 0.528510 0.424083 0.337253 0.000000 0.000000
323 N02 not_connected 100.00% 8.06% 62.37% 0.00% 100.00% 0.00% 20.149689 12.441022 2.854750 13.422355 10.530799 12.816784 8.165604 3.722662 0.455316 0.386401 0.280902 0.000000 0.000000
324 N04 not_connected 100.00% 2.69% 59.68% 0.00% 100.00% 0.00% 15.084135 15.815973 15.248859 15.660422 15.919461 16.553638 3.714891 3.692080 0.515849 0.410067 0.344069 0.000000 0.000000
329 N12 dish_maintenance 100.00% 29.57% 70.43% 0.00% 100.00% 0.00% 1.607083 7.727109 0.491663 9.914611 4.565376 10.083964 16.095220 0.673116 0.444141 0.356285 0.282677 0.000000 0.000000
333 N12 dish_maintenance 100.00% 40.32% 89.25% 0.00% 100.00% 0.00% 0.678709 7.452700 1.619021 8.853318 1.823041 8.392684 12.204496 0.457597 0.414877 0.320881 0.254559 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [4, 5, 7, 8, 10, 16, 18, 19, 20, 27, 28, 29, 30, 32, 33, 36, 37, 38, 40, 42, 45, 50, 52, 53, 54, 55, 56, 57, 66, 67, 68, 69, 70, 71, 72, 73, 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, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 160, 161, 162, 165, 166, 167, 168, 169, 170, 176, 177, 179, 180, 181, 182, 183, 184, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [3, 9, 15, 17, 21, 31, 41, 46, 51, 65, 81, 100, 116, 118, 157, 158, 163, 164, 178, 185]

golden_ants: [3, 9, 15, 17, 21, 31, 41, 46, 51, 65, 81, 100, 116, 118, 157, 158, 163, 164, 178, 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/H5C_Notebooks/_rtp_summary_/rtp_summary_table_2459800.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.2
In [ ]: