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 = "2459786"
data_path = "/mnt/sn1/2459786"
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-25-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/2459786/zen.2459786.25318.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/2459786/zen.2459786.?????.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/2459786/zen.2459786.?????.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 2459786
Date 7-25-2022
LST Range 15.732 -- 17.732 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 104 / 147 (70.7%)
Cross-Polarized Antennas 104
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N10, N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 82 / 147 (55.8%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 117 / 147 (79.6%)
Redcal Done? ✅
Redcal Flagged Antennas 10 / 147 (6.8%)
Never Flagged Antennas 12 / 147 (8.2%)
A Priori Good Antennas Flagged 78 / 85 total a priori good antennas:
5, 7, 9, 10, 15, 16, 17, 19, 20, 21, 30, 37,
40, 41, 45, 46, 50, 51, 53, 54, 55, 56, 57,
65, 66, 68, 69, 71, 72, 81, 83, 84, 88, 91,
92, 99, 101, 103, 105, 107, 108, 109, 111,
117, 118, 121, 122, 123, 128, 129, 135, 138,
140, 141, 142, 143, 144, 145, 160, 161, 162,
163, 165, 167, 169, 170, 176, 177, 178, 179,
181, 183, 185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 5 / 62 total a priori bad antennas:
3, 67, 98, 100, 116
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_2459786.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.175814 -0.198339 -0.219839 -0.971215 -0.531983 0.236517 -0.436856 -0.021300 0.611638 0.607944 0.379143 11.301788 6.463827
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.580880 5.065150 -0.738568 -0.097512 -0.444858 -0.319397 3.047853 0.474690 0.624994 0.615091 0.376886 34.040179 40.807122
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.158440 1.823798 -0.549317 6.835890 -1.047555 5.575700 0.369744 -1.480588 0.631631 0.621670 0.376721 3.854121 3.360004
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.982109 5.989918 13.134945 13.575553 16.998666 16.050501 -1.706355 7.039193 0.612922 0.605340 0.369311 3.819297 3.612314
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.842617 19.266081 25.693704 27.112977 37.421596 37.108365 1.482308 -0.202577 0.585707 0.572027 0.363955 7.907515 8.127515
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.237077 5.714344 0.477839 13.816555 2.433890 14.873901 0.746362 -0.072232 0.587343 0.579644 0.369990 0.000000 0.000000
10 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% 0.451549 1.932213 -0.879300 0.006550 0.136460 0.006539 -0.308169 3.062976 0.647860 0.637930 0.379969 5.767899 5.452482
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.630197 -0.976003 -1.004358 0.813427 -0.677471 -0.367935 7.256681 5.071857 0.650750 0.644792 0.371002 23.788904 44.140275
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.067027 1.089328 0.454714 0.327787 0.409414 0.041971 16.045875 21.268368 0.644157 0.639635 0.355976 24.074718 24.278161
18 N01 RF_maintenance 100.00% 0.00% 59.14% 0.00% 100.00% 0.00% 10.666899 9.729634 1.813390 3.002916 4.716794 10.275005 87.914924 125.208330 0.560739 0.431427 0.364437 7.001414 3.778347
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
20 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.129793 -0.604467 -0.052109 0.935375 0.244440 0.056857 0.177501 17.577428 0.580526 0.568696 0.363401 6.456648 6.335716
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.086710 29.350068 68.044752 68.550378 52.255495 50.090095 15.542269 11.535780 0.041563 0.046090 0.003401 1.314354 1.315442
28 N01 RF_maintenance 100.00% 45.70% 100.00% 0.00% 100.00% 0.00% 14.781161 26.222638 6.556497 12.082029 48.099620 51.884460 11.629859 74.807373 0.464170 0.247739 0.272942 15.635067 3.993894
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 0.00% -1.613717 -0.812560 0.658581 -0.132214 0.474093 -0.510037 -0.901876 1.320963 0.664542 0.662260 0.361644 2.528773 2.070649
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.895154 -0.025859 -0.443693 -0.609918 -0.292841 -0.784351 7.319438 1.096618 0.650180 0.648405 0.362455 12.934338 23.861798
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 0.00% -0.516672 -0.529220 -0.759137 -0.891498 -0.280830 0.112102 2.341774 2.392694 0.642274 0.632519 0.365278 2.040716 2.383457
32 N02 RF_maintenance 100.00% 16.13% 0.00% 0.00% 100.00% 0.00% 36.603012 41.150197 3.074559 3.556101 17.368001 16.316046 52.761276 94.277355 0.538838 0.552054 0.194613 4.870372 4.484673
33 N02 RF_maintenance 100.00% 0.00% 61.83% 0.00% 100.00% 0.00% -0.349928 7.432906 0.344146 1.628029 17.580266 22.756808 156.965678 208.137754 0.592832 0.423304 0.428442 5.967897 3.878739
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.387770 9.671994 0.273623 1.114422 -0.007000 -0.545353 0.556798 1.891365 0.613894 0.599555 0.359826 8.815380 13.649064
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.612657 0.953563 0.655123 -0.117812 0.224496 0.699592 -0.371771 12.624334 0.646048 0.636768 0.369004 8.485097 7.958684
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.321107 0.069620 -0.509920 -0.482723 1.301268 0.498814 12.629475 2.080364 0.667243 0.659877 0.379119 6.108474 8.224110
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.981262 0.244509 0.185915 -0.886036 -0.661709 -0.923558 0.021300 -0.551367 0.681804 0.681962 0.369757 2.602208 3.135254
41 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.914236 -0.419266 3.616176 -0.852326 4.683647 -0.706783 -0.791025 1.127015 0.678841 0.678040 0.355425 19.999393 41.759825
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 0.00% -0.827649 0.576573 3.015294 0.632458 1.327077 0.318477 -1.317094 -0.404973 0.679865 0.679899 0.369840 5.017200 4.268365
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.107429 0.353721 0.048068 1.422955 0.435852 0.455074 0.525747 27.117412 0.629528 0.618967 0.371928 4.823773 5.046436
46 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.351193 -0.808803 0.774196 -1.045240 0.233470 -1.097067 0.079957 5.407342 0.609216 0.602044 0.378726 4.982602 5.587332
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.208501 3.619116 -0.812457 1.113307 0.403263 2.539488 14.602642 15.659090 0.621744 0.614040 0.343047 0.000000 0.000000
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 1.153960 45.032564 4.664832 85.618471 3.281223 50.340129 0.160226 33.887391 0.653975 0.046680 0.395355 8.255682 1.096412
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 14.401159 50.747694 0.853090 86.498236 7.896085 50.854205 68.665318 35.964035 0.631845 0.045030 0.372326 7.267560 1.127230
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.427715 3.452531 6.387844 5.442845 5.156133 3.608037 2.594004 8.437289 0.689674 0.688442 0.368025 0.000000 0.000000
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.292642 2.393418 0.363375 0.947954 6.055326 6.688967 2.096256 1.857817 0.686864 0.686426 0.337620 36.920840 35.904819
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.145117 -0.057213 0.724064 0.916277 1.073732 2.637590 19.602460 1.094993 0.684542 0.688067 0.355999 166.158951 96.576155
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.639190 4.775924 14.630902 11.951497 18.034542 13.208564 -1.669017 13.852071 0.687382 0.691304 0.368112 38.627012 38.345251
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 28.559707 2.595983 64.406897 1.963144 52.118953 8.823564 10.483061 4.152530 0.051846 0.678258 0.406170 1.246269 34.935536
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 55.26% 1.061735 0.620465 -0.025948 0.736383 1.054921 0.943439 -0.738611 1.448302 0.630487 0.625210 0.360474 5.826158 4.708789
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.850309 1.175191 -0.835222 -0.313049 -0.228607 -1.026668 0.803972 7.549018 0.656654 0.652637 0.353623 18.481031 23.838783
67 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.499859 -1.117557 0.850441 1.046533 0.633462 0.931612 0.967527 1.761218 0.677229 0.676694 0.353121 2.167368 2.146729
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 86.84% 0.115734 0.258965 -0.663714 0.960202 0.691432 0.323096 -0.093185 0.135059 0.684485 0.685063 0.353815 0.000000 0.000000
69 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.571181 4.603611 12.601937 11.712416 16.002824 15.954080 -0.601309 -1.141893 0.690935 0.698539 0.347545 20.930130 81.455015
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.611194 -1.505116 0.555327 -0.889655 -0.044378 -0.610243 0.580596 2.468254 0.691487 0.689871 0.374510 23.531930 31.398530
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% 0.329801 -1.244505 -0.761881 -0.006550 0.594703 0.034415 1.013232 2.467684 0.690454 0.699569 0.361728 10.406154 7.608157
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.049174 -0.938306 0.074907 2.699085 -0.313025 1.888655 1.107294 -0.964316 0.675679 0.684255 0.380702 21.373164 50.082155
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.849084 0.078602 -0.069404 1.243664 1.218124 -0.569835 0.515595 0.696663 0.662359 0.657109 0.392153 3.966253 4.406594
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.862080 4.593321 -0.894696 6.297140 0.029973 5.784165 6.925759 0.534850 0.614561 0.611729 0.341576 8.511189 13.997436
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.055871 0.791083 0.101509 -0.704233 0.263622 -1.673320 0.505173 -0.042042 0.644880 0.644161 0.345208 12.178551 15.384229
83 N07 digital_ok 100.00% 34.95% 0.00% 0.00% 100.00% 0.00% 14.141633 2.731877 48.333211 6.068942 23.379179 4.730845 10.869098 4.021589 0.528868 0.671622 0.403374 3.446025 8.560362
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.542883 11.216088 3.293800 2.830162 2.256859 1.442517 -0.791094 -0.605758 0.689052 0.691883 0.346139 0.000000 0.000000
85 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.019869 36.216796 0.023014 3.212243 -1.010947 13.752777 -0.082538 6.829253 0.696335 0.637034 0.353170 9.964239 14.086806
86 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.939863 5.236214 -0.535885 -0.273626 -0.884262 1.591079 1.956710 4.160747 0.690908 0.685540 0.348156 0.000000 0.000000
87 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
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.042921 27.799402 59.271407 60.435768 52.375964 50.086186 22.085550 13.617890 0.043090 0.044049 -0.000125 1.202828 1.204486
90 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.867919 4.030837 -0.558934 5.538036 0.459793 5.961658 2.947674 0.170518 0.634272 0.635214 0.387049 19.164324 20.180510
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% 100.00% 100.00% 0.00% 100.00% 0.00% 43.396074 67.949436 8.920015 11.591281 54.931139 58.775750 10.071593 19.767939 0.092871 0.090767 0.009996 0.000000 0.000000
93 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.415923 0.594925 4.043070 -0.305809 6.220864 0.706256 -0.111194 1.214098 0.092123 0.091701 -0.011548 0.000000 0.000000
94 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.153343 -1.641092 0.280339 -0.850906 1.405459 0.999305 9.552871 0.374114 0.066070 0.063361 0.008659 0.000000 0.000000
98 N07 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.804678 1.687261 1.211108 0.219122 -0.753963 -1.347906 0.580313 2.398733 0.600619 0.597468 0.342033 6.725279 5.476392
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.155337 -0.319056 3.606059 1.676354 5.380524 -0.471232 6.941652 1.221463 0.626300 0.628305 0.334145 0.000000 0.000000
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.409337 -0.403200 0.538223 0.280664 1.359607 -0.553672 0.524196 0.462953 0.655467 0.655201 0.349895 0.000000 0.000000
101 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
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.392459 0.810769 5.252610 -0.748069 21.922458 14.921653 168.246635 121.877519 0.675476 0.684225 0.360846 3.529960 3.909504
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.158461 10.088014 1.016029 0.371449 -0.327893 -0.078779 1.620232 3.561723 0.691226 0.691472 0.362791 3.182326 3.229794
104 N08 RF_maintenance 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 6.470529 92.812382 1.766895 16.801546 2.924535 6.920162 1.343475 1.264784 0.293395 0.285539 -0.318051 3.167077 3.180366
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 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.133345 1.108483 0.850950 -0.338176 -0.549479 -0.787961 3.687965 -0.026663 0.654984 0.654951 0.379390 4.711034 4.879655
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.222793 26.611656 56.780308 57.823633 52.330080 49.852596 13.396145 14.434865 0.046660 0.048848 0.002669 1.371864 1.381240
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% 100.00% 100.00% 0.00% 100.00% 0.00% -0.980981 -0.098947 -0.227923 0.879775 -1.463642 -0.240881 0.980352 1.386895 0.062229 0.067223 0.008514 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 47.140110 2.589422 5.029559 2.198000 16.549624 5.858326 1.465416 10.080065 0.057907 0.060071 0.004512 1.463879 1.455497
111 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.355277 1.590963 0.142829 2.715817 0.748878 2.849063 0.398062 15.755900 0.061940 0.066067 0.007522 1.048762 1.067766
112 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.815531 -0.687544 0.244175 2.083203 0.409354 0.665221 0.890854 -1.315716 0.080497 0.081359 0.017975 1.743739 1.737287
116 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.470116 2.651723 -0.316107 -0.638825 -0.064690 1.447876 -0.063318 -0.347673 0.585893 0.581307 0.342211 4.460398 4.324216
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.194415 4.473049 10.740342 8.237814 12.278169 6.714166 -1.737366 -1.847885 0.622959 0.621519 0.364478 2.850923 3.190933
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.058978 1.908054 2.876671 0.665554 3.723308 0.130584 6.011977 7.181871 0.629511 0.632195 0.358391 5.321787 4.982620
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.706646 0.916783 11.353619 0.043604 13.963089 -1.100008 -1.769958 -0.290055 0.652108 0.652679 0.360781 0.000000 0.000000
120 N08 RF_maintenance 100.00% 53.76% 100.00% 0.00% 100.00% 0.00% 21.643653 40.659884 5.118361 75.827461 48.475002 50.807187 7.785751 22.175881 0.443861 0.045755 0.297677 3.443016 1.171510
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.512053 6.216758 -0.443608 1.340774 -0.080833 1.327214 32.598410 37.436091 0.676889 0.677176 0.365034 3.434510 3.148235
122 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
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.588377 9.745803 2.235581 0.269713 0.883505 -0.274834 -0.684282 -0.060569 0.671699 0.672686 0.371188 12.954559 10.598949
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.965091 27.521529 59.982397 61.651074 52.312142 50.013284 10.948871 15.876334 0.029592 0.032331 0.001435 1.246050 1.376466
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.922332 28.270763 59.249707 62.142397 52.401390 50.117066 13.137721 15.037153 0.032541 0.032812 -0.001294 1.293506 1.544454
127 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.135916 -0.661437 0.256812 -0.075378 -0.518367 -0.129275 -0.622982 1.083586 0.070041 0.071823 0.009170 0.000000 0.000000
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.745048 1.076113 0.479955 2.680712 -0.937646 3.019860 -0.346189 -0.290789 0.057592 0.057702 0.004226 0.000000 0.000000
129 N10 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
130 N10 digital_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
135 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.294857 -0.723239 -0.907770 -0.808431 -0.931648 -0.705923 0.885463 0.889021 0.065978 0.074065 0.011929 0.965052 0.945556
136 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.757288 12.545724 0.421811 0.690686 2.977805 2.985068 5.945704 13.855838 0.062345 0.067972 0.010279 0.902288 0.912669
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.643152 27.724872 58.437418 59.538503 52.392285 50.088551 12.907417 16.520611 0.036887 0.044507 0.003756 0.000000 0.000000
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 33.299499 3.094831 57.965067 -0.543060 52.436523 -0.723559 13.822446 -0.220029 0.051627 0.624408 0.393401 1.039489 4.689081
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.333004 5.418773 0.090862 -0.357147 2.144367 1.374562 1.982682 2.754164 0.638900 0.634292 0.363182 26.685240 22.528323
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.291001 4.915790 -0.220982 15.239538 1.810366 4.591083 0.392788 20.946570 0.644350 0.626838 0.365226 10.379684 10.631810
142 N13 digital_ok 100.00% 61.83% 100.00% 0.00% 100.00% 0.00% 27.667528 33.327086 7.857505 69.217193 49.688228 50.229692 11.116592 12.408193 0.424806 0.048901 0.231712 24.685315 1.311462
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.356888 -0.019730 -0.858457 1.725236 -0.006539 1.727052 -0.327812 -1.058736 0.649285 0.644500 0.360573 3.728737 3.600189
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% -0.967862 0.243754 0.728731 0.702813 1.201150 0.190432 2.741347 0.351078 0.644015 0.637426 0.378604 5.039461 5.560599
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.872487 27.275418 68.396559 69.761073 52.241469 50.179245 13.579275 16.580154 0.037079 0.038011 -0.000307 1.481941 1.654806
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.999162 30.051568 68.185682 71.004320 52.561875 50.439846 14.975023 16.668359 0.048371 0.051977 0.002331 0.850908 0.846118
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.525224 29.572702 66.830632 68.399903 52.181363 49.837343 15.233044 15.063544 0.033870 0.035192 0.001368 0.957264 0.958285
156 N12 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
157 N12 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
158 N12 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
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.639623 26.773500 67.711493 69.079112 52.259300 50.072158 13.847463 16.039035 0.043791 0.044539 0.000807 1.362817 1.361922
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.844368 51.356061 -0.503095 5.046634 -0.355278 12.870029 0.209527 0.768520 0.636579 0.544776 0.322013 10.629954 13.692698
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 2.378016 1.296056 0.685267 0.188202 1.982103 1.547543 -0.483240 -0.598979 0.635130 0.633294 0.358400 4.101602 3.478582
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 1.302265 -0.632581 0.228908 -0.959812 -1.151310 -1.242938 0.085813 -0.433354 0.638968 0.634030 0.360031 3.355208 3.080945
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.332663 -1.136638 -1.090773 -0.735517 -1.160360 -1.250706 -0.194826 0.853261 0.629745 0.623824 0.365847 2.418260 2.014802
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.605379 0.426631 8.112357 -0.875987 8.599876 -1.172675 -0.756962 0.160156 0.620576 0.614609 0.366252 10.760604 12.657324
166 N14 RF_maintenance 100.00% 8.06% 0.00% 0.00% 100.00% 0.00% 16.686452 3.855187 0.887713 0.087461 12.996951 11.273485 52.950923 12.783449 0.556705 0.578124 0.327569 1.097946 1.124826
167 N15 digital_ok 100.00% 48.39% 45.70% 0.00% 100.00% 0.00% 26.188343 26.426966 20.878333 25.550860 42.814574 39.450683 130.887177 31.447933 0.467685 0.483319 0.175607 0.877946 0.867008
168 N15 RF_maintenance 100.00% 5.38% 8.06% 0.00% 100.00% 0.00% 19.081223 22.422752 26.129801 29.658287 38.482556 41.346745 0.290582 -0.244181 0.552131 0.535322 0.350341 0.000000 0.000000
169 N15 digital_ok 100.00% 8.06% 8.06% 0.00% 100.00% 0.00% 21.387895 20.767428 28.640229 28.027099 42.253572 38.735613 0.436487 -0.446263 0.530542 0.522499 0.338098 0.000000 0.000000
170 N15 digital_ok 100.00% 8.06% 8.06% 0.00% 100.00% 0.00% 21.616470 19.334214 28.809005 26.827335 43.021611 37.069380 0.728293 -0.448810 0.512662 0.514891 0.332224 0.917103 0.913944
176 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.000498 0.000498 -0.892004 1.228907 -0.122967 1.014582 -0.518265 -1.159850 0.044987 0.053193 0.002895 3.097483 4.931696
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.034633 0.943045 1.181548 0.973115 -0.232683 1.226610 9.585374 3.737775 0.056937 0.051966 0.005784 7.759343 17.149603
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.280324 -1.487137 -0.834329 -0.545858 -1.734001 -0.742059 -0.696808 -0.661810 0.059789 0.051250 0.008480 0.928268 0.935007
179 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.265923 0.553888 0.260448 -0.065924 2.214096 0.066786 3.319799 -0.518466 0.063309 0.060211 0.012444 0.902562 0.905090
180 N13 RF_maintenance 100.00% 0.00% 64.52% 0.00% 100.00% 0.00% 0.246357 18.530623 1.372833 62.573357 0.410589 33.966128 -0.464807 10.896171 0.618321 0.381738 0.426427 14.272496 4.570975
181 N13 digital_ok 100.00% 100.00% 96.77% 0.00% 100.00% 0.00% 27.633318 66.610811 68.621922 16.028835 52.279278 51.724250 13.713843 33.777799 0.046511 0.262680 0.133535 1.086702 1.691242
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.825397 12.077088 25.848168 19.487703 37.778860 25.668871 -0.553388 12.200350 0.601291 0.604459 0.363934 12.561511 20.213917
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.034791 0.540071 0.144669 -0.644948 0.087766 -1.323965 0.085196 6.034000 0.627190 0.614537 0.368241 33.143426 48.838850
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 0.00% -0.240224 -1.028499 0.416131 -0.535288 -0.173745 -0.580410 0.503249 -1.051818 0.622781 0.612518 0.359902 1.542528 1.378415
185 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
189 N15 digital_ok 100.00% 5.38% 5.38% 0.00% 100.00% 0.00% 4.313716 4.810605 -0.083026 -0.380512 0.041743 0.329062 0.607960 4.536450 0.560673 0.555083 0.349844 0.000000 0.000000
190 N15 digital_ok 100.00% 45.70% 100.00% 0.00% 100.00% 0.00% 45.787892 31.739477 4.615666 69.690388 25.429025 50.081818 332.034397 15.362640 0.458503 0.051188 0.292206 5.177108 2.196922
191 N15 digital_ok 0.00% 8.06% 8.06% 0.00% 21.05% 34.21% 0.242246 0.700715 -0.535031 -0.652441 0.062925 -0.683760 -0.427127 -0.687172 0.532539 0.522737 0.347876 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% 0.00% 5.38% 0.00% 100.00% 0.00% 13.209357 6.165202 18.810907 0.291522 27.401646 9.069714 41.560791 55.913295 0.577085 0.564018 0.355116 6.675755 6.779139
206 N19 RF_ok 100.00% 8.06% 5.38% 0.00% 100.00% 0.00% 3.890203 9.491182 0.366426 12.836832 10.661760 19.507159 43.255454 43.162365 0.548482 0.558841 0.336797 2.131514 2.345593
207 N19 RF_ok 100.00% 5.38% 8.06% 0.00% 100.00% 0.00% 15.955783 20.977831 21.635889 28.060185 32.124613 39.471240 12.999110 13.915152 0.549835 0.535758 0.337674 1.136486 1.127508
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% 13.494971 14.337432 110.943295 109.476886 3879.975170 4654.333339 18752.358565 26759.885078 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 2.69% 0.00% 100.00% 0.00% 7.548689 13.619314 10.432403 19.991449 15.996743 26.324033 -0.984033 -1.450823 0.565206 0.557874 0.353320 6.852306 5.700490
224 N19 RF_ok 100.00% 8.06% 8.06% 0.00% 100.00% 0.00% 24.633627 24.725187 32.272687 32.282718 48.196978 45.022679 1.016105 -0.099444 0.518031 0.517348 0.328665 0.000000 0.000000
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.419346 15.249826 inf inf 5391.331152 5390.940612 31512.405289 31507.511435 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 32.525636 32.403657 50.128050 50.001946 52.473399 49.901502 20.905401 15.490502 0.070350 0.059357 -0.001755 0.000000 0.000000
321 N02 not_connected 100.00% 37.63% 75.27% 0.00% 100.00% 0.00% 11.545863 9.706277 17.633690 16.438423 27.878071 23.789004 54.333773 54.280487 0.442663 0.391921 0.276798 0.000000 0.000000
323 N02 not_connected 100.00% 51.08% 83.33% 0.00% 100.00% 0.00% 24.734725 13.787838 3.478402 20.836693 21.591215 29.069344 6.873447 0.456329 0.362442 0.369452 0.237499 0.000000 0.000000
324 N04 not_connected 100.00% 43.01% 80.65% 0.00% 100.00% 0.00% 16.577175 18.098230 23.802556 24.682758 34.640794 33.713294 -0.708967 -1.604668 0.426003 0.376106 0.276817 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.056259 8.540450 1.805062 16.379903 2.986057 19.989573 8.347491 -1.656722 0.064707 0.064916 0.017052 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.816798 8.481107 11.873373 14.532565 10.680838 18.900912 3.371735 -0.553757 0.066162 0.065124 0.016651 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 40, 41, 42, 45, 46, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [73, 106, 164]

golden_ants: [73, 106, 164]
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_2459786.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 [ ]: