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 = "2459804"
data_path = "/mnt/sn1/2459804"
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: 8-12-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/2459804/zen.2459804.25311.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/2459804/zen.2459804.?????.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/2459804/zen.2459804.?????.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 2459804
Date 8-12-2022
LST Range 16.913 -- 18.913 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 N18
Nodes Not Correlating N09, N14, N19
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 75 / 147 (51.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 92 / 147 (62.6%)
Redcal Done? ✅
Redcal Flagged Antennas 13 / 147 (8.8%)
Never Flagged Antennas 30 / 147 (20.4%)
A Priori Good Antennas Flagged 67 / 95 total a priori good antennas:
5, 7, 9, 19, 30, 42, 45, 53, 54, 55, 56, 68,
69, 71, 72, 73, 83, 84, 85, 86, 88, 91, 93,
94, 98, 99, 100, 101, 103, 105, 106, 107, 108,
109, 111, 112, 117, 118, 121, 122, 123, 127,
128, 129, 130, 140, 141, 142, 143, 144, 157,
160, 161, 163, 164, 165, 167, 169, 170, 181,
184, 185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 2 / 52 total a priori bad antennas:
82, 135
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_2459804.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 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.498251 -0.329018 -0.665672 -0.862468 -0.192137 -0.349613 0.473102 0.411724 0.729151 0.692364 0.465110 2.181279 1.966457
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.397706 4.097280 -0.589767 1.769881 -0.385428 0.842313 4.945771 1.812510 0.741238 0.698293 0.456172 6.135662 6.055379
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.066189 1.352570 -0.215992 4.522762 -0.454942 2.248157 1.127766 -0.192049 0.751028 0.708019 0.456181 4.411630 4.230451
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.880883 -0.888467 0.737515 0.042050 1.622418 2.010215 2.106452 5.705182 0.755077 0.709403 0.453807 3.389217 3.255693
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.548784 15.849081 17.909096 18.180769 15.471036 17.238112 1.798397 3.930405 0.734448 0.678285 0.457586 3.782597 3.925874
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.203672 -1.246176 -0.055089 0.038754 2.964716 2.131248 1.147412 1.463416 0.740481 0.689142 0.461305 3.392325 2.631832
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.411107 -0.997107 -0.369438 0.587707 -0.708277 0.984257 1.654090 1.115864 0.721648 0.665395 0.472331 2.247329 2.051144
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.718113 1.291494 1.435810 1.045642 0.467644 0.866662 1.436602 1.660106 0.763112 0.720948 0.450891 2.926404 2.659849
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.353491 -0.521306 -0.817366 -0.293533 -0.479136 -0.868582 1.098414 1.859190 0.767363 0.732005 0.448404 2.863354 2.720122
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.754787 1.816792 0.058227 0.388130 -0.025399 0.226977 0.372027 0.279992 0.774375 0.736869 0.445956 2.986841 3.229904
18 N01 RF_maintenance 100.00% 0.00% 13.98% 0.00% 100.00% 0.00% 3.005564 2.912812 2.403375 -0.398177 2.850298 2.776551 29.903660 25.676220 0.751759 0.580763 0.502293 3.224167 2.130349
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.303265 0.899534 -0.064617 3.480201 0.417130 5.226520 2.810217 3.282203 0.764461 0.724414 0.449233 5.202565 4.820017
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.161541 0.202631 -0.493629 -0.528509 1.826481 1.427197 0.481548 0.408043 0.752015 0.703487 0.448792 3.125881 2.412433
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.305706 1.653388 0.653194 1.469389 -0.587291 0.585106 1.248391 0.653785 0.734722 0.681512 0.470327 3.562832 2.472491
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.297704 21.679999 54.729069 55.875677 22.870085 24.266634 4.617045 4.300101 0.041629 0.047067 0.003437 1.194496 1.195813
28 N01 RF_maintenance 100.00% 0.00% 97.31% 0.00% 100.00% 0.00% 12.277265 13.493745 7.902980 10.775057 22.032850 23.689335 5.658719 27.051826 0.541283 0.309483 0.328991 19.801804 4.610604
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.004994 -0.156152 0.794631 -0.286503 -0.628096 -0.725386 0.297289 0.755240 0.790396 0.759854 0.441522 2.868221 3.057486
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.039028 0.141475 0.310414 -0.418097 2.071274 0.648935 5.793302 0.276309 0.783786 0.753114 0.435613 3.690760 3.896139
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.639220 -0.383272 -0.755943 0.352782 -0.374932 0.321433 1.252289 1.154699 0.781450 0.742749 0.451607 2.199740 2.005428
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 29.959082 28.458753 2.731551 2.688342 8.942274 8.378470 8.340695 9.018700 0.713759 0.678274 0.265516 11.263591 9.461629
33 N02 RF_maintenance 100.00% 0.00% 13.98% 0.00% 100.00% 0.00% -0.504503 3.269899 -0.545286 0.851310 -0.683588 0.800913 -0.138845 7.852760 0.744888 0.562249 0.557614 5.314679 2.805892
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.080442 5.566743 0.215101 0.570789 2.424282 1.019263 0.431960 0.246247 0.737063 0.694172 0.444006 7.715429 8.329778
37 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.449495 1.105688 -0.155072 0.259324 -0.225484 -0.056777 -0.779158 1.712705 0.759667 0.718247 0.440475 2.643759 2.776314
38 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.809919 -0.063767 -0.743122 -0.779826 2.922803 -0.520407 1.897961 0.065569 0.775890 0.741152 0.437764 2.493451 2.306592
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.088590 -0.485895 0.165299 -0.150717 2.011538 1.350624 -0.695669 -0.970801 0.791773 0.766949 0.430560 3.482531 3.037533
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.827884 -0.831385 2.568743 1.507494 1.226619 -0.622100 -1.002394 -0.145056 0.797948 0.776140 0.433983 3.218239 2.945698
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 63.16% 0.185109 0.443157 2.416162 1.249874 0.366425 -0.301371 -0.791065 -0.762595 0.802082 0.773850 0.447545 4.264794 4.709001
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.221072 0.550949 -0.727692 0.877467 -1.233285 -0.540380 -0.649883 3.470968 0.770629 0.727800 0.468175 3.572141 3.328362
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.726414 -0.427935 0.626074 -0.779117 -0.830459 -1.265133 -0.866503 0.394963 0.755230 0.706433 0.486551 2.004300 1.776302
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.804658 7.804004 0.212042 0.321969 12.435764 5.220006 34.711063 26.572211 0.735157 0.674496 0.403348 5.000188 7.691226
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.260179 1.426085 -0.804757 -0.661438 1.854611 -0.668164 -0.865325 -0.354320 0.764669 0.730099 0.424728 2.407737 2.663428
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.975141 4.832151 -0.163481 0.007445 -0.795913 -0.512354 -0.238535 0.933436 0.784141 0.750036 0.423506 7.660921 6.689365
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% 0.797104 1.128761 -0.126380 -0.203348 -1.407249 -0.561863 0.104382 1.079019 0.798065 0.773666 0.422238 2.602888 2.936711
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 39.47% 1.167954 0.395566 1.251111 0.836520 0.632198 1.447960 -0.190949 -0.849069 0.808987 0.784271 0.428980 3.592663 3.889764
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 1.234819 -0.011663 -0.693925 0.810275 1.139006 2.312955 -0.426308 -0.935493 0.809499 0.787756 0.435513 5.606171 4.708397
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 94.74% -0.237233 0.642744 1.263832 1.427427 0.533591 -0.178002 -0.960405 0.250297 0.807252 0.786230 0.440006 3.722886 3.312230
57 N04 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 20.900214 12.469463 52.140465 0.658150 22.778518 21.339836 2.945613 3.177717 0.051515 0.545902 0.304654 1.303043 3.360479
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.513248 0.041841 0.085042 0.780165 1.648483 2.187312 -0.538937 -0.275398 0.758344 0.709780 0.451175 2.472150 2.362800
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.005876 -0.425699 -0.749627 0.792031 0.413435 0.827683 -0.801974 0.517148 0.773707 0.736539 0.425775 2.918095 2.679864
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.899258 -0.098695 -0.615050 0.305368 0.895813 0.907003 -0.342400 0.231486 0.793418 0.762059 0.414643 3.023583 3.588783
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 10.53% -0.316867 0.170428 0.397838 0.096145 3.377529 2.349018 -0.598767 0.576077 0.805343 0.781832 0.410330 2.644186 3.834696
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.382777 -0.360730 -0.491758 0.359276 -0.208715 -0.914088 -0.591354 -0.963718 0.814970 0.794184 0.426776 4.669196 5.917049
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.287459 -1.265882 0.205184 -0.711009 -0.771521 -0.444759 -0.768712 -0.606585 0.812376 0.790270 0.447631 29.760139 29.563335
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.307226 -0.952171 -0.736792 -0.438875 -0.754094 -0.957664 -0.819622 -0.748100 0.818173 0.797340 0.433617 47.584802 36.928145
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 94.74% 1.667199 -0.673501 -0.551103 1.401560 0.669101 0.276560 0.481776 -1.085912 0.803075 0.775857 0.468225 3.165047 2.955153
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 21.957615 3.073361 53.859942 -0.176177 22.639262 0.215990 2.952492 -0.625123 0.035324 0.752500 0.446088 1.191567 3.129602
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.517870 2.981843 -0.361957 3.389101 -0.257870 1.912745 2.500049 -0.242929 0.754866 0.707173 0.443755 2.165903 2.184196
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.230804 -0.811365 0.797619 1.443232 -0.373512 -0.009270 -0.679094 -0.736199 0.780344 0.736087 0.445026 6.060595 5.374617
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.053870 3.551907 2.238130 4.686880 -0.189046 1.647844 -0.666503 -1.185238 0.794648 0.762071 0.420235 4.417992 4.136937
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.216630 7.294631 0.344664 1.767631 -0.750527 -0.403279 -0.794486 -0.818747 0.754296 0.723438 0.408761 3.467523 3.317149
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 81.58% -0.005876 1.642377 1.040063 2.592977 -0.790724 -0.220734 -0.733014 -0.669888 0.750678 0.721368 0.428290 2.609911 2.409587
86 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 94.74% 1.543608 2.573262 -0.103159 -0.536627 -0.098973 0.032252 -0.412962 0.044863 0.750283 0.714089 0.421504 3.192318 2.817471
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.093502 8.034123 5.726153 1.063211 5.376370 0.590784 10.976848 -0.751535 0.744173 0.722670 0.437940 2.872166 2.667185
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.940394 20.803521 48.112468 49.507090 23.437080 24.677796 5.230076 3.684156 0.032451 0.031877 0.002308 1.154612 1.155494
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.216558 21.236527 48.064338 49.175546 22.922968 24.218778 2.869567 2.632942 0.032447 0.028714 0.000787 1.185569 1.185145
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.064835 20.817405 48.044283 50.248556 23.053394 24.624124 3.843152 3.900148 0.030246 0.030107 -0.000073 1.186431 1.178444
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.477263 44.262850 10.569719 13.887573 23.092687 27.429722 4.265092 7.842080 0.252660 0.202402 0.093968 3.121062 2.342419
93 N10 digital_ok 100.00% 5.38% 40.86% 0.00% 100.00% 0.00% 1.600246 10.872143 3.892652 14.147400 0.690822 12.559495 0.083030 1.368360 0.561340 0.484912 0.387207 3.717018 3.176349
94 N10 digital_ok 0.00% 8.06% 40.86% 0.00% 42.11% 0.00% 0.779103 0.427410 -0.003614 -0.749847 0.021643 0.823978 2.922524 1.206879 0.540882 0.476775 0.362027 2.061669 1.749405
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.620355 4.447663 0.457649 -0.103000 -1.142569 -0.983058 -0.624709 -0.233707 0.756792 0.697194 0.451051 6.322514 5.425991
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.327347 0.397260 3.142821 -0.134759 2.297737 -0.204095 0.120071 -0.017705 0.774352 0.730591 0.440960 4.433460 3.880320
100 N07 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
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.497898 6.747882 3.793736 0.054335 0.624562 -0.779581 0.205881 -0.274035 0.750746 0.708403 0.435338 3.074407 2.814091
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 20.406806 17.240076 7.848726 6.588821 297.561212 267.561934 3378.126479 3321.819847 0.643273 0.679307 0.427111 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.797207 7.106107 -0.248282 0.020022 0.288088 -0.942434 -0.069905 -0.334742 0.743730 0.709049 0.429312 3.292988 3.060147
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.350956 66.685537 0.765835 14.498992 -0.347522 3.067684 -0.261197 0.284640 0.736283 0.698455 0.450620 3.090106 2.730283
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.609547 25.984279 45.632950 47.808361 23.214781 24.702805 3.286884 3.415012 0.032995 0.031904 0.000897 1.165389 1.160021
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.963074 22.432529 47.233348 49.349425 22.954167 24.385096 3.799940 2.967648 0.029431 0.028403 0.000814 1.118425 1.108952
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.200277 19.867744 48.656799 49.861244 23.007146 24.208627 3.507045 3.920745 0.029954 0.031499 0.001553 1.088426 1.093643
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.525196 20.140065 47.477583 49.791978 22.951772 24.334985 2.693932 2.772124 0.030481 0.031414 0.001622 0.832001 0.836588
109 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 269.734702 270.027686 inf inf 1988.847546 1982.670090 5321.914524 5449.977688 nan nan nan 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 269.566256 269.810383 inf inf 1493.070255 1489.041671 4434.102590 4455.348437 nan nan nan 0.000000 0.000000
111 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 269.841387 270.077682 inf inf 1657.304595 1677.153237 3591.250885 3720.733173 nan nan nan 0.000000 0.000000
112 N10 digital_ok 0.00% 8.06% 40.86% 0.00% 42.11% 0.00% -0.733380 -0.430466 -0.653203 0.859832 1.022832 -0.336400 0.414850 -0.044863 0.527499 0.465065 0.349259 1.589397 1.641227
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.032119 1.626361 -0.281683 -0.550858 -1.077230 0.323931 -0.666065 -0.882913 0.753564 0.697971 0.450390 2.020289 1.744214
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.377341 3.293333 5.575690 5.395489 2.432490 2.697356 -1.057953 -1.167804 0.777611 0.726136 0.467432 4.232447 4.167854
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 2.254882 22.229509 2.674925 49.676789 1.548245 24.425711 0.213272 2.584538 0.788325 0.045992 0.520041 3.973744 1.215125
119 N07 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
120 N08 RF_maintenance 100.00% 19.35% 100.00% 0.00% 100.00% 0.00% 17.377088 27.826514 10.062893 61.326991 19.621270 25.061123 2.384975 5.193589 0.477942 0.057359 0.346860 2.437823 1.216040
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.904206 4.419451 -0.421442 0.733080 -0.810005 0.087017 7.741711 7.773194 0.736331 0.697415 0.430782 3.140668 2.889484
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.700849 5.647730 1.639328 1.354363 0.417166 -0.487810 -0.758126 -0.607101 0.727985 0.685178 0.442843 3.532340 3.028038
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.296463 6.894201 0.465564 0.137285 -0.272514 0.388674 -0.675925 -0.719133 0.715263 0.673942 0.449354 3.047924 2.629647
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.075664 20.991780 48.744139 50.510952 23.031561 24.352156 3.055023 4.145812 0.028768 0.028538 0.000234 1.076625 1.084542
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.288320 21.102389 48.153421 50.860418 23.081005 24.431737 3.508956 3.866446 0.028642 0.028662 0.000843 0.823947 0.831527
127 N10 digital_ok 0.00% 5.38% 32.80% 0.00% 34.21% 0.00% -0.061407 -0.285030 0.065440 -0.230078 -0.005055 0.426749 -0.430393 -0.376829 0.581840 0.519021 0.400872 1.501637 1.583283
128 N10 digital_ok 0.00% 5.38% 35.48% 0.00% 36.84% 0.00% -1.001642 0.905106 -0.275764 1.556651 -1.162244 -0.136979 -0.609859 -0.942631 0.567346 0.500175 0.379556 1.587463 1.611908
129 N10 digital_ok 0.00% 5.38% 38.17% 0.00% 39.47% 0.00% -0.500705 -1.392034 -0.766426 -0.926968 0.005055 0.063455 0.062497 0.139831 0.549670 0.486486 0.362087 1.662366 1.534133
130 N10 digital_ok 0.00% 8.06% 40.86% 0.00% 42.11% 0.00% -0.616129 0.484310 0.936968 1.351809 0.173800 1.273365 0.338638 2.325324 0.529476 0.466646 0.346955 1.709523 1.666350
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.500286 -0.505012 -0.883237 -0.883543 -1.205998 -0.534246 0.828446 0.304971 0.692320 0.631652 0.445207 5.663917 4.672462
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.093066 9.656086 -0.475925 0.656196 4.591885 5.264356 0.229130 1.928409 0.700166 0.642688 0.424706 5.793032 5.664114
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.363343 20.203541 47.460209 48.812611 22.988850 24.316853 3.480455 4.188415 0.036424 0.040673 0.004440 1.238963 1.258797
138 N07 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
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.782630 19.385391 53.639342 55.925687 22.717871 24.254030 2.784348 2.938675 0.041869 0.044950 0.001107 0.909692 0.964751
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.831896 5.356255 0.059486 11.204246 2.345097 4.284328 -0.445355 2.630637 0.770850 0.724001 0.469810 3.561092 2.917453
142 N13 digital_ok 100.00% 10.75% 100.00% 0.00% 100.00% 0.00% 19.891618 24.582890 9.562552 56.166237 22.989441 24.458483 3.142098 3.449169 0.471181 0.045928 0.281388 2.759192 1.168951
143 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.036478 -0.965934 1.276115 1.156161 0.516064 1.305297 0.329613 -0.146634 0.104865 0.104521 0.025469 0.000000 0.000000
144 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.261610 1.320801 0.686734 -0.668437 -0.645225 0.214332 0.927746 1.413369 0.096441 0.090985 0.018539 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.483077 21.144031 55.046120 56.555603 22.982328 24.363747 5.173275 5.788827 0.031866 0.035165 0.000011 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.278287 22.991092 54.848121 57.515603 23.162775 24.578815 4.761277 5.228167 0.050957 0.055217 0.002478 1.255198 1.253435
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.677459 22.373474 53.743295 55.475247 22.785454 24.132271 3.750489 4.112734 0.043610 0.043761 -0.000260 1.323736 1.322674
156 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.229990 0.713205 1.856106 -0.224670 -0.318785 -0.652586 -0.869276 1.055282 0.694668 0.629507 0.443526 3.378448 2.936439
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.407197 0.682309 0.019896 3.123484 0.783002 1.189109 -0.565464 -0.648372 0.697087 0.642333 0.440524 3.490693 3.161275
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.567600 -1.165772 -0.134784 -0.032477 -0.589652 -0.034999 0.968179 -0.708117 0.705010 0.648894 0.441115 2.987574 3.274356
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.084591 19.083611 54.462078 55.996697 22.813672 24.248616 3.554271 4.143304 0.045805 0.046575 0.001714 1.233498 1.233046
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.686877 38.217271 -0.041172 4.007195 -0.736431 8.100177 -0.610325 -0.256759 0.750080 0.631968 0.416407 3.891756 6.322854
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.293099 1.084822 0.200529 -0.701603 1.842282 1.081152 -0.654314 -0.555769 0.745718 0.694067 0.476462 1.756499 1.500844
163 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.542635 -0.316827 0.020999 -0.811167 -0.674037 -1.126595 -0.431386 -0.491513 0.063339 0.073135 0.009354 1.247990 1.246968
164 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.932959 -0.851502 -0.675452 -0.717488 -0.478132 -0.100987 0.173456 0.046144 0.076715 0.066231 0.004709 1.251020 1.248699
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.370612 0.777603 6.290612 -0.771134 3.294120 -0.914466 1.399422 0.705584 0.085414 0.063514 0.004732 1.267392 1.269426
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.003640 14.218767 3.789881 2.918087 5.508590 7.516968 8.509103 16.188918 0.077419 0.079070 0.005450 1.218956 1.214493
167 N15 digital_ok 100.00% 0.00% 16.67% 0.00% 100.00% 0.00% 16.606605 19.590313 16.813054 16.983657 18.218400 19.239440 13.271433 17.959968 0.639739 0.546805 0.274021 4.446827 3.082103
168 N15 RF_maintenance 100.00% 0.00% 5.91% 0.00% 100.00% 0.00% 16.438855 18.513912 18.188869 20.040509 16.095911 19.489441 1.232150 3.977209 0.666743 0.592226 0.460687 3.727624 3.165596
169 N15 digital_ok 100.00% 0.00% 5.91% 0.00% 100.00% 0.00% 18.211961 17.100347 19.891139 18.914765 17.627669 18.039990 2.465115 4.185852 0.645766 0.572735 0.448445 3.818883 3.170578
170 N15 digital_ok 100.00% 0.00% 5.91% 0.00% 100.00% 0.00% 18.288761 15.838359 20.077383 18.285043 18.057239 17.492162 2.562874 3.897918 0.629961 0.559821 0.438503 3.413220 3.165138
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.127036 -0.334272 -0.525148 0.680844 1.067756 0.674945 -0.848242 -0.770352 0.668251 0.600909 0.439554 2.925644 2.794897
177 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.304051 1.103588 1.230306 -0.106502 -0.868764 1.069460 0.051668 0.686972 0.672520 0.607552 0.435546 3.116476 3.216219
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.989208 -1.286810 0.994076 -0.617840 -0.560577 -1.194631 -0.593926 -0.956484 0.677564 0.617773 0.429426 2.732736 2.555130
179 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.510269 0.290712 -0.895427 -0.067646 1.857918 -0.713109 -0.425373 -1.047428 0.675860 0.619064 0.432988 2.170647 2.271330
180 N13 RF_maintenance 100.00% 0.00% 38.17% 0.00% 100.00% 0.00% 0.791332 13.173145 0.725800 50.396305 -0.721828 14.464573 -0.908927 2.019837 0.733382 0.480734 0.528047 153.390041 42.958661
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.700662 46.536745 55.194671 6.603860 22.897149 26.121984 3.592304 7.802146 0.051182 0.320729 0.164737 1.218380 4.061626
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.464382 10.929579 18.102931 13.730459 15.661657 28.256013 0.581928 4.919707 0.711530 0.670208 0.477617 4.754438 4.208408
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.063170 -0.675480 0.003614 -0.880931 -0.885616 -1.708410 -0.647509 -0.269776 0.736365 0.678451 0.492018 1.570190 1.374404
184 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.463695 -0.082069 -0.087166 0.683332 0.350321 0.911974 1.277288 0.781783 0.065224 0.059012 0.004237 1.252725 1.248982
185 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.042679 0.408611 1.374492 1.147730 4.803407 -0.234501 0.106825 -0.232963 0.047650 0.051544 0.003358 1.281151 1.275890
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.031121 0.585426 3.634858 2.238519 0.503385 0.305753 1.798538 0.016896 0.061560 0.072610 0.009854 1.286286 1.285875
187 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.743126 0.718768 0.048590 0.673530 -0.333763 -0.903399 2.201559 0.090505 0.080420 0.094410 0.017383 1.221053 1.218743
189 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 269.712683 269.970611 inf inf 956.546286 968.399340 4244.135951 4215.010603 nan nan nan 0.000000 0.000000
190 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 269.726181 270.021459 inf inf 1153.696915 1174.194671 4321.783432 4331.385051 nan nan nan 0.000000 0.000000
191 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 269.680315 270.018903 inf inf 986.080427 1012.086548 4039.630286 4109.485854 nan nan nan 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% 100.00% 100.00% 0.00% 100.00% 0.00% 11.835369 5.731457 13.242253 -0.188812 11.818011 3.639335 8.642170 12.355010 0.054710 0.037275 0.003993 1.238077 1.251811
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.798421 8.391384 -0.039865 9.263193 4.585538 9.674587 9.497625 9.130974 0.037462 0.043121 0.001724 1.328070 1.315039
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 13.846431 11.108954 15.248141 12.743136 13.523887 11.930587 2.981134 2.326274 0.055114 0.052075 0.004518 1.139933 1.141918
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% 10.260710 7.441124 85.747159 88.018333 2278.049877 2626.844617 4182.527751 5591.765836 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.390804 12.034989 7.967285 13.922092 6.137382 12.756666 -0.040167 -0.361838 0.042148 0.056723 0.003194 0.942601 0.925543
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.795730 20.107682 22.367309 21.852715 20.252314 21.106122 1.394330 2.196388 0.062636 0.063420 0.004803 0.834697 0.827935
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% 10.196791 12.787670 inf inf 3151.639508 3151.584107 6887.722579 6886.985208 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.786806 23.728456 40.811251 41.327201 23.121236 24.186077 5.221007 4.024482 0.067156 0.061139 -0.002033 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 62.37% 0.00% 100.00% 0.00% 10.299932 8.089131 12.414427 11.126472 11.876152 10.990656 9.141054 8.993903 0.542540 0.405760 0.358838 0.000000 0.000000
323 N02 not_connected 100.00% 0.00% 67.74% 0.00% 100.00% 0.00% 18.668250 11.721402 2.423702 14.515860 9.672868 14.493595 2.365224 0.092611 0.464864 0.370079 0.299164 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 62.37% 0.00% 100.00% 0.00% 14.532141 14.732376 16.600951 16.675216 13.997641 15.396106 0.321764 0.052476 0.533827 0.394869 0.366528 0.000000 0.000000
329 N12 dish_maintenance 100.00% 18.82% 75.81% 0.00% 100.00% 0.00% 1.403351 7.405203 0.025390 10.681949 2.598110 8.282444 3.654462 -0.250532 0.466344 0.343891 0.303906 0.000000 0.000000
333 N12 dish_maintenance 100.00% 26.88% 91.94% 0.00% 100.00% 0.00% 0.606371 7.061315 1.241369 9.692982 1.985309 8.258727 0.406736 -0.263412 0.436470 0.306860 0.277234 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: [4, 5, 7, 8, 9, 18, 19, 27, 28, 30, 32, 33, 36, 42, 45, 50, 52, 53, 54, 55, 56, 57, 68, 69, 70, 71, 72, 73, 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, 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, 157, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 180, 181, 182, 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: [3, 10, 15, 16, 17, 20, 21, 29, 31, 37, 38, 40, 41, 46, 51, 65, 66, 67, 81, 116, 156, 158, 162, 176, 177, 178, 179, 183]

golden_ants: [3, 10, 15, 16, 17, 20, 21, 29, 31, 37, 38, 40, 41, 46, 51, 65, 66, 67, 81, 116, 156, 158, 162, 176, 177, 178, 179, 183]
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_2459804.csv
In [24]:
# Load antenna positions
data_list = sorted(glob.glob(os.path.join(data_path, f'zen.{JD}.?????.sum.uvh5')))
hd = io.HERAData(data_list[len(data_list) // 2])

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Metadata¶

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