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 = "2459791"
data_path = "/mnt/sn1/2459791"
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-30-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/2459791/zen.2459791.25313.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 370 ant_metrics files matching glob /mnt/sn1/2459791/zen.2459791.?????.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 37 ant_metrics files matching glob /mnt/sn1/2459791/zen.2459791.?????.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 2459791
Date 7-30-2022
LST Range 16.059 -- 18.059 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 111 / 147 (75.5%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N08, N10
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 78 / 147 (53.1%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 101 / 147 (68.7%)
Redcal Done? ✅
Redcal Flagged Antennas 13 / 147 (8.8%)
Never Flagged Antennas 18 / 147 (12.2%)
A Priori Good Antennas Flagged 73 / 87 total a priori good antennas:
5, 7, 10, 16, 17, 19, 20, 30, 31, 37, 41, 42,
45, 50, 51, 54, 55, 56, 57, 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, 141, 142,
143, 144, 145, 160, 161, 162, 163, 164, 165,
167, 169, 170, 176, 177, 178, 179, 181, 186,
187, 189, 190
A Priori Bad Antennas Not Flagged 4 / 60 total a priori bad antennas:
3, 38, 67, 100
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_2459791.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% 0.575469 -0.692198 -0.681466 -0.835437 -1.021100 -0.893015 -0.729793 -0.661920 0.655119 0.645146 0.416740 4.604931 4.440776
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.009138 4.173012 -0.067012 2.239482 -0.815892 0.006361 2.587153 0.218458 0.667924 0.651969 0.412027 5.301465 5.102403
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.517385 2.138602 1.037983 6.842741 1.841419 4.872787 0.998944 -0.002420 0.676720 0.663170 0.411015 6.633552 7.508974
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.427297 -1.055893 1.101193 0.770565 0.014429 0.623359 -0.095431 5.047744 0.670654 0.658420 0.399228 4.576671 5.444547
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.174126 15.037010 24.256252 24.981094 22.418777 22.851345 0.085587 -0.269261 0.645922 0.628616 0.393136 5.479466 5.458279
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.631979 -0.834555 -0.053605 1.105365 0.478145 0.671659 -0.893399 -1.177236 0.649740 0.640007 0.395409 1.570783 1.525441
10 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.338989 3.771511 3.465300 10.756324 2.671490 9.598979 5.363561 4.861599 0.630860 0.614881 0.404046 6.102520 6.965081
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.006047 0.984166 1.716890 -0.087932 -0.032203 -0.161290 -0.019227 0.506061 0.684859 0.671691 0.412936 1.931448 1.970328
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.919211 -0.235452 -0.237951 1.019967 -0.264340 2.487011 1.025119 6.970182 0.690805 0.678693 0.405589 7.911753 12.460527
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.70% 0.221093 0.903156 -0.124929 0.322025 0.943505 0.713474 2.798867 0.977889 0.692045 0.683098 0.396230 1.698817 1.800907
18 N01 RF_maintenance 100.00% 0.00% 45.95% 0.00% 100.00% 0.00% 5.328685 5.777558 1.054221 4.691670 1.354897 5.622311 13.975170 27.660330 0.622188 0.488022 0.404289 4.267260 3.125828
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.561556 0.577291 10.195517 3.970106 9.189475 4.867239 0.165062 0.439097 0.678090 0.669348 0.392183 6.031036 6.822518
20 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.161612 6.507947 -0.904691 12.356492 1.397215 11.414072 0.319959 -0.101048 0.664812 0.645271 0.391978 9.001033 10.259882
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.065290 -0.641749 0.647306 0.042649 0.453040 0.765468 2.003138 3.832350 0.648140 0.635159 0.399974 1.718828 1.670526
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.607632 23.883628 69.347410 70.478258 84.181585 77.751179 126.083224 114.533116 0.041825 0.047549 0.003747 1.245837 1.251888
28 N01 RF_maintenance 100.00% 40.54% 100.00% 0.00% 100.00% 0.00% 11.370001 16.151244 8.389022 14.953680 28.741093 32.588330 2.473642 13.428493 0.466243 0.243772 0.272607 23.284425 4.709939
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.890314 -0.439896 1.655332 -0.583437 0.003696 0.149540 -0.363398 0.359954 0.706395 0.697968 0.402231 1.825043 2.015653
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.138378 -0.213006 1.049677 -0.831052 0.202546 0.285060 5.631577 0.325101 0.699692 0.692425 0.396761 6.353953 7.667972
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.41% 0.198787 -0.415816 -0.662884 -0.863007 0.496287 0.416825 -0.206342 -0.387996 0.698099 0.686057 0.396460 1.652192 1.709997
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 27.012069 26.510668 3.362040 7.849042 11.989893 19.264086 24.279999 104.830762 0.614092 0.619817 0.224475 11.184940 9.509667
33 N02 RF_maintenance 100.00% 0.00% 43.24% 0.00% 100.00% 0.00% 0.546258 3.192378 1.789756 1.029262 4.213980 4.337418 7.726842 10.646521 0.660081 0.496346 0.469212 10.583384 4.658673
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.300280 6.338598 0.476335 0.749919 3.843411 3.184261 2.838635 3.778928 0.645954 0.626918 0.400932 3.908708 3.767136
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.060729 1.332010 -0.225314 -0.291082 2.701107 5.412147 1.376067 7.186883 0.672005 0.655924 0.406626 4.383898 4.241956
38 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.347669 0.046700 -0.632269 -0.242975 1.171557 -0.034163 2.271947 1.044180 0.689571 0.676681 0.411893 6.268440 6.073437
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.434040 0.215424 -0.374273 -0.777990 -1.026626 -1.313519 -0.868133 -1.151544 0.706394 0.698732 0.407889 1.766105 1.807723
41 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.444032 -0.091486 4.485597 1.844088 1.850845 -0.296907 -0.891833 0.104797 0.710478 0.701340 0.400587 10.940369 10.414392
42 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 281.525428 281.574450 inf inf 517.913496 513.405226 735.159890 726.566847 nan nan nan 0.000000 0.000000
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.321680 0.453580 -0.647105 1.393938 -0.261309 1.619605 0.573607 13.405040 0.690297 0.674465 0.409904 6.483748 6.174700
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.091776 -0.986933 0.662353 -0.623750 -1.096878 -1.318521 -0.823152 1.631467 0.673632 0.660827 0.417530 1.808433 1.779018
50 N03 digital_ok 100.00% 0.00% 10.81% 0.00% 100.00% 0.00% -0.512714 22.883558 -0.609902 2.597868 0.465238 8.122740 4.258303 11.820937 0.650992 0.584915 0.367918 4.939634 6.487811
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 0.791698 32.369583 -0.596940 87.035051 1.327330 141.010784 3.010991 130.829564 0.675618 0.040525 0.371153 5.513564 1.279998
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 10.120121 32.981074 1.703579 84.254052 3.426657 32.548508 4.850594 8.692239 0.653773 0.040847 0.356928 16.814596 1.242311
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.880441 1.070026 0.343667 -0.582875 -0.297353 -0.675516 2.031586 1.484556 0.704177 0.694077 0.405550 1.682151 1.859570
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 281.506107 463.018775 inf inf 1326.777155 -3212.866470 2298.315773 -4608.788251 nan nan nan 0.000000 0.000000
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.383817 -0.003620 0.362392 1.450042 1.440327 0.470024 5.615542 -0.393490 0.714694 0.709247 0.411901 5.169458 5.210109
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.698755 0.418048 2.859060 2.372967 1.321082 1.433592 -0.207910 5.954200 0.721727 0.714958 0.417838 4.837571 4.936782
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 21.861035 2.621430 68.937615 5.401371 51.934023 4.925592 23.932645 1.523500 0.045365 0.713092 0.432856 1.195521 4.321836
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.951280 0.231733 0.592181 0.625404 0.524659 -0.044335 -0.102734 -0.438552 0.657678 0.639648 0.408837 1.512416 1.591586
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.196683 -0.173633 -0.099313 1.358211 -0.106624 1.281669 -0.433522 1.153995 0.676292 0.660219 0.403275 1.528567 1.579155
67 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.338215 -0.602700 -0.038605 0.789391 0.324832 0.971264 -0.440609 0.144609 0.692451 0.681579 0.403097 6.080452 10.309702
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.51% 0.139609 0.030834 0.234126 0.902695 0.969915 1.386333 -0.624729 -0.534307 0.699482 0.690253 0.403542 2.124950 2.256461
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 51.35% -1.122541 -0.673521 0.108329 -0.325621 -0.334204 0.280726 -0.349390 -1.011159 0.705824 0.704976 0.404983 5.044774 5.634650
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.986840 -1.308150 0.314266 -1.015982 -0.193908 -0.762984 -0.309404 -0.153886 0.721311 0.713415 0.430800 12.788996 9.626344
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 86.49% -0.249309 -1.183674 -0.789111 0.066251 0.776873 -0.176961 1.049780 -0.609372 0.714141 0.715222 0.421919 16.730212 21.122714
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 301.971242 2046.609184 inf inf -2327.481959 -31020.383993 -9413.890189 -189771.873992 nan nan nan 0.000000 0.000000
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 97.30% 0.049012 0.292843 -0.763977 0.290933 1.444557 2.378429 3.681377 2.732461 0.708941 0.698273 0.436535 4.918582 4.783738
81 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 676.496458 496.885525 inf inf 5942.772055 -5067.439019 38491.342099 -33560.566012 nan nan nan 0.000000 0.000000
82 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 713.949617 732.338977 inf inf 9303.562266 14233.439979 35546.627638 58216.798111 nan nan nan 0.000000 0.000000
83 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 286.481035 286.729580 inf inf 3085.661666 3094.350838 6885.975809 6937.245623 nan nan nan 0.000000 0.000000
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.815691 7.521695 0.871385 1.796840 1.386595 1.735757 0.949540 0.835476 0.086857 0.090892 0.014623 1.190251 1.194031
85 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.630567 25.166788 2.099279 2.774071 0.166533 9.095250 -0.481629 6.274996 0.072987 0.083182 0.008407 1.196997 1.195479
86 N08 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.154803 2.944948 -0.632167 -0.131150 -0.136742 0.581161 -0.417513 -0.299950 0.065360 0.067759 0.006556 1.201285 1.204851
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.849959 10.900913 8.508910 14.919124 18.505921 10.668362 36.250751 -1.359501 0.083607 0.097948 0.015909 1.168577 1.163227
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.750345 19.070857 60.980632 62.705186 31.926458 31.232976 4.356294 2.288423 0.052320 0.058923 0.003099 1.194164 1.202062
90 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.149544 3.184777 0.819779 5.352272 -0.157256 2.781623 0.099527 -1.275586 0.686503 0.681204 0.424553 4.734164 4.301292
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.500076 19.487550 60.833800 63.586045 31.902031 31.252555 3.283368 3.006928 0.037844 0.041100 0.001036 1.211840 1.205478
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.092733 47.178109 10.922512 13.955293 38.757120 39.220797 6.696749 8.710528 0.095754 0.092362 0.012630 0.972598 0.976625
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.886784 0.169752 4.879334 -0.741601 3.001928 1.785661 -0.611454 0.229748 0.095612 0.095525 -0.013817 0.976994 0.969356
94 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.933474 -1.025933 -0.907936 -0.908070 -1.162613 0.274549 0.415890 1.278623 0.058270 0.066206 0.005620 0.000000 0.000000
98 N07 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.421275 14.120904 24.941531 17.183905 23.291122 14.526603 -0.391668 -0.835466 0.616857 0.609496 0.383041 6.143286 5.689057
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.176040 14.459617 25.090835 23.692509 23.389405 21.453889 0.001938 -0.808173 0.631656 0.626651 0.379537 5.851585 6.335161
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.129550 -0.111000 1.921872 -0.015084 0.536070 -0.677930 0.088059 -0.497359 0.679463 0.668630 0.410743 6.957222 7.170538
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.854500 7.395792 13.888245 1.092138 10.068481 0.008790 0.849693 1.008346 0.114033 0.090804 0.016758 1.194425 1.200498
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.754050 2.122290 32.471905 22.791945 43.055577 28.136064 132.351186 82.409612 0.061251 0.065001 0.008119 1.166639 1.161073
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.713005 7.193960 -0.335990 0.684703 -0.720558 -0.891450 -0.355141 -0.710865 0.064016 0.063222 0.005158 1.208538 1.207272
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.538020 66.369722 1.611673 15.641882 2.540445 9.307273 2.692290 3.823086 0.074693 0.078138 0.011090 1.179592 1.180007
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.480892 25.390080 57.632055 60.344198 33.595531 33.400782 7.155120 7.614049 0.037274 0.040638 0.003662 1.202731 1.197178
106 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.828632 15.471421 25.019849 24.610752 23.312449 22.389193 -0.130747 -0.537595 0.682287 0.675773 0.428874 4.137391 3.612382
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.993900 18.912357 58.508482 60.064990 31.843620 31.019660 2.922995 2.785800 0.050482 0.056839 0.004626 1.243435 1.251243
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.373354 4.227400 -0.514661 4.860409 -0.989615 1.986017 -0.052714 -0.345764 0.676970 0.672597 0.430743 4.373132 4.481593
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.166388 -0.006047 0.942673 0.314934 -0.879059 -0.769462 0.678461 -0.065804 0.088260 0.086239 0.018795 1.259927 1.278026
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 35.868686 2.420907 4.910646 2.576171 6.995824 5.902910 6.077061 65.278203 0.073646 0.064026 0.007106 1.336621 1.319227
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.800449 0.714232 -0.389658 2.743289 -0.269741 1.211934 -0.748609 -0.356864 0.056923 0.055673 0.003641 1.155993 1.154470
112 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.580569 -0.370462 -0.693843 2.363718 0.163777 -0.013787 -0.546344 -1.370423 0.055943 0.072105 0.006208 1.317796 1.312528
116 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.748800 15.424452 -0.376302 24.540360 0.531402 22.683786 -0.145032 -0.606182 0.628688 0.592889 0.395149 6.893354 5.180433
117 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 281.567965 281.608853 inf inf 1251.401721 1245.211796 1180.327285 1225.174932 nan nan nan 0.000000 0.000000
118 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 281.576483 281.625921 inf inf 1852.563167 1706.033720 2028.461284 2966.020212 nan nan nan 0.000000 0.000000
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.829389 0.634928 13.517863 0.391674 10.883958 0.684021 -0.951693 1.512508 0.680074 0.673147 0.420466 4.934624 4.988758
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.191373 27.630579 10.372558 77.936890 29.448336 31.977149 1.501568 4.201471 0.108372 0.041431 0.055865 1.253940 1.214103
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.537776 4.594781 0.020062 1.007093 -1.000532 -0.008872 10.391509 5.056890 0.074627 0.070733 0.006806 1.209299 1.209703
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.661544 6.468621 11.666013 3.099032 9.592500 3.155288 2.036002 4.021823 0.096995 0.082180 0.012394 1.213039 1.222672
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.825841 7.640506 2.874867 0.444186 0.356947 -1.048822 -0.693234 0.605051 0.115168 0.112656 0.025859 1.254151 1.253499
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.418179 19.441555 61.612401 63.870584 31.889569 31.243931 2.506584 3.642635 0.032975 0.037752 0.002464 1.218449 1.216321
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.142297 20.266996 60.895436 64.277025 40.530853 42.301605 12.065836 14.375043 0.039855 0.039550 -0.001397 1.236358 1.239773
127 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.691688 -0.869234 -0.208122 -0.708669 -0.100724 -0.531715 -0.605169 -0.629766 0.078743 0.080480 0.016752 0.000000 0.000000
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.047244 1.181394 -0.294686 3.394213 -0.107105 2.341308 0.599965 0.601870 0.067278 0.071147 0.009714 0.000000 0.000000
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.400131 -1.315034 -0.315095 -1.003893 -0.023962 0.291232 -0.197500 0.670521 0.061088 0.054970 0.004868 1.007247 1.012373
130 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.699349 0.037076 1.013450 0.921599 -0.208922 0.371495 1.511151 2.243979 0.063261 0.061802 0.007331 0.000000 0.000000
135 N12 digital_ok 0.00% 32.43% 32.43% 0.00% 32.43% 0.00% -0.591546 -1.013963 -0.567481 -0.374131 -0.001983 -0.890869 2.820248 0.610932 0.552420 0.538224 0.352999 2.105493 2.031647
136 N12 RF_maintenance 100.00% 32.43% 32.43% 0.00% 100.00% 0.00% 3.019747 7.867449 -0.329568 0.877095 1.716201 1.413978 0.528363 3.559845 0.549803 0.532739 0.338118 5.335002 5.736178
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 283.705913 282.791254 inf inf 2549.126541 3938.235852 4064.984424 9335.077752 nan nan nan 0.000000 0.000000
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 24.524664 2.563706 56.508198 -0.391928 32.076172 -0.582981 2.715595 -0.255814 0.048186 0.660415 0.433500 1.307550 5.645350
140 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.512518 3.469216 0.470272 1.788217 1.231854 2.080067 -0.250069 1.294965 0.677038 0.671475 0.418085 2.034537 2.140010
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.455827 3.901490 0.800087 12.149684 2.363025 4.577374 2.691069 15.863217 0.679620 0.666322 0.418289 6.246728 7.181497
142 N13 digital_ok 100.00% 48.65% 100.00% 0.00% 100.00% 0.00% 19.827166 23.659921 9.171897 71.372560 31.165225 31.432736 2.524685 3.113459 0.437545 0.045482 0.236395 7.777187 1.377619
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.62% -0.029058 -0.201245 1.335765 2.102685 0.717474 0.326775 -0.718127 -1.182602 0.695606 0.689107 0.408436 2.743888 2.749833
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.62% -0.217534 -0.275113 2.112794 -0.569838 1.938052 -0.783436 1.123008 0.335776 0.697359 0.690053 0.417387 2.501748 2.604238
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.666205 19.212465 70.036469 72.014101 31.927171 31.805753 3.614401 5.082377 0.036650 0.037740 -0.000120 1.538978 1.655544
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.064720 23.883487 69.521455 72.690052 69.135467 85.701732 30.744489 49.693768 0.053156 0.056963 0.002060 1.088815 1.093210
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.454002 23.343283 68.116583 70.226798 91.278849 84.056021 80.176583 71.992825 0.042641 0.042552 -0.000415 1.343993 1.409047
156 N12 RF_maintenance 100.00% 32.43% 32.43% 0.00% 100.00% 0.00% 7.267919 6.825371 14.272834 13.094425 11.100839 9.896281 0.570350 2.008337 0.554062 0.539295 0.352452 6.247215 6.785792
157 N12 RF_maintenance 100.00% 32.43% 32.43% 0.00% 100.00% 0.00% 0.282024 7.914626 0.825794 15.384082 2.623032 13.166011 4.438207 1.500801 0.557148 0.547301 0.355786 7.944742 7.458913
158 N12 RF_maintenance 0.00% 29.73% 32.43% 0.00% 100.00% 0.00% -0.066063 -1.208842 0.663648 1.639775 -0.431609 0.699205 0.573134 -0.425373 0.571628 0.566225 0.365938 7.296013 8.453294
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.173673 19.239825 69.196376 70.986088 52.460692 68.544536 24.493235 39.064618 0.043677 0.045921 0.002486 1.220588 1.230196
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.823945 36.699248 0.401777 5.040772 -0.239185 7.187733 -0.226650 -0.484371 0.684463 0.601043 0.382540 5.568613 8.070187
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.62% 1.063359 0.711009 1.608377 0.484302 2.851742 2.287255 0.225599 2.189283 0.682613 0.678902 0.399586 3.083628 3.362465
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 16.22% 0.791950 -0.193345 0.067704 -0.520910 -0.744342 -1.162917 -0.572001 -0.529999 0.692352 0.687347 0.399003 2.757141 2.925226
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.41% -1.090773 -0.409672 -0.480918 -0.749890 -0.728364 -0.747554 1.246951 0.162879 0.688277 0.680524 0.401728 2.417817 2.607707
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.222781 0.585558 8.317316 -0.518981 5.335156 0.219423 1.040564 2.562394 0.687481 0.679338 0.401855 8.159983 10.389198
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.955951 2.761350 3.865327 -0.199848 11.854367 11.030245 28.843399 61.680400 0.628121 0.651111 0.335252 3.835809 4.874316
167 N15 digital_ok 100.00% 29.73% 16.22% 0.00% 100.00% 0.00% 19.222882 19.105121 18.667644 23.526705 26.821344 23.788086 32.523748 19.394794 0.548732 0.562112 0.190239 3.341282 3.875032
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.307334 17.525620 24.708933 27.334730 22.989989 25.390357 -0.272888 -0.333504 0.625315 0.606758 0.393427 4.842947 4.943645
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.939723 16.166596 26.915048 25.879924 25.341608 23.695263 -0.073878 -0.345653 0.602139 0.589316 0.387575 4.185300 4.675898
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.112652 15.047634 27.136416 24.865591 25.703264 22.643467 0.313467 -0.258455 0.581977 0.579338 0.386294 6.998055 7.381963
176 N12 digital_ok 0.00% 32.43% 32.43% 0.00% 32.43% 0.00% -0.010204 0.146780 0.015084 1.701890 -0.060401 0.224767 -0.855029 -0.378692 0.540300 0.531048 0.348701 1.861488 1.908564
177 N12 digital_ok 0.00% 32.43% 32.43% 0.00% 32.43% 0.00% 1.065513 0.698787 2.219313 0.676403 0.284486 0.323476 0.019227 1.019690 0.550245 0.538767 0.354575 1.958899 1.942795
178 N12 digital_ok 0.00% 32.43% 32.43% 0.00% 32.43% 0.00% -0.642636 -1.016422 1.445372 -0.778194 -0.673466 -1.235891 -0.680569 -0.940447 0.559303 0.551251 0.359349 1.891570 1.861324
179 N12 digital_ok 0.00% 29.73% 32.43% 0.00% 32.43% 0.00% -0.277642 0.143632 -0.751524 -0.425789 0.585090 -0.801523 0.516777 -1.092325 0.566973 0.556600 0.369574 2.044291 2.074072
180 N13 RF_maintenance 100.00% 0.00% 51.35% 0.00% 100.00% 0.00% 1.209024 12.544332 2.398931 64.134750 0.856026 19.829943 -0.881852 2.358061 0.670307 0.460099 0.476509 71.818747 18.225223
181 N13 digital_ok 100.00% 100.00% 70.27% 0.00% 100.00% 0.00% 20.540002 45.299098 70.168191 7.271662 52.728834 32.756637 37.685361 8.629249 0.049391 0.306534 0.157343 1.243340 2.771666
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.465879 2.431338 24.450309 12.036095 22.632954 2.893888 -0.351357 39.009592 0.656413 0.660965 0.411967 5.988523 6.523635
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.377680 -0.312348 -0.702947 -0.786550 -0.857111 -0.481158 0.516635 2.249199 0.682495 0.670617 0.408108 2.381952 2.293340
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.211687 -0.866626 -0.672579 1.525740 0.095051 0.001983 1.439096 0.505980 0.681741 0.671356 0.393926 2.244870 2.344375
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.000357 0.675461 3.502588 1.598703 0.746523 -0.547854 -0.920131 -0.959504 0.683146 0.676497 0.393931 2.123164 2.062066
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 10.81% 0.885404 0.697158 3.772799 2.185088 0.982537 1.034557 3.258287 1.660945 0.672838 0.667936 0.388853 2.508739 2.557669
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.940556 0.931096 7.990609 2.209565 4.645797 -0.437164 1.945884 0.147362 0.670094 0.667344 0.392567 4.682731 4.981885
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 29.73% 2.70% 3.225928 3.738600 0.729936 -0.190133 -0.575190 -0.739716 -0.606793 -0.326295 0.629645 0.621670 0.394759 1.258805 1.346171
190 N15 digital_ok 100.00% 43.24% 100.00% 0.00% 100.00% 0.00% 42.908695 22.401262 8.144603 71.846020 17.331088 31.326950 54.011785 2.919500 0.485023 0.049744 0.283599 4.224676 1.909651
191 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 32.43% 0.00% -0.621521 0.408892 -0.755623 -0.655889 -1.025131 -1.245750 1.112299 3.344528 0.599052 0.583200 0.401959 1.151852 1.168978
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 390.118470 7247.144421 inf inf 3817.596043 -47847.358126 16966.727825 -202506.964554 nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.274607 4.728047 18.127462 0.982844 18.748416 5.538302 8.455603 11.404114 0.642520 0.627584 0.382864 9.808372 8.449360
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.747208 7.817612 3.438028 12.155158 7.327304 12.623424 12.297598 9.197395 0.614863 0.625586 0.374133 4.085332 4.445243
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.298959 10.973120 20.762723 17.824944 21.246199 17.699906 3.112719 2.428077 0.619822 0.620837 0.376527 5.681177 6.120765
220 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 281.478140 531.864372 inf inf 1567.403351 -4910.777405 3783.298776 -8795.165377 nan nan nan 0.000000 0.000000
221 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 282.215652 282.522322 inf inf -1167.830175 -1131.433625 -1769.088293 -2614.789225 nan nan nan 0.000000 0.000000
222 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.891421 11.401766 110.031552 113.124071 2209.376567 2563.194961 4136.421850 5634.697336 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.402181 11.822578 10.389915 19.471790 11.105470 18.620071 0.843922 0.071399 0.630715 0.617586 0.392467 3.359302 3.134430
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 19.661656 19.271138 30.263125 29.742695 30.764738 29.457492 1.397356 0.903346 0.584955 0.580594 0.374549 1.889881 1.903177
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 281.455470 329.182313 inf inf -2303.474362 -2803.775417 -4627.965592 -4763.706961 nan nan nan 0.000000 0.000000
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 281.521205 281.565184 inf inf 1093.317725 1091.057016 965.822076 944.012585 nan nan nan 0.000000 0.000000
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.474323 11.879043 inf inf 3081.024629 3092.934255 6725.959434 6740.204130 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.285896 22.644222 51.902472 52.358891 32.037232 31.192457 4.596437 3.161668 0.063990 0.053850 -0.002574 0.000000 0.000000
321 N02 not_connected 100.00% 21.62% 64.86% 0.00% 100.00% 0.00% 10.311292 8.245698 17.065067 15.416900 17.768095 15.263412 11.073659 10.740891 0.488309 0.419459 0.312059 0.000000 0.000000
323 N02 not_connected 100.00% 37.84% 67.57% 0.00% 100.00% 0.00% 19.203897 11.593035 3.729566 19.568333 12.888918 18.739773 4.225461 1.299589 0.408703 0.392155 0.262251 0.000000 0.000000
324 N04 not_connected 100.00% 27.03% 64.86% 0.00% 100.00% 0.00% 13.377484 14.148637 22.511929 22.825119 20.777227 20.643766 -0.308792 -0.894597 0.471134 0.403798 0.314378 0.000000 0.000000
329 N12 dish_maintenance 100.00% 64.86% 75.68% 0.00% 100.00% 0.00% 2.698249 7.260811 2.456238 15.328803 1.911308 12.918769 5.218456 -0.426275 0.380514 0.339114 0.244823 0.000000 0.000000
333 N12 dish_maintenance 100.00% 72.97% 97.30% 0.00% 100.00% 0.00% 3.513444 7.260423 11.094014 13.971093 11.013485 12.623115 12.729339 2.279180 0.334867 0.309774 0.210566 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, 10, 16, 17, 18, 19, 20, 27, 28, 30, 31, 32, 33, 36, 37, 38, 41, 42, 45, 50, 51, 52, 54, 55, 56, 57, 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, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [9, 15, 21, 29, 40, 46, 53, 65, 66, 140, 183, 184, 185]

golden_ants: [9, 15, 21, 29, 40, 46, 53, 65, 66, 140, 183, 184, 185]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/rtp_summary_table_2459791.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 [ ]: