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 = "2459830"
data_path = "/mnt/sn1/2459830"
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-7-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/2459830/zen.2459830.25328.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

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

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 372 ant_metrics files matching glob /mnt/sn1/2459830/zen.2459830.?????.sum.ant_metrics.hdf5

Load chi^2 info from redcal¶

In [8]:
use_redcal = False
glob_str = os.path.join(data_path, f'zen.{JD}.?????.sum{redcal_ext}')

redcal_files = sorted(glob.glob(glob_str))
if len(redcal_files) > 0:
    print(f'Found {len(redcal_files)} ant_metrics files matching glob {glob_str}')
    post_redcal_ant_flags_dict = {}
    flagged_by_redcal_dict = {}
    cspa_med_dict = {}
    for cal in redcal_files:
        hc = io.HERACal(cal)
        _, flags, cspa, chisq = hc.read()
        cspa_med_dict[cal] = {ant: np.nanmedian(cspa[ant], axis=1) for ant in cspa}

        post_redcal_ant_flags_dict[cal] = {ant: np.all(flags[ant]) for ant in flags}
        # check history to distinguish antennas flagged going into redcal from ones flagged during redcal
        tossed_antenna_lines =  hc.history.replace('\n','').split('Throwing out antenna ')[1:]
        flagged_by_redcal_dict[cal] = sorted([int(line.split(' ')[0]) for line in tossed_antenna_lines])
        
    use_redcal = True
else:
    print(f'No files found matching glob {glob_str}. Skipping redcal chisq.')
Found 38 ant_metrics files matching glob /mnt/sn1/2459830/zen.2459830.?????.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 2459830
Date 9-7-2022
LST Range 18.626 -- 20.626 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 372
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 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 N09, N18
Nodes Not Correlating N02, N04
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 81 / 147 (55.1%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 109 / 147 (74.1%)
Redcal Done? ✅
Redcal Flagged Antennas 3 / 147 (2.0%)
Never Flagged Antennas 21 / 147 (14.3%)
A Priori Good Antennas Flagged 76 / 95 total a priori good antennas:
3, 5, 7, 9, 10, 16, 19, 20, 21, 30, 31, 37,
38, 40, 41, 42, 45, 53, 54, 55, 56, 67, 68,
69, 71, 72, 73, 83, 84, 86, 88, 91, 93, 94,
99, 101, 103, 105, 106, 107, 108, 109, 111,
112, 117, 118, 121, 122, 123, 129, 130, 140,
141, 142, 144, 156, 157, 158, 160, 161, 164,
165, 167, 169, 170, 177, 179, 181, 183, 184,
185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 2 / 52 total a priori bad antennas:
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_2459830.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% 100.00% 100.00% 0.00% 100.00% 0.00% -0.732917 -1.321009 -0.013168 -0.450714 1.769550 1.522177 1.656352 14.052473 0.054207 0.063696 0.012693 1.283808 1.276457
8 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.123884 13.586281 21.230959 21.569750 26.025624 24.480598 -0.365786 -3.827264 0.103923 0.078298 0.011260 1.274099 1.267883
9 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.069006 -1.692422 -0.465056 -0.357083 -0.904683 -0.503610 -0.406561 0.680151 0.073851 0.050776 0.005025 1.245379 1.243651
10 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.743747 -0.610572 -0.882400 -0.456120 -0.509707 1.324196 0.724170 0.300614 0.091467 0.064899 0.011956 1.303072 1.300018
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.471300 0.967312 1.101619 0.620300 -0.853729 -0.632336 -0.274044 0.301790 0.800814 0.495507 0.604647 1.652048 1.481165
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.912744 -1.241812 -0.484865 -1.181647 -0.851417 -0.402518 4.983458 2.144121 0.803132 0.498734 0.597831 4.898170 6.485498
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.769928 -0.106164 0.302571 0.516430 0.320029 -0.342086 3.188211 0.189408 0.804373 0.500397 0.606530 1.634961 1.369351
18 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 9.638172 13.641496 3.487206 0.800518 5.840406 5.574747 21.135157 64.475936 0.777523 0.273404 0.646146 4.082016 2.322768
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.113685 -1.518016 2.023775 0.547196 0.391939 5.550874 18.401282 14.541125 0.062948 0.064964 0.010923 1.319504 1.307995
20 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -2.546923 1.818932 -0.630042 -0.085285 -0.966145 0.339708 0.684704 -0.062052 0.066985 0.054248 0.005480 1.187102 1.185957
21 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.858975 -1.282484 0.799491 1.494284 -0.414627 1.994670 2.635913 12.512507 0.080973 0.067712 0.011534 1.271930 1.270518
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 32.325830 34.343733 35.891200 36.981507 39.895369 35.942979 7.056712 4.775750 0.037004 0.039354 0.002183 1.315233 1.298765
28 N01 RF_maintenance 100.00% 40.32% 100.00% 0.00% 100.00% 0.00% 22.045438 41.403399 0.262637 1.483739 26.199776 29.853514 6.505123 50.345922 0.403073 0.161196 0.287101 7.570243 2.947335
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.446546 -0.414019 -0.017743 -0.305130 -0.494069 -1.494881 -0.099237 0.635420 0.808510 0.508031 0.597407 1.611008 1.304308
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.436193 0.146932 0.297627 -0.895334 -0.031853 -0.552044 13.693569 0.627987 0.797022 0.506335 0.594013 6.142561 6.668801
31 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.665291 -1.724602 -1.044381 -0.531118 1.854841 2.108541 1.725278 2.656296 0.074654 0.088793 0.026289 1.290317 1.277112
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 51.617781 42.442836 2.199469 1.407979 11.538321 15.805875 33.376908 45.771914 0.098541 0.094312 0.013120 1.301359 1.294334
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.315978 12.200231 2.579915 1.948918 52.528853 50.646198 200.737979 217.748397 0.051752 0.094516 0.041414 1.474992 1.449167
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.673280 12.110689 0.218918 -0.352662 2.436842 -0.171192 0.189662 1.303937 0.807400 0.533376 0.565366 6.790783 4.596110
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.036104 1.076440 -1.123375 -0.646155 0.104331 0.239634 0.592988 25.430988 0.814381 0.543844 0.563942 5.207772 4.022814
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.239417 -0.733294 -1.059449 -0.970895 -0.917035 1.482736 13.163688 4.296425 0.812324 0.544544 0.569296 4.756569 4.020355
40 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.688057 -0.484647 -0.682919 -0.583800 0.941536 -1.089448 -0.279118 -0.977849 0.082014 0.096937 0.022801 1.223582 1.225549
41 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.252965 -0.370875 2.223068 1.093645 3.249357 -0.975367 -0.817132 -1.080499 0.054521 0.085439 0.018772 1.282653 1.279828
42 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.534788 1.138584 1.452228 1.045984 -0.994306 -0.262930 -0.376689 -0.495111 0.094836 0.093934 0.027583 1.268357 1.264252
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.144941 0.594581 -1.087311 0.807571 -1.441207 0.832968 0.289353 57.350053 0.801245 0.487077 0.607124 5.734624 4.813778
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.401906 -0.678747 0.032536 -0.702498 0.328524 -0.080738 -0.046774 2.756697 0.801362 0.477738 0.619467 1.102546 0.847903
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.986848 5.317998 0.105000 2.570175 1.692765 0.589356 17.594067 0.855013 0.765655 0.551121 0.489840 6.947361 5.312637
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.161605 3.687130 -0.992245 -0.268991 1.339536 0.982120 0.220567 2.203217 0.810662 0.569841 0.537561 1.706730 1.403208
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.086160 10.311010 1.231779 -0.082815 3.661880 -1.326788 1.882282 0.655664 0.816754 0.566744 0.542638 5.306006 4.572636
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.941020 2.972767 -0.947793 0.079171 -0.607993 0.161802 5.305963 12.839209 0.810788 0.569279 0.551650 5.201646 4.354181
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.580126 22.870577 1.387894 1.288152 0.789526 5.660819 1.275403 2.703064 0.084630 0.096669 0.020770 1.241719 1.240192
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.927331 1.633326 -0.169192 0.595718 1.389618 -0.830963 7.579902 -0.304383 0.067301 0.064342 0.008190 1.227429 1.228226
56 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.488403 0.555643 1.499599 1.441350 0.021780 -0.867458 -0.768894 -0.580414 0.054130 0.055608 0.005368 1.243515 1.240681
57 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 49.170711 -0.618348 11.393398 2.644989 20.964648 1.196897 12.307146 1.307550 0.120037 0.069678 0.017008 1.234562 1.239000
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.823811 0.508971 2.813860 1.015217 -0.478316 -0.359441 -0.404734 0.978218 0.812979 0.557105 0.555249 1.788937 1.471153
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.755648 1.246778 -0.668566 0.509119 0.950649 2.194637 -0.261617 2.055243 0.815029 0.579727 0.528666 1.782928 1.487410
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.875262 -1.206367 -0.469295 0.835470 2.086317 1.934023 2.047620 5.497864 0.814969 0.590915 0.518046 4.481201 5.018111
68 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.280798 1.054715 2.943337 1.643151 2.649919 5.132762 0.348670 1.649101 0.809846 0.586904 0.521752 4.815321 4.530988
69 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.150735 -1.538530 0.065275 -0.112409 -0.321759 2.288442 -0.226670 2.706243 0.100476 0.103063 0.030016 1.255059 1.249145
70 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.311974 -1.756946 1.161567 -1.114440 1.352190 0.776556 0.031375 2.720704 0.071283 0.067517 0.008593 1.262702 1.263470
71 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.617604 -0.458540 -0.939213 -0.525633 1.622549 -1.102282 -0.286602 -0.446523 0.083681 0.082697 0.014591 1.235441 1.234946
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.505755 -1.049080 -0.789439 1.407915 3.183383 -0.825843 4.539166 -1.207966 0.095660 0.068599 0.013957 1.226195 1.223577
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 30.055037 -0.024816 35.214341 0.987785 39.730666 -0.218043 3.499208 0.861380 0.031694 0.516194 0.280393 1.177536 2.819479
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.019294 0.847566 -0.925744 3.897589 0.294407 1.890439 0.760295 -1.702527 0.803522 0.553936 0.541123 1.829915 1.645435
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.238427 1.015880 1.556791 0.238860 -0.857066 -1.381797 -0.419362 -0.902231 0.814357 0.573078 0.540902 5.201088 5.448701
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.530522 1.828379 2.269046 4.510849 0.242749 1.416139 -0.735016 -1.415053 0.816599 0.596899 0.517408 4.268482 4.637247
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.952381 16.537365 1.813190 0.712513 -0.370727 0.131610 -0.057114 -0.489891 0.819459 0.600223 0.510268 4.645964 5.457097
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.380433 0.421474 0.490739 1.610929 -1.023172 -1.795278 -0.319426 -1.021962 0.807550 0.590662 0.533609 1.449632 1.127851
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.380646 6.457886 1.052871 -0.496320 1.203707 2.281428 1.315925 0.979518 0.806815 0.550854 0.546644 5.816447 4.207403
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 53.418819 17.409570 2.494157 1.164019 13.109691 -0.005674 14.719941 -0.735850 0.703672 0.573918 0.449498 3.664702 3.607709
88 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
90 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
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 63.348525 81.285886 3.012437 4.624064 31.040784 43.626418 4.001854 13.300354 0.314827 0.206270 0.151993 4.880939 3.424053
93 N10 digital_ok 100.00% 0.00% 16.13% 0.00% 100.00% 0.00% 0.247655 -0.358326 3.385973 0.165170 4.665621 -0.917454 4.289555 -1.216791 0.737094 0.436512 0.551268 4.861743 4.095833
94 N10 digital_ok 100.00% 0.00% 16.13% 0.00% 100.00% 0.00% -1.440522 -1.525487 -0.869157 -1.138520 -0.591093 6.976892 3.870383 10.286625 0.735995 0.423118 0.557967 4.379318 3.846687
98 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.920024 3.295297 1.450828 2.206167 0.105484 0.159201 -0.104131 2.028153 0.797622 0.537550 0.557013 1.970823 1.539220
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.242009 1.263789 3.220863 0.043476 4.910037 0.506986 2.481830 -0.838435 0.811090 0.568450 0.537096 5.949533 6.577980
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.182962 -0.030744 0.056865 -0.053617 2.645481 -0.649878 -0.295580 -0.905716 0.814751 0.582535 0.535142 1.809430 1.625446
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.684372 15.434133 3.731198 1.346735 -0.634435 -0.309794 12.676475 0.029507 0.824749 0.599117 0.526252 5.027229 4.923705
102 N08 RF_maintenance 100.00% 0.00% 73.12% 0.00% 100.00% 0.00% 34.261167 34.728754 1.181105 1.063122 723.481767 723.711659 10719.136410 10664.665454 0.722240 0.392094 0.538653 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.507135 15.585613 -0.574249 -0.220051 -1.486943 -0.275951 -0.052881 0.004826 0.816396 0.594794 0.531672 5.898272 5.055563
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.060422 113.654350 0.008648 13.154794 1.439420 -0.620047 0.267307 -0.984487 0.819952 0.573875 0.568061 5.675776 4.362522
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
106 N09 digital_ok 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% 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
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
109 N10 digital_ok 0.00% 0.00% 2.69% 0.00% 2.63% 0.00% -1.044249 0.186808 0.144322 0.762188 0.631555 1.146296 -0.269508 -0.397857 0.745108 0.458386 0.555725 1.693811 1.576328
110 N10 RF_maintenance 100.00% 0.00% 37.63% 0.00% 100.00% 0.00% 58.968753 38.697246 2.679384 1.171127 3.470851 14.521054 0.919307 7.004849 0.655627 0.406421 0.392575 5.960693 5.849226
111 N10 digital_ok 0.00% 0.00% 13.44% 0.00% 13.16% 0.00% 0.156479 1.781140 -0.872852 0.823968 0.316402 3.545968 -0.350786 3.822908 0.745538 0.445758 0.547945 1.918680 1.635855
112 N10 digital_ok 0.00% 0.00% 16.13% 0.00% 15.79% 0.00% -1.019285 -0.220304 -0.680415 0.174072 1.540686 -0.186831 -0.215753 -1.451230 0.735145 0.438148 0.553874 1.888347 1.590011
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.599249 3.156349 -0.800130 -0.866782 -0.234649 0.990426 0.046774 -1.031078 0.804820 0.539606 0.562426 2.021381 1.513567
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.768332 0.851405 5.508717 5.461893 3.426457 0.961183 -1.067331 -1.981150 0.814647 0.562164 0.553002 5.913226 5.181606
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 2.820747 38.223801 2.506528 31.843548 -0.564185 36.475544 2.058794 0.980446 0.820689 0.047775 0.503794 4.754117 1.342757
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.755858 1.965837 9.838380 0.312186 6.841352 0.179952 -1.936070 -0.874448 0.829135 0.577832 0.547797 4.911170 4.423881
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 25.800739 51.900371 0.570869 41.608882 27.294228 36.111757 1.722980 11.267577 0.465105 0.043248 0.304420 3.319420 1.193521
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.200858 9.068833 -0.863690 3.343518 0.227473 1.245492 69.541828 26.968624 0.824724 0.598273 0.528097 6.742224 5.544573
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.878295 11.883761 1.283817 0.945629 -1.471225 -0.687794 0.367298 0.298506 0.827449 0.594831 0.543772 6.377111 5.247649
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.856847 15.067814 0.191166 2.583555 -1.602148 -1.403699 1.759576 0.956862 0.820204 0.584804 0.551803 7.431403 6.148354
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% 0.00% 0.00% 0.00% 0.00% 0.00% -0.350146 -0.016385 0.053014 -0.308128 0.658332 1.516743 0.345259 1.614689 0.742665 0.470000 0.553285 1.881561 1.501057
128 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.881230 3.747308 -0.555410 0.886666 0.572837 0.741096 0.135773 -1.101259 0.745263 0.468660 0.544653 2.035321 1.631600
129 N10 digital_ok 0.00% 0.00% 2.69% 0.00% 2.63% 0.00% -0.988013 -1.526585 0.764561 0.607596 -0.715904 -0.690650 -0.580501 -1.076576 0.745188 0.460398 0.544061 2.007249 1.676822
130 N10 digital_ok 100.00% 0.00% 13.44% 0.00% 100.00% 0.00% 0.728496 -0.228241 0.055512 1.403290 1.389057 1.326999 4.471779 6.226522 0.733252 0.441769 0.545699 5.475552 5.927478
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.314623 -0.010609 -1.091157 -0.979768 -0.504443 0.360673 1.402941 0.059715 0.740147 0.478849 0.527520 4.432546 3.247637
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.487944 16.545935 -0.934247 0.019317 4.435210 2.327573 2.695825 4.572398 0.741836 0.469911 0.507600 6.835005 4.986926
137 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.323896 0.329481 14.644436 2.585410 14.618307 9.289838 -2.042536 2.803394 0.815933 0.559777 0.557557 8.440643 6.158060
138 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.792266 0.030077 2.958545 0.786471 -0.627024 -1.177949 3.200038 -1.051820 0.815745 0.569320 0.553766 7.463666 5.636934
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.071257 32.600688 35.005514 37.035405 39.860615 36.070414 2.676849 2.472666 0.039387 0.042375 0.001508 1.182885 1.173044
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.921866 4.412641 3.049025 7.862212 1.240602 3.399525 1.755748 30.946777 0.816969 0.560493 0.550205 6.382113 5.671474
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 36.240516 40.126493 1.112724 37.263956 32.815144 35.973463 5.088813 5.021914 0.474389 0.042828 0.250728 11.067112 1.354312
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.408918 -1.165728 1.420167 0.151858 0.641596 -0.830831 -0.232292 -1.611400 0.811033 0.582766 0.544648 1.485808 1.069551
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.432051 -0.500183 1.885290 -0.048401 0.356521 0.399949 0.103651 22.189190 0.816844 0.567757 0.569336 8.353370 9.106292
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 33.108987 35.195940 36.142477 37.661930 39.959586 36.055827 5.803271 7.890274 0.032738 0.033593 -0.000281 1.465677 1.455725
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 35.101566 37.904056 36.059309 38.412087 39.996038 36.104026 6.457776 6.867717 0.044683 0.044790 0.000187 1.199116 1.196047
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.781696 30.705296 35.095375 36.690241 39.851672 36.032312 6.442474 6.476014 0.037992 0.035275 0.000971 1.338522 1.329019
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.104041 0.841765 1.217076 -0.085767 0.054273 1.088563 8.595457 20.398676 0.753884 0.472794 0.532157 5.612105 5.091596
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.860568 0.580531 -0.465396 2.794633 -0.364886 0.633537 0.564906 0.093156 0.748750 0.492022 0.523636 1.691652 1.294634
158 N12 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 30.615356 -1.793404 35.940618 -0.914344 40.020267 0.022291 3.143552 3.456910 0.038234 0.503789 0.262785 1.485859 5.533791
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 31.253183 32.076582 35.704346 37.102279 39.994168 36.262249 6.105912 7.506237 0.041245 0.041851 0.002900 1.264942 1.259351
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.555585 60.507530 -0.112832 2.810776 -1.132600 3.806272 0.377015 -0.977370 0.810586 0.467384 0.534040 5.394621 5.835751
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 0.00% 0.579241 -0.199482 -0.900357 -1.156521 0.714797 0.326806 3.447405 0.911648 0.815927 0.574167 0.558730 1.785420 1.514799
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 0.00% 0.114572 0.010609 -0.277978 -0.569982 -1.247299 -0.269946 0.318285 1.189087 0.810546 0.575040 0.553571 1.736995 1.275000
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -1.775951 -1.570831 -1.145823 -0.496914 -0.633560 0.374031 0.668831 1.954648 0.811694 0.562899 0.568784 1.667215 1.617125
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
167 N15 digital_ok 100.00% 0.00% 13.44% 0.00% 100.00% 0.00% 48.620293 27.119495 17.970409 21.427242 29.676966 28.376971 13.075871 8.227094 0.642020 0.414965 0.411616 4.277395 3.233029
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.058482 17.407883 21.438298 24.027142 25.729120 28.413639 -3.929405 -5.089067 0.794691 0.505484 0.577553 5.141762 3.961986
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.145346 16.247001 23.820336 22.706755 30.917698 26.912224 -3.971158 -4.514501 0.793436 0.492657 0.588639 5.106894 3.410092
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.393896 13.528823 24.063842 21.576111 31.268247 23.939831 -3.493913 -4.359996 0.788872 0.497093 0.587168 5.052066 3.707016
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 0.00% 0.670234 -0.902378 -0.926552 0.239614 0.015795 -0.015795 -0.439446 1.609854 0.750077 0.446200 0.556826 1.608069 1.314350
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.614389 0.516685 0.987097 2.519062 -0.899991 1.778120 -0.241441 7.958328 0.743818 0.456806 0.539321 5.588046 5.544436
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 0.00% -0.623787 -1.759675 0.503639 -0.618895 -1.575098 -0.926896 0.140896 -1.131704 0.742707 0.478703 0.534834 1.718398 1.313564
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.121219 1.152893 -1.055763 0.021338 6.891660 -1.530655 7.063952 -1.058322 0.745007 0.486747 0.540188 4.885598 5.100486
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 0.374998 26.052420 0.099981 34.797876 0.381057 28.300817 -0.113151 4.462440 0.809459 0.259456 0.651223 11.903415 2.622106
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 33.577095 82.167161 36.321250 7.407145 39.969056 32.927723 5.754150 7.186355 0.045520 0.315463 0.150361 1.291529 3.084100
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.656442 7.717757 21.461123 21.041305 25.592522 5.401337 -3.810343 40.986779 0.800238 0.483697 0.584249 5.101394 3.428949
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -2.021469 -1.693142 0.007976 -1.229981 -1.072348 -1.289981 -0.237947 9.568394 0.808223 0.556030 0.571376 4.938200 4.322453
184 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.170402 0.137348 1.478453 0.742352 -0.832390 -1.194556 9.674827 -1.039045 0.810008 0.550354 0.577059 6.311408 5.546154
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.030266 -0.255239 3.761882 2.213775 1.038857 -0.870844 4.757324 -0.569347 0.800889 0.539661 0.574584 4.481773 4.330577
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% -0.192252 1.156133 0.017743 0.371122 0.305230 -0.045576 3.990341 1.887602 0.800863 0.540122 0.574698 2.213438 1.468190
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.987328 4.055430 0.188432 0.793732 1.011772 1.725211 0.762745 7.800304 0.797941 0.509047 0.593229 5.306634 4.235489
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 71.840450 38.813530 3.131867 37.606854 24.045396 36.130252 23.637330 6.548844 0.675550 0.040940 0.449999 3.314339 1.069224
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.882615 0.080885 -0.909140 2.116341 1.141477 0.084077 0.486577 9.980984 0.802822 0.496295 0.614871 5.477481 3.736222
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% 59.68% 59.68% 0.00% 100.00% 0.00% 30.630175 27.965490 20.856582 0.994604 36.177932 24.182856 27.232456 36.366376 0.330675 0.219636 0.219216 1.205198 1.222589
206 N19 RF_ok 100.00% 59.68% 59.68% 0.00% 100.00% 0.00% 25.011405 25.197804 6.058354 10.096862 29.323407 25.573349 28.125853 29.436153 0.321575 0.223437 0.210853 1.381618 1.393026
207 N19 RF_ok 100.00% 59.68% 59.68% 0.00% 100.00% 0.00% 28.724931 25.883023 17.483701 13.912011 31.946289 25.975653 11.501060 8.862589 0.321618 0.230165 0.209118 1.297755 1.303163
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% 55.565229 55.484825 inf inf 5425.846696 6573.701525 11367.797600 18410.308085 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 59.68% 59.68% 0.00% 100.00% 0.00% 25.730793 26.448830 9.159617 16.020409 25.266025 26.802111 -3.948424 -5.349202 0.321989 0.225168 0.214491 1.146704 1.130210
224 N19 RF_ok 100.00% 59.68% 59.68% 0.00% 100.00% 0.00% 34.875550 35.102424 26.089008 25.361091 38.517287 34.178073 -4.622855 -5.841322 0.309741 0.208987 0.209744 0.898884 0.917566
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% 55.788236 55.590183 inf inf 7670.741133 7670.650241 21905.104229 21904.300286 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 40.749118 37.671712 24.241510 24.800267 39.605042 35.731994 11.798144 6.598216 0.051476 0.047817 0.003910 0.000000 0.000000
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.102666 3.744005 14.232045 12.592630 18.721774 14.511878 38.786418 38.576792 0.103539 0.074619 0.056797 0.000000 0.000000
323 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 35.988133 7.102324 1.108908 16.201396 14.439554 13.252162 6.354297 -0.190498 0.099402 0.075577 0.049162 0.000000 0.000000
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.117489 6.365048 18.745385 11.781399 21.553443 9.549406 -1.934167 0.681720 0.115590 0.076545 0.064415 0.000000 0.000000
329 N12 dish_maintenance 100.00% 0.00% 88.71% 0.00% 100.00% 0.00% 11.390073 3.367018 1.470715 11.666741 13.792375 12.466961 6.892788 -1.576413 0.651737 0.343626 0.531689 0.000000 0.000000
333 N12 dish_maintenance 100.00% 0.00% 94.09% 0.00% 100.00% 0.00% 10.173917 3.845136 1.288378 10.766055 11.243713 10.026061 5.707899 -1.522212 0.638166 0.330599 0.525271 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 10, 16, 18, 19, 20, 21, 27, 28, 30, 31, 32, 33, 36, 37, 38, 40, 41, 42, 45, 50, 52, 53, 54, 55, 56, 57, 67, 68, 69, 70, 71, 72, 73, 82, 83, 84, 86, 87, 88, 90, 91, 92, 93, 94, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 117, 118, 119, 120, 121, 122, 123, 125, 126, 129, 130, 135, 136, 137, 138, 140, 141, 142, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [15, 17, 29, 46, 51, 65, 66, 81, 85, 98, 100, 116, 127, 128, 143]

golden_ants: [15, 17, 29, 46, 51, 65, 66, 81, 85, 98, 100, 116, 127, 128, 143]
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_2459830.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.dev47+ga570afb
3.1.4.dev14+g122e1cb
In [ ]: