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 = "2459820"
data_path = "/mnt/sn1/2459820"
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: 8-28-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/2459820/zen.2459820.25314.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/2459820/zen.2459820.?????.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/2459820/zen.2459820.?????.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 2459820
Date 8-28-2022
LST Range 17.965 -- 3.986 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: 32
RF_ok: 11
digital_maintenance: 3
digital_ok: 95
not_connected: 3
Commanded Signal Source None
Antennas in Commanded State 0 / 147 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N10, N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 57 / 147 (38.8%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 113 / 147 (76.9%)
Redcal Done? ✅
Redcal Flagged Antennas 13 / 147 (8.8%)
Never Flagged Antennas 12 / 147 (8.2%)
A Priori Good Antennas Flagged 84 / 95 total a priori good antennas:
3, 5, 7, 15, 17, 19, 21, 29, 30, 31, 37, 38,
40, 41, 42, 45, 46, 53, 54, 55, 56, 66, 67,
68, 69, 71, 72, 73, 81, 83, 84, 86, 88, 91,
93, 94, 98, 99, 101, 103, 105, 106, 107, 108,
109, 111, 112, 117, 118, 121, 122, 123, 127,
128, 129, 130, 140, 141, 142, 143, 144, 156,
157, 158, 160, 161, 163, 164, 165, 167, 169,
170, 176, 177, 178, 179, 181, 183, 184, 186,
187, 189, 190, 191
A Priori Bad Antennas Not Flagged 1 / 52 total a priori bad antennas:
90
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_2459820.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% 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
4 N01 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
5 N01 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
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.513237 -1.273292 0.303532 -0.104124 -0.041079 1.073969 -0.039383 11.119925 0.759663 0.659507 0.439164 4.114971 4.888156
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.255869 9.579401 24.072479 24.720555 45.670432 48.417838 -0.015967 -3.581693 0.754865 0.637621 0.441828 4.636122 5.083795
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.352725 -1.389512 0.454219 -0.349295 0.870617 0.906217 -0.378615 0.816541 0.751252 0.650813 0.445281 1.802078 1.551063
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.536045 -1.231764 -0.914314 0.459514 -0.326835 1.287798 1.212201 1.852941 0.739723 0.638076 0.457136 1.676047 1.473883
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.53% 0.598934 1.601245 1.766431 0.792701 -0.529828 0.245926 -0.110608 1.309048 0.774076 0.661245 0.438319 2.114325 1.985775
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.121030 -0.149743 -0.823307 -0.095300 0.323064 2.118267 3.244709 2.542838 0.777906 0.670247 0.438490 2.122770 1.743482
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.67% 0.137868 1.206392 0.678740 0.782290 1.620450 -0.095653 0.915129 0.773846 0.764853 0.667111 0.429311 2.218831 1.991772
18 N01 RF_maintenance 100.00% 0.00% 75.19% 0.00% 100.00% 0.00% 20.784237 28.283176 1.296932 0.731360 45.989728 28.984752 110.268599 82.505629 0.699559 0.406754 0.477711 3.331394 2.401353
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.405697 6.179111 -0.928462 19.297483 -1.154145 31.823437 1.103838 2.225520 0.762225 0.673964 0.437327 3.820672 4.874365
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -2.242069 2.604096 0.022883 -0.252402 -0.406665 0.828926 0.511581 -0.687827 0.762619 0.652488 0.440147 1.736635 1.590220
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.712688 -0.929720 1.082007 1.633162 4.519155 2.120353 2.070598 0.288205 0.743768 0.653966 0.447960 4.925981 4.688052
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.537327 25.310773 35.584683 36.804739 66.488348 68.781166 6.259777 5.203834 0.042188 0.045509 0.002193 1.228086 1.230825
28 N01 RF_maintenance 100.00% 38.67% 100.00% 0.00% 100.00% 0.00% 21.259196 44.498902 0.685053 2.355346 36.650121 46.130707 6.100808 46.155915 0.420895 0.186668 0.274259 8.612810 2.214425
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.07% -1.046968 -0.922258 0.361336 -0.360965 -2.092074 -1.427568 -0.497487 -0.521167 0.777923 0.681871 0.422163 1.854157 1.864958
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.536181 -0.438914 -0.339955 -0.479258 -0.130670 2.300674 10.425166 0.822505 0.772089 0.683065 0.424417 4.736645 5.465844
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.260517 -0.803446 -0.334113 1.709463 14.296243 22.857548 40.347878 40.591685 0.779039 0.678034 0.437901 4.259136 4.143357
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 50.023709 11.825752 2.999050 2.331469 23.830093 42.318394 45.266283 50.351544 0.659825 0.656389 0.348939 6.446926 4.374442
33 N02 RF_maintenance 100.00% 0.00% 26.32% 0.00% 100.00% 0.00% 0.604021 26.550909 -0.090166 0.201111 64.297868 63.113903 259.725293 250.501822 0.750911 0.473142 0.536823 4.990405 2.235443
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.246222 11.469417 0.152872 -0.031847 5.457803 3.385039 1.849850 1.210246 0.778837 0.684426 0.417814 5.280610 4.342452
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.850071 2.003460 0.691879 0.504993 -1.557712 -0.190899 0.047712 21.764947 0.783444 0.697996 0.412016 4.548832 4.100501
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.415607 0.148982 -0.137384 0.085826 4.995233 19.340428 9.232270 3.371561 0.788533 0.704189 0.411464 4.020507 4.086784
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 3.21% 0.011754 -0.495644 0.020548 -0.435051 0.299393 -0.292679 -0.490198 -0.956891 0.781795 0.699484 0.405389 1.815292 1.680093
41 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.229919 -0.972831 3.361522 1.323213 5.658891 -2.193649 -0.378371 0.267218 0.788872 0.695559 0.410298 4.913724 5.426489
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.67% -0.142509 2.732657 2.319937 1.004789 -0.355026 -0.305844 -0.528322 -0.630203 0.789084 0.691056 0.420978 1.730691 1.618926
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.166427 1.061316 -0.407194 -0.299264 1.704718 2.690597 0.062792 9.821000 0.767688 0.665928 0.434051 4.434234 4.316832
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.53% -1.005801 0.013202 -0.280187 -0.779893 0.634802 -1.441358 0.283762 2.259659 0.759709 0.666555 0.443173 1.545798 1.422689
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.015255 29.164406 -0.034845 1.533570 27.847263 11.868484 30.853878 5.553163 0.745604 0.640798 0.365203 5.150836 5.481047
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.960166 3.641697 -0.810700 -0.659443 1.228890 -0.097778 -0.174457 1.036263 0.782532 0.709321 0.405674 1.621015 1.492087
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.281427 10.550016 2.023719 0.143290 15.623165 0.415849 3.406238 2.252369 0.790077 0.717622 0.396313 3.883301 3.999510
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.992822 3.398188 -0.682068 0.033535 0.426101 0.429821 4.164053 9.664999 0.795930 0.724077 0.397153 4.288812 4.283867
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.443531 2.954496 1.131213 1.142228 0.300717 11.202453 0.492268 4.520073 0.786355 0.706989 0.393285 4.245019 3.731064
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.770825 3.153721 -0.395571 1.223138 10.922925 -1.660857 5.955876 -0.106694 0.785874 0.709272 0.391594 4.140242 3.651857
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.435689 1.701812 1.476951 1.127759 1.249252 1.661950 0.447038 5.358879 0.789579 0.713876 0.397525 4.378412 3.717709
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 46.247154 -0.914049 10.789767 2.985319 31.535230 1.455193 8.460077 10.621224 0.648200 0.708340 0.355452 4.698082 3.467920
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.873824 1.175073 0.899729 1.019517 2.791665 2.554826 -0.620034 1.033217 0.770502 0.693751 0.423290 1.586750 1.439806
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.158825 2.024507 -0.783751 1.121316 1.029734 7.149627 -0.073956 3.383468 0.780095 0.711803 0.403934 4.674860 5.020066
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.872552 -0.686068 0.057090 0.917358 6.258470 3.967479 1.298846 5.703593 0.786039 0.723593 0.389779 4.192813 4.540392
68 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.192410 1.184471 -0.059118 2.677139 3.110297 17.175543 0.601494 1.089188 0.788415 0.725724 0.378227 5.042608 4.876040
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.35% 0.339365 -0.851591 -0.481413 -0.120541 2.409847 2.856243 -0.018397 3.382165 0.793136 0.729629 0.382493 1.786700 1.541766
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.353067 -1.473501 -0.124232 -0.860073 20.355922 4.018431 1.242641 0.764547 0.794954 0.719848 0.388021 16.790737 11.939017
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 96.79% -0.011754 -0.487382 -0.938250 -0.582620 1.340505 1.787809 -0.472849 0.022100 0.789769 0.726884 0.381140 17.257329 25.539201
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.328342 -0.456575 -0.622889 1.455982 3.501769 1.003664 5.900627 -0.718279 0.782102 0.711995 0.392824 4.101593 3.813323
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 21.569247 -0.029863 34.830515 2.918230 66.185640 2.085101 2.788263 0.059962 0.043425 0.694872 0.364305 1.225085 3.808817
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.097187 2.151252 -0.787865 4.921032 4.578584 8.010041 3.497725 0.740878 0.750395 0.681591 0.430645 4.390712 4.077330
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.447806 0.469654 1.739414 0.650641 4.040130 -1.613761 0.200846 -0.593936 0.761311 0.695560 0.416751 4.747176 4.050732
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.900803 1.981217 2.690570 5.329116 0.555087 3.188974 -0.649889 -1.045337 0.779693 0.720608 0.402757 4.206135 4.426662
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.221487 15.032129 0.359319 1.272964 9.637161 2.454155 38.665378 1.429280 0.789884 0.727137 0.382714 5.074244 5.879466
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.146668 0.973415 -0.858772 -0.656308 -0.545388 -1.216118 -0.747063 -0.970555 0.785947 0.726673 0.389285 1.619851 1.420103
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.399753 7.728783 -0.766183 0.263724 12.102688 5.986494 0.583934 -0.097673 0.786175 0.698626 0.385285 5.112628 3.857026
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.386775 16.321585 5.899571 1.477166 18.783805 0.745389 10.826457 0.538183 0.789961 0.728445 0.382348 4.092286 3.750733
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.735644 10.420147 29.329474 25.227432 57.794656 46.392392 -0.854218 -4.511557 0.758782 0.710631 0.403199 3.576165 3.611571
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.851642 -0.551820 0.677767 3.151415 0.505842 1.698486 0.210737 0.329257 0.778910 0.687059 0.418856 2.339003 2.106107
91 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.857299 11.840622 26.445172 27.099764 51.001910 54.082876 -2.492973 -4.353917 0.763548 0.672531 0.441065 4.491445 3.781517
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 63.347446 80.542160 3.740605 5.534110 46.184228 50.140129 2.079226 16.682887 0.085148 0.084182 0.009497 0.000000 0.000000
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.225633 -0.360596 4.490239 0.836838 7.792813 -1.549509 3.443526 -0.959281 0.069891 0.081264 0.009829 0.000000 0.000000
94 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.353949 -1.659899 0.019094 -0.771066 1.053488 2.979745 5.655166 7.871715 0.069217 0.092060 0.009582 0.000000 0.000000
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.776769 40.302846 1.181207 2.920012 0.887483 24.796942 1.500698 8.765674 0.744972 0.632811 0.413931 4.998102 5.104256
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.180028 0.204874 3.512300 -0.490483 2.053119 3.160254 3.856183 -0.323962 0.759081 0.681557 0.420953 4.674077 4.707967
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.193283 -0.432656 1.296136 -0.235861 3.795273 -0.817711 -0.449455 0.018397 0.772006 0.698838 0.418384 1.632538 1.499695
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.644217 14.281804 3.422636 0.073542 -0.190087 -1.513778 4.116684 1.632832 0.789961 0.720827 0.399052 4.910472 5.225633
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.615549 13.835199 15.968190 22.120263 226.849148 344.252717 887.416672 1327.750750 0.695408 0.571788 0.399103 3.310831 2.775775
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.297874 13.377273 0.179233 -0.105630 3.523870 1.233851 0.658209 0.270021 0.794662 0.724696 0.386169 5.015864 4.575048
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.036598 104.713562 1.280429 13.310007 9.447245 10.265965 1.622107 -0.333295 0.794616 0.720421 0.396445 4.462347 3.957139
105 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.389969 3.842865 9.851869 14.901496 12.279032 20.289039 1.028534 -1.639725 0.796417 0.724757 0.393071 5.347617 4.591416
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.044064 8.373194 25.073992 22.519535 48.334908 41.084152 -2.414584 -2.216074 0.776374 0.699560 0.414667 4.538754 4.258099
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.012552 6.317994 9.627125 0.708550 13.603603 1.224091 1.230699 1.672933 0.740471 0.690642 0.438259 3.712741 3.733878
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.749923 0.588695 0.180820 0.812174 -0.417933 -0.819227 1.456128 0.195629 0.077881 0.076857 0.014715 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 53.683832 11.047193 3.225928 0.847299 15.192088 29.625165 1.306939 13.130319 0.087853 0.063955 0.010298 0.000000 0.000000
111 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.040558 1.282911 0.023062 1.384856 0.426141 1.668825 1.101886 5.767296 0.054409 0.059132 0.004304 0.000000 0.000000
112 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.061474 -0.243520 -0.535920 1.293290 -0.682635 -0.058704 -0.667402 -1.391529 0.063861 0.069516 0.009048 0.000000 0.000000
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.080580 2.404675 0.318424 -0.460802 0.469778 3.162544 3.953439 -0.903649 0.733449 0.653314 0.448179 1.592249 1.473008
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.767217 1.406291 5.863985 5.663937 7.720127 2.459588 -0.288660 -1.287972 0.755697 0.674018 0.442981 4.692822 4.935374
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 4.185083 29.146308 2.447325 31.061740 -0.474223 70.714619 2.503867 0.635577 0.763066 0.051658 0.479086 4.403567 1.300430
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.077186 3.401391 8.907204 -0.594727 9.714843 1.670142 -1.169985 -0.523378 0.782795 0.687344 0.419209 4.696256 4.322923
120 N08 RF_maintenance 100.00% 36.52% 100.00% 0.00% 100.00% 0.00% 24.370610 42.107261 1.661500 41.513541 37.885751 69.394368 1.223053 11.091114 0.440617 0.049117 0.305961 3.123300 1.196534
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.347923 8.732865 -0.640823 1.062515 5.154305 6.112898 34.381362 27.395893 0.795858 0.717461 0.391486 5.537675 4.707109
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.681101 10.684102 1.113501 1.744426 0.716192 -0.159959 0.925632 0.967738 0.797347 0.716587 0.389717 6.269754 5.235428
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.551369 12.867673 -0.114382 0.133458 -0.180957 -0.178929 1.112209 0.941150 0.801175 0.721345 0.388387 9.720049 7.732206
125 N09 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
126 N09 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
127 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.436694 -0.239731 0.143339 -0.223297 -0.472340 0.508361 -0.074930 1.123014 0.089350 0.085382 0.021053 0.000000 0.000000
128 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.387281 5.864497 0.001110 2.382894 0.479166 5.275149 0.434908 -0.307859 0.081424 0.073685 0.014683 0.000000 0.000000
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.122055 -1.213358 -0.762888 -0.671214 -0.356941 1.568867 -0.629384 -0.624243 0.050317 0.063283 0.004656 0.000000 0.000000
130 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.523830 -0.242958 0.397748 1.236979 2.412206 -0.136318 0.582870 5.893363 0.065836 0.071417 0.009535 0.000000 0.000000
135 N12 digital_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.079635 0.077319 -0.899308 -0.884137 0.269485 0.075550 0.676304 -0.025789 0.081835 0.085986 0.016544 1.270711 1.270520
136 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.757208 18.969560 -0.726130 0.824528 4.309153 2.362258 2.866155 5.465080 0.079761 0.088213 0.014809 1.247847 1.246746
137 N07 RF_maintenance 100.00% 63.37% 100.00% 0.00% 100.00% 0.00% 26.091695 24.094179 10.568169 30.521271 38.820540 69.694544 26.249844 7.275945 0.360180 0.051849 0.197270 2.841444 1.234537
138 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.441093 1.707480 24.653429 0.714655 48.232261 -0.178141 -2.380638 -0.177876 0.765699 0.672788 0.436399 4.524444 4.078605
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.665037 24.044665 34.659657 36.889398 66.371697 68.676894 1.959660 2.313377 0.044050 0.045264 0.000444 1.152636 1.144070
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.906010 3.958772 0.323496 9.039004 0.616822 6.636672 1.039300 35.938943 0.779687 0.671929 0.398131 7.203641 7.051049
142 N13 digital_ok 100.00% 32.76% 100.00% 0.00% 100.00% 0.00% 37.207637 30.468985 1.771834 37.058869 37.921950 68.783597 5.085474 4.520039 0.456195 0.045609 0.252559 11.512274 1.491013
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.53% 0.689771 -1.300966 0.942541 1.361010 -0.642433 -1.447060 -0.556075 -1.028992 0.783507 0.710983 0.393622 0.933903 0.749753
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.346353 -1.040797 1.842834 1.894681 4.831163 35.741106 3.064267 5.757745 0.787523 0.700391 0.403487 11.483711 10.689379
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.852123 25.536558 35.812566 37.406924 66.725835 69.528261 4.851205 7.035820 0.039543 0.039135 -0.000483 1.414828 1.439934
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.439467 29.330242 35.647652 38.221492 66.792327 68.977963 6.257908 6.709594 0.051465 0.052464 0.000498 0.000000 0.000000
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.691806 22.496275 34.139850 36.538904 65.077478 68.747804 26.241276 5.594456 0.034398 0.032107 0.001403 0.000000 0.000000
156 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.003980 -0.141186 1.603718 -0.483816 1.029771 6.645444 4.550922 24.625111 0.046851 0.060128 0.004623 1.280986 1.278030
157 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.587445 -0.802101 0.142724 3.469513 2.429589 -0.366433 0.672678 0.380612 0.065959 0.057457 0.005773 1.276864 1.276674
158 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.305533 -1.789833 0.376223 0.274849 3.128392 -0.189623 1.893605 3.782598 0.079000 0.067592 0.010174 1.291089 1.293628
160 N13 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
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.223410 54.188611 0.017797 3.374370 -1.021847 14.154436 0.096333 -0.472536 0.775881 0.571906 0.392828 5.081601 6.505013
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.125994 0.739928 0.138362 -0.623109 1.555374 -0.427726 0.090709 -0.716093 0.784418 0.692212 0.410741 2.158336 1.993639
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.53% 0.476826 0.155311 -0.020548 -0.925102 -0.504354 1.006042 -0.721900 0.553495 0.786363 0.699878 0.407216 2.197759 1.964650
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.60% -0.556028 -1.397079 -0.849979 -0.878833 -1.255444 -0.324803 0.297748 1.643809 0.783787 0.697924 0.408947 2.358850 2.032974
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.265310 2.057986 6.597349 -0.741239 3.601691 -0.781717 3.327791 3.800643 0.788795 0.698543 0.409906 5.746457 6.838013
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 34.514539 19.175874 1.501372 1.058256 24.291241 22.754287 34.419689 58.201622 0.702591 0.638175 0.359531 0.000000 0.000000
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 36.551473 19.806752 22.513773 25.396318 57.565331 55.354413 70.575186 6.145162 0.597365 0.559606 0.283420 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.919631 13.268330 24.494212 27.606641 45.547016 55.960817 -2.906605 -5.028992 0.759663 0.655945 0.438325 0.000000 0.000000
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.309042 11.825461 27.175495 25.951389 52.368342 50.907053 -3.803842 -3.714368 0.747509 0.642768 0.447901 0.000000 0.000000
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.129973 9.601153 27.578070 24.668724 53.736518 46.551655 -3.445187 -4.449629 0.731665 0.650037 0.456778 0.000000 0.000000
176 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.455195 -0.665599 -0.376955 0.902056 -0.055985 1.675831 -0.694271 -0.606118 0.056953 0.066692 0.007811 0.887608 0.886776
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.025608 1.923951 0.882745 2.672268 -0.887230 3.342306 0.549482 7.776987 0.070173 0.063028 0.007000 1.288106 1.282235
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.508640 -0.863624 1.026012 -0.355262 -0.666347 1.643468 -0.203237 -0.837893 0.072083 0.060730 0.008134 1.231279 1.228985
179 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.138878 0.929840 -0.733980 -0.139017 5.522436 0.119448 6.961818 -0.044019 0.063990 0.065472 0.011197 1.213106 1.211349
180 N13 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
181 N13 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
182 N13 RF_maintenance 100.00% 0.00% 44.15% 0.00% 100.00% 0.00% 9.829794 15.556082 24.174927 31.286431 43.189761 19.395903 -2.730088 40.627750 0.773249 0.403611 0.504380 5.127231 2.729458
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -2.088085 -0.999056 -0.119178 -0.988501 -2.556159 0.123182 -0.246443 10.618753 0.777988 0.681118 0.424430 5.345036 5.236422
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.60% 0.683383 -0.242211 -0.383595 0.710867 0.055985 0.356574 1.703636 -0.287105 0.781336 0.688255 0.415040 2.409509 2.019330
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.094351 0.190205 2.449308 1.164057 -0.408823 -0.211886 0.353883 -1.224053 0.788827 0.690670 0.417997 2.016108 1.784415
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.397375 -0.334554 3.122966 1.968789 1.455795 -1.431681 5.996173 -0.087101 0.777147 0.686985 0.413911 4.575205 5.002195
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 50.80% 0.048535 1.389039 -0.033376 1.058574 -1.182497 -1.914160 1.182373 -1.019388 0.772080 0.690720 0.416287 0.000000 0.000000
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.365759 3.882812 0.759053 -0.607441 2.522979 0.675605 0.679951 7.843229 0.752012 0.667896 0.438850 0.000000 0.000000
190 N15 digital_ok 100.00% 8.06% 100.00% 0.00% 100.00% 0.00% 77.242125 29.532492 5.423476 37.361485 36.876631 69.397207 16.350442 5.854430 0.573122 0.050068 0.377748 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.595542 0.666699 -0.765796 -0.894966 0.476990 -1.782384 4.171696 4.743444 0.743209 0.653171 0.466768 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% 24.927892 24.690915 15.356029 1.810555 26.537374 17.737137 39.311317 60.807231 0.757785 0.613271 0.446194 6.692768 4.565249
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 23.893740 23.812514 1.348629 9.969155 14.690327 15.739889 41.298129 42.511496 0.701230 0.637359 0.440819 3.797979 3.981691
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 25.698171 24.567044 19.133418 15.410774 35.583570 28.280266 16.289230 16.266219 0.736179 0.639987 0.420470 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% 46.470570 46.386388 inf inf 4837.910304 5673.695989 13007.322442 17561.638227 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 23.949613 23.807133 8.404231 15.974579 8.937738 23.833746 0.070304 -1.105808 0.737650 0.633250 0.447754 5.371805 4.010229
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 29.860824 28.840455 30.099136 29.210088 63.244555 63.016738 -6.228163 -6.553623 0.712517 0.600897 0.438101 4.582914 3.948537
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% 46.077693 45.993064 inf inf 6647.938033 6656.182941 20986.186691 20983.913969 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.724972 28.782640 23.378283 23.996722 65.734930 68.373150 9.841732 6.415667 0.058295 0.055213 0.002678 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 10.74% 0.00% 100.00% 0.00% 4.655264 2.975713 16.127051 14.313974 33.955889 27.522027 40.986733 40.273796 0.682276 0.542630 0.462101 0.000000 0.000000
323 N02 not_connected 100.00% 36.52% 13.96% 0.00% 100.00% 0.00% 33.779488 5.879306 1.847634 18.896387 33.205007 32.216424 3.513825 -0.133824 0.480147 0.519065 0.369687 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 10.20% 0.00% 100.00% 0.00% 8.079007 5.299299 20.226286 13.116366 33.385646 21.555916 -1.399868 -0.602069 0.674407 0.531224 0.444065 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.615516 2.350214 2.590402 13.631278 27.886472 24.632097 4.065736 -1.027015 0.088675 0.083119 0.035443 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.419538 3.010817 -0.465074 12.731813 17.928471 18.954393 3.719587 0.053076 0.086285 0.083933 0.036116 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, 15, 17, 18, 19, 21, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 40, 41, 42, 45, 46, 50, 52, 53, 54, 55, 56, 57, 66, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 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, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 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: [9, 10, 16, 20, 51, 65, 85, 100, 116, 162, 185]

golden_ants: [9, 10, 16, 20, 51, 65, 85, 100, 116, 162, 185]
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_2459820.csv
In [24]:
# Load antenna positions
data_list = sorted(glob.glob(os.path.join(data_path, f'zen.{JD}.?????.sum.uvh5')))
hd = io.HERAData(data_list[len(data_list) // 2])

# Figure out where to draw the nodes
node_centers = {}
for node in sorted(set(list(nodes.values()))):
    if np.isfinite(node):
        this_node_ants = [ant for ant in ants + unused_ants if nodes[ant] == node]
        if len(this_node_ants) == 1:
            # put the node label just to the west of the lone antenna 
            node_centers[node] = hd.antpos[ant][node] + np.array([-14.6 / 2, 0, 0])
        else:
            # put the node label between the two antennas closest to the node center
            node_centers[node] = np.mean([hd.antpos[ant] for ant in this_node_ants], axis=0)
            closest_two_pos = sorted([hd.antpos[ant] for ant in this_node_ants], 
                                     key=lambda pos: np.linalg.norm(pos - node_centers[node]))[0:2]
            node_centers[node] = np.mean(closest_two_pos, axis=0)
In [25]:
def Plot_Array(ants, unused_ants, outriggers):
    plt.figure(figsize=(16,16))
    
    plt.scatter(np.array([hd.antpos[ant][0] for ant in hd.data_ants if ant in ants]), 
                np.array([hd.antpos[ant][1] for ant in hd.data_ants if ant in ants]), c='w', s=0)

    # connect every antenna to their node
    for ant in ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', zorder=0)

    rc_color = '#0000ff'
    antm_color = '#ffa500'
    autom_color = '#ff1493'

    # Plot 
    unflagged_ants = []
    for i, ant in enumerate(ants):
        ant_has_flag = False
        # plot large blue annuli for redcal flags
        if use_redcal:
            if redcal_flagged_frac[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=7 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=rc_color, alpha=redcal_flagged_frac[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot medium green annuli for ant_metrics flags
        if use_ant_metrics: 
            if ant_metrics_xants_frac_by_ant[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=antm_color, alpha=ant_metrics_xants_frac_by_ant[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot small red annuli for auto_metrics
        if use_auto_metrics:
            if ant in auto_ex_ants:
                ant_has_flag = True                
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, lw=0, color=autom_color)) 
        
        # plot black/white circles with black outlines for antennas
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4 * (2 - 1 * float(not outriggers)), fill=True, color=['w', 'k'][ant_has_flag], ec='k'))
        if not ant_has_flag:
            unflagged_ants.append(ant)

        # label antennas, using apriori statuses if available
        try:
            bgc = matplotlib.colors.to_rgb(status_colors[a_priori_statuses[ant]])
            c = 'black' if (bgc[0]*0.299 + bgc[1]*0.587 + bgc[2]*0.114) > 186 / 256 else 'white'
        except:
            c = 'k'
            bgc='white'
        plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color=c, backgroundcolor=bgc)

    # label nodes
    for node in sorted(set(list(nodes.values()))):
        if not np.isnan(node) and not np.all(np.isnan(node_centers[node])):
            plt.text(node_centers[node][0], node_centers[node][1], str(node), va='center', ha='center', bbox={'color': 'w', 'ec': 'k'})
    
    # build legend 
    legend_objs = []
    legend_labels = []
    
    # use circles for annuli 
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgecolor='k', markerfacecolor='w', markersize=13))
    legend_labels.append(f'{len(unflagged_ants)} / {len(ants)} Total {["Core", "Outrigger"][outriggers]} Antennas Never Flagged')
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='k', markersize=15))
    legend_labels.append(f'{len(ants) - len(unflagged_ants)} Antennas {["Core", "Outrigger"][outriggers]} Flagged for Any Reason')

    if use_auto_metrics:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=autom_color, markersize=15))
        legend_labels.append(f'{len([ant for ant in auto_ex_ants if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas Flagged by Auto Metrics')
    if use_ant_metrics: 
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=antm_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum([frac for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants]), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Ant Metrics\n(alpha indicates fraction of time)')        
    if use_redcal:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=rc_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum(list(redcal_flagged_frac.values())), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in redcal_flagged_frac.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Redcal\n(alpha indicates fraction of time)')

    # use rectangular patches for a priori statuses that appear in the array
    for aps in sorted(list(set(list(a_priori_statuses.values())))):
        if aps != 'Not Found':
            legend_objs.append(plt.Circle((0, 0), radius=7, fill=True, color=status_colors[aps]))
            legend_labels.append(f'A Priori Status:\n{aps} ({[status for ant, status in a_priori_statuses.items() if ant in ants].count(aps)} {["Core", "Outrigger"][outriggers]} Antennas)')

    # label nodes as a white box with black outline
    if len(node_centers) > 0:
        legend_objs.append(matplotlib.patches.Patch(facecolor='w', edgecolor='k'))
        legend_labels.append('Node Number')

    if len(unused_ants) > 0:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='grey', markersize=15, alpha=.2))
        legend_labels.append(f'Anntenna Not In Data')
        
    
    plt.legend(legend_objs, legend_labels, ncol=2, fontsize='large', framealpha=1)
    
    if outriggers:
        pass
    else:
        plt.xlim([-200, 150])
        plt.ylim([-150, 150])        
       
    # set axis equal and label everything
    plt.axis('equal')
    plt.tight_layout()
    plt.title(f'Summary of {["Core", "Outrigger"][outriggers]} Antenna Statuses and Metrics on {JD}', size=20)    
    plt.xlabel("Antenna East-West Position (meters)", size=12)
    plt.ylabel("Antenna North-South Position (meters)", size=12)
    plt.xticks(fontsize=12)
    plt.yticks(fontsize=12)
    xlim = plt.gca().get_xlim()
    ylim = plt.gca().get_ylim()    
        
    # plot unused antennas
    plt.autoscale(False)    
    for ant in unused_ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', alpha=.2, zorder=0)
        
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='w', ec=None, alpha=1, zorder=0))
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='grey', ec=None, alpha=.2, zorder=0))
        if hd.antpos[ant][0] < xlim[1] and hd.antpos[ant][0] > xlim[0]:
            if hd.antpos[ant][1] < ylim[1] and hd.antpos[ant][1] > ylim[0]:
                plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color='k', alpha=.2) 

Figure 1: Array Plot of Flags and A Priori Statuses¶

This plot shows all antennas, which nodes they are connected to, and their a priori statuses (as the highlight text of their antenna numbers). It may also show (depending on what is finished running):

  • Whether they were flagged by auto_metrics (red circle) for bandpass shape, overall power, temporal variability, or temporal discontinuities. This is done in a binary fashion for the whole night.
  • Whether they were flagged by ant_metrics (green circle) as either dead (on either polarization) or crossed, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.
  • Whether they were flagged by redcal (blue circle) for high chi^2, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.

Note that the last fraction does not include antennas that were flagged before going into redcal due to their a priori status, for example.

In [26]:
core_ants = [ant for ant in ants if ant < 320]
outrigger_ants = [ant for ant in ants if ant >= 320]
Plot_Array(ants=core_ants, unused_ants=unused_ants, outriggers=False)
if len(outrigger_ants) > 0:
    Plot_Array(ants=outrigger_ants, unused_ants=sorted(set(unused_ants + core_ants)), outriggers=True)

Metadata¶

In [27]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.3.dev44+g7d4aa18
3.1.4.dev3+g68bd8c3
In [ ]: