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 = "2459789"
data_path = "/mnt/sn1/2459789"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H5C_Notebooks/_rtp_summary_"
good_statuses = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
In [4]:
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 7-28-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H5C_Notebooks/blob/main/antenna_report/antenna_{ant}_report.html'

Load Auto Metrics¶

In [6]:
use_auto_metrics = False

# find the auto_metrics file
glob_str = os.path.join(data_path, f'zen.{JD}*.auto_metrics.h5')
auto_metrics_file = sorted(glob.glob(glob_str))

# if it exists, load and extract relevant information
if len(auto_metrics_file) > 0:
    auto_metrics_file = auto_metrics_file[0]
    print(f'Found auto_metrics results file at {auto_metrics_file}.')
    
    auto_metrics = load_metric_file(auto_metrics_file)
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
    auto_ex_ants = auto_metrics['ex_ants']['r2_ex_ants']
    
    use_auto_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping auto_metrics.')
Found auto_metrics results file at /mnt/sn1/2459789/zen.2459789.25301.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

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

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 372 ant_metrics files matching glob /mnt/sn1/2459789/zen.2459789.?????.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/2459789/zen.2459789.?????.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 2459789
Date 7-28-2022
LST Range 15.925 -- 17.925 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: 42
RF_ok: 11
digital_maintenance: 1
digital_ok: 87
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 113 / 147 (76.9%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N10
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 69 / 147 (46.9%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 120 / 147 (81.6%)
Redcal Done? ✅
Redcal Flagged Antennas 7 / 147 (4.8%)
Never Flagged Antennas 9 / 147 (6.1%)
A Priori Good Antennas Flagged 81 / 87 total a priori good antennas:
5, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29, 30,
31, 37, 45, 46, 50, 51, 53, 54, 55, 56, 57,
65, 66, 68, 69, 71, 72, 73, 81, 83, 84, 88,
91, 92, 93, 99, 101, 103, 105, 106, 107, 108,
109, 111, 117, 118, 121, 122, 123, 128, 129,
130, 135, 138, 140, 141, 142, 143, 144, 145,
160, 161, 164, 165, 167, 169, 170, 176, 177,
178, 179, 181, 183, 185, 186, 187, 189, 190,
191
A Priori Bad Antennas Not Flagged 3 / 60 total a priori bad antennas:
3, 100, 116
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/array_health_table_2459789.csv

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.226623 -0.305161 0.411584 -0.849328 -0.206494 -0.099303 -0.177485 2.799504 0.618392 0.610698 0.416529 0.000000 0.000000
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.931990 4.636572 -0.806390 -0.158109 -0.492765 -0.113454 3.078800 -0.527974 0.627973 0.614635 0.417045 0.000000 0.000000
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.338885 1.982401 -0.920771 5.864283 -0.772073 3.497042 0.258590 -2.805343 0.635686 0.623568 0.416497 0.000000 0.000000
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.477075 7.220505 11.796308 12.418463 13.737866 13.758285 -1.962727 21.355017 0.628205 0.616852 0.398683 29.226541 24.217336
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 19.807038 21.385441 23.851107 25.437668 34.721145 35.463046 6.506985 1.972486 0.607396 0.592186 0.389844 0.000000 0.000000
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.316558 7.355878 0.753889 13.031701 1.279877 15.626471 1.229050 -2.395732 0.611494 0.601279 0.391651 0.000000 0.000000
10 N02 digital_ok 100.00% 2.69% 0.00% 0.00% 100.00% 0.00% 21.558388 18.790101 25.344166 23.491613 37.737048 32.757217 39.022402 36.384658 0.563796 0.559363 0.376688 0.000000 0.000000
15 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
16 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
17 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
18 N01 RF_maintenance 100.00% 0.00% 53.76% 0.00% 100.00% 0.00% 4.971983 5.847754 1.658590 0.742134 16.318947 15.189241 270.611186 172.101521 0.624293 0.454441 0.436291 9.747803 4.630743
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 19.623543 12.310337 23.611009 17.335995 34.665338 22.764929 3.125814 12.672766 0.622265 0.628024 0.388510 10.986865 13.264421
20 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.480672 22.295827 15.124106 25.534940 20.422270 36.581173 -1.442060 1.852621 0.620538 0.585077 0.393806 19.015543 10.471895
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.370322 -0.462027 -0.735251 -0.961251 0.382034 -0.486805 3.933724 17.416370 0.607110 0.593241 0.388545 11.187375 8.358820
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.004021 32.617167 68.354587 68.338725 49.368500 48.787264 24.926698 18.351459 0.040304 0.044808 0.002508 1.122767 1.123487
28 N01 RF_maintenance 100.00% 51.08% 100.00% 0.00% 100.00% 0.00% 15.732101 21.527207 8.291136 11.216476 41.356584 52.180701 27.975693 155.219261 0.439875 0.227211 0.286636 2.113020 1.123199
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 97.37% 2.63% -1.803726 -0.856710 -0.363546 0.278473 -0.341996 -0.317352 -0.303807 1.429997 0.675672 0.669450 0.407448 0.000000 0.000000
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.621428 0.242720 7.292613 0.112170 4.845354 -0.109982 5.457988 1.491933 0.660965 0.659573 0.399489 0.000000 0.000000
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.832632 -1.149479 -0.136348 -0.369847 0.740284 1.317784 7.015140 4.661551 0.663494 0.651970 0.396966 5.959775 6.298931
32 N02 RF_maintenance 100.00% 8.06% 2.69% 0.00% 100.00% 0.00% 37.060258 43.793927 2.978067 3.946862 12.765160 12.941567 78.012932 83.074814 0.570547 0.576426 0.202263 7.690165 7.252248
33 N02 RF_maintenance 100.00% 0.00% 53.76% 0.00% 100.00% 0.00% 0.507275 5.442405 2.489042 1.221828 14.750482 16.184931 231.796559 277.402983 0.618796 0.452018 0.454248 3.951140 2.240076
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.852798 9.329821 0.280662 1.504034 0.928928 0.549706 1.438318 3.741567 0.630435 0.614021 0.390895 11.764229 10.894703
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.454230 0.718714 2.061017 0.073807 0.771105 -0.206039 -0.277956 29.304712 0.658201 0.644979 0.398057 28.477370 28.489553
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.733660 0.019302 -0.284813 -0.732907 1.905781 0.500865 18.111948 9.795001 0.676300 0.665927 0.406691 22.634892 21.858834
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.082294 0.206526 0.713080 -0.218536 -0.652113 -0.968079 0.225745 -1.513918 0.688925 0.683284 0.404182 1.919917 1.826986
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.821147 -0.571920 2.239969 -0.889898 0.808388 -0.241380 -1.133475 -1.404663 0.688577 0.683774 0.392820 1.046749 0.954741
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.207855 0.965951 1.830164 1.061460 -0.301283 -0.062242 -1.518022 -1.291204 0.691743 0.688531 0.407702 1.600644 1.601504
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.155817 1.738835 0.291796 2.288162 -0.316921 1.211662 2.049106 69.782277 0.654562 0.638758 0.405157 47.111366 59.784967
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 31.58% -1.652226 -0.986837 -0.474355 -0.886347 0.105053 -0.662412 0.229264 0.667344 0.634722 0.623003 0.410628 6.948835 7.119979
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.529861 33.354268 -0.869258 4.375256 0.692859 7.391030 5.499555 6.600631 0.641366 0.579004 0.358808 4.153682 3.095425
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 1.272127 45.123954 3.812090 85.156085 1.806558 49.408495 0.864324 51.841523 0.668389 0.042790 0.436232 6.667360 1.226310
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 15.054034 51.744318 0.907357 86.200742 2.995156 50.139148 5.389575 54.764626 0.646713 0.037823 0.420621 17.669874 1.169847
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.633917 3.726031 5.429875 4.716779 3.802651 2.316709 7.011954 13.681885 0.701242 0.694883 0.395132 3.187034 3.157597
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.042947 1.026078 -0.570023 1.191842 7.743482 11.549490 7.352100 61.197450 0.702849 0.698135 0.372306 29.606078 25.251522
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.799971 0.109568 -0.730302 0.610997 2.927000 1.154185 6.215935 0.902692 0.702176 0.699703 0.389996 147.741276 49.808597
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.175588 5.833947 13.362301 11.503217 16.889765 14.647747 -1.900517 8.996141 0.703271 0.702759 0.399776 16.822294 19.051811
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 30.170720 -1.141083 64.925578 4.569591 49.050034 14.811813 17.359309 8.328795 0.049112 0.695945 0.448983 1.840587 34.406705
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 1.414760 0.514763 -0.194541 0.133661 0.681678 0.256991 -0.725164 1.436549 0.651916 0.640453 0.395605 2.432472 2.595309
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.054501 1.386254 0.155496 -0.384621 2.740636 -1.180220 0.550335 8.397685 0.674656 0.665074 0.384617 23.386589 31.016532
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.023717 -1.058601 -0.650707 -0.985755 -0.906401 0.147623 3.783626 8.977816 0.693578 0.686365 0.376497 18.176369 25.375616
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% 0.802178 0.306298 -0.828193 1.357435 1.333100 1.652479 0.429992 -0.383387 0.702215 0.697285 0.377725 0.729479 0.711625
69 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.710969 5.185900 11.530053 10.258495 15.293455 13.808765 -0.429254 0.417548 0.709305 0.712822 0.374883 83.596392 175.766613
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.685479 -1.415406 0.158508 -0.631856 -0.044156 -0.059883 1.796044 4.448353 0.713157 0.708986 0.401082 51.177430 64.112826
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 36.84% 0.357173 -1.133430 0.457884 0.106202 -0.123717 1.160991 0.336296 -0.284186 0.713516 0.718980 0.392719 4.070710 3.539087
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.430899 -0.811597 0.024517 2.413632 1.056486 2.914159 9.684011 -1.526729 0.697732 0.702933 0.408920 57.993130 74.544636
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 39.47% 1.519140 0.607046 0.522532 0.980142 1.397927 0.310423 2.305291 -0.124630 0.685195 0.676949 0.426510 6.045375 8.359722
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.984967 5.008614 -0.213072 5.391670 0.012194 5.324541 2.213203 -1.246531 0.638687 0.630785 0.378459 4.348330 3.929429
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.213941 1.358082 1.760803 -0.617047 3.254168 -1.207895 -0.322896 -1.195300 0.666826 0.660857 0.377761 15.618875 15.484937
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.924138 3.456811 44.121291 5.398935 51.994078 4.678544 21.865626 -2.071817 0.606430 0.689326 0.407148 4.716317 7.282116
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.481944 11.859120 2.373169 2.668750 0.651376 1.395046 -0.495634 -1.398270 0.711490 0.709706 0.368594 4.488397 3.851039
85 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.085587 39.073098 -0.652395 3.726208 -0.883495 12.908050 0.471322 26.705379 0.720949 0.660343 0.377153 23.354555 17.596663
86 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.070365 5.023714 -0.684187 -0.388684 4.690350 2.892674 1.711351 1.154361 0.720616 0.710286 0.378649 7.504424 6.313824
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.838574 22.843719 22.543524 26.331434 30.876341 36.920327 10.574239 1.759657 0.689623 0.698451 0.405077 0.000000 0.000000
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.079011 28.689341 59.907151 60.610436 49.532041 49.266837 33.024265 22.008847 0.045342 0.047139 0.000707 0.854385 0.850809
90 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.356292 4.396837 -0.727744 4.966294 0.011817 4.908910 9.765693 -1.620218 0.658645 0.656661 0.425286 7.054929 8.375252
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 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 43.942106 68.271209 10.563153 13.335106 48.268747 49.737059 23.362422 48.563205 0.093277 0.090146 0.012101 0.000000 0.000000
93 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.024881 0.319146 2.855082 0.108991 3.149988 1.061255 -0.666166 3.574788 0.092115 0.091994 -0.014519 0.000000 0.000000
94 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.917481 -1.236178 0.842443 -0.686563 -0.298381 2.176449 10.165268 10.915727 0.059629 0.060739 0.004859 0.000000 0.000000
98 N07 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.754700 2.730844 1.557518 0.969985 -0.526300 -0.590578 1.300985 10.301455 0.630443 0.619752 0.374653 14.022223 12.903104
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.450625 -0.284412 3.007011 1.216796 4.170331 1.672635 11.124181 0.472810 0.658494 0.651700 0.370629 24.673035 20.562794
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.039757 -0.535546 -0.435280 0.668858 -1.204677 0.004219 -0.326233 0.681638 0.686468 0.680650 0.381333 33.124528 35.624236
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.764247 21.382116 25.139007 25.284217 36.574650 34.894251 3.942129 0.826763 0.692490 0.687984 0.381846 19.046660 21.420631
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.509684 0.818848 16.097027 4.463228 29.903168 21.229391 414.053776 222.630992 0.697295 0.708832 0.387690 50.715492 27.681501
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.173927 11.160945 1.620589 0.347480 1.190772 0.191205 -0.189712 -0.304555 0.723654 0.719582 0.386404 24.670451 17.907692
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.536850 99.280229 2.528600 18.424925 1.386475 7.692944 2.309690 1.277607 0.715325 0.712596 0.406078 25.833936 23.919601
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% 27.097238 28.057102 57.528474 58.141145 48.914126 48.264932 21.291980 22.825420 0.048781 0.052424 0.003597 0.868895 0.880157
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% 100.00% 100.00% 0.00% 100.00% 0.00% -1.115035 0.522144 -0.674795 1.368574 -1.038019 1.291184 0.201128 0.590643 0.084540 0.084246 0.017697 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 39.957615 2.659597 3.702374 2.215678 34.454998 -0.058946 84.506322 -1.843310 0.070510 0.065556 0.007103 0.000000 0.000000
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.410621 0.549098 0.748326 1.697267 0.433592 1.983614 0.416953 3.564007 0.051576 0.054837 0.003267 0.000000 0.000000
112 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.927249 -0.252293 1.081304 1.129838 0.421925 -0.899363 1.185448 -2.332410 0.055021 0.065183 0.006733 0.000000 0.000000
116 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.968587 2.574384 -0.003215 -0.244455 1.941527 -0.072041 0.254989 -1.191997 0.620938 0.610787 0.373624 0.000000 0.000000
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.212056 5.701069 9.441420 7.317835 9.759323 5.641839 -2.160385 -3.242996 0.659109 0.652389 0.393307 0.000000 0.000000
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.385509 2.075363 2.670846 0.661565 3.301703 1.238633 2.842085 1.811423 0.668284 0.665356 0.384761 0.000000 0.000000
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.666119 3.585872 12.346497 0.371155 14.962864 1.194048 -2.118612 -0.170789 0.690155 0.687174 0.389400 0.000000 0.000000
120 N08 RF_maintenance 100.00% 40.32% 100.00% 0.00% 100.00% 0.00% 24.463191 40.788429 6.158718 75.789495 43.077378 49.475312 15.455133 32.951785 0.483740 0.052628 0.365753 0.000000 0.000000
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.119813 6.185823 -0.159798 1.428892 -0.384842 0.714545 81.893623 44.529618 0.713463 0.713525 0.390967 0.000000 0.000000
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.226811 21.748052 24.352867 25.136716 35.616137 34.919790 1.541975 0.390549 0.692698 0.690487 0.395536 0.000000 0.000000
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.288416 10.746797 1.221509 0.323390 -0.180109 -0.639194 1.029153 3.297996 0.702835 0.702408 0.405445 0.000000 0.000000
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 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.101449 -0.621577 -0.674187 0.118766 -0.181698 1.166267 -0.046866 2.437173 0.081344 0.080609 0.019004 0.000000 0.000000
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.975681 0.440207 -0.266253 1.494229 -0.667304 0.834352 0.430278 0.459586 0.071660 0.071652 0.010490 0.000000 0.000000
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.105198 0.024881 -0.827508 0.864431 -0.708628 -0.004219 -0.495299 -1.508532 0.055302 0.056835 0.005251 0.000000 0.000000
130 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.215315 -0.528944 -0.612797 -0.677314 0.756491 0.786754 1.279626 18.784882 0.065144 0.066061 0.007630 0.000000 0.000000
135 N12 digital_ok 0.00% 32.26% 37.63% 0.00% 100.00% 0.00% -0.209133 -1.007424 -0.209137 -1.001286 -0.415294 -0.803231 0.046866 -1.087179 0.535390 0.524257 0.344639 0.000000 0.000000
136 N12 RF_maintenance 100.00% 32.26% 37.63% 0.00% 100.00% 0.00% 4.933650 13.373710 0.983436 0.779306 2.743425 1.408485 3.538268 6.299988 0.539884 0.525631 0.322969 0.000000 0.000000
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.204408 30.639946 58.950758 59.714781 49.285052 48.751651 21.175228 25.614204 0.037315 0.046238 0.003837 0.000000 0.000000
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 35.575712 3.289391 55.499956 1.200807 49.239847 2.217497 23.470003 -1.278919 0.047714 0.666785 0.453614 0.000000 0.000000
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.106258 5.732078 -0.174457 -0.316018 1.678165 1.679448 2.271488 -0.727616 0.682873 0.678599 0.392922 0.000000 0.000000
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.658118 6.410325 -0.383441 15.750772 1.483605 6.925996 8.548160 42.382493 0.680612 0.663602 0.393756 0.000000 0.000000
142 N13 digital_ok 100.00% 51.08% 100.00% 0.00% 100.00% 0.00% 28.275096 35.020216 9.616793 69.232693 43.711766 49.084690 22.285737 19.228261 0.438290 0.046059 0.262161 0.000000 0.000000
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 94.74% 5.26% -0.207200 -0.320915 -0.326325 0.926963 0.702264 -0.070838 -0.254852 -2.132506 0.676692 0.670991 0.394129 0.000000 0.000000
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.758943 0.364786 0.565883 0.123087 -0.891648 0.260949 2.685448 15.173855 0.670773 0.662466 0.407997 0.000000 0.000000
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.993520 29.473718 68.780238 69.753417 49.360484 48.938758 22.018227 26.556527 0.035613 0.037660 -0.000431 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.090604 31.943739 68.535438 70.965017 49.397012 48.946768 24.930640 25.968100 0.051687 0.052585 0.000722 0.000000 0.000000
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.730922 30.294464 67.179758 68.413163 49.532577 48.989808 24.148269 22.568734 0.044223 0.042044 0.001068 1.185274 1.176700
156 N12 RF_maintenance 100.00% 32.26% 37.63% 0.00% 100.00% 0.00% 21.176729 22.037016 25.139712 25.546116 37.180407 35.827645 5.032297 5.510009 0.532942 0.522709 0.346860 9.844469 10.968672
157 N12 RF_maintenance 100.00% 32.26% 37.63% 0.00% 100.00% 0.00% 20.847317 23.190664 24.570567 26.439764 36.085642 37.804698 2.300579 1.980167 0.535448 0.523784 0.349255 9.361838 8.958240
158 N12 RF_maintenance 100.00% 32.26% 32.26% 0.00% 100.00% 0.00% 16.181513 20.071226 20.836829 24.513729 28.804802 33.996726 -0.439462 2.009495 0.557382 0.546649 0.365323 3.114530 3.002307
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.726970 26.586872 68.071089 69.046579 49.357788 48.912068 23.029894 26.687311 0.042270 0.043676 0.002216 1.331038 1.278289
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.013425 52.476158 -0.853472 4.803059 -0.028146 11.766896 1.165417 0.765844 0.671560 0.583326 0.359867 20.501338 12.099427
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.377456 1.827847 -0.353529 -0.397739 2.590791 1.968740 -0.255926 -0.695302 0.665118 0.662033 0.396071 1.231023 1.080581
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.069317 -0.560902 -0.287300 -0.502449 -1.008792 -0.250195 1.731852 1.392829 0.667232 0.662056 0.390185 1.089945 1.024174
164 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.456945 -1.056241 -0.411840 -0.318428 0.110523 -0.704257 9.816933 5.080053 0.656806 0.651325 0.392804 16.787097 20.141543
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.880097 1.268062 7.490916 -0.749587 9.040577 -0.901960 -0.196878 2.879224 0.650929 0.643618 0.390387 11.085333 13.304859
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.924291 3.138733 1.757782 0.765080 7.108023 11.895889 18.491729 24.571651 0.620501 0.624803 0.369092 0.000000 0.000000
167 N15 digital_ok 100.00% 8.06% 37.63% 0.00% 100.00% 0.00% 24.647925 29.234949 23.013148 24.161373 40.043213 38.837771 13.936378 7.922082 0.550057 0.520866 0.278623 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.113084 25.213523 24.118267 27.931902 34.835205 39.867913 1.891743 4.700180 0.581439 0.563038 0.380301 0.000000 0.000000
169 N15 digital_ok 100.00% 5.38% 0.00% 0.00% 100.00% 0.00% 23.696635 23.201204 26.657541 26.389209 39.376975 37.377053 4.128030 1.854144 0.555952 0.546568 0.370740 0.000000 0.000000
170 N15 digital_ok 100.00% 21.51% 0.00% 0.00% 100.00% 0.00% 23.906561 21.413023 26.854003 25.231554 39.816855 35.350475 4.979213 2.563552 0.536947 0.537435 0.366549 0.000000 0.000000
176 N12 digital_ok 0.00% 32.26% 37.63% 0.00% 39.47% 0.00% -0.390152 -0.483172 -0.566601 0.703896 0.111827 0.542758 -0.227663 -0.177032 0.527196 0.520434 0.348457 1.166455 0.954284
177 N12 digital_ok 100.00% 32.26% 37.63% 0.00% 100.00% 0.00% 1.826580 1.478051 0.675694 1.858486 -0.051543 2.503913 7.846215 15.223353 0.539384 0.527922 0.357370 20.263320 34.462469
178 N12 digital_ok 0.00% 32.26% 32.26% 0.00% 36.84% 0.00% -1.395057 -1.644625 -1.021440 -0.246362 -1.549435 -0.684946 -0.707629 -1.578590 0.547255 0.538392 0.360051 1.692104 1.588183
179 N12 digital_ok 100.00% 32.26% 32.26% 0.00% 100.00% 0.00% 1.599892 0.575233 0.461580 0.337508 2.403717 0.962984 10.636522 -0.863088 0.551506 0.540530 0.365771 12.688198 19.064063
180 N13 RF_maintenance 100.00% 0.00% 56.45% 0.00% 100.00% 0.00% 0.640218 19.156895 0.368142 62.464708 0.654981 33.375759 0.506404 18.223116 0.652162 0.425288 0.463280 6.735745 3.012497
181 N13 digital_ok 100.00% 100.00% 80.65% 0.00% 100.00% 0.00% 29.131113 67.395775 68.972597 16.929139 49.370401 45.294941 21.623774 26.394994 0.043750 0.284046 0.150588 1.328391 2.228518
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 20.044771 13.988432 24.056374 18.504750 35.188399 24.604742 1.157746 112.360287 0.633765 0.635960 0.405985 6.569772 7.535569
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.235999 0.702006 1.063734 -0.640429 1.450089 -0.291236 1.008227 8.768973 0.655910 0.644424 0.402765 29.020246 36.697416
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 36.84% 0.00% 0.465485 -0.452159 1.718440 -0.788180 1.038577 0.192461 3.543941 1.199018 0.650251 0.641665 0.385981 1.749533 1.715262
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.043758 1.019841 5.237222 6.121462 3.585578 2.184787 10.106929 0.694876 0.645358 0.640935 0.387130 13.132227 17.301690
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.429389 1.922935 26.756301 27.526294 4.063421 3.162895 8.494073 2.517805 0.613928 0.609137 0.370447 6.523414 6.819233
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.680509 22.111048 21.393808 25.776799 30.205863 36.093211 1.161522 1.746596 0.617120 0.604218 0.376681 0.000000 0.000000
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.965647 5.640481 -0.321034 0.388086 -0.190040 1.212482 1.498059 14.361312 0.585210 0.580048 0.379712 0.000000 0.000000
190 N15 digital_ok 100.00% 43.01% 100.00% 0.00% 100.00% 0.00% 51.270326 33.029547 4.411344 69.735929 20.381084 48.926152 54.357990 24.350114 0.491547 0.047817 0.337705 0.000000 0.000000
191 N15 digital_ok 0.00% 5.38% 0.00% 0.00% 100.00% 0.00% 0.029046 0.727404 0.003215 -0.757955 0.877554 -0.095392 0.557647 0.529567 0.554581 0.543216 0.381585 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% 15.031059 7.356584 17.332318 -0.143771 25.453580 6.612024 59.884554 99.679653 0.608077 0.595370 0.376650 7.958791 8.748933
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.495029 11.122131 -0.424545 12.247716 8.965758 18.794996 62.368284 62.458349 0.583442 0.588333 0.364248 3.002884 3.076290
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.885940 23.522841 20.022465 26.497286 30.003718 37.855343 17.942743 19.902150 0.578147 0.563327 0.365909 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% 14.018573 15.634838 109.166260 107.835395 3288.835930 3917.610006 28003.730165 39326.919488 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.576212 16.435703 9.617245 19.495763 15.508732 26.616023 -0.037500 0.689170 0.596142 0.587480 0.385423 6.662084 5.808800
224 N19 RF_ok 100.00% 5.38% 0.00% 0.00% 100.00% 0.00% 27.183747 27.386036 30.081105 30.465833 44.971604 43.637793 5.156678 3.074634 0.548182 0.546012 0.362976 3.128248 3.487063
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% 11.153375 18.011082 inf inf 4560.928044 4560.759962 46561.614197 46557.937606 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 34.341140 33.615701 50.677176 50.333184 49.595996 48.805313 34.301215 24.532563 0.071814 0.056958 -0.000775 0.000000 0.000000
321 N02 not_connected 100.00% 32.26% 72.58% 0.00% 100.00% 0.00% 12.749424 11.403694 16.134225 15.412446 24.214548 21.678384 74.140127 74.221701 0.458239 0.397719 0.300786 0.000000 0.000000
323 N02 not_connected 100.00% 48.39% 75.27% 0.00% 100.00% 0.00% 26.312949 15.875158 4.402499 19.498898 20.223419 25.965265 27.450868 2.176803 0.378194 0.371772 0.254399 0.000000 0.000000
324 N04 not_connected 100.00% 43.01% 72.58% 0.00% 100.00% 0.00% 18.406507 20.199595 22.005860 23.156766 31.436938 31.836698 -0.191965 -1.622043 0.442121 0.383235 0.300417 0.000000 0.000000
329 N12 dish_maintenance 100.00% 69.89% 77.96% 0.00% 100.00% 0.00% 4.938608 9.739908 7.784869 15.020686 8.729028 18.270782 2.467216 -2.800146 0.370492 0.321411 0.245788 0.000000 0.000000
333 N12 dish_maintenance 100.00% 80.65% 100.00% 0.00% 100.00% 0.00% 6.886378 9.613700 12.490122 13.403636 8.067331 15.524285 9.214131 -0.941499 0.304730 0.295217 0.201426 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 45, 46, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 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: [40, 41, 42, 162, 163]

golden_ants: [40, 41, 42, 162, 163]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/rtp_summary_table_2459789.csv
In [24]:
# Load antenna positions
data_list = sorted(glob.glob(os.path.join(data_path, f'zen.{JD}.?????.sum.uvh5')))
hd = io.HERAData(data_list[len(data_list) // 2])

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Metadata¶

In [27]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.2
3.1.1.dev2+g1b5039f
In [ ]: