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 = "2459801"
data_path = "/mnt/sn1/2459801"
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-9-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/2459801/zen.2459801.27110.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

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

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

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.845750 -0.443918 -0.714037 -0.931602 -1.263001 -0.631941 -0.853873 2.988454 0.747246 0.682381 0.486095 1.864220 1.510305
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.393535 3.874094 -0.977249 1.619694 -1.364244 0.679555 -0.177026 -0.600364 0.765389 0.694070 0.481559 8.744550 7.249452
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.059630 1.533445 -0.588939 4.268212 -1.580243 2.965895 -0.770932 -2.170819 0.777365 0.709676 0.480551 5.630559 4.947595
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.029670 -1.031322 0.320300 -0.164548 0.053988 1.642640 -0.574868 14.707753 0.781019 0.715117 0.476545 4.785112 4.743148
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.317155 16.185248 17.638603 18.119843 28.531680 31.056948 4.693474 3.529970 0.760572 0.682284 0.480016 4.026156 4.309700
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 47.37% -0.339989 -1.086673 0.203652 -0.215337 3.091302 1.717874 -0.210725 -1.115672 0.764898 0.689815 0.480386 3.968327 3.790143
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.125321 -1.086173 -0.664094 0.343204 -0.744344 -0.243917 1.671308 2.761387 0.746179 0.665899 0.494397 2.103408 1.878182
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.724114 1.399025 1.502472 0.599509 0.642030 0.253307 0.671196 0.412881 0.781434 0.712624 0.472485 2.600982 2.244847
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.073832 -0.659802 -0.708921 -0.374254 -1.415001 -1.782673 8.659362 5.915650 0.788443 0.730402 0.466329 7.637705 7.946841
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% 0.663928 1.451039 0.062309 0.334526 -0.174455 -0.248577 0.949651 -0.159309 0.796024 0.737733 0.458972 2.740896 2.565881
18 N01 RF_maintenance 100.00% 0.00% 16.67% 0.00% 100.00% 0.00% 3.786214 3.537442 1.001417 0.537798 10.060039 4.200354 248.925814 103.487015 0.761901 0.577510 0.514560 4.717381 2.484198
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.384250 1.243745 0.226609 4.676337 -0.499158 4.091971 20.345747 32.622877 0.785988 0.726505 0.466033 4.939342 5.116114
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 31.58% -1.326152 0.413243 -0.372905 -0.843226 1.898886 0.615767 0.648556 0.305219 0.773671 0.704200 0.467154 3.540033 2.396197
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.370288 1.764728 0.689282 1.099305 -0.316909 0.233233 3.910986 -1.160487 0.757721 0.682942 0.490966 2.195910 1.916088
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.438895 22.260131 53.740032 54.593496 41.991962 43.738922 17.747041 16.415974 0.041593 0.047074 0.004161 1.211448 1.214507
28 N01 RF_maintenance 100.00% 0.00% 97.31% 0.00% 100.00% 0.00% 13.028473 14.492942 6.835916 10.456423 38.834597 39.839961 17.381237 108.496912 0.542892 0.304096 0.325022 21.725492 4.102217
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.107047 -0.155820 0.313826 -0.370702 -1.560720 -1.981146 -0.632345 -0.572113 0.803914 0.754698 0.452474 2.393910 2.421262
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.431850 0.134972 -1.018607 -0.577616 0.215299 -0.174465 6.936415 2.767001 0.798993 0.749182 0.446967 6.846779 7.336571
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.373060 -0.318700 -1.017445 0.339257 -1.245937 0.141351 -0.083305 0.668384 0.796504 0.741349 0.463466 2.276302 2.183602
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 32.636795 29.139279 2.669828 2.398700 12.557414 12.225125 35.405381 38.536921 0.732927 0.676352 0.291760 17.127529 14.393991
33 N02 RF_maintenance 100.00% 0.00% 19.35% 0.00% 100.00% 0.00% -0.532116 3.398354 -0.524876 0.663800 -1.100654 1.325800 5.311199 23.146607 0.766163 0.559564 0.577652 6.827533 3.204157
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.509610 6.009017 0.052675 0.449791 2.001014 0.216285 3.358861 1.596162 0.750136 0.678288 0.478297 4.382982 4.270886
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.827677 1.024740 0.593406 0.257353 2.303470 0.928991 2.021574 23.037358 0.768636 0.700746 0.470251 4.603599 4.963358
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.110801 -0.042186 -0.632491 -0.986365 4.376393 1.309341 10.033098 4.959226 0.781493 0.722976 0.462126 4.690900 4.298529
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.150766 -0.523371 0.365025 -0.060708 2.767419 1.793666 -0.262862 0.348148 0.795633 0.748664 0.445992 2.976090 2.606830
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.685053 -0.386775 2.014049 1.491691 1.352982 -0.686531 -0.946827 0.764194 0.803311 0.760472 0.447346 2.740949 2.138807
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.05% -0.213330 0.480597 1.911107 1.200962 -0.098661 -0.838330 -1.328759 0.641599 0.806971 0.759956 0.459362 2.485552 2.439355
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.492594 0.815312 -0.690894 1.201407 -1.586603 -0.159339 -0.031239 52.656390 0.784389 0.717808 0.483200 5.231317 4.928687
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.084811 -0.802462 0.524665 -0.960487 -1.284711 -1.345365 -0.088137 2.074445 0.776237 0.698013 0.506881 2.085556 1.820224
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 25.979726 2.465139 5.204517 2.410124 5.057810 1.408182 6.214078 0.162838 0.706502 0.679517 0.402535 5.768753 4.139441
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.574893 1.458465 -0.790194 -0.764259 0.003969 -0.454073 0.334097 0.188180 0.770848 0.709362 0.462932 1.728757 1.738393
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.003000 5.160392 -0.343665 -0.127082 0.705252 0.295985 5.574047 1.320282 0.786273 0.729170 0.457014 4.976527 5.219259
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.905483 1.103430 -0.638720 -0.265306 -1.216183 0.379892 3.842503 13.440904 0.796878 0.752882 0.450666 5.091306 5.512264
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.283371 0.368615 1.412171 1.092257 2.760003 2.781324 6.375786 1.858404 0.807140 0.763370 0.453197 6.792876 6.262605
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.471024 -0.208317 -0.800417 0.651037 1.387305 2.685253 6.114337 -0.358553 0.808731 0.765666 0.460007 8.867987 8.695255
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 10.53% -0.404895 0.324949 0.886438 1.102407 0.658935 0.882267 -0.821350 0.368010 0.805576 0.763774 0.459201 2.820558 2.315024
57 N04 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 20.913372 12.730125 53.501765 2.524579 42.201159 40.457275 13.778077 18.024719 0.048030 0.530529 0.276058 1.393134 9.343616
65 N03 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
66 N03 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
67 N03 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
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.045367 0.103030 0.100722 -0.234951 2.824277 2.034366 0.793501 0.469026 0.797291 0.754865 0.446343 1.983360 1.933008
69 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.243267 -0.528997 -0.721550 -0.047241 0.092809 0.560228 0.001457 5.765337 0.806198 0.763475 0.464007 4.851752 6.055554
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.461479 -1.209099 -0.030246 -0.936164 -0.756415 -1.035631 -0.061780 1.650774 0.804074 0.760253 0.480957 51.101986 37.843755
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.330403 -1.169878 -0.585947 -0.554021 -0.339047 -0.939583 -0.283950 0.677785 0.808584 0.766337 0.469145 58.531369 57.010345
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.635581 -0.178820 -0.475997 1.353524 0.774086 0.672513 9.804456 -1.490854 0.798880 0.748878 0.492911 5.171649 4.121211
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 21.736073 3.181546 52.896018 -0.542587 41.910208 -0.321114 13.354974 1.359167 0.033574 0.732276 0.409652 1.182542 3.762111
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.553510 2.871353 -0.421524 3.092333 0.371432 2.952522 0.729465 -1.875176 0.757916 0.684498 0.462789 1.781416 1.773074
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.323556 -0.582261 0.080345 1.089738 -0.202051 -0.984877 -1.003496 -0.497256 0.775862 0.710472 0.466599 5.969564 6.273994
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.057255 3.927713 1.940569 4.682140 0.185908 3.809135 -1.007792 -2.027343 0.785118 0.731582 0.447941 4.655625 4.836528
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.794571 7.557900 0.000913 1.531330 -1.001246 0.488759 -0.990890 1.077681 0.048253 0.061553 0.006848 1.215091 1.216357
85 N08 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.215112 1.010152 -0.937414 -0.234762 -1.852372 -1.618381 -0.447875 -0.446432 0.066519 0.067720 0.007326 1.211281 1.209301
86 N08 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.831842 2.776190 -0.222118 -0.703428 0.968535 0.497921 -0.006053 -0.493228 0.069435 0.072248 0.008583 1.176945 1.178971
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.431805 8.885271 5.383591 1.215804 7.054949 0.226105 17.849646 1.156321 0.084282 0.068681 0.012240 1.173882 1.175598
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.724734 20.027835 47.209903 48.356784 42.597323 44.423297 23.276605 17.029168 0.032905 0.032026 0.002522 1.176374 1.178152
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.897275 21.895176 47.106083 47.980352 42.289775 43.991288 12.850555 12.199631 0.033241 0.030994 0.001859 1.140943 1.136677
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.691951 20.813987 47.084950 49.036446 42.329297 44.120102 18.170707 17.933566 0.030169 0.030259 0.000188 1.083550 1.082415
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 31.054561 43.986220 9.873461 12.429914 40.968824 46.570463 13.546801 32.429715 0.271615 0.217193 0.097885 4.230938 3.231977
93 N10 digital_ok 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 0.173754 0.202632 2.879056 -0.846253 2.408423 1.244289 -0.970342 5.481782 0.206729 0.209059 -0.276206 4.524308 4.495392
94 N10 digital_ok 100.00% 0.00% 38.17% 0.00% 100.00% 0.00% 0.640232 0.228798 -0.044764 -0.789115 -0.234347 0.816431 4.432728 16.336857 0.581441 0.488790 0.386437 3.887281 3.828094
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.487323 3.370163 0.167880 0.132432 0.201369 -1.387546 -0.712521 8.406830 0.760412 0.679161 0.466454 10.721087 8.791706
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.227542 0.605764 2.625491 -0.061354 3.236042 0.824657 4.950760 -0.734075 0.770451 0.708069 0.443556 7.149379 6.473042
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.693988 0.109036 0.181321 0.189699 -0.669426 -0.802644 -0.827546 -0.361450 0.785192 0.727086 0.465749 1.889183 1.834198
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.848898 7.468087 3.466592 -0.075097 1.594801 -0.636084 4.235724 -0.584625 0.080812 0.063754 0.007432 1.207630 1.209441
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.168049 16.084637 7.534439 4.698869 427.849260 357.069550 14093.991715 13929.973251 0.088842 0.090144 0.017252 0.000000 0.000000
103 N08 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
104 N08 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
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.464102 26.225017 44.673676 46.605435 42.667595 44.743587 14.848655 15.265342 0.034160 0.032383 0.001163 1.167194 1.161573
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.792148 22.617366 46.310945 48.409853 42.244294 44.345397 16.764049 13.767505 0.029402 0.028379 0.000886 1.192694 1.193095
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.120168 19.903121 45.358691 46.363117 42.419339 44.088685 16.099821 17.962822 0.031768 0.029996 0.001419 1.241912 1.236266
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.347067 20.092716 46.518552 48.579254 42.283088 44.272819 12.010886 12.814059 0.030607 0.031033 0.001246 0.000000 0.000000
109 N10 digital_ok 0.00% 0.00% 38.17% 0.00% 39.47% 0.00% -0.685645 0.306212 0.205692 0.508109 -0.494968 -0.122892 1.624757 0.847655 0.616473 0.519114 0.419772 1.804433 1.763913
110 N10 RF_maintenance 100.00% 0.00% 38.17% 0.00% 100.00% 0.00% 29.040571 2.943170 2.458392 0.694534 25.965360 16.435449 114.534818 89.478115 0.571525 0.504726 0.343306 19.025133 11.681424
111 N10 digital_ok 100.00% 0.00% 38.17% 0.00% 100.00% 0.00% 0.460589 1.141705 -0.282091 1.203887 1.538033 2.392398 0.070245 9.577964 0.591181 0.489954 0.385704 7.063866 8.621179
112 N10 digital_ok 0.00% 0.00% 38.17% 0.00% 39.47% 0.00% -0.454304 -0.265767 -0.508674 0.693016 -0.391446 0.273945 -0.776032 -1.839751 0.569679 0.477634 0.377847 1.565516 1.555505
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.785289 1.767181 -0.327597 -0.589006 -0.003969 -0.142433 -0.349766 -1.059104 0.757845 0.682746 0.463819 2.041578 2.035554
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.275175 3.490976 5.124829 5.254556 4.162591 4.867847 -2.024756 -2.347669 0.775723 0.707200 0.469291 10.080132 12.081229
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.198376 1.084610 2.500311 0.242809 3.141679 0.487983 -0.172296 1.699079 0.782334 0.720472 0.469579 1.912490 1.922175
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.704019 0.348729 7.697218 3.107327 9.356649 -0.110831 -1.781890 1.329766 0.790078 0.726034 0.487649 6.488913 4.938191
120 N08 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
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.649875 4.632505 -0.691664 0.528118 -0.689472 0.321803 52.244489 18.700806 0.067293 0.070402 0.008852 1.197181 1.194550
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.817238 6.216688 1.279333 1.217384 0.586556 -0.605485 -0.109185 -0.043152 0.083399 0.086471 0.014497 1.208428 1.206984
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.498586 7.345549 0.295574 -0.007059 -0.536864 0.180515 -0.278384 1.972627 0.087912 0.086611 0.018480 1.196518 1.192837
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.975396 20.997190 47.731980 49.270300 42.611065 44.254943 13.516120 19.490411 0.029785 0.029593 0.000550 1.153497 1.151406
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.188320 21.134793 47.172013 49.613771 42.535828 44.470344 15.435956 17.735905 0.029178 0.029029 0.000890 0.874277 0.873686
127 N10 digital_ok 0.00% 0.00% 32.80% 0.00% 34.21% 0.00% -0.078978 -0.116950 0.209860 -0.230295 0.360641 0.465795 0.560699 2.461975 0.616672 0.517668 0.418347 1.739629 1.605827
128 N10 digital_ok 0.00% 0.00% 38.17% 0.00% 39.47% 0.00% -0.829957 1.084070 -0.258831 1.433759 -1.130062 0.929059 0.119873 -0.794375 0.607779 0.506771 0.398022 2.286022 1.692263
129 N10 digital_ok 0.00% 0.00% 38.17% 0.00% 39.47% 5.26% -0.100876 -1.291825 -0.599709 -1.075256 -0.684555 -0.777197 -0.839620 -0.758056 0.592694 0.498614 0.382131 2.382874 1.870771
130 N10 digital_ok 100.00% 0.00% 38.17% 0.00% 100.00% 0.00% -0.133916 0.338002 0.911404 1.291872 0.523577 1.228271 0.741181 7.722959 0.572845 0.480272 0.373231 7.158352 6.262969
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.750714 -0.385376 -1.003334 -1.013853 -0.889570 -1.476324 0.536670 -0.285588 0.700355 0.619452 0.454648 6.056659 5.320131
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.241842 9.516450 -0.607371 0.478233 5.204530 4.926629 4.108566 5.609142 0.703126 0.628628 0.428084 9.454274 9.458810
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.199143 20.395992 46.494310 47.615258 42.351786 44.217515 15.617315 19.793991 0.037214 0.044482 0.003553 1.321521 1.430702
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 25.350215 2.157774 46.195791 1.515252 42.631661 -0.153326 16.309578 0.282461 0.046082 0.715151 0.436255 1.315888 5.658664
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.851553 20.208434 52.675349 54.730164 41.972936 44.126661 12.499180 13.606648 0.040468 0.041525 0.001387 1.086349 1.088023
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.897696 5.915881 -0.356328 10.707895 1.646047 4.509039 1.364791 27.095843 0.764837 0.697286 0.505013 3.588497 2.896468
142 N13 digital_ok 100.00% 32.26% 100.00% 0.00% 100.00% 0.00% 19.620843 24.810818 8.252707 54.942125 36.467716 44.406858 13.120945 15.662140 0.451862 0.043593 0.239549 2.182861 1.181746
143 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.060794 -0.817868 1.353186 0.903027 0.824383 0.561438 0.073754 -1.885100 0.118984 0.119345 0.031691 1.115371 1.123856
144 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.915215 1.701989 -0.840436 1.387028 -1.357114 0.434729 1.149805 0.249490 0.107460 0.100068 0.022917 0.929315 0.913217
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.427922 21.299674 54.048523 55.318411 42.155625 44.098006 16.025583 19.105272 0.031442 0.034607 -0.000241 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.501530 23.680665 53.807992 56.220335 42.590517 44.619683 17.085061 19.170259 0.052638 0.054802 0.001634 1.272996 1.262797
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.011354 21.445694 52.818318 54.311232 42.002009 43.901259 17.850554 18.651592 0.043062 0.040924 0.001055 1.401534 1.387136
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.101326 1.186229 0.979151 -0.199469 0.324207 0.572639 6.671334 12.242218 0.696818 0.613767 0.447990 7.008262 6.929322
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% 0.374719 1.834198 0.119150 2.832923 0.522305 1.746573 0.626201 -0.712686 0.694887 0.624660 0.443735 2.330797 1.951400
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.758381 -1.312168 -0.765905 -0.432288 0.293071 0.553374 0.006053 1.194317 0.700608 0.627935 0.449235 1.943365 1.811035
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.741173 19.103926 53.500698 54.803465 42.098273 44.068175 16.320767 20.013537 0.043977 0.043809 0.002149 1.285316 1.288741
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.614619 39.848411 -0.486445 3.817645 -0.809295 13.263384 0.279275 1.064492 0.755023 0.614524 0.454389 3.831199 3.189401
162 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.351856 1.289092 -0.542594 -0.789692 2.455997 1.262098 5.375420 2.887278 0.758120 0.680739 0.506543 3.140203 2.783602
163 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.392312 -0.264302 0.060708 -0.704859 -0.596634 -0.789544 0.463917 1.322501 0.088044 0.091410 0.016162 1.227635 1.234317
164 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.197187 -0.648404 -1.096488 -0.702549 -1.355453 -0.564102 0.830948 3.772138 0.079116 0.072366 0.005968 1.230098 1.229710
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.865544 1.207211 5.942208 -0.871124 5.986130 -1.792174 1.899885 1.415748 0.090361 0.070354 0.005014 1.243379 1.248706
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.553865 2.405201 -0.069788 0.618148 15.475207 5.347032 49.035561 12.068498 0.098654 0.082969 0.009972 1.229531 1.233898
167 N15 digital_ok 100.00% 0.00% 27.42% 0.00% 100.00% 0.00% 17.991430 20.591321 17.328423 18.076867 33.137723 32.697134 8.228699 9.305230 0.676719 0.582285 0.384354 4.618798 3.466369
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.096357 18.893188 17.926112 20.054067 29.444541 35.357800 2.419703 4.728481 0.706069 0.597494 0.494868 4.496716 3.557911
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.088079 17.533199 19.635319 18.939698 32.598913 32.934951 4.254568 3.824838 0.689245 0.577370 0.486149 4.351645 3.478622
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.220671 16.034248 19.835466 18.200167 33.207690 31.419894 4.602767 3.011923 0.673889 0.566006 0.481629 3.668847 3.306751
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.045367 -0.394425 -0.858016 0.471897 0.275407 0.268524 -1.132693 -1.607232 0.674777 0.584389 0.453363 2.319944 2.286826
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.141737 2.118295 0.558818 0.702031 -1.295553 -0.675550 2.646409 10.174085 0.675413 0.590006 0.445434 14.190232 16.152373
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.708366 -1.505785 1.138924 -0.684887 0.387304 -1.490136 -0.453396 -1.190927 0.680725 0.598451 0.441065 2.388528 2.179935
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.352538 0.596134 -1.003010 -0.142270 4.053279 -0.920051 12.549276 -0.936352 0.681594 0.603442 0.446302 5.421335 5.626094
180 N13 RF_maintenance 100.00% 0.00% 40.86% 0.00% 100.00% 0.00% 0.663741 13.157545 0.454745 49.346191 -1.079886 27.080527 -0.797258 15.004846 0.746996 0.464708 0.553557 12.648048 4.557259
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.414618 48.391119 54.198314 5.790141 42.179196 47.594267 16.107279 30.644051 0.049843 0.317371 0.149912 1.215011 2.736223
182 N13 RF_maintenance 100.00% 0.00% 27.42% 0.00% 100.00% 0.00% 15.609132 11.071183 17.862274 43.084177 28.996829 14.840664 2.148705 53.335965 0.730290 0.547436 0.508908 2.601069 1.910032
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.249860 -0.469672 -0.133828 -0.845193 -0.138952 -2.253775 -0.145601 6.825205 0.756669 0.670775 0.524169 3.288852 2.681448
184 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.618695 0.221694 -0.137607 0.578914 0.040332 0.237157 1.984026 -0.306787 0.066864 0.060944 0.004735 1.230188 1.233574
185 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.373720 0.560723 -0.271968 1.014993 -0.399212 0.396133 7.385999 -0.453837 0.051578 0.067054 0.005034 1.197622 1.209734
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.522218 0.608579 3.854039 2.105586 2.224159 0.903877 5.617586 0.071346 0.066867 0.073875 0.009983 0.000000 0.000000
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.977970 1.062954 0.183915 0.457982 -0.054603 -1.953230 5.251650 -0.121882 0.090739 0.102024 0.018951 1.241148 1.232815
189 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
190 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
191 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
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.732694 6.184296 12.827129 -0.256647 19.866097 5.357243 41.325459 58.497832 0.054340 0.040611 0.003404 0.000000 0.000000
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.494773 8.388022 -0.421559 9.095100 9.119576 16.254785 40.942038 43.141294 0.041742 0.054026 0.002361 0.949665 0.974868
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 13.587382 11.399441 14.958784 12.656195 24.616591 20.993720 15.788465 13.212024 0.061046 0.061484 0.005811 0.852593 0.850340
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% 12.424364 12.061374 86.087972 88.645275 3248.944521 3770.093258 17689.446201 23837.871183 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.120865 6.178909 7.448177 6.433021 10.560181 9.597178 0.263741 5.498571 0.045123 0.047373 0.001704 0.000000 0.000000
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.615597 20.457771 22.112379 21.871528 37.671667 38.801892 5.201946 5.430610 0.065922 0.065850 0.005344 0.982689 0.961560
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.922276 15.195961 107.525721 108.918330 4494.737933 4494.512319 29114.534210 29114.677672 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.878480 23.889455 40.016770 40.300735 42.440292 44.049103 23.196775 17.944615 0.062675 0.055762 0.001057 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 59.68% 0.00% 100.00% 0.00% 10.226781 8.277825 12.064377 11.043233 20.813006 19.060449 43.762935 41.986610 0.573759 0.402738 0.398246 0.000000 0.000000
323 N02 not_connected 100.00% 0.00% 65.05% 0.00% 100.00% 0.00% 18.913183 11.768887 2.724868 14.302588 16.936302 24.800587 12.036331 1.389322 0.484429 0.367345 0.329340 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 59.68% 0.00% 100.00% 0.00% 14.165974 14.996257 16.067266 16.478839 25.042136 27.509801 1.346706 1.694374 0.569209 0.393841 0.409308 0.000000 0.000000
329 N12 dish_maintenance 100.00% 10.75% 73.12% 0.00% 100.00% 0.00% 1.880557 7.598711 1.165600 10.349973 2.861212 14.354033 5.412892 -0.576836 0.490224 0.337579 0.335288 0.000000 0.000000
333 N12 dish_maintenance 100.00% 24.19% 97.31% 0.00% 100.00% 0.00% 0.928091 6.974555 1.624734 9.404245 2.287116 13.998491 8.184854 -0.685540 0.461797 0.300467 0.310600 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [4, 5, 7, 8, 9, 16, 17, 18, 19, 20, 27, 28, 30, 32, 33, 36, 37, 38, 42, 45, 50, 52, 53, 54, 55, 56, 57, 65, 66, 67, 69, 70, 71, 72, 73, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 117, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 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: [3, 10, 15, 21, 29, 31, 40, 41, 46, 51, 68, 81, 100, 116, 118, 158, 176]

golden_ants: [3, 10, 15, 21, 29, 31, 40, 41, 46, 51, 68, 81, 100, 116, 118, 158, 176]
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_2459801.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 [ ]: