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 = "2459809"
data_path = "/mnt/sn1/2459809"
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-17-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/2459809/zen.2459809.33561.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 245 ant_metrics files matching glob /mnt/sn1/2459809/zen.2459809.?????.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 25 ant_metrics files matching glob /mnt/sn1/2459809/zen.2459809.?????.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 2459809
Date 8-17-2022
LST Range 19.227 -- 22.037 hours
X-Engine Status ✅ ✅ ✅ ❌ ✅ ✅ ✅ ✅
Number of Files 258
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 32
RF_ok: 11
digital_maintenance: 3
digital_ok: 95
not_connected: 3
Commanded Signal Source None
Antennas in Commanded State 0 / 147 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N09, N14, N15, N19
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 116 / 147 (78.9%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 117 / 147 (79.6%)
Redcal Done? ✅
Redcal Flagged Antennas 8 / 147 (5.4%)
Never Flagged Antennas 8 / 147 (5.4%)
A Priori Good Antennas Flagged 88 / 95 total a priori good antennas:
3, 5, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29,
30, 31, 37, 40, 41, 42, 45, 53, 54, 55, 56,
66, 69, 71, 72, 73, 81, 83, 84, 85, 86, 88,
91, 93, 94, 98, 99, 101, 103, 105, 106, 107,
108, 109, 111, 112, 116, 117, 118, 121, 122,
123, 127, 128, 129, 130, 140, 141, 142, 143,
144, 156, 157, 158, 160, 161, 162, 163, 164,
165, 167, 169, 170, 176, 177, 178, 179, 181,
183, 184, 185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 1 / 52 total a priori bad antennas:
4
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_2459809.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% 8.00% 3.191823 -0.669178 -0.514730 -0.645229 -0.227014 -1.129125 -0.584414 0.314047 0.794744 0.528769 0.588704 1.397425 1.103090
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.076460 3.589360 -0.729821 1.579326 3.766723 3.215773 3.815431 0.943553 0.809267 0.528621 0.592602 4.064377 3.438299
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.328371 -0.219446 -0.670635 4.478825 24.596254 24.908774 7.712772 3.821949 0.812127 0.542328 0.591884 3.987063 3.546599
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.745547 -0.912308 0.329516 0.570123 17.211110 24.584283 4.985758 15.157919 0.803934 0.526534 0.599904 2.996219 2.446648
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.915979 8.204177 19.951813 20.589076 43.414644 42.615894 4.675455 3.037166 0.799545 0.494691 0.609149 2.823075 2.253255
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.270635 -1.063063 0.394639 -0.060833 21.333721 20.870586 18.465190 17.775646 0.808208 0.514175 0.621266 3.109352 2.568501
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 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.783341 0.972897 1.587203 0.834687 0.767781 0.470657 0.323325 8.852932 0.809288 0.534979 0.580243 4.297470 3.654165
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 4.00% 4.00% -0.706909 -0.653546 -0.671126 -0.090795 1.851587 3.352170 2.557162 3.805501 0.814006 0.555229 0.571187 1.586564 1.326162
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.348546 0.675661 0.510478 0.436896 11.198149 10.154844 5.651375 2.418031 0.811857 0.551434 0.576813 3.816119 3.576167
18 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 9.466096 12.665344 1.290584 0.312439 28.479217 16.153039 96.406096 32.593680 0.764081 0.294736 0.593425 2.765195 1.679378
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% 289.972793 290.016685 inf inf 10229.219854 10228.621000 4053.466492 4052.637490 nan nan nan 0.000000 0.000000
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.536152 0.764090 0.699181 0.893424 0.060118 42.226930 -0.228489 1.047946 0.802660 0.507505 0.618802 3.604566 2.735963
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.803781 22.725256 32.913508 33.602357 56.489499 51.892523 8.794847 7.009109 0.038394 0.043891 0.002822 1.159004 1.157724
28 N01 RF_maintenance 100.00% 4.08% 100.00% 0.00% 100.00% 0.00% 13.784885 31.487345 0.495803 1.861012 19.353292 25.431274 2.541967 28.362879 0.431327 0.186856 0.277969 13.368417 2.442213
29 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.336352 -0.032819 0.392325 -0.170792 5.842510 5.986716 1.633733 1.559297 0.817002 0.561122 0.562880 3.518575 3.242901
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.192192 0.206368 0.104784 -0.332963 29.926851 27.930843 13.394893 3.997371 0.809419 0.558658 0.562339 3.319578 3.182146
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 8.00% 1.134895 -0.804950 -0.575457 0.731215 0.561183 1.335523 -0.580981 -0.762386 0.812188 0.551897 0.582528 1.499309 1.316517
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 35.032931 22.474157 2.457787 1.444928 24.491240 50.723437 48.246853 161.357668 0.703867 0.491536 0.404790 6.478100 3.963474
33 N02 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% -0.226996 8.831437 -0.074092 -0.112683 1.101518 4.955393 -0.184792 8.983688 0.794611 0.321221 0.654986 3.377035 1.899677
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.734002 8.357767 0.112893 0.412939 2.570103 -0.512105 0.160754 -0.538746 0.809334 0.555019 0.575984 4.079857 3.634673
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.081353 0.848981 -0.437448 0.344350 8.637631 8.713176 2.996530 9.762594 0.814317 0.573526 0.560795 4.814395 4.229513
38 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.990921 -0.308103 -0.242359 -0.808515 0.647280 -0.293474 3.207293 -0.227977 0.812193 0.582466 0.554730 1.897226 1.574997
40 N04 digital_ok 0.00% 6.12% 6.12% 0.00% 8.00% 0.00% 0.763930 -0.244398 -0.037257 -0.392143 0.015910 -0.590318 -0.657016 -0.373419 0.784090 0.564081 0.531044 2.271786 1.897517
41 N04 digital_ok 0.00% 6.12% 6.12% 0.00% 8.00% 0.00% 0.679803 -0.536580 2.844063 1.051683 1.947172 -1.107092 -0.862182 0.691966 0.787485 0.559379 0.536580 2.701488 1.912963
42 N04 digital_ok 0.00% 6.12% 6.12% 0.00% 8.00% 0.00% 0.138109 0.781024 2.029208 0.798338 -0.606456 -0.812544 -0.648842 -1.256031 0.785675 0.557387 0.541839 2.192879 1.805088
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.376841 1.424771 -0.470970 0.074777 -1.145415 0.902572 -0.256055 4.699961 0.809604 0.529635 0.595407 3.241827 2.939321
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 8.00% 0.00% -0.892304 -0.061456 0.045958 -0.763331 0.517235 0.588499 -0.478929 3.592903 0.806008 0.515916 0.610343 1.506051 1.353155
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 32.484025 17.034663 2.797346 1.160839 19.645961 19.217085 51.101217 39.265168 0.732964 0.508909 0.455643 4.261338 4.326751
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.365718 2.373589 -0.670878 -0.556029 -1.375496 -1.315185 -0.788919 0.634394 0.811676 0.594199 0.547118 1.708919 1.620536
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.423711 8.392777 0.476237 0.157682 3.516255 0.841823 0.751276 0.819327 0.814320 0.600320 0.538903 4.650108 4.720454
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 8.00% 1.886737 2.072258 -0.571638 0.060391 -0.544555 -0.734781 2.951746 2.897313 0.815769 0.612219 0.534530 2.119131 1.818778
54 N04 digital_ok 0.00% 6.12% 6.12% 0.00% 8.00% 0.00% 0.402273 -0.949613 1.225075 1.198300 0.424588 0.391406 2.010145 -0.458080 0.785771 0.577403 0.519541 2.294924 2.093559
55 N04 digital_ok 100.00% 6.12% 6.12% 0.00% 100.00% 0.00% 1.773532 1.305094 -0.492510 1.134896 18.565921 -0.352231 8.570489 0.378444 0.784147 0.568244 0.525627 4.840523 4.697634
56 N04 digital_ok 0.00% 6.12% 6.12% 0.00% 8.00% 0.00% 0.008948 0.597061 1.375914 1.241224 0.033351 -0.203809 -0.826368 3.915649 0.785201 0.570289 0.532210 2.160622 1.766834
57 N04 RF_maintenance 100.00% 6.12% 6.12% 0.00% 100.00% 0.00% 30.390356 -0.046100 14.363992 2.783909 31.502749 1.063148 2.807989 -0.029878 0.622035 0.553549 0.396822 4.235866 3.355814
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.347057 0.310171 0.947298 1.066746 -0.648078 0.565436 -0.371160 0.031304 0.810531 0.568074 0.574707 1.653635 1.582849
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.616279 1.070357 -0.604218 1.070452 -0.162369 3.473131 0.198504 0.832799 0.814148 0.595592 0.544838 3.807888 4.302265
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.490621 -0.580506 0.182063 0.418535 1.280673 3.687600 0.341674 0.222816 0.811110 0.612810 0.523219 2.039370 1.723094
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.148743 0.815179 0.035441 0.349550 0.556216 1.911199 0.165781 1.922328 0.812321 0.616884 0.518975 2.109011 1.870871
69 N04 digital_ok 100.00% 6.12% 6.12% 0.00% 100.00% 0.00% 0.503423 -0.744084 -0.310330 -0.097045 0.386842 7.329217 -0.398263 -0.861171 0.785594 0.590701 0.509709 4.462837 4.246096
70 N04 RF_maintenance 100.00% 6.12% 6.12% 0.00% 100.00% 0.00% 8.374083 -0.902167 0.168390 -0.864417 2.030311 -1.251794 -0.285892 -0.814490 0.783922 0.567123 0.528584 16.956562 13.573113
71 N04 digital_ok 0.00% 6.12% 6.12% 0.00% 8.00% 92.00% 0.536641 0.030501 -0.766810 -0.300002 0.307403 -1.717891 -0.550133 -1.052270 0.785495 0.584991 0.516890 17.740623 14.605366
72 N04 digital_ok 100.00% 6.12% 6.12% 0.00% 100.00% 0.00% 3.253971 -0.205021 -0.541128 1.574534 7.519476 -1.141506 5.215197 -1.067054 0.781917 0.555068 0.539405 4.359880 3.423064
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 17.806838 0.175627 32.191925 0.015261 39.973970 0.771029 1.369348 0.227753 0.032696 0.544553 0.275782 1.230622 3.191255
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.280400 1.473607 -0.508920 3.670893 1.088261 0.487940 5.421461 0.228309 0.802062 0.553082 0.578718 3.207993 3.076844
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.346540 0.826168 1.451637 0.656598 -0.551944 -0.624782 3.656958 0.666178 0.808106 0.575077 0.562471 3.424263 2.760941
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.326926 1.394768 2.037768 4.493166 -0.982485 -0.586358 -0.559005 -1.321696 0.812141 0.605248 0.536769 3.482633 3.543676
84 N08 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 10.872893 11.800042 0.071419 1.561229 6.270483 -0.278186 35.740783 -1.366485 0.750446 0.536851 0.493710 3.960215 4.450708
85 N08 digital_ok 0.00% 0.00% 4.08% 0.00% 4.00% 8.00% 0.666007 0.458280 -0.720988 -0.556465 -1.448733 -1.218910 -0.928263 -1.420782 0.746289 0.536921 0.499213 1.875856 1.687148
86 N08 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 1.514287 4.685490 -0.663485 0.022207 2.925508 2.391792 0.128351 -0.274851 0.740974 0.498511 0.501749 4.108931 4.483211
87 N08 RF_maintenance 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 3.231391 12.266765 5.331062 1.270907 8.886113 -1.192629 24.779666 -0.642363 0.733590 0.518919 0.510220 3.154820 3.032122
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.433398 22.850876 27.722063 28.621881 40.348675 34.771791 4.289834 1.269383 0.037190 0.034075 0.002130 1.127833 1.135255
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.996585 1.109659 16.979170 1.024211 17.873235 0.758464 -1.421492 -0.634866 0.045853 0.037825 0.001886 1.247685 1.245845
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.026924 22.085205 5.424467 29.271853 23.433144 34.648606 5.048944 1.652675 0.064980 0.036300 0.028308 0.828881 0.812143
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 42.726618 55.058187 2.922592 4.499085 30.461183 45.723252 1.135684 6.542389 0.269159 0.185592 0.116616 0.000000 0.000000
93 N10 digital_ok 100.00% 0.00% 93.88% 0.00% 100.00% 0.00% -0.196204 3.736856 3.729363 15.573598 10.839896 16.556675 2.222563 0.002214 0.665552 0.340943 0.507400 0.000000 0.000000
94 N10 digital_ok 100.00% 0.00% 93.88% 0.00% 100.00% 0.00% -0.675612 -1.238617 0.295426 -0.329666 -0.277965 7.352763 2.505870 0.912921 0.668729 0.348890 0.509353 0.000000 0.000000
98 N07 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
99 N07 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
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.177687 -0.154907 0.888762 0.100317 -1.022929 -0.448359 -0.175630 -1.049011 0.810960 0.571603 0.564998 1.459865 1.314054
101 N08 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 10.388650 11.197565 2.968206 0.137048 -0.777384 -1.197992 4.445666 0.705810 0.750389 0.522569 0.512060 3.758699 3.100939
102 N08 RF_maintenance 100.00% 0.00% 40.82% 0.00% 100.00% 0.00% 5.774495 10.993382 15.503783 22.044440 269.310362 22.825560 22.922312 0.891637 0.674532 0.405375 0.488685 3.817472 3.368624
103 N08 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 4.489949 11.128972 0.174977 0.059997 -0.654741 -0.394245 0.390064 -0.484253 0.749095 0.516934 0.509851 3.332470 2.838672
104 N08 RF_maintenance 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 8.349740 76.449136 1.318193 11.877195 1.382333 -0.027974 1.259292 -1.191236 0.751989 0.497414 0.538044 4.048754 3.260907
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.333765 9.869759 20.993869 22.977600 28.335922 27.079554 -1.247354 -2.617406 0.058595 0.056850 0.012140 1.182873 1.181687
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.365243 9.020591 4.124676 21.547841 0.911944 23.285043 -0.427444 -2.629514 0.038074 0.045544 0.007539 1.183216 1.167467
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.475404 19.815958 20.291056 27.141184 33.376332 34.814442 -0.898967 1.505957 0.063646 0.037372 0.023935 0.820281 0.813493
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.814447 20.873643 27.233585 28.932601 40.338776 34.725781 0.891205 0.006785 0.029254 0.036204 0.001803 1.102061 1.106718
109 N10 digital_ok 100.00% 0.00% 93.88% 0.00% 100.00% 0.00% -0.637347 0.520037 -0.060514 0.756382 5.863008 6.394614 2.572339 6.548182 0.675156 0.326624 0.527955 0.000000 0.000000
110 N10 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 35.472952 28.677337 2.509718 1.546265 4.855978 8.972983 -0.317452 0.380572 0.563719 0.325265 0.325774 0.000000 0.000000
111 N10 digital_ok 100.00% 0.00% 93.88% 0.00% 100.00% 0.00% 0.807954 0.245386 0.228823 1.262837 6.674163 8.982835 7.003411 5.466250 0.670183 0.335728 0.515994 0.000000 0.000000
112 N10 digital_ok 0.00% 0.00% 93.88% 0.00% 92.00% 0.00% -0.853242 -0.008948 -0.277025 1.108593 -0.936374 -0.951834 0.242430 -1.426568 0.668324 0.345847 0.515780 0.000000 0.000000
116 N07 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
117 N07 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 0.734919 0.687022 5.460434 5.576472 2.022948 -0.100511 -0.493427 -1.505872 0.809801 0.543380 0.595062 2.768355 2.334286
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 2.706925 22.535395 2.298263 28.821053 -0.789388 34.735004 0.539175 -0.199662 0.814758 0.039882 0.541603 4.220973 1.139641
119 N07 RF_maintenance 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 1.321899 0.972196 9.891321 0.304877 4.580763 -0.111993 -1.160364 -0.788600 0.821625 0.558920 0.581243 3.781358 2.862375
120 N08 RF_maintenance 100.00% 63.27% 100.00% 0.00% 100.00% 0.00% 17.317747 33.918854 0.918675 37.776790 21.853599 34.234155 2.585636 3.748196 0.387306 0.042793 0.257003 2.534049 1.246816
121 N08 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 3.782441 7.090276 -0.476499 0.792613 1.709346 0.488113 18.770345 11.992121 0.752513 0.505769 0.516738 4.488137 2.569248
122 N08 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 10.462723 9.245861 1.106073 1.337685 -0.763220 -1.355948 -0.566986 -1.122907 0.755254 0.498689 0.520054 3.744879 2.555805
123 N08 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 8.545227 10.225936 0.052436 0.176109 -1.571256 -1.747902 -0.663228 -1.225019 0.753516 0.483901 0.546185 3.846061 2.547567
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 8.164267 10.658641 21.979001 23.325496 29.224225 27.537810 -1.411597 -2.636428 0.061418 0.057858 0.008939 1.159089 1.150079
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 13.191527 7.794915 19.492883 19.632992 27.798334 21.524968 0.324205 -2.506187 0.070259 0.046272 0.005495 0.862974 0.870685
127 N10 digital_ok 100.00% 0.00% 93.88% 0.00% 100.00% 0.00% 0.349937 0.223500 0.437185 -0.077628 2.873853 5.411292 0.783461 0.828375 0.667702 0.331173 0.517410 0.000000 0.000000
128 N10 digital_ok 0.00% 0.00% 93.88% 0.00% 92.00% 0.00% -1.069394 2.882227 0.139024 1.995884 -0.350446 0.669038 -0.337665 -1.020518 0.668499 0.329989 0.513555 0.000000 0.000000
129 N10 digital_ok 0.00% 0.00% 93.88% 0.00% 92.00% 0.00% -0.576726 -0.547379 -0.368973 -0.701573 -0.079074 -0.870201 -0.210374 -0.625805 0.668214 0.333291 0.515719 0.000000 0.000000
130 N10 digital_ok 100.00% 0.00% 93.88% 0.00% 100.00% 0.00% 0.916803 0.166749 0.305738 1.152724 28.184806 29.579002 5.113385 6.389788 0.659832 0.347993 0.502246 0.000000 0.000000
135 N12 digital_maintenance 0.00% 0.00% 4.08% 0.00% 100.00% 0.00% -0.895028 0.195381 -0.686465 -0.772294 0.348405 -0.956639 3.322159 0.811392 0.743031 0.454720 0.565272 2.316889 1.847855
136 N12 digital_maintenance 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 2.087629 9.378945 -0.640841 0.459160 3.276259 1.572494 -0.036715 4.545784 0.744414 0.439368 0.554272 2.773986 2.034190
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.468869 20.995126 27.253027 28.197765 39.965377 34.445738 1.960393 2.055739 0.033567 0.037294 0.003122 1.125138 1.128398
138 N07 RF_maintenance 100.00% 100.00% 4.08% 0.00% 100.00% 0.00% 24.554974 2.088217 25.110405 -0.633069 40.067081 -1.248460 2.427810 -0.368506 0.043397 0.540672 0.312297 1.256117 2.498521
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.705865 20.967468 32.004880 33.667999 40.027070 34.474884 1.099176 0.360272 0.039420 0.042130 0.001633 1.151485 1.134745
141 N13 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 1.543320 2.258315 -0.123517 8.336695 1.975000 1.425689 0.797203 5.352500 0.819473 0.526892 0.584037 4.412420 2.332179
142 N13 digital_ok 100.00% 4.08% 100.00% 0.00% 100.00% 0.00% 24.822694 25.735105 1.327251 33.832826 25.004888 34.359866 2.560623 1.511064 0.448648 0.043666 0.268192 2.325373 1.214998
143 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.485803 -0.758335 1.201016 1.119270 3.221231 2.300195 0.362536 0.965427 0.066284 0.064618 0.013805 0.000000 0.000000
144 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.675627 -0.293458 -0.833508 -0.312702 27.868956 27.608619 6.178090 5.022689 0.055419 0.063316 0.014139 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.762032 22.429482 33.056282 34.210217 40.154100 34.453662 2.194698 2.244501 0.029463 0.030712 -0.000029 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 207.332512 204.551431 inf inf 6523.696314 5830.315490 3191.359819 3004.476761 nan nan nan 0.000000 0.000000
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.763870 21.018829 32.113092 33.356202 39.925598 34.312640 2.537064 2.011984 0.039783 0.037559 0.000434 1.373351 1.351212
156 N12 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 0.631177 0.556718 1.398498 1.295668 -0.055346 72.194509 2.614103 9.156185 0.758545 0.450859 0.567989 5.640500 4.863613
157 N12 digital_ok 0.00% 0.00% 4.08% 0.00% 12.00% 0.00% -0.393741 -0.339669 0.285702 3.160241 0.982819 -0.340080 1.473709 0.267946 0.750677 0.472413 0.553720 1.860045 1.363400
158 N12 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% -0.508469 -1.022269 -0.186295 0.177786 7.226539 6.693365 3.051017 2.549152 0.755202 0.476731 0.556584 4.795882 5.231194
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.820107 20.651797 32.635088 33.733622 40.172416 34.652995 2.186624 1.925158 0.040093 0.042556 0.004325 1.269289 1.261695
161 N13 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% -0.426455 39.983565 -0.430352 2.884182 -0.267755 4.782238 0.447427 -0.241748 0.808918 0.433269 0.568771 4.518279 3.900891
162 N13 digital_ok 0.00% 0.00% 4.08% 0.00% 8.00% 4.00% 1.549013 -0.051182 -0.035441 -0.692881 0.355167 -0.015910 -0.287420 0.250588 0.815606 0.538286 0.599185 1.587902 1.372044
163 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.536791 0.515512 0.312662 -0.757579 20.802197 21.354169 5.187332 6.003464 0.058230 0.058644 0.009283 1.267351 1.243153
164 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.944764 -0.612195 -0.776956 -0.677856 -0.679944 1.656066 -0.456980 -0.374006 0.060221 0.060865 0.008362 1.321735 1.307337
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 304.557941 304.727095 inf inf 7653.606507 7691.722246 5261.136120 5297.425371 nan nan nan 0.000000 0.000000
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 163.956923 163.934780 inf inf 4900.714891 4977.700972 2136.401798 2584.090474 nan nan nan 0.000000 0.000000
167 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
168 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.410776 10.350250 20.369095 22.899829 25.895678 27.278050 -0.680268 -1.829622 0.057391 0.064817 0.011408 0.000000 0.000000
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.002391 9.457012 22.420343 21.546534 35.193284 30.225440 2.513594 3.580922 0.066234 0.056363 0.007705 0.000000 0.000000
170 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.331182 8.143851 22.622714 20.622425 47.264167 40.998558 4.285294 2.763783 0.062111 0.056391 0.006097 0.000000 0.000000
176 N12 digital_ok 0.00% 0.00% 4.08% 0.00% 12.00% 0.00% 0.456492 -0.734843 -0.619149 0.611636 -1.196301 -0.410790 -0.031304 0.845975 0.752593 0.436123 0.583126 1.859065 1.331257
177 N12 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 0.770689 1.467731 0.639109 8.577691 -0.905939 36.290748 0.134953 -0.131079 0.751106 0.450247 0.569017 6.092583 6.654807
178 N12 digital_ok 0.00% 0.00% 4.08% 0.00% 8.00% 4.00% -0.710360 -0.712957 1.175160 -0.294805 -1.348785 0.246118 0.359785 1.579745 0.744665 0.460414 0.558733 1.966782 1.335628
179 N12 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 0.158854 1.222794 -0.785487 0.053779 10.167110 -1.186644 1.030518 -0.960301 0.747687 0.462248 0.568722 3.737974 3.572393
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 0.310477 17.766232 0.382870 32.044053 0.530265 28.225374 0.327467 1.072312 0.811337 0.209930 0.660138 10.735508 2.123916
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.114124 60.672956 33.184924 5.761502 41.577867 29.652324 3.916187 7.497271 0.044967 0.292954 0.153023 1.268771 3.041975
182 N13 RF_maintenance 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% 6.843498 8.426426 20.205425 21.086240 24.681677 23.867052 -0.087295 -1.746298 0.800478 0.507984 0.610648 4.699514 4.177464
183 N13 digital_ok 100.00% 0.00% 4.08% 0.00% 100.00% 0.00% -1.211010 -0.473654 0.186305 -0.728516 -1.385768 3.979986 0.940358 7.708906 0.806122 0.519215 0.613906 3.819738 3.130117
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 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.334828 0.447121 2.464303 1.035241 5.518605 5.429517 1.585508 0.981080 0.068903 0.057835 0.009800 0.947569 0.946056
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.431622 0.473973 2.995439 1.603246 2.735553 -0.284449 6.396128 5.308693 0.070054 0.063404 0.012564 1.226079 1.219480
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.028178 1.517425 0.295681 0.541788 0.483782 0.182790 5.301160 3.175279 0.074518 0.068331 0.015459 0.000000 0.000000
189 N15 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.125572 2.199999 0.649843 -0.604992 0.538690 0.089366 0.530655 -1.082065 0.041660 0.044018 0.003867 0.000000 0.000000
190 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 53.486866 24.761935 3.671111 34.143157 34.290291 34.581619 111.573725 2.415007 0.059518 0.034531 0.030624 0.000000 0.000000
191 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.698219 0.624140 -0.304569 -0.088896 4.694249 28.870836 12.721473 6.338341 0.044268 0.042258 0.002654 0.000000 0.000000
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.693413 3.754283 14.269155 -0.140793 13.762166 4.035555 -1.087070 6.834603 0.050675 0.044807 0.005277 0.000000 0.000000
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.442593 3.088383 -0.443180 10.110479 7.211777 4.366291 1.489175 0.704619 0.050555 0.044633 0.004461 1.201130 1.191907
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.344246 4.811994 17.039031 14.079808 20.709002 13.154029 -0.872782 -1.918343 0.055065 0.053743 0.007104 0.000000 0.000000
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% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.117577 5.193625 8.483050 15.875447 6.165284 13.009700 0.983895 -1.525277 0.042013 0.059086 0.002454 0.000000 0.000000
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 10.959044 11.784803 25.662611 25.062955 37.791154 31.156931 -1.659852 -2.755525 0.060824 0.065230 0.008659 0.000000 0.000000
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% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.407463 24.025374 22.173568 22.474810 39.939672 34.452511 4.993851 2.473339 0.052431 0.048604 0.004552 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 8.16% 0.00% 100.00% 0.00% 2.977709 1.855579 13.428060 12.126387 28.527594 23.035243 19.195835 18.243225 0.781722 0.416534 0.665489 0.000000 0.000000
323 N02 not_connected 100.00% 0.00% 73.47% 0.00% 100.00% 0.00% 23.323948 4.422720 1.288605 16.080061 18.021467 13.980649 7.085128 -1.082315 0.602156 0.395167 0.493929 0.000000 0.000000
324 N04 not_connected 100.00% 6.12% 42.86% 0.00% 100.00% 0.00% 5.572686 3.899425 17.205434 11.389106 20.211754 10.273335 5.939060 7.035720 0.764460 0.393208 0.633752 0.000000 0.000000
329 N12 dish_maintenance 100.00% 0.00% 93.88% 0.00% 100.00% 0.00% 2.656839 1.970570 5.276555 11.708974 17.466752 9.121179 6.987882 -0.236217 0.715553 0.350704 0.597748 0.000000 0.000000
333 N12 dish_maintenance 100.00% 0.00% 93.88% 0.00% 100.00% 0.00% 4.962647 2.005406 -0.308291 10.796006 7.824211 6.041189 0.188616 -1.013177 0.676458 0.338061 0.562301 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 30, 31, 32, 33, 36, 37, 40, 41, 42, 45, 46, 50, 52, 53, 54, 55, 56, 57, 66, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [38, 51, 65, 67, 68, 100]

golden_ants: [38, 51, 65, 67, 68, 100]
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_2459809.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 [ ]: