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 = "2459807"
data_path = "/mnt/sn1/2459807"
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-15-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/2459807/zen.2459807.25316.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/2459807/zen.2459807.?????.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/2459807/zen.2459807.?????.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 2459807
Date 8-15-2022
LST Range 17.112 -- 19.111 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 N09, N18
Nodes Not Correlating N14, N19
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 69 / 147 (46.9%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 92 / 147 (62.6%)
Redcal Done? ✅
Redcal Flagged Antennas 13 / 147 (8.8%)
Never Flagged Antennas 27 / 147 (18.4%)
A Priori Good Antennas Flagged 71 / 95 total a priori good antennas:
5, 7, 9, 17, 20, 30, 37, 38, 42, 45, 53, 54,
55, 56, 66, 69, 71, 72, 73, 83, 84, 85, 86,
88, 91, 93, 94, 101, 103, 105, 106, 107, 108,
109, 111, 112, 117, 118, 121, 122, 123, 127,
128, 129, 130, 140, 141, 142, 143, 144, 156,
160, 161, 163, 164, 165, 167, 169, 170, 176,
177, 179, 181, 183, 184, 185, 186, 187, 189,
190, 191
A Priori Bad Antennas Not Flagged 3 / 52 total a priori bad antennas:
4, 82, 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_2459807.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.403124 -0.742428 -0.869598 -1.002930 -0.731730 -0.758731 -0.968940 -0.670335 0.730197 0.671553 0.482723 2.384840 2.014589
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.518774 3.749432 -0.902325 1.322402 -0.877343 1.224548 -0.898694 -0.080254 0.744535 0.678431 0.478802 6.416286 6.303975
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.373704 1.510533 -0.461118 3.764648 -1.017283 2.496716 -0.166970 -2.256785 0.755917 0.689855 0.480149 5.055870 4.379313
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.700414 -1.124910 0.356913 0.106151 0.346687 0.710641 1.215780 15.930938 0.762346 0.695060 0.481011 3.940979 3.721796
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.440691 15.177515 14.437984 14.831191 16.840260 18.333436 5.334661 6.433553 0.742122 0.663177 0.484451 3.793194 4.338034
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 7.89% -0.105485 -1.330941 0.079617 -0.314199 2.365307 1.056963 -0.015930 0.051290 0.750462 0.675811 0.488977 3.266366 3.017339
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.001334 -1.207531 -0.390686 0.080614 -0.886644 -0.063985 -0.840673 -0.149133 0.734461 0.654462 0.498196 2.183462 2.069697
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.552553 1.161137 1.055342 0.536927 0.775927 0.552433 0.751035 3.447050 0.763067 0.698407 0.471069 2.700254 2.723481
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.380651 -0.681971 -0.856351 -0.057005 -1.060743 -1.076554 -0.105997 0.072876 0.769144 0.713732 0.467379 2.824466 2.766451
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 10.53% 0.318684 1.513961 -0.211742 0.007397 -0.446746 0.488257 1.181999 0.348747 0.778363 0.719639 0.469700 3.251978 3.310161
18 N01 RF_maintenance 100.00% 0.00% 27.42% 0.00% 100.00% 0.00% 3.954034 6.106569 0.559923 3.278285 0.780899 3.683852 63.748501 178.216638 0.717470 0.541619 0.501998 3.005179 2.414919
19 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.903471 -0.562855 -0.873984 -0.543022 -0.752435 -0.513164 2.857392 3.271961 0.772079 0.711567 0.474918 2.628385 2.482712
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% -1.490652 0.253225 -0.638979 -0.805978 0.376025 0.943326 0.109522 0.535456 0.761087 0.689953 0.473533 4.112051 3.118623
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.330086 -0.368031 0.163210 1.121224 0.458224 0.215874 -0.070542 -1.588772 0.747486 0.671773 0.495324 2.853244 2.278336
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.655584 20.158179 45.801956 46.624210 24.913900 25.880179 26.196501 24.273528 0.044157 0.049484 0.002864 1.191085 1.195777
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 11.928496 15.026917 5.494980 10.256201 22.977781 25.471126 18.098371 79.920606 0.522513 0.273331 0.330104 19.528062 3.874128
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.986140 -0.424673 0.362977 -0.682079 -1.023333 -1.022136 -1.724675 1.431798 0.791281 0.741974 0.465351 2.886638 3.144477
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.016387 -0.374100 -0.251716 -0.962420 0.078520 0.027194 5.690113 0.543224 0.788332 0.735448 0.463746 4.353070 4.666866
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.667010 0.976818 -0.956823 2.178083 -0.366110 2.177817 0.812225 1.618504 0.787417 0.727106 0.477855 2.677229 2.314127
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 32.658302 7.577729 2.504518 0.551332 10.194623 19.074982 57.855919 102.477094 0.728299 0.694341 0.358219 13.144967 4.715774
33 N02 RF_maintenance 100.00% 0.00% 27.42% 0.00% 100.00% 0.00% -0.071877 3.179786 0.274743 0.404671 5.612881 6.527581 141.694835 178.396783 0.757449 0.544551 0.582948 5.421596 2.678103
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.992545 5.122299 -0.043772 -0.115841 2.209666 0.344602 0.739249 1.734469 0.739335 0.675910 0.462314 4.410728 4.078936
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.283394 1.198679 -0.163076 -0.044453 0.272991 0.892599 -0.231396 15.025396 0.759314 0.697625 0.458985 4.438003 5.049119
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.054891 0.010019 -0.656222 -0.409750 2.590387 1.274865 9.816156 4.763352 0.772895 0.719311 0.454011 3.800155 3.803470
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.009695 -0.831883 0.224935 -0.658388 1.831771 0.629611 0.655973 -0.209645 0.787948 0.744780 0.449230 3.211147 2.914983
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.978152 -0.890410 2.233562 0.920517 2.041649 -0.085677 -1.949997 0.839938 0.795448 0.755599 0.454121 2.977436 2.816378
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% 0.132179 0.414226 1.941580 0.699224 0.454161 -0.670990 -1.991921 -0.284592 0.800324 0.754527 0.468818 3.146237 3.107683
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.757608 0.081711 -0.579539 0.314167 -0.531349 -0.399959 0.465202 46.020044 0.778879 0.713325 0.492703 4.087741 3.789246
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.077665 -0.631002 0.214854 -0.950691 -0.741586 -1.248022 -0.662817 0.253311 0.768022 0.692600 0.511543 2.080045 1.781581
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 24.818445 1.646538 4.558873 1.996960 2.536780 0.854990 3.204148 -0.839737 0.696056 0.682085 0.378656 7.983718 5.208022
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.430579 1.417296 -0.761116 -0.633327 0.326104 -0.927517 -0.978271 -0.471215 0.764352 0.711656 0.443827 2.207083 2.288756
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.723629 4.477091 -0.167239 -0.380483 0.509228 -0.064507 3.667391 3.270256 0.781591 0.731781 0.441473 4.466898 4.625189
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.746080 1.013227 -0.363271 -0.752888 -1.139405 -0.371994 4.837748 13.741144 0.793872 0.755228 0.440006 4.484521 5.510029
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% 2.797308 0.599003 0.785290 0.596066 0.604790 1.153149 2.617802 0.274724 0.803978 0.763654 0.435873 2.584140 2.804326
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 2.342797 -0.079344 -0.007397 0.551327 0.944801 2.163279 2.812272 0.203497 0.807673 0.768549 0.455668 6.626260 7.003570
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.490738 -0.298181 0.756475 0.531651 0.390862 -0.549081 -1.167482 12.359172 0.806130 0.767262 0.462053 3.810833 3.461445
57 N04 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 19.305682 10.830264 43.508052 3.722233 24.904539 22.525094 18.984076 22.630700 0.051190 0.533549 0.304872 1.298313 3.778326
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.308798 0.236838 0.401671 0.513053 2.024347 1.326180 -0.186079 2.965776 0.758924 0.692361 0.464438 2.219443 2.238519
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.167483 -0.246269 -0.480876 0.231157 -0.313856 0.879013 -0.668910 9.450576 0.773346 0.722019 0.442086 8.087033 6.566475
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.611500 -0.120218 -0.662220 0.041446 0.656017 0.421495 1.379410 3.727050 0.791057 0.746894 0.430113 2.517597 3.162609
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.264373 0.071210 0.065286 -0.232217 1.972123 1.673556 -0.574502 0.135757 0.801731 0.766174 0.426964 2.608255 3.101744
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.203190 -0.829867 -0.837017 -0.282773 -0.320277 0.891199 0.887334 -0.096532 0.811925 0.776420 0.444085 4.396774 5.760189
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.104950 -1.326645 -0.185463 -0.963157 -0.603405 -0.645685 -0.234655 1.174209 0.810320 0.773254 0.466873 28.432096 24.832000
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.044016 -1.171957 -0.925492 -0.895242 -0.088235 -0.866478 -0.329409 0.029739 0.814588 0.778948 0.451497 52.959421 42.580225
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 1.813799 -0.184755 -0.689008 0.816149 0.162098 0.118229 2.809102 -1.194332 0.803934 0.758860 0.485154 3.692092 3.223808
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 20.767290 2.816881 45.078310 -0.250644 24.772970 0.704193 19.133441 0.334800 0.036624 0.740566 0.446401 1.204815 3.376595
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.125908 3.620102 -0.818648 2.787297 -0.378272 2.435054 1.992481 -1.246795 0.755832 0.691154 0.455590 2.452662 2.683115
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.488333 -0.664752 0.602996 0.181810 0.182655 -0.388956 -1.772470 -0.439377 0.779433 0.721790 0.453854 4.965427 5.160500
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.091561 3.499186 1.739876 3.722752 0.195609 2.070825 -1.712402 -2.021035 0.792000 0.747684 0.431723 3.978555 5.147932
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.524186 6.931522 0.101306 1.098225 -0.438806 0.262618 -0.490626 0.294311 0.744715 0.704785 0.413750 3.851291 3.879456
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 71.05% -0.112678 1.160892 0.549770 1.498206 -0.419343 0.996036 -0.126558 1.104516 0.742175 0.702992 0.437420 2.317243 2.318788
86 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 86.84% 1.265490 2.138180 -0.640045 -0.725206 0.184120 -0.025155 -0.401169 0.648360 0.740524 0.693485 0.433754 2.895862 2.622125
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.643314 7.601597 4.175959 0.608590 3.301549 1.464769 2.215636 0.903862 0.739120 0.702902 0.453795 2.773579 2.519228
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.154071 43.990271 7.889560 9.716336 24.594607 26.645453 18.668777 33.559139 0.267824 0.215297 0.098277 4.326353 3.282166
93 N10 digital_ok 100.00% 0.00% 32.80% 0.00% 100.00% 0.00% 1.986269 10.419278 3.087144 11.563386 1.279898 13.705180 2.826481 1.161568 0.590964 0.494894 0.401025 4.028495 3.611548
94 N10 digital_ok 100.00% 0.00% 32.80% 0.00% 100.00% 0.00% -0.415156 -0.611189 -0.230556 -0.242714 0.180782 0.161857 12.952042 -0.325756 0.570652 0.487955 0.381455 3.492864 3.219535
98 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.257587 3.104799 -0.085584 -0.534087 -0.457242 -0.995795 -1.156813 0.577993 0.758960 0.684504 0.466629 2.530644 3.054181
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.535573 0.009695 2.354208 -0.856809 2.494360 -0.275422 -0.684610 -0.974738 0.774951 0.717805 0.451201 2.515394 2.591124
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.822883 -0.024062 0.729900 -0.345805 -0.085231 -0.579450 -1.242842 1.628784 0.792513 0.741546 0.459818 2.308669 2.671753
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.157186 6.892686 2.734837 0.041622 0.844538 -0.596717 5.750203 1.667062 0.742453 0.692535 0.439341 3.356835 3.222595
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.969633 17.889758 6.825966 6.755838 271.921241 265.486435 20006.590542 19847.643677 0.615534 0.645149 0.424740 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.540260 6.811238 -0.352879 -0.273198 0.517319 -0.815434 0.387480 0.032400 0.735687 0.693027 0.442402 3.049067 2.813681
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.929331 63.784844 0.616991 9.534843 0.376580 1.526512 2.020226 2.562112 0.732626 0.683896 0.465698 3.272298 2.904279
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
109 N10 digital_ok 0.00% 0.00% 32.80% 0.00% 34.21% 0.00% -0.353888 -0.229856 0.181833 0.158112 -0.596821 -0.183258 -1.297379 0.218319 0.609381 0.525394 0.418035 2.291720 2.417432
110 N10 RF_maintenance 100.00% 0.00% 32.80% 0.00% 100.00% 0.00% 37.926460 1.852580 3.164220 1.574263 7.239169 -0.324910 1.685103 -1.194269 0.549335 0.509299 0.338040 31.261141 5.974524
111 N10 digital_ok 0.00% 0.00% 32.80% 0.00% 34.21% 0.00% 0.059310 1.428458 -0.244869 1.021199 1.145995 0.959140 0.338767 0.011294 0.579063 0.488746 0.380684 1.931512 2.428623
112 N10 digital_ok 0.00% 0.00% 32.80% 0.00% 34.21% 0.00% -0.992680 -0.420844 -0.885732 0.976179 0.767050 -0.274372 -0.678647 -1.773806 0.558703 0.476057 0.371897 2.473859 2.968571
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.709339 1.825978 0.227849 -0.755982 -0.609912 -0.376072 3.584351 -0.647806 0.755824 0.684524 0.467562 2.474336 2.741174
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.616556 3.252085 4.575282 4.563470 3.474236 3.514751 -2.422754 -2.486888 0.777564 0.713454 0.478666 5.406003 6.589484
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 2.144674 20.949333 1.948409 41.203573 1.636491 26.074906 -0.334084 17.572086 0.787605 0.046947 0.513154 4.049562 1.212370
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.520460 0.984973 6.549216 2.215263 5.991727 0.323501 -2.070770 0.569874 0.799793 0.743473 0.477598 3.449467 3.195414
120 N08 RF_maintenance 100.00% 30.11% 100.00% 0.00% 100.00% 0.00% 15.921934 26.582072 7.435653 51.025589 22.027139 26.716233 14.498901 34.168758 0.461068 0.054793 0.339039 2.541471 1.180354
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.701072 4.401784 -0.625541 0.365157 -0.493936 -0.001321 38.204826 38.080380 0.729576 0.681840 0.442572 3.208243 2.858839
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.797214 5.781229 0.852498 1.193886 0.220039 -0.110578 -0.957680 -1.225210 0.724637 0.670176 0.457522 2.879060 2.517990
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.028527 6.516168 0.185779 -0.150093 -0.173849 0.247923 -0.672658 -0.235985 0.716196 0.659756 0.469619 2.915729 2.522976
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% 0.00% 32.80% 0.00% 34.21% 0.00% -0.456923 -0.392615 -0.611265 -0.716259 -0.192936 -0.326715 -0.056415 1.108665 0.609093 0.524272 0.416725 1.979420 1.922579
128 N10 digital_ok 0.00% 0.00% 32.80% 0.00% 34.21% 0.00% -1.113444 1.012215 -0.471117 1.675897 -0.282344 1.007145 0.284931 -1.187777 0.598537 0.508334 0.396983 2.588139 2.319442
129 N10 digital_ok 0.00% 0.00% 32.80% 0.00% 34.21% 0.00% -0.303617 -1.480656 -0.818683 -1.008907 -0.242333 -0.237736 -0.858046 -0.392494 0.583385 0.497661 0.378731 2.736563 2.549435
130 N10 digital_ok 100.00% 0.00% 32.80% 0.00% 100.00% 0.00% -0.574553 0.128058 0.459698 0.584512 -0.087467 1.650786 0.219240 12.814272 0.563813 0.478397 0.368765 4.702923 3.989915
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.693370 -0.585889 -0.983452 -0.925845 -0.992081 -0.876412 -0.324756 0.191064 0.693167 0.617589 0.460604 4.055520 3.704625
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.286117 7.929993 -0.587955 0.507299 4.124002 4.427431 3.351845 8.954542 0.699653 0.631087 0.437214 4.584138 4.125379
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.556296 18.527121 39.651661 40.645991 25.241612 26.140240 22.414411 27.482094 0.036849 0.041011 0.004376 1.186826 1.213899
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 24.082050 1.850456 37.223051 -0.739230 25.369753 -0.037370 23.775431 0.537758 0.048757 0.725278 0.463950 1.260324 3.466031
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.978475 17.385795 44.927924 46.699653 24.831561 25.946029 18.098377 20.172314 0.041081 0.043380 0.000954 1.163981 1.159669
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.423423 4.774913 0.045413 8.036001 1.780252 2.704344 1.085404 36.817123 0.773849 0.715922 0.481964 3.349216 2.904983
142 N13 digital_ok 100.00% 16.13% 100.00% 0.00% 100.00% 0.00% 18.030925 23.229748 6.505133 46.841868 22.679944 26.141409 17.978665 23.767092 0.468105 0.045239 0.285082 2.220817 1.173729
143 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.272472 -0.961545 0.214584 1.099211 -0.151676 0.754139 0.260692 -1.440267 0.098178 0.100457 0.024766 1.076391 1.079936
144 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.876890 1.862718 0.402791 1.922163 0.981084 0.812320 3.484914 0.911143 0.079317 0.080110 0.016113 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.877468 19.241100 46.027083 47.182493 25.013447 26.070092 22.578671 28.789384 0.030926 0.033140 -0.000117 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.939081 21.933015 45.832026 47.923196 25.106735 26.072472 24.360451 27.539715 0.051447 0.054023 0.001816 1.263791 1.261637
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.916007 20.628653 45.047458 46.342323 24.905759 25.855002 24.863333 26.704841 0.041811 0.041781 -0.000346 1.389110 1.375023
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.347102 0.961253 1.046539 -0.726735 -0.445698 -0.323492 -0.088617 9.477135 0.694373 0.614926 0.456367 5.063719 4.590708
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.165435 2.280688 -0.081127 2.392365 0.260236 1.557204 0.304232 -2.141542 0.696259 0.626663 0.454709 1.843084 1.659797
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.085092 -0.910547 0.140916 0.234280 -0.008494 0.029864 -1.408526 0.635315 0.702609 0.632082 0.454292 1.615120 1.576162
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.986640 19.824880 45.586080 46.774182 25.077049 26.145683 24.459955 29.326929 0.045870 0.045210 0.000750 1.303229 1.297047
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.767746 37.427582 -0.377418 3.086852 -0.571170 7.777354 -0.498385 1.937514 0.757432 0.623731 0.438293 4.648217 5.127306
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.782065 1.028924 0.061650 -0.347784 1.447190 0.976317 2.731337 0.808045 0.756441 0.687327 0.498696 1.679101 1.554234
163 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.074387 -0.513818 -0.348477 -0.969270 -0.679011 -0.921351 -0.643380 -0.489389 0.058269 0.072450 0.009564 1.283202 1.276270
164 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.232843 -1.138943 -0.698940 -1.009170 -0.989561 -0.633396 -0.011650 -0.036094 0.073271 0.065541 0.004899 1.335646 1.337555
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.368838 0.941068 4.683508 -0.836636 3.509448 -1.165452 -1.656605 -0.119412 0.079589 0.062725 0.004621 1.287773 1.290450
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.726528 15.270857 2.908671 2.583600 5.480258 8.489655 5.756403 5.447993 0.075510 0.075879 0.004480 1.203536 1.203494
167 N15 digital_ok 100.00% 0.00% 24.73% 0.00% 100.00% 0.00% 14.357051 18.859900 12.505384 14.074659 19.504478 20.247753 57.632602 20.729549 0.646209 0.566383 0.319245 4.815730 3.461346
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.223697 17.637757 14.759812 16.379974 17.825539 20.938434 4.558590 8.476839 0.693193 0.595644 0.478727 5.612526 4.417947
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.966965 16.236999 16.057647 15.364359 19.421631 19.269608 6.077474 6.406890 0.675865 0.576280 0.469382 4.933380 4.354614
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.086017 15.022798 16.233221 14.863298 19.860232 18.576084 6.204638 5.306929 0.660825 0.563884 0.461035 4.999434 4.729457
176 N12 digital_ok 0.00% 0.00% 5.38% 0.00% 5.26% 0.00% -0.392968 -0.346493 -0.462624 0.551688 0.795464 0.677991 -0.941524 -1.489851 0.671732 0.584653 0.458698 1.942903 1.856995
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.038555 1.989363 0.626407 1.347900 -0.727608 0.005747 -1.424585 5.523293 0.672952 0.591492 0.453058 6.880421 7.371271
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.953745 -1.307088 0.650223 -0.710334 0.008494 -0.792602 0.290568 -0.352669 0.678111 0.600900 0.447222 1.903049 1.817887
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.814595 0.004005 -0.890562 -0.638346 0.747795 -0.783118 16.240787 -0.308001 0.678129 0.604573 0.451847 3.977016 3.904360
180 N13 RF_maintenance 100.00% 0.00% 40.86% 0.00% 100.00% 0.00% 1.123835 12.152250 0.753931 42.036255 -0.520656 15.677380 -1.428164 18.157599 0.743816 0.469909 0.547012 155.458412 39.920417
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.032950 45.106929 46.162845 4.701511 25.009238 28.197955 23.078022 22.347760 0.050819 0.308885 0.160576 1.258442 2.831224
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.681526 5.014893 14.610590 6.867580 17.377692 6.252070 3.564871 18.164287 0.723263 0.672403 0.498747 3.734505 3.431617
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.583729 -1.084103 -0.591200 -0.972755 -0.541022 -0.862008 -0.376855 4.657571 0.751394 0.673343 0.518749 3.740476 3.318552
184 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.104642 -0.011755 -0.932669 0.132042 -0.083027 0.163533 0.288388 0.159893 0.061970 0.056138 0.003745 1.298884 1.295871
185 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.755478 0.513206 1.450938 0.679109 0.323741 -0.164236 0.253494 -0.361042 0.055125 0.050602 0.003404 1.197233 1.196042
186 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.145790 -0.122582 2.321464 1.161399 0.998714 0.431391 3.639441 0.087833 0.063153 0.075100 0.010475 1.108570 1.123916
187 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.077575 0.221045 -0.399617 0.669872 -0.380150 -0.958058 1.775561 -0.223783 0.087199 0.088539 0.017394 1.280520 1.280451
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% 3.268713 3.924489 0.143394 -0.568553 -0.594762 -0.728170 -0.011294 1.887277 0.696880 0.603943 0.480815 1.964135 1.583752
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 35.296699 22.104554 3.501854 47.126907 10.674014 26.062767 59.414589 26.593221 0.585236 0.049044 0.412564 9.472272 1.675959
191 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 2.63% -0.365445 0.980753 -0.971833 1.402961 0.538072 0.816497 -0.759426 1.185535 0.673954 0.566640 0.474370 1.327805 1.145718
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% 11.105029 5.333639 10.579252 -0.335007 12.424176 3.320144 57.042272 74.865599 0.050274 0.041540 0.003968 0.849184 0.847705
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.241912 7.546428 1.502527 7.104030 3.933662 9.098966 58.419004 58.349190 0.037231 0.051285 0.001706 1.281679 1.278509
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.871128 10.683996 12.287838 10.429714 14.919926 12.712773 23.411474 19.568754 0.056465 0.057826 0.005122 1.329647 1.331398
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% 11.864448 10.652663 inf inf 2051.877417 2379.200290 24277.775717 33022.971405 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.515852 2.255387 5.892465 1.389427 6.313602 -0.005301 -1.372987 16.375519 0.043692 0.040489 0.002287 0.865927 0.881320
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.339107 19.074661 18.089455 17.826395 22.360807 22.862590 7.993794 8.998658 0.060745 0.061484 0.004774 1.221127 1.207483
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% 14.220693 14.112448 inf inf 2842.224377 2842.155787 40696.481426 40699.063338 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.344412 22.442268 34.242281 34.516670 25.194269 25.882491 33.869740 26.411764 0.066154 0.060727 -0.002634 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 62.37% 0.00% 100.00% 0.00% 9.725729 7.877378 10.083920 9.177981 13.062656 12.092388 58.135407 58.411519 0.556440 0.396435 0.386685 0.000000 0.000000
323 N02 not_connected 100.00% 0.00% 65.05% 0.00% 100.00% 0.00% 17.957023 11.172785 1.963365 11.810708 10.072901 14.707155 6.692447 2.745714 0.472098 0.361197 0.321253 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 62.37% 0.00% 100.00% 0.00% 13.457407 14.065006 13.230240 13.567750 15.296988 16.698951 2.526984 3.318231 0.550233 0.387658 0.394677 0.000000 0.000000
329 N12 dish_maintenance 100.00% 29.57% 70.43% 0.00% 100.00% 0.00% 2.601450 7.240347 5.848835 8.718578 1.950770 9.156400 28.219730 0.993016 0.458679 0.333743 0.313344 0.000000 0.000000
333 N12 dish_maintenance 100.00% 29.57% 97.31% 0.00% 100.00% 0.00% 0.181242 6.897714 0.559060 8.033479 2.296212 8.725714 3.082258 -0.131192 0.448673 0.296802 0.304181 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [4, 5, 7, 8, 9, 17, 18, 20, 27, 28, 30, 32, 33, 36, 37, 38, 42, 45, 50, 52, 53, 54, 55, 56, 57, 66, 69, 70, 71, 72, 73, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [3, 10, 15, 16, 19, 21, 29, 31, 40, 41, 46, 51, 65, 67, 68, 81, 98, 99, 100, 116, 157, 158, 162, 178]

golden_ants: [3, 10, 15, 16, 19, 21, 29, 31, 40, 41, 46, 51, 65, 67, 68, 81, 98, 99, 100, 116, 157, 158, 162, 178]
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_2459807.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 [ ]: