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 = "2459783"
data_path = "/mnt/sn1/2459783"
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: 7-22-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/2459783/zen.2459783.25312.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 371 ant_metrics files matching glob /mnt/sn1/2459783/zen.2459783.?????.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/2459783/zen.2459783.?????.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 2459783
Date 7-22-2022
LST Range 15.533 -- 17.533 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: 43
RF_ok: 11
digital_maintenance: 2
digital_ok: 85
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 115 / 147 (78.2%)
Cross-Polarized Antennas 93, 104
Total Number of Nodes 15
Nodes Registering 0s N09, N18
Nodes Not Correlating N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 61 / 147 (41.5%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 101 / 147 (68.7%)
Redcal Done? ✅
Redcal Flagged Antennas 8 / 147 (5.4%)
Never Flagged Antennas 31 / 147 (21.1%)
A Priori Good Antennas Flagged 60 / 85 total a priori good antennas:
7, 9, 19, 21, 29, 37, 40, 41, 42, 45, 50, 51,
53, 54, 55, 56, 57, 69, 71, 72, 83, 84, 88,
91, 92, 99, 101, 103, 105, 106, 107, 108, 121,
122, 123, 135, 138, 140, 141, 142, 145, 160,
161, 163, 165, 167, 169, 170, 176, 177, 178,
179, 181, 183, 184, 185, 186, 187, 190, 191
A Priori Bad Antennas Not Flagged 6 / 62 total a priori bad antennas:
3, 100, 110, 112, 116, 127
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_2459783.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 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.045696 -1.218863 0.216445 -0.836474 0.117611 -1.202596 0.776371 0.490490 0.555593 0.554903 0.341346 3.790890 3.732340
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.962946 3.957366 -0.360135 -1.315812 0.342466 -0.578056 0.427865 -0.406672 0.572518 0.563593 0.343407 5.027456 5.415936
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.856499 1.111457 -0.435944 1.698900 -0.010998 1.507116 -0.119932 -1.750075 0.580270 0.572671 0.343819 1.969080 2.331431
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.633042 -0.648710 -0.610654 -0.258947 -0.643123 -0.467999 -0.018747 16.354656 0.570505 0.562283 0.334004 3.765133 4.198681
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.308703 13.739642 8.078506 8.104436 16.510135 15.525364 1.363961 -0.812989 0.549701 0.535775 0.325849 4.194343 4.132099
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.857022 -0.987456 0.201256 0.010493 2.255405 -0.644515 -0.036208 -0.099087 0.549816 0.545815 0.329444 1.691521 1.552446
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.442471 0.285069 -0.242013 0.701613 -0.558606 3.146083 2.095985 1.106062 0.525096 0.513889 0.322772 1.763961 1.949994
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.547861 0.775845 -0.276444 -0.661258 0.787380 0.323444 0.093176 0.802374 0.591515 0.581400 0.347022 1.985898 2.469773
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.809744 -0.803428 -1.289599 -0.356125 -0.245025 -1.385523 2.346039 0.101984 0.600046 0.593424 0.345830 2.175935 2.273083
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.109285 -0.031830 -0.663350 -1.488422 0.438529 -0.274301 0.233676 -0.498565 0.595623 0.592968 0.338865 2.048953 2.489699
18 N01 RF_maintenance 100.00% 0.00% 67.39% 0.00% 100.00% 0.00% 3.997363 7.318317 -0.006043 3.078836 3.959507 3.460964 86.624085 66.200475 0.564964 0.386607 0.367281 4.069296 2.383575
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.528437 -1.059555 0.454491 0.516139 0.655305 1.803767 -0.667481 28.226631 0.583072 0.573867 0.331738 5.030275 4.922959
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.679882 0.169479 0.125908 -0.318079 1.894679 -0.406873 0.001024 -0.144450 0.565835 0.547082 0.325458 1.883239 1.856724
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.630160 -0.268846 0.755177 0.976756 0.623495 1.132388 1.045152 9.225370 0.543264 0.531762 0.323220 5.354298 5.259568
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.815160 24.538797 20.124235 20.840181 24.333771 22.332447 4.942029 4.590045 0.038143 0.040433 0.002408 1.200009 1.225049
28 N01 RF_maintenance 100.00% 61.99% 100.00% 0.00% 100.00% 0.00% 11.205658 21.132012 0.345545 8.427606 20.809311 23.665084 10.733330 53.330571 0.413421 0.217398 0.242865 16.220328 5.747572
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -1.256925 -0.669099 0.140446 -0.760476 -0.715838 -0.340073 -0.859050 0.568631 0.615978 0.611065 0.339845 2.173852 2.656526
30 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.743478 0.639513 -0.285618 0.648029 -0.609458 0.144909 3.110447 0.527760 0.601886 0.599779 0.334295 1.965818 1.989874
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.486387 -0.236685 0.016342 0.994378 1.373005 0.817164 0.685034 1.097676 0.602029 0.589546 0.335340 1.735383 1.876003
32 N02 RF_maintenance 100.00% 24.26% 18.87% 0.00% 100.00% 0.00% 30.766526 37.614798 1.511936 2.404035 8.192020 11.392458 52.763910 64.415787 0.495521 0.505883 0.167452 7.359227 6.411804
33 N02 RF_maintenance 100.00% 0.00% 70.08% 0.00% 100.00% 0.00% 0.203268 5.639276 0.314743 0.951894 -0.307586 0.840578 2.960472 18.675478 0.558395 0.386971 0.389924 4.951915 2.507906
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.751217 7.656545 -0.437704 -0.186336 -0.388091 -0.773386 0.816647 2.000381 0.557444 0.543028 0.321317 3.398741 3.287018
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.655019 0.073802 -0.635654 -1.263415 0.865389 -0.444829 0.352162 18.777198 0.587002 0.578128 0.332395 3.247919 3.821937
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.478924 -0.195794 -0.097646 -0.474113 1.574702 -0.367425 9.450883 3.319629 0.607017 0.601507 0.347416 2.947618 3.143050
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 65.79% 0.866964 1.052000 0.183439 0.540726 -0.044073 0.284895 -0.001024 0.013884 0.621815 0.619283 0.343014 2.979770 3.549726
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 23.68% 0.524895 -0.822197 0.980794 -1.335709 1.249554 -1.584221 -1.266969 -0.627117 0.625290 0.621763 0.335782 2.976748 2.788728
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 60.53% -0.536126 0.382755 0.872614 -0.401691 -0.145674 0.177415 -1.264088 -0.395828 0.629610 0.627987 0.346188 5.901219 5.690207
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.442109 1.576010 0.062556 1.547026 0.170342 1.537072 0.440379 40.571779 0.589559 0.572569 0.339581 3.653940 3.726005
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.983700 -0.179548 -0.018167 0.320112 -1.161266 0.819468 -0.749175 3.334961 0.577050 0.562298 0.345282 1.628256 1.680206
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.826627 1.262608 -1.194358 -0.001256 4.860110 -0.448728 21.302814 1.789545 0.556926 0.557811 0.309373 4.753965 4.295793
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 6.894490 37.667998 5.355189 26.492885 9.679198 22.515855 -1.058505 13.514064 0.589506 0.043414 0.384249 3.634128 1.169308
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 10.029930 38.355415 -0.617553 25.374030 1.248219 22.648377 4.934510 9.564245 0.574993 0.037539 0.371182 4.064079 1.152403
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.160157 9.675195 6.386903 5.833560 12.235717 10.137801 -0.010120 1.616012 0.620831 0.618924 0.337379 3.483328 3.677265
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.352875 1.275362 -0.643068 -0.779619 2.420196 3.253037 6.724108 1.687667 0.623986 0.631975 0.315372 3.776513 4.818669
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.661624 0.204482 1.040390 -0.045394 -0.093571 0.638609 13.000968 0.839870 0.626852 0.632731 0.334762 3.780541 4.323764
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 15.79% -0.822930 0.217581 0.820314 0.594914 -0.092210 0.206619 -1.329231 -0.980204 0.636966 0.637556 0.342325 1.897064 1.961172
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 23.190222 1.194590 19.993166 0.217904 24.269312 2.202315 4.805790 3.174374 0.044894 0.627957 0.412536 1.390093 3.881338
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.555162 -0.120409 -0.859666 -0.348814 1.467868 0.770982 -0.348219 1.335857 0.572540 0.565520 0.323893 1.466666 1.508899
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.237224 0.123354 -0.834295 2.853137 -1.537199 1.784046 -0.663947 3.244008 0.598599 0.589380 0.321803 1.583544 1.699555
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.289272 -0.570077 -1.278425 2.960958 -1.279631 2.154027 1.347163 5.695992 0.617594 0.612867 0.323459 3.506047 4.610782
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.031830 -0.225698 -0.346841 1.040236 -0.444001 -0.233826 -0.086708 0.121262 0.624329 0.624294 0.323915 1.411714 1.544849
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 97.37% -1.770611 -0.439745 -0.026813 -1.335982 -0.664934 -0.635818 -0.332131 -0.263677 0.634888 0.642022 0.322234 3.182616 3.684898
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.257051 -1.719285 -0.450952 -0.908184 -0.370715 -0.574033 0.966185 1.550167 0.640028 0.640587 0.351845 27.354102 16.886990
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.090209 -0.907079 -0.823077 -0.252728 -0.835450 -0.591275 -0.559865 0.078512 0.636617 0.645892 0.336646 7.614098 10.460367
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.756211 -1.333297 -0.105416 0.559676 0.730594 0.127689 1.584554 -1.116717 0.622826 0.634804 0.356534 3.889191 3.735781
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.490138 -0.746212 0.278721 1.518725 1.647952 1.187080 0.625552 0.904406 0.610834 0.603844 0.361031 3.254794 3.238539
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.303553 2.942450 -0.053548 1.590624 -0.287213 1.606472 0.512989 -1.503305 0.551848 0.554461 0.306988 1.549765 1.645400
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.382760 -0.206854 0.593687 -0.169496 -0.403401 -0.083344 0.003559 -0.195043 0.577429 0.582789 0.311944 6.336058 5.086209
83 N07 digital_ok 100.00% 83.56% 0.00% 0.00% 100.00% 0.00% 20.084059 2.110102 16.869275 1.578032 22.916496 1.149526 3.801705 -1.347503 0.266127 0.613271 0.435059 1.395105 4.179160
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.718817 8.247589 4.998638 4.580972 8.980392 7.855045 -1.769484 -1.554937 0.624868 0.628142 0.316748 4.012900 4.210777
85 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.894503 28.095958 4.333659 0.409241 6.998871 5.653575 -1.566957 3.022265 0.640403 0.574911 0.326812 3.017014 3.533738
86 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.349688 14.865455 3.519807 7.652871 6.492882 15.312994 -1.329733 -1.595301 0.639630 0.614122 0.338247 2.905015 2.890974
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.159666 13.280566 6.759051 8.103117 15.035882 15.816068 44.166900 -1.530753 0.624157 0.623673 0.345976 3.468265 3.253447
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 digital_ok 100.00% 88.95% 100.00% 0.00% 100.00% 0.00% 36.337462 53.899596 3.651008 6.640504 24.004193 24.487794 6.910155 13.819661 0.303412 0.242443 0.109560 4.506955 4.067597
93 N10 RF_maintenance 0.00% 0.00% 0.00% 100.00% 100.00% 0.00% 1.008201 1.241818 1.288060 1.984249 3.083142 3.239546 -0.762440 0.903733 0.235411 0.233841 -0.288305 3.583688 3.572998
94 N10 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.411014 -0.178621 -1.050403 0.153393 -0.258946 1.123097 12.174670 6.933916 0.546334 0.537497 0.331275 4.495245 3.854440
98 N07 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.693689 29.826157 -0.832276 2.477967 -1.171258 1.477312 0.059383 5.118567 0.543406 0.516409 0.289607 5.021811 5.336841
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.883961 -0.014621 1.169897 0.818613 2.169678 -0.478530 0.936323 0.480376 0.567256 0.565416 0.303592 5.686430 4.645613
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.658699 -0.463186 0.029610 -0.498004 -0.454851 -0.644624 0.296091 0.889992 0.597105 0.596911 0.319385 5.539630 4.485950
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.998797 8.473346 5.456626 3.835740 9.660231 5.443678 2.342904 -1.594202 0.618531 0.622766 0.326173 3.718928 3.621880
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.201966 0.845779 6.264939 -1.442169 14.547051 8.536441 18.685400 84.812912 0.619072 0.626591 0.326781 3.078243 3.131866
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.516035 8.673574 4.691369 4.071283 8.080000 6.273473 -1.738396 -2.017757 0.636163 0.636568 0.333779 3.253136 3.276532
104 N08 RF_maintenance 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 8.455611 70.654759 3.420689 15.442774 7.013357 2.516377 -1.266738 0.960388 0.286706 0.253634 -0.274213 2.021245 1.825824
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% 0.00% 0.00% 0.00% 0.00% -0.852572 0.412379 -0.010493 -0.075861 -1.003436 0.030966 -0.074046 0.816406 0.582974 0.576797 0.348058 1.556016 1.846420
110 N10 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.269699 1.621321 0.834299 0.468444 0.682491 -0.844693 -0.861929 -1.473653 0.566914 0.574394 0.336979 4.631371 6.095924
111 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.426071 0.364398 -1.246016 0.336920 0.012579 -0.553320 -0.056796 1.378328 0.558284 0.554389 0.325970 1.472278 1.810770
112 N10 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.901359 -0.658270 -0.930624 0.098275 -0.623919 -0.804780 -0.400555 -1.230301 0.533647 0.534274 0.319994 3.096511 3.875043
116 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.651460 1.725796 1.217394 -0.952164 -0.075965 -0.522910 0.172857 -0.804932 0.521279 0.525850 0.305490 4.058290 4.472579
117 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.118062 3.046261 2.452005 2.151115 3.093802 2.346974 -1.722464 -1.947466 0.565172 0.564965 0.327133 1.566038 1.500657
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.512890 1.174603 1.163121 -1.418553 2.061870 -1.195223 0.290130 1.308646 0.573920 0.576903 0.324335 1.585762 1.608247
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.775885 0.450723 4.481825 -1.391040 7.743226 -1.724375 -1.691991 -0.662059 0.593671 0.598287 0.326362 3.504481 3.895764
120 N08 RF_maintenance 100.00% 67.39% 100.00% 0.00% 100.00% 0.00% 16.942181 34.619084 2.345408 23.319205 21.738215 22.558182 2.161583 9.109556 0.404427 0.050070 0.295159 2.451942 1.223800
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.888069 5.594086 4.777161 0.796235 9.041226 0.509128 25.320822 16.208534 0.623180 0.627924 0.333401 3.002338 3.181251
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.615867 7.386905 4.041515 4.539525 6.409247 7.414460 -1.228991 -0.618787 0.626541 0.622239 0.341440 2.996101 3.132889
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.650075 10.122421 6.206716 6.591982 11.866589 12.317307 -1.697475 -1.437480 0.618887 0.612633 0.350283 3.995568 3.740152
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 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.366051 0.073861 -0.543332 0.685632 -0.364109 0.662324 0.073681 1.213466 0.588553 0.584968 0.347736 4.918067 5.382189
128 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.918741 1.082585 -1.084267 0.263632 -1.414981 0.425803 -0.312827 -0.221404 0.581562 0.574420 0.331471 1.535774 1.668573
129 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.512659 -0.935828 -0.536788 -1.355350 -0.911959 -1.589392 -0.362560 -0.220850 0.563828 0.564123 0.323243 1.541813 1.672424
130 N10 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.505488 -0.209501 -0.248502 -1.440846 -0.818249 -0.665990 0.100799 6.619849 0.538728 0.541389 0.314103 4.150764 4.175229
135 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.412992 -0.994605 -0.049833 -0.779215 0.215559 -1.138660 1.016540 -0.213668 0.083788 0.087493 0.020137 1.302195 1.300890
136 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.715577 9.954793 -0.903726 -0.607252 0.974256 0.674670 0.133358 2.771549 0.073517 0.082885 0.013670 1.251454 1.250182
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.386129 24.758169 16.942298 17.785466 24.347660 22.371822 4.855502 5.481641 0.034417 0.043434 0.004184 1.287323 1.482833
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 26.391899 1.712342 15.846986 0.496245 24.336073 -0.437410 4.666410 1.035266 0.043399 0.563647 0.375667 1.277364 3.665769
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.247933 3.411903 -1.246602 -1.191912 -0.390252 -0.183477 0.861409 0.335111 0.590991 0.585063 0.331892 2.820700 3.000517
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.182795 3.455150 -0.253639 9.897605 -0.198064 2.089685 1.349233 19.350326 0.594695 0.547330 0.340994 3.576236 3.377801
142 N13 digital_ok 100.00% 75.47% 100.00% 0.00% 100.00% 0.00% 23.617615 26.688453 5.306251 21.026226 21.038889 22.411636 6.307051 5.483440 0.381615 0.041162 0.219141 8.908602 1.336642
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.047517 -0.523688 0.079176 -0.035853 -0.241362 0.016514 -0.033991 -1.104264 0.603772 0.601819 0.338995 1.205005 1.181540
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.086685 0.217027 2.356078 2.293950 1.393928 1.706199 2.114622 2.388416 0.600395 0.596930 0.350518 1.196663 1.200679
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.978625 23.889563 20.270819 21.180714 24.320223 22.376765 5.866982 7.128265 0.031812 0.033335 -0.000159 1.585412 1.678068
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.987758 26.067709 20.326306 21.702062 24.268219 22.288134 8.017659 8.625090 0.045098 0.047738 0.001862 1.284735 1.281305
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.007655 23.591337 19.725760 20.708969 24.373647 22.327921 4.733595 4.575030 0.032046 0.034898 0.002074 0.000000 0.000000
156 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.828049 0.687675 -0.033898 -1.448381 1.077668 0.107578 10.765633 21.495666 0.038578 0.048560 0.002258 0.000000 0.000000
157 N12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.066526 0.774783 0.766103 1.007787 -0.105032 2.005640 0.879706 -0.630121 0.056775 0.059412 0.005438 1.304108 1.293080
158 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.370204 0.964446 5.323544 2.457862 1.297819 2.402601 2.983534 3.395702 0.072448 0.066997 0.011121 1.279510 1.283760
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.980939 22.497021 20.031540 20.878535 24.317209 22.265808 4.623177 4.850031 0.039562 0.041671 0.002941 1.367680 1.364614
161 N13 digital_ok 100.00% 0.00% 18.87% 0.00% 100.00% 0.00% 0.622251 42.988298 -0.489568 7.140114 0.333383 2.372433 0.476456 0.893375 0.588523 0.469306 0.310501 4.230821 4.351326
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 13.16% 0.00% 1.455368 0.053613 -1.266568 -0.507376 -0.000958 0.000958 3.868260 0.817939 0.588279 0.586153 0.332346 1.086777 1.100727
163 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.337716 -0.060484 2.075227 4.793648 1.216090 1.715135 0.886607 2.687370 0.592345 0.581615 0.328601 7.899636 8.984053
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 13.16% 0.00% -0.229940 0.239324 -0.153869 3.417955 0.243259 0.787531 0.278561 1.229879 0.593201 0.583532 0.332254 1.069155 1.096055
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.704817 1.041178 2.874960 3.076076 4.624169 1.039851 -1.194962 0.655188 0.595247 0.582888 0.335465 4.770585 4.886675
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.349226 6.771588 -0.465144 -0.649566 4.568776 6.904857 4.915170 25.601776 0.558395 0.550211 0.292791 2.725015 2.781001
167 N15 digital_ok 100.00% 51.21% 43.13% 0.00% 100.00% 0.00% 25.227944 19.658025 6.457614 7.751371 18.365297 17.491320 28.969140 17.721909 0.450406 0.467886 0.175351 2.952518 2.767391
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.075952 16.429071 8.156356 9.051914 16.923907 17.973335 -1.262646 -1.088608 0.547434 0.531277 0.316736 4.067102 3.768452
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.334883 15.101723 9.163693 8.462317 19.253734 16.594255 -0.734767 -1.329649 0.523757 0.515335 0.314029 4.527350 3.957479
170 N15 digital_ok 100.00% 5.39% 0.00% 0.00% 100.00% 0.00% 16.602929 13.747946 9.218023 7.998309 19.626660 15.792745 -0.505333 0.242829 0.498662 0.504202 0.307683 3.803515 4.245623
176 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.105785 -0.092621 -0.493501 -0.038411 -0.805648 -0.095174 -0.771069 -1.163327 0.048715 0.047200 0.003946 1.163788 1.164280
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.749125 0.619124 0.450146 5.512024 -0.618844 2.218209 -0.432484 5.567705 0.057504 0.054615 0.004574 1.282893 1.284146
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.742323 -1.439001 -1.500136 -1.070893 -1.540005 -1.757106 -0.342148 -0.720892 0.069027 0.063096 0.010694 1.320184 1.320045
179 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.865564 0.872596 1.423295 0.888589 1.756214 1.431820 3.477491 -0.155332 0.075827 0.077264 0.016850 1.337927 1.338610
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% -0.085860 24.189626 0.215476 21.135550 -0.471691 21.942915 3.121508 8.987870 0.569892 0.105417 0.396906 7.275666 1.587196
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.072979 40.820931 20.327470 14.813731 24.332800 21.187992 4.729572 8.873078 0.040475 0.182674 0.091999 1.290458 1.656279
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.270199 11.269420 8.132825 7.037500 16.949145 13.616340 -1.120293 10.669705 0.558055 0.549361 0.336796 4.174062 4.641076
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.491748 0.360881 -0.854558 1.880935 0.018532 0.495396 -0.169177 5.117394 0.584932 0.566248 0.340518 4.445198 4.558185
184 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.231548 0.068191 3.516683 4.342458 0.897551 0.775684 1.456332 1.127807 0.579410 0.567539 0.327224 3.959591 3.856281
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.213005 0.150197 -0.539948 -0.069946 -1.320356 -0.051274 9.162873 -0.030587 0.592020 0.585510 0.333088 3.940112 3.806194
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.449738 -0.123594 6.592551 7.312985 0.505803 0.871267 3.716155 0.502923 0.561336 0.559252 0.318126 2.724191 2.822030
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.178298 0.049927 4.756801 0.087995 1.356284 -0.992070 3.839905 3.668990 0.565897 0.584618 0.334160 3.024388 3.476428
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.262264 3.021488 0.748210 0.318178 0.496674 0.878456 0.611950 1.155395 0.537491 0.534851 0.323063 1.517301 1.412480
190 N15 digital_ok 100.00% 56.60% 100.00% 0.00% 100.00% 0.00% 45.955861 25.483855 4.162883 21.203897 13.048075 22.381124 20.074789 5.017244 0.402961 0.042187 0.275950 4.068032 1.845257
191 N15 digital_ok 0.00% 5.39% 5.39% 0.00% 5.26% 0.00% -0.488063 -0.266931 0.085344 -1.136780 0.666490 0.180305 -0.071328 0.489934 0.508229 0.500922 0.320504 1.187668 1.199153
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.613630 6.044917 8.862311 3.553384 19.230183 6.802469 23.618033 34.955806 0.536809 0.550389 0.324907 3.237342 3.570100
206 N19 RF_ok 100.00% 13.48% 0.00% 0.00% 100.00% 0.00% 3.889222 13.766613 0.273531 7.656877 4.651249 16.006133 26.447041 23.882894 0.505292 0.523848 0.307364 2.150512 2.351372
207 N19 RF_ok 100.00% 2.70% 0.00% 0.00% 100.00% 0.00% 16.952768 15.093114 9.297127 8.416136 20.259830 16.691083 8.807294 4.244832 0.508749 0.515096 0.302107 3.290062 3.416518
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% 14.637624 11.403713 32.447520 32.410517 2131.178096 2457.517170 10146.472264 14603.744662 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.077605 15.800590 7.587577 8.854528 16.017614 17.490417 -0.943821 -1.579207 0.529856 0.506202 0.330010 3.001983 2.807975
224 N19 RF_ok 100.00% 13.48% 13.48% 0.00% 100.00% 0.00% 19.137319 18.370334 10.481304 10.027243 22.447921 20.044577 -0.534709 -1.285154 0.488922 0.488044 0.300441 3.103039 3.042687
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% 13.024173 15.793007 inf inf 3001.218345 3001.238523 18445.055835 18444.485482 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.718184 26.952557 14.295529 14.704845 24.451815 22.289758 8.427132 5.621473 0.065776 0.058218 -0.002539 0.000000 0.000000
321 N02 not_connected 100.00% 48.52% 86.25% 0.00% 100.00% 0.00% 9.332595 7.219125 5.778254 4.983534 12.912330 10.661935 34.127468 34.631739 0.411267 0.365810 0.247004 0.000000 0.000000
323 N02 not_connected 100.00% 64.69% 91.64% 0.00% 100.00% 0.00% 20.087838 10.271747 0.555735 6.376954 9.792697 12.726178 6.938470 0.451816 0.323346 0.349239 0.211137 0.000000 0.000000
324 N04 not_connected 100.00% 48.52% 91.64% 0.00% 100.00% 0.00% 12.758698 13.710171 7.796421 7.662874 15.895964 14.714252 -1.271959 -1.810045 0.394291 0.347040 0.244644 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.205747 6.333507 1.391911 4.834124 1.682881 7.768868 6.480125 -1.488438 0.064465 0.065721 0.019777 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.345248 6.406140 7.438909 4.248556 16.908568 7.741629 2.549642 -1.108533 0.055580 0.066988 0.020838 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, 7, 8, 9, 18, 19, 21, 27, 28, 29, 32, 33, 36, 37, 38, 40, 41, 42, 45, 50, 51, 52, 53, 54, 55, 56, 57, 67, 69, 70, 71, 72, 73, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 112, 116, 119, 120, 121, 122, 123, 125, 126, 127, 130, 135, 136, 137, 138, 140, 141, 142, 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, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [5, 10, 15, 16, 17, 20, 30, 31, 46, 65, 66, 68, 81, 109, 111, 117, 118, 128, 129, 143, 144, 189]

golden_ants: [5, 10, 15, 16, 17, 20, 30, 31, 46, 65, 66, 68, 81, 109, 111, 117, 118, 128, 129, 143, 144, 189]
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_2459783.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.2
3.1.1.dev2+g1b5039f
In [ ]: