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

Load Auto Metrics¶

In [6]:
use_auto_metrics = False

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

# if it exists, load and extract relevant information
if len(auto_metrics_file) > 0:
    auto_metrics_file = auto_metrics_file[0]
    print(f'Found auto_metrics results file at {auto_metrics_file}.')
    
    auto_metrics = load_metric_file(auto_metrics_file)
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
    auto_ex_ants = auto_metrics['ex_ants']['r2_ex_ants']
    
    use_auto_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping auto_metrics.')
Found auto_metrics results file at /mnt/sn1/2459817/zen.2459817.25308.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/2459817/zen.2459817.?????.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/2459817/zen.2459817.?????.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 2459817
Date 8-25-2022
LST Range 17.767 -- 19.767 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 N10, N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 59 / 147 (40.1%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 85 / 147 (57.8%)
Redcal Done? ✅
Redcal Flagged Antennas 21 / 147 (14.3%)
Never Flagged Antennas 26 / 147 (17.7%)
A Priori Good Antennas Flagged 71 / 95 total a priori good antennas:
3, 5, 9, 17, 19, 20, 21, 37, 40, 41, 42, 45,
53, 54, 55, 56, 67, 68, 69, 71, 72, 73, 81,
84, 85, 86, 88, 91, 93, 94, 99, 101, 103, 105,
106, 107, 108, 109, 111, 112, 118, 121, 122,
123, 127, 128, 129, 130, 140, 141, 142, 143,
144, 156, 157, 158, 160, 161, 165, 167, 169,
170, 176, 177, 178, 179, 181, 187, 189, 190,
191
A Priori Bad Antennas Not Flagged 2 / 52 total a priori bad antennas:
82, 90
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H6C_Notebooks/_rtp_summary_/array_health_table_2459817.csv

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 328.427068 328.728360 inf inf 611.179575 644.225075 1969.613362 2072.796953 nan nan nan 0.000000 0.000000
4 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 328.324943 328.653591 inf inf 592.213273 551.063215 1949.012332 1920.154517 nan nan nan 0.000000 0.000000
5 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 328.392736 328.692138 inf inf 803.802014 812.353939 1627.315003 1755.639378 nan nan nan 0.000000 0.000000
7 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.323986 -1.493712 0.204885 -0.168341 0.298157 0.258093 1.351403 2.696234 0.800012 0.642933 0.523843 1.880775 1.747764
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.947805 15.975284 16.533257 17.138024 26.025602 26.903732 1.731771 3.427653 0.784808 0.602243 0.527076 2.949205 4.260942
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 15.79% -0.600443 -1.111174 0.696886 -0.683488 1.120555 0.367090 2.235992 2.176545 0.791180 0.615554 0.529042 2.117812 1.742210
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.586074 -0.906545 -1.013075 0.159513 -0.331437 0.392736 1.713643 1.268407 0.782744 0.599617 0.537986 1.681469 1.597135
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.239734 1.664666 1.764300 0.973535 0.862128 -0.053677 3.099808 1.765496 0.805603 0.639840 0.529640 2.255464 2.078288
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.243510 -0.415679 -0.535232 -0.592636 -0.127735 -0.471174 1.644526 2.615462 0.810332 0.656160 0.525029 2.238718 1.981082
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.494699 1.720157 0.722515 0.565219 0.754031 0.709956 4.187629 3.274000 0.813633 0.661576 0.516739 4.155277 4.268834
18 N01 RF_maintenance 100.00% 0.00% 56.99% 0.00% 100.00% 0.00% 5.599593 6.049511 2.083318 -0.454057 4.552559 5.295478 24.432511 19.167584 0.790824 0.469558 0.573998 3.242825 1.772746
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.006650 11.026438 -0.556059 13.255841 0.997409 23.573381 3.815824 3.977954 0.809444 0.649832 0.515797 3.238131 3.259630
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% -1.095444 0.189631 0.191606 -0.845374 0.208579 1.472838 1.186681 1.057689 0.801733 0.631027 0.511397 2.318766 1.989925
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.071044 0.212166 0.803476 1.412872 1.692997 1.797395 1.296047 1.121470 0.791494 0.615999 0.531746 2.087833 1.846446
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.375975 25.348799 43.114986 43.715518 36.435558 36.303545 3.815364 3.530491 0.039474 0.044066 0.003176 1.186933 1.193735
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 14.595943 19.879488 3.742317 5.566344 32.278581 34.752726 4.082866 19.022659 0.505535 0.257728 0.331641 13.976447 3.224179
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.146542 -0.077879 0.119103 -0.321906 -0.574420 -0.806012 1.333512 1.419123 0.825299 0.682626 0.506344 2.143179 2.213275
30 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.394901 -0.041643 -0.543360 -0.671958 0.192475 0.811400 3.400272 1.020329 0.820798 0.678744 0.499367 2.084224 1.972904
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.257851 -0.593335 -0.814301 0.514849 0.123638 1.784633 1.632665 1.597120 0.819689 0.669901 0.511147 1.983361 1.945742
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 44.159946 14.713926 2.782155 0.586606 9.527108 18.106058 16.218602 51.048984 0.756468 0.622138 0.379707 9.448519 4.417932
33 N02 RF_maintenance 100.00% 0.00% 54.30% 0.00% 100.00% 0.00% 0.987737 5.397661 0.947301 -0.182506 3.847800 7.542041 8.944943 15.462332 0.797960 0.482713 0.613361 3.776736 2.124954
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.672745 6.422420 0.024441 -0.366244 0.759094 -0.356115 0.019205 -0.123598 0.793693 0.631403 0.516049 3.321809 2.913870
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.779741 1.408163 0.124903 0.431465 -0.976020 -0.311402 0.034283 2.254840 0.806910 0.651688 0.506703 3.389737 3.297890
38 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.823571 -0.372517 -0.343165 -0.963659 -0.452557 -0.892756 2.016052 0.553102 0.814699 0.673799 0.501672 1.849881 1.685865
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.339532 -0.512447 0.490941 -0.082007 0.670504 -0.509813 -0.522386 -0.603886 0.822326 0.693232 0.484114 2.316450 2.052808
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% 0.147726 -0.957295 2.096379 1.336521 2.395851 -1.005967 -0.722412 -0.690505 0.830576 0.700777 0.487982 2.392873 2.124161
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% -0.537521 0.439101 1.627145 0.936003 -0.000503 -1.426657 -0.639415 -0.672627 0.830282 0.696653 0.495990 2.097621 1.919494
45 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 7.89% -0.407493 0.311281 -0.473605 0.151546 -0.287086 -1.376161 -0.588995 0.002328 0.813569 0.657447 0.519888 1.678646 1.619811
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.118826 -0.606904 -0.177138 -0.859716 -1.074353 -1.763067 -0.602690 1.162018 0.807858 0.638068 0.539661 1.768016 1.589170
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.188446 6.995588 0.789097 0.931071 9.021176 4.398452 18.927473 2.681783 0.774180 0.603961 0.464846 3.842334 4.415303
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.753752 1.835069 -0.876639 -0.782278 1.111293 -0.241855 -0.341777 1.040572 0.810340 0.671515 0.491592 1.850650 1.692432
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.872654 6.261614 0.648206 -0.110738 2.843233 -0.673592 -0.074841 -0.048197 0.822774 0.688162 0.485047 3.967907 3.887831
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 26.32% 1.260000 1.319019 -0.760450 -0.216778 -1.324259 -0.733770 0.453470 0.636527 0.828435 0.710769 0.479288 2.657914 2.454871
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 50.00% 0.837481 -0.306333 1.319126 1.057010 -0.334606 -0.447355 -0.254084 -0.719210 0.832571 0.710875 0.477885 2.826214 2.688585
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 97.37% 3.455653 0.458394 -0.591764 0.790032 0.080776 -0.059307 -0.199556 -0.660758 0.838818 0.719027 0.485101 3.058178 2.665916
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 86.84% -0.448957 1.352876 0.603977 0.855047 0.156208 -0.042123 -0.641117 0.041430 0.836424 0.715704 0.483656 3.210206 2.598819
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 29.645983 -0.435206 14.125798 1.979171 11.625131 2.643756 1.143964 0.713251 0.712549 0.696805 0.352054 4.990711 2.373038
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.386875 0.186864 0.743964 0.921706 0.612392 0.870702 0.053573 0.292609 0.801878 0.641096 0.509216 1.870958 1.740115
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.067456 -0.348731 -0.878149 0.469787 0.071250 1.850125 -0.362911 0.516614 0.812754 0.678280 0.486170 1.884697 1.695681
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 23.68% -0.927212 0.121318 -0.462547 0.162597 1.722946 1.225436 -0.002328 0.010076 0.824876 0.702462 0.470250 2.018731 1.872465
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 44.74% 0.653606 0.583511 -0.080662 -0.100655 -0.185776 1.329653 -0.229239 -0.422309 0.830530 0.719384 0.458333 2.753654 3.421898
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.915168 -0.790020 -0.702017 -0.315436 -1.382036 0.324285 -0.515374 -0.639050 0.838221 0.726355 0.473110 2.920820 2.452647
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.184100 -1.193739 0.071562 -0.898306 -0.745667 -1.489977 -0.635205 -0.530998 0.835706 0.723220 0.472615 15.294653 17.380409
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.988486 -0.984864 -0.716940 -0.605681 -1.104759 -1.144457 -0.630770 -0.709467 0.836126 0.728239 0.462825 16.961869 12.085221
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 55.26% 2.216198 -1.436970 -0.461257 0.952967 0.364642 0.523069 -0.094568 -0.836959 0.830074 0.709675 0.480466 2.453931 2.115073
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 24.275565 0.013344 42.317071 1.017455 36.206731 0.859834 1.014506 -0.669551 0.037625 0.691866 0.367590 1.195348 2.724568
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.716260 2.542550 -0.261488 3.172678 -0.344675 4.508395 1.493084 -0.242725 0.794164 0.634462 0.496026 3.943641 3.527449
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.375736 -0.553245 0.630317 0.577636 -0.043673 -0.654439 -0.646183 -0.754399 0.811776 0.665859 0.497056 3.624816 3.283452
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.079706 3.282957 1.526681 3.878312 0.666932 3.617099 -0.749656 -0.848056 0.820691 0.697017 0.472531 1.757359 1.672309
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.128897 9.503435 0.600020 1.143740 -0.430413 0.403788 0.841596 0.390744 0.829437 0.711954 0.454821 3.283303 3.389571
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 63.16% 0.401127 -0.053730 -0.855365 -0.478684 -1.630819 -1.727128 -0.638469 -0.732442 0.834618 0.721948 0.475057 2.306226 2.215491
86 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 97.37% 1.886000 2.904959 -0.769320 -0.692531 -0.580559 1.144170 -0.598966 -0.641709 0.830223 0.701990 0.471090 2.968888 2.443535
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.493421 10.774955 1.310152 1.289313 23.258822 1.529736 10.932456 -0.644539 0.802599 0.724465 0.444074 2.657278 2.520703
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 20.133730 17.203683 19.907479 17.777844 31.768225 27.303019 0.881245 1.721637 0.792437 0.696490 0.478656 2.535752 2.442463
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.274413 -0.039097 -0.334499 3.427456 -1.581812 0.750315 -0.559302 -0.229226 0.822035 0.675952 0.509011 3.153604 2.653026
91 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.407022 18.841954 18.067701 18.777992 28.635006 29.653902 2.362823 4.328643 0.787231 0.633285 0.528969 2.799062 2.415581
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 40.118131 56.962374 6.407950 7.652261 33.802276 39.627817 1.800083 3.669467 0.101043 0.095298 0.012215 0.000000 0.000000
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.224763 -1.006600 3.747928 0.449876 4.986603 -0.282746 0.969203 0.413777 0.075894 0.082748 0.012162 43.781689 56.241643
94 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.064489 -0.373467 -0.078779 -0.703689 -0.762008 1.172883 1.209582 4.368111 0.087837 0.091410 0.013774 15.035802 14.940087
98 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.087357 1.232046 0.254780 2.729951 -0.348081 -0.414831 -0.354952 -0.387182 0.793986 0.618140 0.520748 2.083211 2.160426
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.940897 0.218867 2.492118 -0.605995 2.789646 -1.533639 0.055159 -0.680856 0.804131 0.652810 0.496076 3.790424 4.797243
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.459834 -0.077765 0.284111 0.151361 -0.032805 -1.350849 -0.653712 -0.637128 0.817414 0.678064 0.500355 1.856668 1.730446
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.791149 9.393770 2.452970 -0.121604 0.797155 -1.171719 0.181221 0.010820 0.828609 0.698510 0.484821 3.085071 2.848510
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.287082 5.017442 25.227691 25.189371 50.797792 70.716718 55.857063 69.181909 0.751887 0.633890 0.473256 2.151148 2.140580
103 N08 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
104 N08 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
105 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.152887 10.319992 8.732907 12.074578 11.235595 17.292003 -0.642643 0.184674 0.830885 0.706029 0.489022 3.008974 2.629484
106 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.708459 17.860626 6.329170 17.977776 3.534730 28.047848 6.535589 9.437961 0.815699 0.679952 0.496748 2.919873 2.527181
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.604800 14.279109 17.331274 15.814609 26.821862 24.013919 -0.212106 1.240057 0.808194 0.677137 0.498150 3.008493 2.670743
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.530764 4.152764 5.414691 0.958195 1.573813 -0.766446 -0.146486 -0.537790 0.808652 0.672011 0.507762 3.119185 2.771632
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.763024 0.959486 -0.103191 0.355583 -0.678477 0.361199 0.490988 0.439564 0.076687 0.078086 0.013720 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 50.601610 1.826801 3.499641 1.586679 5.271235 0.350115 0.400742 -0.286564 0.085115 0.069572 0.008147 15.835970 40.536019
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.481634 1.070651 0.201838 0.783651 0.132046 0.946651 0.773141 3.142306 0.059333 0.066970 0.006003 14.422590 15.683361
112 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.535610 -0.476118 -0.529023 0.677024 0.340369 -0.194575 -0.224198 -0.473269 0.068411 0.080364 0.011437 10.354055 9.002342
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.177784 1.987589 0.533275 -0.808149 -1.019439 -1.299770 -0.345911 -0.740248 0.789335 0.615528 0.530263 2.013279 1.719685
117 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.882444 1.894961 3.925535 3.706619 3.616925 2.838962 -0.787475 -0.791969 0.799646 0.635222 0.526339 1.911886 1.684048
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 2.771247 28.679154 1.557459 38.392574 0.085004 36.772078 0.116977 0.704878 0.811180 0.053152 0.522711 4.057866 1.321839
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.281520 2.288741 7.988689 -0.001836 9.827544 -0.365295 -0.782730 -0.712996 0.820460 0.667748 0.517787 2.734313 2.709437
120 N08 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
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.278970 5.540111 -0.662233 0.457390 -0.578477 -0.390997 5.085498 4.306261 0.824267 0.698822 0.486890 2.926675 2.743087
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.299765 7.979678 0.695269 0.974410 -0.674557 -0.239194 -0.557095 -0.638414 0.825811 0.699395 0.485601 3.255052 3.005672
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.837641 8.809119 -0.281626 -0.029535 -0.892971 -0.696596 0.996704 1.044392 0.827691 0.703889 0.485213 3.847402 3.200168
125 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.265312 18.377608 9.723090 13.126481 12.624747 19.376093 -0.785899 1.086357 0.818170 0.679044 0.476505 4.531168 3.595055
126 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 23.525209 7.608858 4.251461 5.593522 13.794863 6.681892 2.159442 1.396149 0.717511 0.674554 0.395778 3.354038 3.046041
127 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.083592 -0.033517 -0.052037 -0.498924 0.512820 -0.282016 -0.075266 -0.068941 0.090500 0.080588 0.018583 0.000000 0.000000
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.141344 1.739004 -0.005525 1.334682 0.715618 1.556954 0.213970 -0.002778 0.075799 0.077042 0.011673 21.716889 17.107527
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.253203 -1.491753 -0.748488 -1.008833 0.173650 -0.093079 0.239405 0.199260 0.062693 0.069021 0.007105 15.995723 13.358412
130 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.493019 0.404784 0.903697 1.388912 0.506193 0.402319 0.715196 1.854908 0.085361 0.079239 0.014629 11.584481 6.845793
135 N12 digital_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.695376 -0.020239 -0.895388 -0.940352 -1.373590 -1.465802 -0.162888 -0.512453 0.102146 0.099111 0.026526 1.235580 1.229867
136 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.076935 14.303650 -0.554209 0.624096 1.256704 1.373437 -0.164990 0.641000 0.097054 0.092131 0.020987 1.208640 1.205466
137 N07 RF_maintenance 100.00% 67.74% 100.00% 0.00% 100.00% 0.00% 20.917403 56.059754 19.171206 36.262767 34.841354 37.495307 0.198837 1.840740 0.404510 0.067392 0.217350 3.749730 1.335641
138 N07 RF_maintenance 100.00% 100.00% 65.05% 0.00% 100.00% 0.00% 25.959663 28.864485 34.763635 1.720314 36.683787 35.317914 1.543214 0.945494 0.048891 0.416323 0.227355 1.281499 2.737314
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.460698 23.349760 42.176722 43.806467 36.311214 36.520179 0.876888 0.897147 0.041220 0.043570 0.001157 1.194319 1.201747
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.179981 4.788648 -0.021495 8.967838 0.217072 2.303794 -0.485875 3.407464 0.815568 0.668617 0.500034 4.575848 3.724449
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 23.945766 28.993814 5.038012 44.001442 33.161985 36.638513 1.147861 1.315495 0.512153 0.045105 0.295687 9.218119 1.285980
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.05% 0.020239 -1.595185 1.032667 1.106298 0.905571 0.283526 0.968178 0.723467 0.817949 0.693590 0.481325 2.025096 1.608779
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 23.68% -0.574121 -0.526816 0.582195 -0.848006 0.200998 0.327305 1.057073 0.744279 0.817218 0.686849 0.487930 1.870280 1.473163
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.398527 24.272150 43.373229 44.360800 36.556973 36.764641 4.280948 4.647267 0.036430 0.039162 -0.000176 1.551477 1.630526
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.228647 26.181205 43.230248 45.179580 36.656043 36.788838 3.798668 4.094257 0.049620 0.052299 0.001676 0.936003 0.952401
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.577894 25.167669 42.273794 43.428833 36.313217 36.370781 1.976659 1.960543 0.036547 0.037818 0.000430 1.175253 1.172151
156 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.060192 1.127719 0.837683 -0.287580 -0.539741 -0.976367 0.555104 1.473618 0.063411 0.063309 0.005921 1.224696 1.223105
157 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.219821 -0.207873 -0.084478 2.764264 0.173251 0.970001 -0.556844 -0.723429 0.066051 0.069233 0.005312 1.236433 1.232171
158 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.568605 -1.270455 -0.631800 -0.385514 -1.061469 -0.571774 -0.067426 -0.205373 0.083115 0.070797 0.007172 1.226659 1.232332
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.181960 22.621504 42.874902 43.854061 36.398132 36.567543 1.445781 1.751300 0.044093 0.045032 0.001947 1.205479 1.203246
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.402479 48.302335 -0.630452 3.282215 -0.988595 7.767924 -0.541760 -0.403361 0.802432 0.583054 0.445021 3.764483 5.451903
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.647498 0.408661 -0.529239 -0.924016 0.269590 -0.497974 -0.575374 -0.698034 0.807541 0.661865 0.494803 2.167214 2.098913
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.378260 -0.550673 0.005525 -0.876032 0.000503 -0.766229 0.711787 0.716658 0.808871 0.674872 0.489227 2.192128 2.086517
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.495705 -0.965821 -0.995395 -0.893566 -0.771967 -0.752331 0.894536 0.787647 0.809724 0.671576 0.498741 2.239973 2.239462
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.447786 1.199699 5.057204 -0.865945 4.891086 -1.204133 1.845190 1.056955 0.806956 0.669328 0.497838 4.230365 5.333057
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 29.085880 15.201747 2.741573 0.583467 7.653620 6.373929 7.924228 6.080920 0.706151 0.604732 0.350756 1.024996 1.040990
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 28.916903 20.258925 12.453685 16.419230 28.178151 28.934090 7.583537 4.854705 0.662817 0.536321 0.287021 1.003000 1.029788
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.138848 19.022522 16.902310 19.075533 26.446828 30.253538 2.083878 4.202386 0.764138 0.589969 0.514573 0.968686 0.957411
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.406271 17.677240 18.538616 17.929828 29.386027 28.513965 2.935570 4.483621 0.752086 0.568542 0.521664 0.964177 0.965191
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.365832 15.987677 18.770810 17.278572 29.753740 26.882556 2.418414 3.719126 0.744274 0.563544 0.528051 0.381286 0.390337
176 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.224189 -0.852810 -0.636670 0.537542 -0.782006 -0.828412 -0.603303 -0.698305 0.055491 0.066193 0.007605 1.237482 1.231811
177 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.876737 2.647507 0.219375 -0.121617 -1.160313 3.825906 -0.478677 0.840152 0.077587 0.068472 0.005784 1.229114 1.225704
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.300130 -1.722577 1.086833 -0.589457 0.062284 -0.764394 -0.481743 -0.686618 0.071787 0.065979 0.006217 1.216511 1.213673
179 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.793452 0.337476 -0.930570 -0.205615 0.433579 -0.792208 0.299115 -0.806917 0.072188 0.084719 0.014958 1.207773 1.211174
180 N13 RF_maintenance 100.00% 0.00% 65.05% 0.00% 100.00% 0.00% 0.905097 17.259401 0.221579 40.353831 -0.215585 25.669197 -0.668710 0.823651 0.795072 0.394775 0.591597 22.877875 4.962992
181 N13 digital_ok 100.00% 100.00% 78.49% 0.00% 100.00% 0.00% 24.307713 58.182172 43.498284 4.293653 36.460189 37.052517 1.361227 1.571022 0.048359 0.328645 0.172269 1.197106 2.381634
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.682966 3.189414 16.826495 22.675547 25.854713 81.386069 -0.379603 12.062639 0.784669 0.607957 0.516129 3.404875 2.659579
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.814479 -0.904268 0.123860 -0.981662 -1.073514 -2.005627 -0.513607 0.074119 0.802952 0.653007 0.506704 2.090144 1.832576
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.734611 0.185338 -0.269373 0.471249 -0.041378 0.417927 1.713534 1.167116 0.803989 0.661395 0.501563 2.352821 1.910558
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.958231 0.076846 0.329357 0.996510 3.019987 1.192519 0.920917 0.676354 0.803393 0.655589 0.509086 1.958369 1.742989
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.532620 0.042074 3.079036 1.968757 0.717251 0.165810 1.895444 0.763094 0.792733 0.643194 0.504006 1.907079 1.796901
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 78.95% 0.480557 0.853510 0.064601 0.666919 0.433169 -0.730204 1.394497 0.836512 0.790982 0.645838 0.501238 0.000000 0.000000
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.376551 4.717122 0.567484 -0.576622 1.127734 0.118834 2.390490 2.365694 0.773238 0.603693 0.521986 0.818248 0.823667
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 42.581791 26.804295 2.892031 44.383923 18.261230 36.861417 26.248594 4.612267 0.678106 0.047029 0.461802 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.130612 3.131457 -0.526616 5.087957 -0.275328 3.500669 2.767212 3.912506 0.760719 0.563036 0.544428 0.918512 0.906007
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 23.571976 22.252189 10.844189 0.701990 17.963799 5.042268 5.275001 7.531688 0.773462 0.583660 0.528414 5.391814 3.787207
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 19.625061 21.383960 1.166149 7.621510 5.358976 12.126937 5.527599 5.643704 0.759208 0.594532 0.525689 3.229410 3.044990
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 43.214652 43.627320 inf inf 2835.137997 2779.314737 2991.722665 2885.010148 nan nan nan 0.000000 0.000000
220 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
221 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
222 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 55.656788 55.864822 inf inf 2854.261963 2780.374952 3019.664961 2857.990475 nan nan nan 0.000000 0.000000
223 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
224 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
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% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.410356 27.820333 31.403790 31.520450 36.489218 36.432826 3.396072 2.544752 0.059935 0.056441 0.000439 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 51.08% 0.00% 100.00% 0.00% 9.676300 7.489971 11.189527 10.221069 18.197908 15.506102 6.107616 5.961099 0.664607 0.406869 0.494321 0.000000 0.000000
323 N02 not_connected 100.00% 0.00% 61.83% 0.00% 100.00% 0.00% 21.630222 11.511052 1.381463 13.730013 11.630617 19.103000 2.577708 -0.412585 0.551065 0.372241 0.404636 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 51.08% 0.00% 100.00% 0.00% 13.433814 8.712655 14.185663 9.357913 21.697786 13.708389 0.333035 0.028790 0.666226 0.403970 0.498351 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.711649 7.101712 0.308489 9.677383 9.254500 13.708284 0.604956 -0.796410 0.096376 0.077531 0.039246 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.505800 6.849512 0.459609 9.108583 2.389073 11.692417 0.303364 -0.190292 0.098582 0.077233 0.038992 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, 8, 9, 17, 18, 19, 20, 21, 27, 28, 32, 33, 36, 37, 40, 41, 42, 45, 50, 52, 53, 54, 55, 56, 57, 67, 68, 69, 70, 71, 72, 73, 81, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [7, 10, 15, 16, 29, 30, 31, 38, 46, 51, 65, 66, 83, 98, 100, 116, 117, 162, 163, 164, 183, 184, 185, 186]

golden_ants: [7, 10, 15, 16, 29, 30, 31, 38, 46, 51, 65, 66, 83, 98, 100, 116, 117, 162, 163, 164, 183, 184, 185, 186]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H6C_Notebooks/_rtp_summary_/rtp_summary_table_2459817.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 [ ]: