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 = "2459785"
data_path = "/mnt/sn1/2459785"
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-24-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/2459785/zen.2459785.25301.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 1862 ant_metrics files matching glob /mnt/sn1/2459785/zen.2459785.?????.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 187 ant_metrics files matching glob /mnt/sn1/2459785/zen.2459785.?????.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 2459785
Date 7-24-2022
LST Range 15.662 -- 1.683 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1862
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 106 / 147 (72.1%)
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 76 / 147 (51.7%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 111 / 147 (75.5%)
Redcal Done? ✅
Redcal Flagged Antennas 6 / 147 (4.1%)
Never Flagged Antennas 22 / 147 (15.0%)
A Priori Good Antennas Flagged 70 / 85 total a priori good antennas:
5, 7, 9, 16, 19, 21, 30, 37, 40, 41, 42, 45,
50, 51, 53, 54, 55, 56, 57, 68, 69, 71, 72,
73, 81, 83, 84, 88, 91, 92, 99, 101, 103, 105,
106, 107, 108, 109, 111, 117, 118, 121, 122,
123, 128, 129, 135, 138, 140, 141, 142, 143,
145, 160, 161, 163, 165, 167, 169, 170, 176,
177, 178, 179, 181, 185, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 7 / 62 total a priori bad antennas:
3, 4, 38, 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_2459785.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.747290 -0.540244 -0.566894 -0.706554 1.488214 -0.675867 -0.646412 -0.521861 0.728290 0.629014 0.416320 4.861514 4.562470
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.253046 3.509092 -0.610822 0.023641 -0.275033 -0.367105 3.481402 0.790326 0.745435 0.631438 0.422530 5.694268 5.043821
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.122348 1.844571 0.170473 14.240821 -0.074315 7.810255 0.251000 -1.160303 0.746595 0.641383 0.417998 7.679266 6.951654
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.634780 10.391467 38.275315 38.765034 33.976658 32.239973 -1.472135 0.772343 0.723492 0.621718 0.415735 5.617499 5.681456
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.647012 10.301941 36.516735 38.642201 32.001607 32.297637 -0.552596 -1.698077 0.722638 0.610096 0.418655 6.046592 5.720300
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.499340 10.510646 6.236448 38.601093 1.821731 31.836116 -0.441814 -1.647524 0.718717 0.604732 0.426879 7.952248 7.456631
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.201011 -1.085274 -0.614080 -0.488692 0.173249 0.673199 -0.549771 -0.504780 0.707987 0.603403 0.430573 1.017753 0.830260
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% 0.174002 0.912423 -0.960457 0.264000 -0.473927 1.119301 0.549205 1.294608 0.750909 0.638721 0.416916 1.769815 1.817687
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.780254 -0.136496 -0.519737 6.677203 -0.833057 1.361915 2.756996 -0.000911 0.755618 0.657851 0.410710 6.683476 9.036440
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% -0.211350 0.246464 0.778110 1.329807 -0.669553 0.013412 3.001336 3.017113 0.748552 0.653027 0.405093 1.936458 1.788226
18 N01 RF_maintenance 100.00% 0.00% 75.30% 0.00% 100.00% 0.00% 13.658123 13.517776 5.974220 8.733364 5.352629 15.390328 21.393007 35.606779 0.660029 0.397821 0.434456 3.662636 2.557615
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.721949 0.429424 2.881267 11.443843 -0.272925 28.406802 -0.197130 3.755655 0.740523 0.632457 0.417188 4.983382 5.153476
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% -1.380454 0.806111 -0.083551 1.955097 0.382772 0.637218 -0.833395 -0.917271 0.731525 0.619556 0.415868 1.599170 1.614156
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.245322 -0.645208 6.940245 2.008339 2.700674 2.299010 -0.407853 3.612924 0.712489 0.617454 0.420919 6.891490 7.216143
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.593143 19.825772 69.296941 70.248690 45.135392 43.260904 1.598338 1.217461 0.040582 0.045444 0.003951 1.375780 1.368768
28 N01 RF_maintenance 100.00% 40.39% 100.00% 0.00% 100.00% 0.00% 12.046243 28.294656 3.453811 7.988912 25.134374 32.604889 1.467831 12.497097 0.427362 0.190586 0.260073 10.065807 3.245788
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% -1.047241 -0.761395 1.547770 -0.778062 -1.054727 -1.254118 -0.576333 0.438571 0.759302 0.661660 0.404938 1.863202 1.806509
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.286156 -0.461195 0.835683 -0.896057 0.187103 -0.390736 11.870229 -0.341700 0.751175 0.660921 0.400205 6.200816 7.862534
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% 0.107583 -0.606826 -0.666567 -0.257890 1.254027 1.523379 0.228683 -0.036059 0.755508 0.655224 0.408265 1.612412 1.561350
32 N02 RF_maintenance 100.00% 3.76% 0.00% 0.00% 100.00% 0.00% 37.096567 -0.068214 5.964404 8.196180 12.017030 4.997022 10.139265 10.459191 0.646903 0.642989 0.350993 10.542868 6.771217
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.321532 13.986998 inf inf 3271.069780 3248.709179 8321.819337 8321.903206 nan nan nan 0.000000 0.000000
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.755359 7.458073 0.642409 0.728580 1.263620 0.891340 -0.500874 -0.102881 0.744624 0.641691 0.405020 11.215229 6.566594
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.114271 1.119556 1.566539 -0.268934 -0.610632 -0.032559 -0.600247 5.354046 0.755096 0.660345 0.398984 0.000000 0.000000
38 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.795991 -0.052988 0.262661 -0.471702 2.423782 0.552016 2.433553 0.716905 0.760014 0.668309 0.398702 11.186483 7.347193
40 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.121388 1.230738 5.197655 3.400065 0.254361 0.147690 -0.440238 -0.764841 0.761772 0.671884 0.397758 8.806838 6.010998
41 N04 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
42 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.159123 0.431779 9.126023 0.494084 3.064353 -0.236237 -0.660821 -0.692127 0.767546 0.675434 0.404793 3.732093 3.053028
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.059416 0.435880 0.184975 0.744452 -0.944524 -0.059970 -0.387657 8.217853 0.743535 0.636494 0.413606 6.799426 6.540202
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% -0.904216 -0.646902 1.200861 -0.727691 -0.947087 -1.024226 -0.793929 1.851085 0.733139 0.635495 0.420526 1.490152 1.401747
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.096469 2.968832 -0.827318 6.619703 0.377469 5.383593 10.059916 41.525780 0.742012 0.642465 0.386470 8.176560 7.125844
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 4.589973 35.018771 25.470828 90.242515 19.071456 42.423778 -0.535871 4.815551 0.757006 0.051396 0.458164 5.987725 1.325612
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 7.319285 36.849538 3.745201 91.443899 11.471627 42.882416 35.295542 3.736421 0.728287 0.036854 0.424945 9.999311 1.229063
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.958814 3.013994 8.796065 7.638187 2.319936 1.425913 1.136587 2.660653 0.775278 0.693389 0.388335 5.287211 4.329194
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.121586 2.099219 -0.141899 2.155140 4.576630 5.718090 3.978034 1.990729 0.766189 0.664105 0.373910 10.160093 6.994160
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.059776 0.842361 1.006396 7.632961 1.216558 3.582495 9.147443 -0.408053 0.765261 0.684994 0.386713 2.920510 2.859343
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.775431 9.915495 38.829279 37.618174 34.067366 30.781579 -1.543665 0.265129 0.757814 0.671105 0.393162 9.015596 6.669634
57 N04 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
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.411489 0.837659 -0.325891 1.576299 0.275112 1.117877 -0.797048 -0.321267 0.744857 0.660608 0.404214 1.828990 1.623379
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.943227 1.251561 -0.376513 0.231544 0.154540 -0.505150 -0.469502 1.173254 0.758608 0.679983 0.391147 1.678657 1.428461
67 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.524087 -0.625222 0.891402 0.520252 0.675782 0.141529 -0.120991 1.436129 0.765800 0.693796 0.380282 6.371795 9.307325
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 8.56% 0.835220 0.662215 0.548628 0.161936 1.123747 1.776362 0.992240 1.271490 0.770182 0.696662 0.377711 1.697536 1.651689
69 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.826981 10.155506 37.456670 37.691833 32.358954 31.073752 -1.161496 -1.942150 0.765544 0.687879 0.374327 4.525726 4.159325
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.726032 -1.341750 1.528413 -1.182683 2.226579 -0.013549 0.621416 -0.265235 0.773217 0.690139 0.393932 12.679575 8.876291
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.037272 -0.744828 -0.966144 0.116681 0.038102 0.115661 0.062743 1.444694 0.766527 0.694941 0.382083 16.627231 16.619132
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.004891 -0.273061 -0.495744 8.352779 0.633936 3.282209 4.743799 -0.849558 0.763669 0.684715 0.398783 0.000000 0.000000
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 98.93% 0.440220 -0.013526 -0.404678 0.769852 -0.003553 0.003553 1.103968 2.054219 0.756434 0.657153 0.414686 9.590861 7.473238
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.382349 4.101355 -0.869067 13.336818 1.075094 8.126974 0.862278 -0.252872 0.728345 0.651472 0.399835 5.636216 5.838040
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.910370 0.963641 1.984464 -0.129313 -0.260417 -0.800674 6.018815 1.692948 0.738019 0.671172 0.397170 6.816320 5.359826
83 N07 digital_ok 100.00% 40.39% 0.00% 0.00% 100.00% 0.00% 14.693733 2.443853 55.618447 12.772329 38.765102 6.488161 0.826040 0.570604 0.430885 0.692207 0.471726 1.845116 5.517091
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.228742 10.116172 5.074419 3.989951 0.525810 0.514955 -0.459311 -1.034969 0.773418 0.702896 0.372459 5.248820 5.109689
85 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.861338 26.929145 5.156780 5.063081 0.614077 13.835489 0.035621 4.775327 0.777642 0.610564 0.374751 4.564610 4.950237
86 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.383205 6.480248 0.900748 17.785835 1.987281 13.789366 0.387997 -0.069572 0.766038 0.675636 0.378593 3.865280 3.124338
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% 17.816276 19.501255 58.894870 60.390579 45.346045 43.566573 1.649123 0.699043 0.040606 0.040780 -0.000157 1.227262 1.212622
90 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.274190 2.469186 1.129283 12.447329 0.638516 7.013661 0.484113 0.389273 0.748138 0.657144 0.411208 0.000000 0.000000
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.086145 18.580099 58.655688 61.379880 45.311320 43.489730 1.029675 0.770565 0.036493 0.038577 0.000774 -0.000000 -0.000000
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 38.382466 54.598463 7.318850 10.080597 30.756956 36.946114 18.188532 15.381902 0.078012 0.078349 0.005946 0.000000 0.000000
93 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.652968 1.297736 10.752539 0.019913 8.742956 4.497227 -0.683529 -0.263053 0.078428 0.078130 -0.008161 0.000000 0.000000
94 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.357916 -1.488140 0.495781 -1.110178 -0.298215 0.445362 2.195215 4.953628 0.064437 0.070176 0.007917 0.000000 0.000000
98 N07 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.188386 2.395575 1.072531 -0.588404 1.469860 2.536643 -0.203032 0.223543 0.716122 0.634112 0.409111 0.000000 0.000000
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.868417 -0.014415 9.980893 6.630226 6.908680 0.172774 1.538657 -0.069920 0.733695 0.646085 0.392220 5.480333 4.114130
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.415472 -0.242926 2.307004 -0.438140 1.271048 -0.482790 -0.400394 -0.927244 0.753471 0.675904 0.393478 3.259173 2.696945
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% 4.027592 0.433981 30.741684 6.661897 97.642810 32.735048 251.957696 94.755636 0.709501 0.684824 0.401005 3.350757 3.534006
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.958366 9.146678 0.679281 0.780612 0.067975 -0.298769 0.103905 0.055203 0.776316 0.699400 0.385292 2.944243 2.595471
104 N08 RF_maintenance 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 7.028889 69.080372 0.881738 53.399536 3.493101 7.476016 0.022530 0.107784 0.377141 0.333476 -0.255926 1.729225 1.620486
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.100909 23.167061 54.890062 57.704874 45.259134 43.419304 0.559593 0.358747 0.036445 0.039263 0.003250 1.220129 1.211577
106 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 90.37% 8.56% 0.408796 0.800211 1.590872 0.000608 -0.157805 -0.016060 0.874393 -0.056735 0.754496 0.667524 0.403696 0.000000 0.000000
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.360610 17.227834 55.923713 57.395919 45.314811 43.501641 0.701904 0.797427 0.042941 0.043745 0.003232 1.028494 1.023751
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.001709 4.767610 -0.802598 11.548508 -0.583288 5.604476 -0.404423 -1.081729 0.743846 0.654358 0.420323 0.000000 0.000000
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.914338 -0.666526 0.433531 1.662960 -0.862792 -0.887600 0.000069 -0.449493 0.061481 0.064442 0.008929 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 35.727798 20.031747 5.484961 3.680840 9.498481 18.172990 8.233675 61.030624 0.069285 0.061254 0.003856 0.000000 0.000000
111 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.606749 0.442374 0.713075 8.371023 0.404562 3.358102 0.043303 4.141595 0.053786 0.052279 0.002845 0.000000 0.000000
112 N10 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
116 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.120257 2.116648 -0.518831 0.300005 1.014872 2.186172 -0.676849 -0.784358 0.709912 0.625237 0.417167 8.469073 5.811213
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.137675 3.222994 14.814338 15.850247 9.149060 9.033434 -0.956665 -1.316597 0.734133 0.652387 0.418904 3.028450 2.587731
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.386754 1.517891 8.837049 -0.462039 3.879273 0.619276 0.548789 1.164861 0.740811 0.653945 0.407461 0.000000 0.000000
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.091810 0.866573 19.159501 3.911830 12.283812 -0.209253 -1.067162 -0.559385 0.757575 0.663840 0.400477 2.910410 2.322349
120 N08 RF_maintenance 100.00% 39.85% 100.00% 0.00% 100.00% 0.00% 15.468953 30.408110 2.095736 78.757918 25.756118 43.386105 0.272079 2.740029 0.438577 0.041625 0.298807 0.000000 0.000000
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.664077 5.681042 3.061148 1.105434 -0.004531 -0.290934 13.351592 10.432110 0.773962 0.693552 0.386260 0.000000 0.000000
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% 7.895087 9.638779 7.777495 8.206870 2.014898 2.756015 0.324068 2.476414 0.776587 0.692834 0.386258 0.000000 0.000000
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.987651 17.759221 59.678044 61.744643 45.288217 43.508646 0.416237 0.960531 0.028473 0.031183 0.001484 1.107535 1.101367
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.451319 18.918199 58.804977 62.382211 45.308281 43.492164 0.649983 0.882841 0.032374 0.031803 -0.000230 0.000000 0.000000
127 N10 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
128 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
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.159432 -0.735209 0.898364 -0.778227 -0.526799 -0.587827 -0.801306 -0.809026 0.049545 0.055414 0.003385 0.000000 0.000000
130 N10 digital_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.370683 -0.233335 -0.061571 0.333652 1.310030 0.262880 0.091382 2.095856 0.058684 0.055853 0.004448 0.000000 0.000000
135 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.682455 -0.534938 -1.059063 -0.000608 -0.678932 -0.268373 1.189093 0.134692 0.090663 0.095465 0.020085 0.984112 0.975582
136 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.187149 9.859922 -0.630235 2.474196 2.795156 2.921134 1.614932 4.500538 0.086593 0.097439 0.018302 0.000000 0.000000
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.015679 18.973044 57.829473 59.346180 45.224777 43.485570 0.700386 1.005280 0.034685 0.042935 0.004022 -0.000000 -0.000000
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 20.405190 2.185022 57.485556 2.778155 45.218317 -0.111571 0.549571 -0.649815 0.046729 0.638288 0.400967 0.000000 0.000000
140 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 98.93% 3.889172 2.562182 0.788701 0.026078 1.203187 2.144824 0.218736 1.667079 0.749385 0.662984 0.396661 6.606939 5.308201
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.717069 3.678166 1.525232 32.901886 1.158695 8.543731 4.732321 10.600221 0.754893 0.613969 0.407397 0.000000 0.000000
142 N13 digital_ok 100.00% 35.02% 100.00% 0.00% 100.00% 0.00% 23.265011 21.831009 4.985254 70.828122 28.002610 43.365051 1.404011 0.987200 0.447506 0.046197 0.235348 2.142318 1.106378
143 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.920674 -0.615813 0.059584 8.438179 0.182618 2.986356 -0.687272 -0.819218 0.758856 0.683843 0.384861 2.582923 2.698802
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 98.93% 0.00% -0.912776 -0.184850 1.711989 -0.712262 1.261293 0.801657 2.408889 0.202835 0.758144 0.673275 0.398137 -0.000000 -0.000000
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.198055 18.685521 69.631251 71.408354 45.191107 43.324818 1.136897 1.638285 0.035614 0.036452 -0.000211 1.003246 0.997851
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.356719 21.103572 69.823534 73.220114 45.187981 43.394148 2.149767 2.311962 0.049825 0.052007 0.001436 0.000000 0.000000
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.176806 18.252608 67.990000 69.925728 45.072867 43.298002 1.457247 1.275705 0.033731 0.034418 0.000784 1.245898 1.265914
156 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.185699 0.441193 -0.901101 -0.439027 -0.172094 0.818543 2.751414 6.498715 0.055495 0.065860 0.006368 37.587461 45.125491
157 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.259926 1.739305 1.166980 11.129809 0.041226 5.358503 0.380469 1.782880 0.069618 0.065526 0.005871 0.900746 0.907565
158 N12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.148324 -1.283877 0.429954 -0.682414 -0.152004 -0.113441 0.432580 0.204607 0.079512 0.067521 0.009659 0.870245 0.870162
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.582066 17.639821 68.958443 70.629527 45.222037 43.391908 1.336139 1.723109 0.041978 0.045235 0.002415 1.242111 1.240199
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.466392 40.811647 -0.286099 6.084954 -0.847750 10.149380 0.752638 0.597425 0.752652 0.555565 0.382425 5.110304 7.414994
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.650421 0.265174 1.248777 1.055281 0.780611 0.422872 -0.404371 -0.648848 0.752300 0.666748 0.390211 2.281410 2.042520
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.60% 0.742467 0.083840 0.937009 2.870795 -0.784078 0.014016 -0.544644 1.061705 0.758831 0.670870 0.385892 2.431435 1.974276
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.008754 -1.062569 -0.805096 -0.623665 -1.441521 -0.539378 -0.631829 -0.514713 0.757029 0.673550 0.391946 2.217875 1.999270
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.589484 0.703797 14.683238 -0.259019 8.255497 -0.897939 3.076719 0.075318 0.756461 0.670217 0.392923 6.242294 6.891585
166 N14 RF_maintenance 100.00% 2.15% 1.61% 0.00% 100.00% 0.00% 25.724105 23.026577 3.538239 3.384531 14.485499 12.999907 16.122613 8.601593 0.654661 0.554781 0.246880 0.000000 0.000000
167 N15 digital_ok 100.00% 10.20% 8.06% 0.00% 100.00% 0.00% 16.585959 16.273312 34.508922 37.506291 36.852619 33.974388 90.597374 28.546107 0.582040 0.528248 0.222227 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.54% 1.61% 0.00% 100.00% 0.00% 10.904023 12.763128 37.336481 42.665706 32.279688 36.171040 -1.274028 -1.886599 0.717414 0.610783 0.412029 0.000000 0.000000
169 N15 digital_ok 100.00% 2.15% 2.15% 0.00% 100.00% 0.00% 12.373135 11.642522 41.080986 40.045015 36.480141 33.658387 -1.555973 -1.407509 0.704325 0.597274 0.417169 0.000000 0.000000
170 N15 digital_ok 100.00% 2.69% 2.15% 0.00% 100.00% 0.00% 12.450052 10.503059 41.643345 38.307205 37.456236 31.508158 -1.424055 -1.755469 0.689096 0.601720 0.421188 0.000000 0.000000
176 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.225543 0.425376 -0.123255 7.313507 -0.150369 2.927545 -0.708877 -0.611081 0.056458 0.074567 0.008644 0.973850 0.968268
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.928727 0.827510 1.812591 3.759098 -0.612824 7.970717 2.414832 2.390517 0.069734 0.065416 0.006592 0.908785 0.910368
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.919251 -0.835822 -0.746537 -0.958910 -1.632582 -1.043950 -0.000069 -0.672132 0.070637 0.059471 0.007304 1.232737 1.230841
179 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.551130 0.443600 -0.513773 -0.599576 0.830139 -0.740603 3.807916 -0.522965 0.077009 0.068093 0.013756 1.197506 1.196599
180 N13 RF_maintenance 100.00% 0.00% 88.18% 0.00% 100.00% 0.00% 0.104121 15.736340 2.261839 67.808905 -0.472828 37.194250 -0.396260 0.919162 0.740871 0.283914 0.522357 13.039864 2.737145
181 N13 digital_ok 100.00% 100.00% 93.02% 0.00% 100.00% 0.00% 17.626825 54.910830 69.974027 11.667626 45.193777 32.786827 1.154410 14.005213 0.046716 0.262604 0.120132 1.275176 2.194901
182 N13 RF_maintenance 100.00% 0.00% 3.87% 0.00% 100.00% 0.00% 9.957232 1.479021 36.754398 4.872514 31.557921 98.674439 -1.441704 21.590904 0.736439 0.613882 0.420320 6.220500 5.389555
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% -1.505780 0.699047 -0.039458 -0.839967 -1.007356 -0.346621 -0.797771 3.726581 0.749711 0.647098 0.405020 2.242208 2.003840
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% 0.438098 0.015146 -0.786475 1.394528 -0.247570 -0.258627 -0.368163 -0.929837 0.756411 0.657916 0.395569 2.396472 2.055881
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.259104 -0.281970 13.037865 0.285565 7.156372 -1.160522 -0.343506 0.384193 0.760216 0.666283 0.396648 6.289988 7.666969
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% 0.013526 -0.359353 0.499620 2.676163 -0.199710 -0.220342 3.772598 -0.458368 0.749151 0.656679 0.392397 1.909052 1.833655
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.709374 1.174805 0.326674 7.537970 -0.539480 1.626155 8.120331 1.855925 0.741435 0.661124 0.395690 0.000000 0.000000
189 N15 digital_ok 100.00% 0.54% 1.07% 0.00% 100.00% 0.00% 2.693962 3.504348 0.146250 8.165924 0.018937 4.359193 -0.305727 -0.050167 0.719757 0.628730 0.413383 0.000000 0.000000
190 N15 digital_ok 100.00% 13.96% 100.00% 0.00% 100.00% 0.00% 35.558254 21.434459 5.460940 71.382129 17.076715 43.404279 39.349200 1.497568 0.572952 0.049582 0.385028 0.000000 0.000000
191 N15 digital_ok 0.00% 2.69% 2.15% 0.00% 100.00% 0.00% -0.737009 0.032108 -0.810070 -0.651353 -0.074297 -0.769455 -0.110463 -0.807820 0.704333 0.607965 0.431753 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% 0.00% 0.00% 100.00% 0.00% 11.988644 3.809235 39.696901 5.746516 35.561892 8.418501 14.260366 20.060767 0.721772 0.611226 0.399251 6.671390 5.605641
206 N19 RF_ok 100.00% 2.15% 0.54% 0.00% 100.00% 0.00% 3.053244 5.187076 2.147883 18.001831 12.075161 13.953173 16.067075 16.032865 0.682954 0.620324 0.398475 4.346158 4.600352
207 N19 RF_ok 100.00% 2.15% 1.61% 0.00% 100.00% 0.00% 12.843809 12.075175 41.871665 40.560361 37.758620 34.320336 5.083691 4.403854 0.693580 0.605649 0.386877 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.423079 9.045693 107.175951 114.230437 2280.186163 2771.360355 4606.722389 7169.770732 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 1.07% 0.00% 100.00% 0.00% 4.503389 12.199116 14.434731 41.316336 11.096039 34.202562 -0.552386 -2.188371 0.712175 0.593928 0.416534 0.000000 0.000000
224 N19 RF_ok 100.00% 2.15% 2.15% 0.00% 100.00% 0.00% 14.252781 13.902919 47.186961 46.660079 43.249707 40.020653 -2.229168 -2.436642 0.681497 0.572989 0.398021 3.616410 3.012030
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% 7.858105 12.621210 152.562807 125.514189 3111.783136 3205.437528 8326.784647 8324.047962 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.345417 21.977058 48.849028 48.729568 45.031574 43.178336 3.883752 1.170760 0.068867 0.057762 -0.000772 0.000000 0.000000
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.095509 12.373497 151.921008 125.308891 3110.588483 3209.744349 8320.551659 8319.387945 nan nan nan 0.000000 0.000000
323 N02 not_connected 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
324 N04 not_connected 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
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.224078 5.127998 -0.141266 25.370917 12.283821 19.685737 1.346253 -1.103918 0.091223 0.083854 0.036163 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.820963 5.240002 18.207474 23.829808 25.948142 18.401182 -0.029389 -0.574621 0.085325 0.084189 0.034075 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, 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, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 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: [10, 65, 66, 162, 164]

golden_ants: [10, 65, 66, 162, 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_2459785.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 [ ]: