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 = "2459787"
data_path = "/mnt/sn1/2459787"
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-26-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/2459787/zen.2459787.25312.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

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

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 372 ant_metrics files matching glob /mnt/sn1/2459787/zen.2459787.?????.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/2459787/zen.2459787.?????.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 2459787
Date 7-26-2022
LST Range 15.796 -- 17.796 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 107 / 147 (72.8%)
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 118 / 147 (80.3%)
Redcal Done? ✅
Redcal Flagged Antennas 3 / 147 (2.0%)
Never Flagged Antennas 17 / 147 (11.6%)
A Priori Good Antennas Flagged 72 / 85 total a priori good antennas:
5, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29, 30,
31, 37, 42, 45, 50, 51, 53, 54, 55, 56, 57,
69, 71, 72, 81, 83, 84, 88, 91, 92, 101, 103,
105, 107, 108, 109, 111, 117, 121, 122, 123,
128, 129, 135, 138, 140, 141, 142, 143, 145,
160, 161, 163, 164, 165, 167, 169, 170, 176,
177, 178, 179, 181, 184, 185, 186, 187, 189,
190, 191
A Priori Bad Antennas Not Flagged 4 / 62 total a priori bad antennas:
3, 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_2459787.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.469387 -0.215856 0.205086 -0.930803 -0.378345 -0.211659 1.906871 2.510861 0.625627 0.621760 0.395453 9.143629 7.177820
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.666641 4.345813 -0.863262 0.093652 0.520083 0.800146 8.805938 5.791292 0.639702 0.630205 0.394091 5.835044 4.611222
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.337733 1.408688 -0.902882 5.276492 -0.427966 2.698264 0.801594 -0.573335 0.645822 0.638375 0.394561 5.498140 4.615964
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.736299 5.505210 9.906732 11.157519 9.828926 10.999083 8.227973 16.914375 0.628259 0.622085 0.384456 3.032218 3.070467
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.516746 18.014381 20.599208 22.563098 23.928694 24.670556 10.678378 8.740981 0.604750 0.593767 0.382764 4.206169 3.969043
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.780524 5.924518 0.449337 11.703729 1.646354 10.343088 2.380550 0.662516 0.603683 0.597248 0.385921 5.196628 5.342820
10 N02 digital_ok 100.00% 2.69% 0.00% 0.00% 100.00% 0.00% 17.833096 15.667628 21.847720 20.884166 26.627795 23.180715 33.676340 33.082196 0.551279 0.549412 0.372776 3.226752 3.444108
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% 0.068607 1.317865 -0.793006 -0.115463 0.195138 0.500924 0.793482 0.772825 0.663013 0.653265 0.394419 6.663670 7.366495
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.095362 -1.509956 0.012116 0.139829 0.847285 -0.350957 6.223963 8.188082 0.665678 0.660718 0.386942 22.521009 29.193923
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.023847 0.530197 -0.735551 0.387626 0.594592 0.775005 7.894292 5.321631 0.660263 0.658095 0.377027 12.278150 14.121427
18 N01 RF_maintenance 100.00% 0.00% 53.76% 0.00% 100.00% 0.00% 4.901382 5.112307 1.935309 -0.267017 7.634512 8.620029 73.169521 68.672925 0.628201 0.464391 0.422292 10.400716 4.295320
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.733736 7.500274 21.638509 13.353191 25.768173 17.829850 6.032260 18.050542 0.612398 0.630199 0.383561 6.175977 8.321625
20 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.411854 18.793599 12.984087 22.679261 13.599585 25.414839 7.470072 9.971805 0.613613 0.579264 0.388461 6.207458 4.870320
21 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
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.550380 29.179690 56.158983 55.519011 33.977331 33.608019 14.019318 11.109388 0.040877 0.045676 0.003754 1.167304 1.165079
28 N01 RF_maintenance 100.00% 43.01% 91.40% 0.00% 100.00% 0.00% 13.213032 20.427676 6.312552 7.150821 29.347168 35.245595 14.391907 57.707423 0.475224 0.270344 0.285261 6.946752 2.376059
29 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -2.000887 -0.663992 -0.452625 -0.482939 -0.012549 0.653259 6.234013 5.990923 0.681887 0.679755 0.377548 2.973768 2.804787
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.132987 0.096158 -0.966468 -0.657419 0.010445 -0.192043 8.261625 2.438453 0.666261 0.665525 0.376724 5.405200 6.010816
31 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 668.751340 397.622562 inf inf 6428.814884 2527.291394 38508.926412 13041.782835 nan nan nan 0.000000 0.000000
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 15.207210 15.703898 inf inf 2728.304390 2455.520360 15387.337725 11488.912741 nan nan nan 0.000000 0.000000
33 N02 RF_maintenance 100.00% 0.00% 59.14% 0.00% 100.00% 0.00% -0.387482 5.394988 0.605325 0.214669 10.817387 13.232230 107.395258 137.853935 0.607833 0.442743 0.448508 3.470081 2.078865
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.594429 8.510142 0.068790 0.808800 -0.264423 -0.223206 0.444254 1.341742 0.631519 0.616374 0.374212 8.536829 7.862138
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.841829 0.917482 -0.521787 -0.233384 -0.846916 0.117304 0.150822 18.619863 0.664226 0.653132 0.383787 18.166194 18.102570
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.650880 -0.104049 -0.360875 -0.294849 0.917449 -0.040376 8.805383 3.814425 0.685215 0.678501 0.394884 13.927631 11.856470
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.010178 0.381883 0.354913 -0.826156 -0.498222 -0.919611 -0.170120 -0.860702 0.697928 0.698211 0.379891 4.558183 4.356555
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.043009 -0.345121 1.485631 -0.749724 0.813185 -0.678736 -0.750814 -1.170972 0.696342 0.697024 0.366133 6.323969 5.080997
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 10.53% -1.377183 0.788293 1.189935 0.116094 -0.962015 0.376964 -0.621246 -0.392989 0.697641 0.700060 0.384341 8.882473 7.210973
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.034162 0.293256 -0.015407 1.223973 -0.212579 1.850048 0.363640 38.836474 0.644447 0.631969 0.390912 15.082127 20.550593
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.227367 -0.716275 -0.649460 -0.937880 -0.501729 -0.025293 0.146202 0.680400 0.623180 0.614738 0.402129 2.324510 2.401547
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.840760 3.783424 -0.660200 0.776791 0.325984 0.849485 5.059614 3.631025 0.639939 0.630988 0.355381 16.550555 12.881489
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 0.672669 40.822247 2.830722 69.667153 0.944801 34.180764 0.545199 23.064072 0.672322 0.040806 0.390498 3.119136 0.899146
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 11.963848 46.866866 0.502034 70.479882 3.140130 34.214626 2.426365 23.957467 0.656639 0.039971 0.378434 14.241633 1.083462
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.912475 2.976463 4.332655 4.192508 1.962053 1.511791 2.578897 6.913051 0.707953 0.706913 0.376448 5.381341 6.118333
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.254829 1.221171 -0.831306 -0.088131 3.483199 5.864465 6.477562 10.702076 0.707360 0.712047 0.351798 3.276188 3.132807
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.594040 0.168887 -0.759022 0.810185 0.366003 1.032237 5.497134 -0.086938 0.704287 0.708302 0.365705 95.548704 48.866606
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.842077 4.054246 11.320666 10.399372 11.038431 9.612793 -1.204401 -1.127316 0.705617 0.709893 0.378118 17.291398 17.203967
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 26.830357 -1.177379 53.286445 4.299070 33.792462 6.074339 6.947859 1.901371 0.048912 0.699391 0.383568 1.236693 29.073079
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.957025 0.350221 -0.392940 0.464802 0.379821 0.090219 -0.668582 0.128162 0.647505 0.640972 0.373322 3.721386 3.893720
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.594158 0.812261 0.402591 -0.242294 1.438703 -1.007808 -0.164476 1.373600 0.676271 0.670375 0.365121 2.984439 2.777942
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.509349 -1.024329 1.006391 0.877013 0.651344 1.480928 1.851794 7.334830 0.697897 0.696326 0.362268 15.003775 36.594450
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.764641 0.214008 -0.879977 0.147217 -0.084343 -0.118046 0.200994 -0.922790 0.705053 0.705834 0.359642 2.588334 3.192696
69 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.939756 3.830594 9.807907 9.259927 9.895223 8.478040 -0.702280 1.165121 0.712276 0.721168 0.355774 21.891262 81.123129
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.801238 -1.392310 -0.109576 -1.102726 -0.166407 -0.870309 0.841065 1.398424 0.710182 0.710635 0.380690 29.496619 37.034045
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 7.89% 0.569659 -1.020748 0.443858 0.166554 -0.318456 0.830468 0.339206 0.191770 0.711547 0.722431 0.372741 8.487507 8.010992
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.776485 -0.798433 0.231199 2.442199 0.380539 1.656732 8.788239 -1.220085 0.692363 0.702836 0.391258 16.782680 33.347631
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.367634 -0.237784 0.559508 0.866514 0.921495 0.981570 2.554501 1.322968 0.677095 0.673431 0.405523 3.152254 3.657681
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.995088 3.780163 -0.094472 4.847113 -0.757862 3.330733 0.698805 -0.835451 0.631710 0.628799 0.356350 19.990039 19.836067
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.187965 0.901070 1.235552 -0.189239 1.304661 -1.048932 -0.673256 -0.966850 0.661787 0.662572 0.354550 17.444891 16.526580
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.462721 2.504073 22.319498 4.876929 6.177955 3.110556 3.164647 -1.414100 0.659273 0.693303 0.364497 14.143960 12.564435
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.096421 9.903767 1.556076 2.341533 -0.109451 1.058390 -0.726734 -0.660995 0.712143 0.714569 0.352962 12.676419 14.438690
85 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.608302 33.823993 1.757436 2.310978 -0.127823 10.070134 -0.257275 10.294368 0.718500 0.662830 0.360463 14.945656 10.823316
86 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.243245 4.773409 -0.599545 -0.268439 2.103607 1.277045 0.662733 -0.365094 0.713981 0.707508 0.360404 7.017137 6.004329
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.479690 18.942618 19.449166 23.341525 21.888805 25.570075 48.929530 1.323970 0.681689 0.694448 0.386026 5.774384 5.149141
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.975547 25.866775 49.103173 49.120973 33.982462 33.594601 15.399321 9.102887 0.038646 0.039945 -0.000489 1.242697 1.245687
90 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.795349 3.275407 -0.546220 4.736182 -0.164819 2.743592 5.968638 0.405065 0.644023 0.646166 0.399839 10.302375 10.741312
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.979283 26.095595 48.972400 49.898883 33.840150 33.483913 10.434834 9.600157 0.041146 0.043216 0.000453 0.912595 0.908111
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 40.308950 62.370823 7.873692 9.487029 34.006234 36.159644 8.750439 15.968508 0.104677 0.098073 0.013265 0.000000 0.000000
93 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.393559 0.363233 2.177783 -0.843575 2.055785 1.367071 -0.590741 3.531944 0.103379 0.101557 -0.017833 13.638470 25.091444
94 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.046137 -1.302536 0.346998 -0.794217 0.465661 2.231584 3.846154 13.199402 0.068638 0.071386 0.006204 10.085237 7.374217
98 N07 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.351809 2.208990 1.202391 0.101877 -0.735314 -0.852146 0.029267 3.713354 0.618744 0.614127 0.357390 20.068120 26.928682
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.714253 -0.526609 2.145590 0.144446 2.433244 -0.228564 1.763165 -0.703489 0.647001 0.647101 0.350638 3.379946 3.620010
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.400774 -0.277778 -0.903037 0.086765 -1.095980 -0.863046 -0.178966 -0.138980 0.678121 0.676346 0.359848 17.034770 25.623085
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.902770 17.693470 21.696563 22.406901 25.080784 24.225178 2.092878 1.509020 0.683767 0.684187 0.363710 8.466266 10.065350
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.907287 1.893057 4.182910 1.937612 30.314987 8.207790 107.784362 63.482910 0.699786 0.706355 0.366510 11.795695 11.988098
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.994097 9.611077 0.328279 0.642678 0.055247 0.275676 -0.128735 -0.646996 0.711543 0.712340 0.373223 10.325670 10.120026
104 N08 RF_maintenance 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 5.414342 87.764410 1.676962 14.668763 1.268348 4.810644 0.861933 0.397392 0.297995 0.280686 -0.315068 3.006170 2.974291
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.040947 32.419196 48.987869 49.810433 33.801034 33.545805 8.289320 7.861864 0.038876 0.043053 0.007255 1.220413 1.227733
106 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.214068 0.830838 0.118014 0.370058 -0.265433 0.781719 0.109189 -0.865397 0.663876 0.665097 0.394023 4.460651 4.050376
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.024996 24.932946 47.129540 47.008128 33.803955 33.335904 9.152620 9.155405 0.040114 0.043392 0.002249 1.261260 1.269477
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.661361 17.687736 21.030491 22.659077 24.497444 24.856488 0.511836 1.411021 0.603942 0.596688 0.396684 10.399194 15.463642
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.274566 -0.043009 -0.805573 0.637078 -1.145536 1.060213 -0.342665 0.050139 0.091027 0.102419 0.022384 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 41.439698 1.963661 3.498431 2.255125 9.574079 -0.107035 8.584436 -1.266700 0.077615 0.078496 0.009450 26.233206 54.686054
111 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.610024 0.400699 0.486733 1.950967 0.680745 0.660782 0.142253 5.444605 0.054364 0.058396 0.003139 -0.000000 -0.000000
112 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.799339 -0.603891 0.810105 1.164507 0.198856 -0.417642 -0.226909 -1.583754 0.063742 0.065452 0.006552 0.000000 0.000000
116 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.478622 2.479125 -0.273986 -0.630070 0.161248 0.171744 -0.131239 -1.008051 0.604970 0.598391 0.358634 7.639625 11.020154
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.318550 3.837693 7.707756 6.429290 6.494522 3.931779 -1.383967 -1.708821 0.643994 0.640520 0.379021 11.243866 11.541718
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.727325 1.437319 1.866101 0.427121 1.500725 0.244917 2.153838 0.785188 0.651788 0.651289 0.368874 0.483699 0.481082
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.627103 2.682723 10.267914 0.487348 10.320673 0.995186 -1.218058 -0.212396 0.672063 0.671763 0.368415 8.565558 9.996808
120 N08 RF_maintenance 100.00% 45.70% 100.00% 0.00% 100.00% 0.00% 19.940190 37.580400 4.424178 61.794649 30.268367 34.029310 5.120199 14.091825 0.464837 0.048737 0.301779 4.145456 1.108915
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.552010 5.514506 -0.213915 0.559188 -0.211054 1.146326 51.228489 20.578494 0.696829 0.695840 0.374573 9.100469 8.622329
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.445747 18.072581 21.047576 22.229104 24.344310 24.256125 0.197544 1.214601 0.671513 0.668569 0.377270 2.387047 2.469091
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.304069 9.125961 0.699797 0.027761 -0.736076 -0.494350 -0.492713 -0.686089 0.680569 0.680094 0.388713 7.586268 7.293553
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.631886 26.437848 49.696814 50.151036 33.821729 33.445732 7.352651 10.846514 0.029401 0.029871 0.000855 1.170665 1.218471
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.400948 26.650748 49.085009 50.552947 33.876846 33.507648 9.183519 9.728874 0.030342 0.030156 -0.001048 0.887090 0.879321
127 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.254672 -0.740981 -0.903205 -0.413249 0.025293 0.593256 0.006997 1.712919 0.096302 0.098736 0.024760 -0.000000 -0.000000
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.531640 1.106412 -0.439869 1.581925 -1.054016 0.535511 -0.006997 -0.434394 0.079074 0.080896 0.013370 69.668875 77.071690
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.216748 -1.191356 1.272120 -0.819379 0.162838 -0.703603 -0.270173 -0.761591 0.062793 0.063843 0.006020 6.677258 5.066017
130 N10 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.120164 -0.240764 -0.769955 -0.351235 -0.371786 0.139970 1.016328 6.425740 0.075731 0.066990 0.007627 3.372004 3.711684
135 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.632707 -1.162850 -0.122408 -0.854624 -0.761396 -0.670245 3.058388 0.681762 0.079561 0.088805 0.017305 1.045112 1.046941
136 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.269160 11.998090 0.873639 0.420712 1.540326 1.677370 2.831424 3.947604 0.067866 0.081587 0.011417 1.288311 1.287455
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.353169 28.385360 48.282272 48.282939 33.871536 33.444930 8.771705 10.619451 0.036407 0.044942 0.004503 1.218561 1.228230
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 31.703011 3.264690 45.414552 1.304191 33.923251 1.275054 9.702167 -0.555838 0.047894 0.640638 0.367251 1.320874 15.565128
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.136695 4.359425 -0.458663 -0.432066 0.334225 0.501367 1.321177 0.438370 0.657730 0.650157 0.373478 5.424872 5.120692
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.737796 4.671967 -0.351050 12.347488 1.061426 3.523498 1.987794 20.163406 0.658304 0.636370 0.378414 5.957525 6.234723
142 N13 digital_ok 100.00% 59.14% 100.00% 0.00% 100.00% 0.00% 25.649418 31.394374 7.553528 56.265090 27.839330 33.733888 8.146743 7.782004 0.420817 0.045241 0.245017 5.723770 1.219370
143 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1437.511893 1802.160737 inf inf -29683.102594 36779.849415 -242611.179072 312536.844826 nan nan nan 0.000000 0.000000
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.230401 -0.325047 -0.086765 -0.699521 -0.541487 0.892592 0.344025 0.291147 0.638649 0.628577 0.400052 1.508132 1.667259
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.662393 26.554127 56.515173 56.754762 33.932261 33.454068 10.545184 12.241150 0.031694 0.031832 -0.000371 1.482167 1.632505
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.773693 28.760802 56.313867 57.732170 34.154578 33.897363 14.063184 14.599260 0.046502 0.047299 0.001069 0.000000 0.000000
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.754485 27.633678 55.145516 55.548946 33.926831 33.505330 10.254332 10.173717 0.038741 0.039585 0.000556 1.212218 1.211212
156 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.752449 18.487617 21.711694 22.591024 25.595686 24.960593 3.094344 4.868028 0.082004 0.085877 0.012739 1.418855 1.423653
157 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.201490 19.309087 21.205557 23.445480 24.921235 26.113167 0.216214 1.599325 0.083884 0.084664 0.010945 1.306072 1.308634
158 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 13.496355 16.687787 18.030892 21.675719 20.317369 23.619303 -0.997085 1.622665 0.081533 0.079839 0.012158 0.960276 0.958731
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.854321 24.250193 55.908610 56.099547 33.927247 33.609525 9.468164 10.405262 0.041452 0.045398 0.002616 1.255677 1.273460
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.763441 47.019759 -1.035742 3.905109 -0.537055 8.578201 0.133260 -0.077976 0.643711 0.545159 0.340223 6.683454 5.773710
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.239507 1.264454 -0.598919 -0.345404 0.402653 0.734695 0.225197 -0.608359 0.635139 0.628179 0.378998 0.531009 0.537040
163 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6882.415267 1562.206978 inf inf 125027.870681 -30021.993077 843901.341887 -206328.081639 nan nan nan 0.000000 0.000000
164 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
165 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
166 N14 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
167 N15 digital_ok 100.00% 40.32% 48.39% 0.00% 100.00% 0.00% 20.576865 24.734370 17.821728 21.450253 28.210039 26.919785 46.070496 11.481713 0.483587 0.475470 0.197662 1.125894 1.134939
168 N15 RF_maintenance 100.00% 5.38% 8.06% 0.00% 100.00% 0.00% 17.692196 21.308936 20.797491 24.771744 24.017147 27.520744 4.658287 6.474562 0.551908 0.531069 0.363906 1.128834 1.127087
169 N15 digital_ok 100.00% 21.51% 16.13% 0.00% 100.00% 0.00% 19.894835 19.582575 23.045166 23.380495 27.303320 25.969231 8.890988 9.436121 0.530778 0.520821 0.346712 0.868863 0.866921
170 N15 digital_ok 100.00% 29.57% 8.06% 0.00% 100.00% 0.00% 20.054616 18.036668 23.194358 22.352542 27.439148 24.462539 7.415556 7.749684 0.515872 0.516060 0.340926 0.868418 0.864110
176 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.322158 -0.147330 -0.278601 0.774731 -0.213819 0.795612 -0.434998 -1.443379 0.048505 0.056623 0.004495 1.315846 1.311721
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.922560 0.601595 0.091356 1.393259 -0.422407 0.919787 1.913764 5.067041 0.057281 0.052406 0.006053 1.167672 1.158027
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.063748 -1.355434 -1.000563 -0.950249 -1.364610 -0.864126 -0.745107 -1.275808 0.060538 0.052098 0.008612 1.258593 1.254300
179 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.840864 0.076024 0.076350 -0.120118 3.798349 0.330211 12.978911 -0.111846 0.068682 0.061639 0.012869 0.926832 0.925083
180 N13 RF_maintenance 100.00% 0.00% 64.52% 0.00% 100.00% 0.00% 0.454882 18.541753 -0.189428 50.944627 -0.170908 23.263333 -0.165824 8.118774 0.621471 0.377289 0.448687 8.922946 3.680962
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.948951 61.179755 56.686790 12.933220 33.930133 31.509631 9.321796 11.558797 0.045060 0.257628 0.134858 1.297849 1.991741
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.691049 10.325427 20.762341 15.635046 24.256360 17.598502 -0.448370 15.691690 0.602305 0.601046 0.381265 7.621269 9.798491
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.627244 0.489180 0.967770 -0.897474 0.959758 -0.668908 -0.266927 2.484977 0.620654 0.603473 0.391753 0.460495 0.472733
184 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
185 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 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% 8.06% 0.00% 100.00% 0.00% 3.982509 4.425900 -0.476501 -0.323806 -0.331194 1.770633 3.099949 6.239052 0.560100 0.551630 0.360022 0.000000 0.000000
190 N15 digital_ok 100.00% 45.70% 100.00% 0.00% 100.00% 0.00% 46.316140 29.631959 3.834755 56.700325 11.972098 33.698236 25.597069 15.649808 0.475060 0.046458 0.293021 0.000000 0.000000
191 N15 digital_ok 100.00% 10.75% 8.06% 0.00% 100.00% 0.00% 0.109082 0.422865 0.074132 -0.709366 1.750641 1.885792 10.108136 10.863652 0.535177 0.523402 0.358482 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% 5.38% 8.06% 0.00% 100.00% 0.00% 12.249310 5.993371 14.868842 -0.049317 17.482747 4.759003 27.726751 39.365646 0.567621 0.550573 0.373503 2.802710 2.565921
206 N19 RF_ok 100.00% 10.75% 8.06% 0.00% 100.00% 0.00% 3.498300 8.973844 -0.636046 11.113925 5.361285 12.867358 28.620163 28.843635 0.547096 0.549758 0.351687 2.408651 2.585469
207 N19 RF_ok 100.00% 8.06% 8.06% 0.00% 100.00% 0.00% 14.803697 19.737071 17.225542 23.383307 20.698388 25.905366 8.122829 8.794044 0.546867 0.530069 0.353010 -0.000000 -0.000000
220 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
221 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
222 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.769744 13.305803 91.836531 90.040400 2487.993837 2994.784777 12873.423198 18308.811187 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 5.38% 8.06% 0.00% 100.00% 0.00% 6.915084 13.096680 8.161828 17.084515 10.092496 17.702029 -0.827780 -1.707864 0.559177 0.549551 0.367238 3.291023 3.055092
224 N19 RF_ok 100.00% 34.95% 32.26% 0.00% 100.00% 0.00% 23.080920 23.449162 26.115942 27.001986 31.039658 30.099149 0.812507 0.465276 0.516060 0.513952 0.341372 2.522493 2.588558
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% 9.859256 12.769674 113.421740 105.056463 3450.337212 3450.394593 21398.483153 21395.214306 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.401221 30.201772 41.331199 40.363866 34.118481 33.536435 14.835958 10.649773 0.064234 0.055897 -0.002772 0.000000 0.000000
321 N02 not_connected 100.00% 34.95% 75.27% 0.00% 100.00% 0.00% 10.196153 8.809494 13.589947 13.528784 17.181504 15.721422 37.276863 36.926949 0.450899 0.396535 0.289633 0.000000 0.000000
323 N02 not_connected 100.00% 53.76% 80.65% 0.00% 100.00% 0.00% 23.326380 12.661718 3.018299 17.187923 13.770883 18.882762 9.449345 0.340759 0.368986 0.372914 0.246051 0.000000 0.000000
324 N04 not_connected 100.00% 37.63% 77.96% 0.00% 100.00% 0.00% 15.061165 16.773922 18.798971 20.448627 21.695775 22.318732 -0.774957 -1.498188 0.435385 0.382464 0.288371 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.518377 7.363486 2.713138 13.080356 1.295119 11.840689 6.004215 -1.536591 0.076386 0.075599 0.025145 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.022438 7.291434 10.774049 11.561130 6.502554 11.466602 3.765623 -1.157067 0.075544 0.075819 0.023369 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, 42, 45, 50, 51, 52, 53, 54, 55, 56, 57, 67, 69, 70, 71, 72, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 116, 117, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 145, 150, 155, 156, 157, 158, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 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: [40, 41, 46, 65, 66, 68, 73, 99, 106, 118, 144, 162, 183]

golden_ants: [40, 41, 46, 65, 66, 68, 73, 99, 106, 118, 144, 162, 183]
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_2459787.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 [ ]: