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 = "2459838"
data_path = "/mnt/sn1/2459838"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H6C_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: 9-15-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_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/2459838/zen.2459838.31219.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 1631 ant_metrics files matching glob /mnt/sn1/2459838/zen.2459838.?????.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 164 ant_metrics files matching glob /mnt/sn1/2459838/zen.2459838.?????.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 2459838
Date 9-15-2022
LST Range 20.569 -- 5.347 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1631
Total Number of Antennas 139
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 32
RF_ok: 3
digital_maintenance: 3
digital_ok: 95
not_connected: 3
Commanded Signal Source None
Antennas in Commanded State 0 / 139 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 14
Nodes Registering 0s N10, N18
Nodes Not Correlating N02, N04
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 68 / 139 (48.9%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 110 / 139 (79.1%)
Redcal Done? ✅
Redcal Flagged Antennas 6 / 139 (4.3%)
Never Flagged Antennas 21 / 139 (15.1%)
A Priori Good Antennas Flagged 78 / 95 total a priori good antennas:
3, 7, 9, 10, 19, 20, 21, 30, 31, 37, 38, 40,
41, 42, 45, 53, 54, 55, 56, 65, 66, 67, 68,
69, 71, 72, 73, 84, 85, 86, 88, 91, 93, 94,
98, 99, 101, 103, 105, 106, 107, 108, 109,
111, 112, 116, 117, 118, 121, 122, 123, 127,
128, 129, 130, 140, 141, 142, 144, 156, 157,
158, 160, 161, 162, 164, 165, 167, 169, 170,
176, 177, 179, 181, 183, 184, 190, 191
A Priori Bad Antennas Not Flagged 4 / 44 total a priori bad antennas:
82, 90, 135, 138
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/H6C_Notebooks/_rtp_summary_/array_health_table_2459838.csv

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.788321 -1.096294 -0.144128 -0.611147 0.826472 -0.505020 -0.699414 1.393617 0.726037 0.676688 0.421214 4.929735 4.457380
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.181251 3.943519 0.348429 0.974736 -0.377158 0.829345 0.231668 -0.067910 0.738029 0.668457 0.427713 7.314135 5.747857
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.280369 0.250667 0.982326 3.002777 0.147310 0.880388 -0.581263 -1.029743 0.732562 0.676304 0.425086 2.027509 1.656688
7 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.565202 -1.495971 -0.039868 -0.460567 -0.667253 0.868917 0.380765 7.601533 0.051141 0.053657 0.009271 1.305727 1.291662
8 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.660115 -0.571274 6.618657 7.922381 -0.248283 0.365954 6.728183 1.658534 0.057346 0.051245 0.005659 0.000000 0.000000
9 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.154612 -1.448558 -0.506303 -0.492860 0.325262 1.363915 -0.745786 0.111997 0.081541 0.067570 0.011993 0.958799 0.952300
10 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.437601 -0.820176 -0.883160 -0.316914 -0.483368 1.126944 -0.164322 0.031494 0.094830 0.077822 0.019958 6.922731 15.323865
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.413818 0.238111 0.884016 0.371354 -0.594702 -1.177795 1.100492 0.025081 0.741637 0.680910 0.417881 1.980380 1.836655
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.521372 0.699315 -0.402073 -0.953823 -0.498111 -0.325909 0.594692 1.514310 0.746997 0.678435 0.421102 2.109850 1.834640
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.569858 0.389472 0.467461 0.515719 -0.055815 -0.705621 2.464775 0.093470 0.729078 0.674928 0.422394 2.239830 1.979207
18 N01 RF_maintenance 100.00% 0.00% 60.70% 0.00% 100.00% 0.00% 13.436745 21.851424 3.437987 1.533152 4.193001 16.879784 8.716156 26.943422 0.697793 0.421411 0.497675 3.930908 2.192981
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.272450 -0.893807 0.993899 0.069297 -0.139436 3.194117 7.156528 3.630022 0.051830 0.052709 0.005246 1.239242 1.226462
20 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -2.058926 3.887392 -0.430396 0.206422 1.020654 -0.769733 -0.243596 -0.839999 0.061675 0.059326 0.007090 1.297077 1.298000
21 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.217361 -1.592165 0.413899 1.144116 1.792134 -0.255614 0.698925 3.925238 0.081560 0.075887 0.015907 0.000000 0.000000
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.332220 20.202762 22.511192 23.562570 19.904382 29.840797 3.433787 2.599711 0.040008 0.044703 0.003390 1.334371 1.336256
28 N01 RF_maintenance 100.00% 52.73% 100.00% 0.00% 100.00% 0.00% 21.655106 41.112445 0.341639 2.623863 18.017492 24.974837 3.517399 17.228685 0.373697 0.159292 0.244902 6.820245 2.495681
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.148753 -0.897771 -0.237330 -0.273401 -0.880526 -0.520182 -0.510224 0.078979 0.741985 0.678460 0.416954 2.074913 2.031927
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.381134 -0.577491 0.282216 -0.549091 -0.521897 -0.218540 10.709946 0.297344 0.728920 0.677634 0.418007 4.772462 4.713662
31 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.790626 -1.120999 -0.360658 -0.581926 4.344751 7.911837 -0.002383 0.161739 0.084477 0.083775 0.019942 1.301872 1.297796
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 31.876068 32.205870 1.521535 1.063851 4.484820 6.653010 0.326768 -0.313669 0.097501 0.095693 0.012427 1.241524 1.243185
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.230366 21.992069 1.729238 1.021840 0.236156 12.135532 1.221293 17.878411 0.065712 0.097939 0.032516 1.276291 1.282107
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.922511 9.984268 -0.119789 -0.288826 1.808223 2.536685 0.444779 0.836207 0.759985 0.701592 0.401802 6.580772 5.338506
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.763893 0.923565 -0.870610 -0.925440 -1.446486 -0.718283 -0.284409 12.590167 0.760131 0.710316 0.395700 5.914891 5.185446
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.403593 -0.001784 -0.618555 -0.861529 3.844938 3.891906 5.154526 2.453812 0.764392 0.711531 0.402703 4.040147 3.918143
40 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 58.202284 120.419839 63.014129 94.527608 55.262106 145.363681 510.305548 1447.042028 0.016835 0.016462 0.000469 0.795215 0.791409
41 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 220.339306 119.227218 77.380984 78.526438 69.051113 68.432625 515.474290 700.369909 0.018866 0.017306 0.001058 1.081087 1.077523
42 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 69.309013 62.151226 70.930823 64.345566 64.413016 66.596606 673.608928 560.515782 0.016994 0.016646 0.000343 1.149828 1.156560
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.645928 2.018922 -0.753666 0.093917 3.051056 2.430934 -0.290755 27.026783 0.724799 0.660216 0.426508 5.187539 4.931978
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.61% 0.00% -1.276581 0.088040 0.454769 -0.762581 2.203311 0.032051 -0.547845 0.028656 0.715230 0.667249 0.435787 1.339856 1.292584
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.635627 4.631034 -0.798551 1.858275 2.205007 3.197228 0.568101 0.350613 0.748295 0.701263 0.391408 6.143486 5.697567
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.306665 2.983365 -0.466693 0.001290 0.137312 2.530931 -0.166060 0.846276 0.763848 0.717416 0.392187 1.123619 0.973138
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.452127 9.060696 1.433126 0.146363 11.854586 0.658077 1.351619 0.506674 0.767907 0.721423 0.381875 5.935476 5.408078
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.119142 2.664564 -0.806091 0.441790 -1.090312 -0.417980 1.920342 5.973246 0.769814 0.719087 0.392907 4.576604 4.870216
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 67.892118 84.055899 71.443569 66.768911 68.429362 67.519417 772.492363 591.556943 0.016827 0.016503 0.000377 0.000000 0.000000
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 88.462079 86.952183 79.594887 67.646916 104.530137 91.918514 1016.687135 605.566286 0.017629 0.016566 0.000828 1.041720 1.039422
56 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 59.655593 78.530261 54.979808 59.310160 42.596853 51.167915 368.245460 385.670432 0.018833 0.017726 0.000606 0.801052 0.797315
57 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 58.301410 83.628423 63.256506 69.746276 60.058294 69.085117 577.857305 616.726658 0.018324 0.016660 0.001391 1.080064 1.077981
65 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
66 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 239.584135 239.688580 inf inf 11664.605066 11706.093746 7714.235927 7791.778639 nan nan nan 0.000000 0.000000
67 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
68 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 3.107781 41.614338 2.624121 33.473430 1.040692 28.055644 -0.171544 6.940325 0.762540 0.037404 0.458230 5.775157 1.251853
69 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 61.719302 95.250392 67.747141 72.787672 69.497318 111.290107 619.144088 784.028551 0.017629 0.016549 0.000817 1.024104 1.012470
70 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 80.276665 95.009380 83.557078 64.375493 109.401472 60.179840 1152.780386 367.310189 0.016365 0.016392 0.000276 1.046017 1.044725
71 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 43.311813 124.180484 53.093704 81.377069 39.563779 100.256708 313.314541 811.218503 0.017121 0.016339 0.000620 0.000000 0.000000
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 68.180054 63.039408 67.469852 71.626450 68.516764 104.042383 634.576751 752.140789 0.018357 0.016840 0.001093 0.813894 0.805595
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 15.593429 1.587315 21.959191 -0.878938 19.574674 0.398915 0.580705 -0.074561 0.037289 0.688573 0.381778 0.000000 0.000000
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.263813 0.565940 1.252216 2.716942 0.964360 2.884944 -0.656435 -0.520174 0.735612 0.705079 0.411873 1.734003 1.612505
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.628447 -0.328088 0.854362 -0.616102 0.793602 -1.554850 -0.934642 -0.987608 0.741085 0.717268 0.401919 4.084318 4.724601
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.134754 0.372845 1.967208 3.406256 -1.693491 -0.499379 -0.962333 -0.970755 0.758571 0.733953 0.393198 1.837344 1.493494
84 N08 digital_ok 100.00% 0.00% 99.39% 0.00% 100.00% 0.00% 10.467097 34.214395 0.694339 27.491922 -1.895993 28.481339 -0.611271 4.304529 0.762845 0.172319 0.618040 5.131002 1.391738
85 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.535101 4.178837 -0.274144 10.471804 0.056716 11.407992 -0.568671 1.012804 0.750931 0.646519 0.425496 4.331196 3.201481
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.861401 11.098795 0.560601 5.586922 14.139185 9.918562 1.767378 10.318474 0.757649 0.668088 0.401431 3.765022 2.690923
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 34.450701 12.853747 1.832212 0.378348 5.321980 -0.156004 -0.208799 -0.808616 0.682886 0.735850 0.366367 2.878314 3.408264
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.264460 4.625316 22.728788 19.514798 13.517386 11.702394 -2.972249 -2.624038 0.751084 0.729249 0.385984 4.443148 4.169252
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.433935 -0.116355 0.509897 1.899566 -0.549479 0.922939 0.117148 0.671338 0.735523 0.696350 0.401039 0.000000 0.000000
91 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.230125 5.243295 21.561282 21.436591 11.324047 18.609515 -2.028675 -2.455562 0.737002 0.701621 0.420433 0.000000 0.000000
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 205.426932 204.291497 inf inf 11356.655017 11422.700220 6437.320849 6644.294220 nan nan nan 0.000000 0.000000
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 314.443728 313.289612 inf inf 13290.835836 13349.603819 9227.577134 9274.722921 nan nan nan 0.000000 0.000000
94 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 194.552087 195.864048 inf inf 12151.467839 12103.343041 8206.817675 8160.083377 nan nan nan 0.000000 0.000000
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.670153 9.142041 -0.019805 3.611622 -0.055120 8.616785 -0.222730 2.062687 0.715176 0.668892 0.410051 4.028109 4.025549
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.471702 -0.102274 2.266585 0.102963 3.128300 5.363602 -0.041125 -0.708103 0.742769 0.710995 0.406756 5.011076 4.655967
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.057394 -0.788257 0.752593 -0.685944 3.777008 -0.876146 -0.543288 -0.763357 0.752177 0.722007 0.400255 1.640313 1.644175
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.647723 11.470405 1.047267 0.686240 0.308274 -0.275882 6.664575 0.774347 0.769447 0.737227 0.385965 4.753381 4.647776
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.647630 4.237204 28.873546 29.584371 822.943437 1011.741581 5555.702459 5400.749626 0.653479 0.617629 0.369251 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.215321 10.255405 0.019312 -0.175019 3.121056 2.509641 -0.507181 -0.593556 0.767357 0.736361 0.375940 4.625502 4.088216
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.966248 87.926775 1.294921 11.657720 3.681002 2.443387 -0.303137 -0.318446 0.764564 0.729761 0.384039 4.067040 3.602331
105 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.179180 0.870117 7.359648 13.747191 -0.399368 2.273229 -0.110248 -1.775132 0.771338 0.746514 0.380526 5.434491 4.258967
106 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.322631 6.317014 3.436514 21.057469 4.497498 16.194903 0.576211 -3.088740 0.735764 0.731241 0.399167 4.622181 4.098666
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.626791 4.881861 10.620022 6.413516 -0.715195 1.970144 1.290414 3.121569 0.763163 0.728740 0.388707 4.580428 4.116856
108 N09 digital_ok 100.00% 46.05% 0.00% 0.00% 100.00% 0.00% 12.701134 4.821495 16.059502 1.599320 7.986476 0.523758 1.664875 1.892633 0.450193 0.715328 0.497849 1.856185 4.913884
109 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 332.707608 332.895689 inf inf 12096.394933 11936.834493 8056.773851 7883.789311 nan nan nan 0.000000 0.000000
110 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
111 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
112 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
116 N07 digital_ok 100.00% 100.00% 80.38% 0.00% 100.00% 0.00% 17.945007 1.336298 18.366463 6.704629 21.601155 10.833289 -0.015945 -0.217281 0.049952 0.308513 0.015568 0.000000 0.000000
117 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.664051 20.016918 18.011575 19.562857 21.465975 31.219233 0.106256 -0.096987 0.028386 0.055758 0.017845 1.173173 1.196367
118 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.776020 19.170352 17.987269 19.867240 21.706991 31.545622 -0.220042 -0.367226 0.029282 0.033090 0.002487 1.236384 1.259185
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.590479 0.170618 7.091764 -0.942400 -0.642680 -0.571345 -0.365403 -0.399725 0.765774 0.726092 0.397263 4.938914 3.763150
120 N08 RF_maintenance 100.00% 42.98% 100.00% 0.00% 100.00% 0.00% 23.803677 33.302057 0.418508 27.203137 18.744276 30.110013 3.024803 4.789286 0.414415 0.038879 0.296179 3.049454 1.296279
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.213235 6.213423 -0.618547 2.115490 1.442690 1.721332 37.302735 4.743799 0.778107 0.744411 0.381065 5.407238 4.902938
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.749563 6.231210 7.328814 1.603513 -0.531235 0.303864 -0.408758 -0.783899 0.757150 0.739185 0.375012 4.936652 4.583352
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.382065 10.665647 1.391113 0.460077 -0.905498 1.581324 -0.365317 0.202755 0.774729 0.749914 0.371787 7.475748 5.341363
125 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.391692 14.966617 7.819226 14.204608 -0.928216 10.187894 -0.692101 0.629183 0.766217 0.731728 0.368273 7.611019 6.665582
126 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.984538 -0.036484 6.873124 6.450711 25.413162 0.029091 3.612121 -0.911071 0.727163 0.729519 0.397420 4.114918 3.385004
127 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 304.369440 303.788588 inf inf 12454.792971 12514.518947 6151.689632 6191.386201 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 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 205.753089 203.379305 inf inf 12830.720094 12710.481758 8747.538478 8734.179313 nan nan nan 0.000000 0.000000
130 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
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.227682 0.126824 -1.040233 -0.763148 0.550772 1.353649 -0.012972 -0.395604 0.654604 0.631734 0.406145 0.000000 0.000000
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.636118 14.075138 -0.827150 -0.103612 -0.070623 2.510712 0.729136 1.303189 0.661357 0.612214 0.384645 2.967557 2.400595
137 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.457927 -0.450554 12.596780 5.246500 5.068760 7.689074 -0.768105 -0.028885 0.747174 0.718492 0.416590 0.000000 0.000000
138 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.844283 0.057394 -0.752635 2.381766 -1.315617 -0.196722 1.410383 -0.935351 0.753148 0.717532 0.414129 4.785383 3.450703
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.351812 18.428674 21.826686 23.708461 19.621768 29.487852 0.991951 1.209727 0.044015 0.049681 0.002344 0.918141 0.923789
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.333315 5.150028 2.394792 7.130575 -0.148684 6.280166 0.416003 14.843015 0.752026 0.702282 0.373236 5.653682 5.227910
142 N13 digital_ok 100.00% 26.98% 100.00% 0.00% 100.00% 0.00% 35.353544 23.900321 1.073636 23.864935 16.480348 29.612171 0.986164 1.539855 0.438777 0.046859 0.250453 5.820874 1.367242
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.61% 0.00% 0.107570 -0.849127 0.949094 -0.176619 0.653057 -0.634357 -0.635403 -0.909537 0.763168 0.745471 0.374221 2.141233 1.716652
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.61% -1.134688 -1.803027 1.229603 3.888863 2.442409 -1.013294 -0.699402 1.050754 0.766230 0.726380 0.384313 2.173597 2.055125
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.708610 20.188742 22.699934 24.182163 19.987524 29.936743 1.747508 3.022445 0.035289 0.034659 -0.000762 1.668073 1.614956
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.062929 22.222967 22.644730 24.771178 20.246088 30.106182 2.118371 2.608036 0.049217 0.049620 0.001378 0.000000 0.000000
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 15.847959 16.815353 21.861516 23.399089 19.620980 30.365416 2.118667 2.992601 0.039833 0.037021 0.001525 0.000000 0.000000
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.025903 11.813566 0.772385 -0.022132 -0.585038 21.223405 0.476550 20.162731 0.665168 0.590982 0.386102 0.000000 0.000000
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 99.39% 0.61% -1.083978 -0.357764 -0.547630 1.933726 0.317662 -0.043276 -0.052236 0.363933 0.673305 0.639504 0.392929 0.000000 0.000000
158 N12 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 16.077705 -1.717846 22.543939 -0.757500 20.180605 -0.769759 1.183280 3.752007 0.036435 0.652893 0.396400 0.000000 0.000000
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 15.941095 17.777246 22.361649 23.752038 19.770641 29.646752 1.807418 2.772428 0.043949 0.047871 0.003625 1.232404 1.224637
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.319681 40.575711 -0.033076 2.219002 -1.093536 7.008780 -0.229491 -0.658904 0.759258 0.606859 0.372528 4.558382 6.679960
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.61% 0.785199 0.681225 -0.673898 -0.890667 -0.165629 -0.695924 0.182574 0.524108 0.761550 0.726362 0.388132 2.335901 2.127915
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.293841 -0.811562 -0.265738 -0.675083 -0.929714 -0.584628 -0.540672 0.920113 0.764243 0.729890 0.389302 2.418838 2.142951
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.61% -0.689841 -0.920870 -0.988082 -0.463877 -1.442236 -0.252215 0.151278 1.020439 0.758758 0.728039 0.390321 2.302992 2.203725
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.812647 -0.035642 5.367737 -0.883446 3.813624 -0.209939 0.308588 -0.303159 0.764902 0.724847 0.399014 5.975678 5.145857
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 29.483915 -0.371631 1.215543 0.815098 15.789644 1.801702 10.765433 0.229439 0.678075 0.720747 0.381990 0.000000 0.000000
167 N15 digital_ok 100.00% 7.97% 0.00% 0.00% 100.00% 0.00% 41.929915 20.861332 18.100304 20.249612 20.329930 20.322800 3.218266 3.246733 0.546748 0.556339 0.234753 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.222949 7.143744 19.690026 22.380823 9.674977 21.480739 -2.318338 -3.035425 0.736617 0.697048 0.426318 0.000000 0.000000
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.459649 5.644173 22.279800 21.104904 12.243858 19.076278 -2.127381 -1.629027 0.723951 0.681446 0.433711 0.000000 0.000000
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.058358 3.733510 22.647202 19.707248 13.877214 14.879790 -1.794332 -0.871472 0.705096 0.691973 0.446911 0.000000 0.000000
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 99.39% 0.61% 0.108678 -0.868400 -0.904010 -0.043431 -0.032051 1.437968 -0.683774 0.158466 0.651494 0.619516 0.400220 0.000000 0.000000
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.268737 1.203272 0.508381 1.878723 1.068149 2.453169 0.634856 4.343023 0.666683 0.612133 0.402871 0.000000 0.000000
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.452588 -1.355287 0.325306 -0.322895 -1.169568 0.466808 -0.790255 -0.854957 0.672411 0.636443 0.403973 0.000000 0.000000
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.008735 0.286624 -0.898944 0.141224 7.428225 -1.639014 3.699609 -0.753475 0.680921 0.645191 0.404134 0.000000 0.000000
180 N13 RF_maintenance 100.00% 0.00% 82.83% 0.00% 100.00% 0.00% 0.612728 16.779975 -0.092527 22.834655 -1.530002 24.415888 -0.477320 1.598047 0.756115 0.339614 0.523652 0.000000 0.000000
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.717871 59.409662 22.828250 8.675427 20.017337 23.346423 1.680786 5.609399 0.044725 0.246014 0.107005 0.844462 1.311428
182 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 4.246101 20.880372 19.636755 23.549325 7.799046 28.599642 -2.616841 2.304017 0.762014 0.059023 0.476045 5.636552 1.668640
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.929213 -1.186699 -0.353923 0.506001 -1.972702 0.819812 -0.651481 4.676351 0.756474 0.712117 0.402746 5.349862 4.566806
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.22% 1.014209 -0.635973 -0.001290 0.394995 0.275001 0.062469 0.769355 -0.274101 0.757879 0.713215 0.397915 2.436502 2.066359
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.886871 -0.667757 1.306454 0.568953 -1.212704 0.398609 1.183186 -0.752675 0.763861 0.714949 0.402260 2.083487 1.884416
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.527292 -0.704943 2.550395 1.577687 1.890845 -0.651012 1.752157 -0.677644 0.744333 0.708626 0.404533 1.964429 1.825876
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.148167 0.524422 -0.096341 -0.122617 0.489409 0.336836 1.643978 1.698244 0.738409 0.717560 0.409252 0.000000 0.000000
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.010303 2.810625 0.229773 0.287804 1.189861 1.067031 0.012972 2.089925 0.720830 0.695540 0.426036 0.000000 0.000000
190 N15 digital_ok 100.00% 12.26% 100.00% 0.00% 100.00% 0.00% 66.690621 22.822740 3.711100 24.138612 19.127579 29.919984 9.587032 2.342363 0.531172 0.045810 0.397999 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.990594 0.193351 -0.644436 1.766122 0.818358 0.085492 0.950749 6.052593 0.712685 0.681082 0.451232 0.000000 0.000000
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 365.073154 365.302984 inf inf 14442.193990 14444.180092 5285.919950 5287.591547 nan nan nan 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% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.049697 21.044837 13.453161 14.193925 19.310221 29.318186 4.250961 2.581470 0.054615 0.049354 0.003545 0.000000 0.000000
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.104976 0.151704 12.572946 10.842463 7.253006 5.691443 2.216233 2.022968 0.098739 0.091019 0.044676 0.000000 0.000000
323 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 34.785186 0.845941 2.235646 14.468681 10.734042 8.499651 0.492377 0.423708 0.078268 0.092691 0.039322 0.000000 0.000000
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.058673 22.148276 24.299921 24.855199 24.062666 40.938191 136.072017 134.893483 0.025099 0.024390 0.000665 0.000000 0.000000
329 N12 dish_maintenance 100.00% 34.33% 2.45% 0.00% 100.00% 0.00% 8.730326 -1.401812 0.322741 9.976832 9.992210 6.097704 0.648442 -0.664278 0.469156 0.533729 0.387311 0.000000 0.000000
333 N12 dish_maintenance 100.00% 34.33% 9.81% 0.00% 100.00% 0.00% 8.171506 0.804850 -0.511491 9.181611 9.318512 6.383114 3.045794 0.919247 0.478415 0.517988 0.380818 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 7, 8, 9, 10, 18, 19, 20, 21, 27, 28, 30, 31, 32, 33, 36, 37, 38, 40, 41, 42, 45, 46, 50, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 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, 162, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 187, 189, 190, 191, 203, 220, 221, 222, 320, 321, 323, 324, 329, 333]

unflagged_ants: [5, 15, 16, 17, 29, 51, 81, 83, 100, 163, 185, 186]

golden_ants: [5, 15, 16, 17, 29, 51, 81, 83, 100, 163, 185, 186]
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/H6C_Notebooks/_rtp_summary_/rtp_summary_table_2459838.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.4.dev7+g7e32def
3.1.5.dev72+g3641fe9
In [ ]: