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 = "2459825"
data_path = "/mnt/sn1/2459825"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H6C_Notebooks/_rtp_summary_"
good_statuses = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
In [4]:
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 9-2-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/2459825/zen.2459825.25309.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/2459825/zen.2459825.?????.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/2459825/zen.2459825.?????.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 2459825
Date 9-2-2022
LST Range 18.293 -- 20.293 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 N02, N04, N10, N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 75 / 147 (51.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 106 / 147 (72.1%)
Redcal Done? ✅
Redcal Flagged Antennas 2 / 147 (1.4%)
Never Flagged Antennas 17 / 147 (11.6%)
A Priori Good Antennas Flagged 79 / 95 total a priori good antennas:
3, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29, 30,
31, 40, 41, 42, 51, 53, 54, 55, 56, 68, 69,
71, 72, 73, 84, 85, 86, 88, 91, 93, 94, 99,
101, 103, 105, 106, 107, 108, 109, 111, 112,
117, 118, 121, 122, 123, 127, 128, 129, 130,
140, 141, 142, 143, 156, 157, 158, 160, 161,
164, 165, 167, 169, 170, 176, 177, 178, 179,
181, 183, 184, 185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 1 / 52 total a priori bad antennas:
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_2459825.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% 0.00% 0.00% 0.00% 100.00% 0.00% 3.165550 -0.399574 -0.712789 -0.531448 10.408255 10.604000 4.750487 4.295631 0.774542 0.534364 0.546019 3.602064 2.775525
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.537519 4.576078 -0.997712 1.332598 7.659640 7.235824 7.982915 5.507466 0.791575 0.532683 0.549458 2.573925 1.996785
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.025030 0.005263 -0.969927 2.965484 2.243359 2.964561 1.211685 0.156868 0.794761 0.542015 0.554105 0.000000 0.000000
7 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.597462 -0.579572 -0.186226 -0.613913 10.623472 9.786142 2.386569 4.956627 0.069405 0.066390 0.012378 1.112535 1.116409
8 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.288980 13.002395 16.726595 17.180629 18.961501 18.186813 0.274800 -0.083205 0.103011 0.081305 0.011397 1.093987 1.093012
9 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.730668 -0.916219 0.049182 -0.642280 8.950117 9.012455 4.256283 4.057936 0.070085 0.052864 0.004770 1.182584 1.185370
10 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.834176 -0.179971 -1.041468 -0.295205 10.566951 10.882540 4.573496 4.188314 0.087617 0.069912 0.011351 1.260784 1.255267
15 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.355368 0.747757 1.197907 0.850090 7.976820 7.741666 3.877347 4.240024 0.795644 0.544522 0.545696 3.381213 2.692796
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.309448 -1.280002 -0.020491 -0.994773 8.805618 8.725483 3.698330 2.462638 0.795636 0.546759 0.538463 3.355055 2.308965
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.537142 0.097516 0.897305 0.909969 8.858249 8.995574 3.435765 3.137630 0.798754 0.544986 0.555079 3.168830 2.232962
18 N01 RF_maintenance 100.00% 0.00% 89.25% 0.00% 100.00% 0.00% 6.446717 9.382789 2.426497 1.280581 9.020827 11.221952 6.410913 11.302561 0.773502 0.333521 0.599219 2.767324 1.386111
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.183666 0.577449 -0.508202 1.992259 13.490788 14.940822 3.037780 3.734750 0.064747 0.060095 0.008025 1.189122 1.184848
20 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.055684 1.051499 -0.086627 -0.580985 9.090471 9.574422 4.363496 3.769318 0.061929 0.049421 0.004000 1.308802 1.301912
21 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.706727 1.782059 0.917756 0.683484 11.012843 10.407454 1.620074 1.256637 0.073775 0.066370 0.010300 1.381503 1.378686
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.657832 29.300466 31.717204 32.356343 27.707591 25.630320 1.634395 1.276432 0.038994 0.043607 0.002835 1.214378 1.192395
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 17.469207 28.978466 0.850888 1.010398 27.325142 30.236112 6.879443 11.794779 0.434740 0.195328 0.286248 2.995773 1.647728
29 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.098846 -0.044698 -0.177894 -0.259509 7.040850 7.142514 2.876601 3.396272 0.802828 0.551750 0.545700 7.504901 4.394251
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.887219 0.077471 -0.616337 -0.733705 0.698155 -0.347839 7.837576 0.137726 0.794105 0.550703 0.546294 4.234505 3.813181
31 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.072068 -1.133362 -0.848241 -1.037123 3.415050 3.982439 1.075951 0.745826 0.074472 0.085732 0.020676 1.215126 1.216567
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 36.657307 36.042927 1.582191 1.321208 11.366703 10.404887 30.721768 17.472658 0.096131 0.090579 0.011238 1.303284 1.297986
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.668704 9.090731 -0.400867 -0.552544 -0.750979 2.506798 0.571559 4.549659 0.062007 0.093972 0.035584 1.444847 1.434198
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.789630 8.710529 0.026858 -0.419685 1.482777 0.899228 -0.015141 1.116562 0.793842 0.558373 0.526626 5.293341 4.865313
37 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.223731 1.185799 -0.932771 -0.802441 -0.788481 -0.778823 -0.663294 1.732179 0.803991 0.569127 0.528041 1.942191 1.460380
38 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.502762 -0.464763 -0.792256 -0.997484 -0.409965 -0.130643 1.266487 -0.418722 0.804624 0.579772 0.530596 1.936104 1.557436
40 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.005263 -0.586202 -0.379538 -0.408539 0.773538 -0.665390 -0.806414 -0.629526 0.081911 0.101656 0.020410 1.182496 1.170289
41 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.589450 -1.235672 1.400609 1.255441 1.683102 -1.247197 -0.752640 0.258513 0.064037 0.087637 0.015359 1.165937 1.168952
42 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.701466 0.398313 0.912295 0.969199 -0.894522 -0.744771 -0.880764 -0.875731 0.098906 0.096768 0.022669 1.170320 1.163606
45 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.022322 0.502805 -0.925892 0.660595 -0.668290 0.038687 -0.643667 0.252718 0.788803 0.527798 0.561395 1.350331 1.083817
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.217380 -0.917545 0.353717 -0.531880 -1.166669 -0.889093 -0.333100 -0.242950 0.789135 0.514242 0.576702 1.335047 1.037340
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 43.322606 1.224503 2.719769 1.673966 4.970805 0.424602 6.021182 1.331549 0.685326 0.571994 0.373370 11.182939 5.589629
51 N03 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
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.315766 8.064467 0.300468 0.114912 0.834837 -0.942607 -0.369216 -0.612798 0.812343 0.599351 0.508122 6.248912 5.394365
53 N03 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
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.595436 6.352998 1.364107 0.424943 -0.965889 7.217102 -0.584822 15.917780 0.078362 0.094471 0.018180 1.194300 1.189275
55 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.527169 0.668160 -0.020743 0.323262 0.511069 -0.930102 0.894708 -0.888181 0.068681 0.067712 0.007516 1.210880 1.213590
56 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.706020 -0.067255 0.836106 1.028154 0.118397 -0.603525 -0.813798 2.628499 0.061490 0.060696 0.007057 1.237270 1.233694
57 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 36.653906 -0.328046 10.520466 1.665801 12.317937 1.229100 1.012685 0.285645 0.125832 0.089798 0.024253 1.255158 1.235506
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.641329 0.517295 0.050980 0.899554 -1.104587 -0.798372 -0.587694 -0.645477 0.806013 0.579769 0.521583 2.435664 2.048121
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.103509 0.669220 -0.206301 0.636361 0.100534 1.863076 -0.802195 -0.318218 0.809460 0.610315 0.495752 2.111676 1.613448
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.865997 -1.218939 0.087122 -0.928125 1.347048 1.313544 -0.532272 0.148997 0.813347 0.627294 0.483870 2.388463 2.065396
68 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.601895 0.706287 -0.020976 3.269602 0.952072 4.956718 -0.486074 1.119662 0.811040 0.625820 0.486856 7.220216 7.799067
69 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.031371 -1.141612 -0.210937 0.228502 -0.906489 1.203532 -0.844661 -0.933466 0.097888 0.110481 0.028378 1.177871 1.173389
70 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.140665 -1.248403 1.045872 -0.992336 -0.908615 0.857089 -0.819655 -0.607561 0.083866 0.073528 0.011330 1.101997 1.106826
71 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.886577 -0.464551 -0.497715 -0.683818 -0.017221 -0.843593 -0.771774 -0.776426 0.083081 0.082917 0.015295 1.237017 1.225016
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.807696 -0.694903 -0.751555 1.066199 1.311611 -0.923016 4.163518 -0.246065 0.106089 0.089604 0.019473 1.207357 1.193451
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 26.482550 -0.406859 31.070433 1.734249 27.549250 0.535219 0.008725 -0.439043 0.034649 0.577489 0.237440 1.322048 4.408842
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.757514 1.160466 -0.383347 2.604829 0.142518 1.645967 1.225814 -0.268839 0.795550 0.575186 0.505208 2.582659 2.354438
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.691188 0.340779 0.705323 0.930712 -0.919066 -0.191208 0.552881 0.625717 0.812257 0.599409 0.511349 7.715748 8.724469
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.082894 1.495909 1.249545 3.372131 -0.302894 0.349071 -0.889003 -0.803950 0.813265 0.633071 0.481557 2.224819 2.144962
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.647380 12.030065 0.654191 0.638365 -0.359646 0.018064 -0.508247 -0.866460 0.819919 0.641334 0.469640 6.989423 9.069015
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.480456 1.117607 0.920506 1.669366 -0.544759 -1.099840 -0.904694 -0.931780 0.806074 0.631019 0.489156 1.910484 2.017325
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.776250 4.554638 0.799228 -0.689850 -0.468241 1.137185 -0.493883 -0.554995 0.806387 0.605888 0.493901 6.118669 4.946562
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.024835 13.385525 5.481250 1.263223 2.705031 0.376452 -0.481396 -0.586042 0.817522 0.632397 0.512613 4.056265 3.725794
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.408680 14.088673 20.227996 17.966737 24.303664 18.423208 -0.305762 -0.814357 0.768139 0.599554 0.510843 2.627953 2.276031
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.478067 -0.093699 -0.345599 2.788216 -1.000572 -0.967325 -0.804114 -0.275915 0.803656 0.574492 0.541684 4.153563 2.735436
91 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.623099 15.664371 18.323145 18.839622 21.019364 20.451981 -0.692590 -0.560433 0.776209 0.537049 0.549527 3.701621 2.639935
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 50.543177 70.140226 3.551733 4.828186 25.529881 31.429766 0.617092 4.861592 0.092056 0.088513 0.012130 0.000000 0.000000
93 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.708252 0.400738 2.616065 -0.304592 1.754650 -0.535474 -0.468658 -0.685688 0.076243 0.095236 0.014303 0.000000 0.000000
94 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.735770 -1.421956 -0.682362 -0.666619 0.464054 3.059760 2.228934 2.411647 0.077155 0.102535 0.017480 0.000000 0.000000
98 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.543848 1.543209 0.597432 2.390141 -0.036245 -0.503407 0.364626 -0.472318 0.795189 0.554073 0.525808 2.630643 2.292053
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.689812 0.445502 2.079656 0.073671 -0.164556 -0.769837 -0.093945 2.168476 0.806210 0.591670 0.510265 7.382153 8.666474
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.210940 -0.517586 -0.392053 0.366526 0.328510 -1.398253 -0.811238 -0.813439 0.814500 0.615707 0.504911 2.710705 2.466090
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.087770 11.743551 2.420496 -0.182492 -0.158285 -0.671370 1.215688 3.105981 0.822592 0.636952 0.487665 6.318032 6.521364
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 28.677047 29.220513 1.071220 1.407791 390.720172 398.702360 1701.959943 1698.416763 0.755362 0.496148 0.508820 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.646202 11.113867 -0.389015 -0.346242 -0.764592 -0.404947 -0.343427 -0.397430 0.816057 0.645696 0.483240 4.632169 3.952681
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.393947 88.400218 0.131060 11.702137 0.974821 1.104447 -0.070419 -0.778906 0.820477 0.636010 0.510926 3.692879 3.263198
105 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.157734 5.451554 6.504488 10.595100 3.489925 7.837112 -0.872152 -0.968961 0.820517 0.638102 0.508957 9.748073 4.597437
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.004478 8.048586 17.401716 15.656468 18.787011 15.500629 0.176298 -0.179947 0.799787 0.585382 0.513732 3.614517 2.466599
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.695595 4.871689 8.904718 0.398057 -0.328329 -1.019328 -0.740700 -0.598051 0.779362 0.576592 0.526357 3.025354 2.309915
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.878918 0.340045 -0.045965 0.794073 -0.311930 -0.356912 0.258265 -0.028627 0.085106 0.078015 0.015932 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 45.640748 29.894714 2.160065 1.427775 2.814173 7.057978 1.733138 5.060396 0.095440 0.084322 0.008169 0.000000 0.000000
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.048412 0.878625 -0.379119 0.392224 -0.203552 1.721034 2.747174 0.028627 0.062950 0.063021 0.007091 0.000000 0.000000
112 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.643636 -0.052282 -0.440330 -0.201119 0.635984 0.079025 0.848594 0.270922 0.064669 0.079216 0.012457 0.000000 0.000000
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.132935 1.865600 0.409709 -0.433084 -0.067979 -0.331149 0.851703 0.389513 0.790331 0.546848 0.540562 2.513411 2.023365
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.750120 1.105408 3.895990 4.078068 2.311273 1.259878 -0.868477 -1.012591 0.803141 0.574982 0.529785 7.383890 6.524702
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 1.753405 31.518340 1.634076 28.282420 -1.098361 25.789033 -0.722465 -0.310416 0.814118 0.049284 0.401485 4.835412 1.268158
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.097391 0.499183 7.401609 -0.326577 4.914929 -0.462258 -0.974022 -0.764423 0.824629 0.607698 0.515363 5.013047 3.802378
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 21.519388 41.618898 1.743283 36.488355 20.453051 25.679477 -0.033556 1.242646 0.493233 0.042561 0.274675 4.488080 1.257699
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.239422 7.065117 -0.781376 0.651598 -0.457031 0.431374 6.345403 5.470125 0.824236 0.647077 0.479799 4.540749 3.382695
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.707980 8.862374 0.826567 0.319633 -0.753569 -0.700291 -0.588731 -0.703900 0.827929 0.645863 0.489981 3.713285 3.079478
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.824965 11.838401 0.005205 0.095810 -0.609564 -1.256269 -0.309244 -0.519079 0.823233 0.647068 0.492430 3.003735 2.102801
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
127 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.186248 -0.024230 0.359303 -0.042400 1.928780 2.807952 1.239013 1.554438 0.098624 0.082769 0.022467 0.000000 0.000000
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.520362 2.373424 -0.294978 0.258992 0.288565 0.879871 0.095312 0.154132 0.088003 0.067689 0.014776 0.000000 0.000000
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.371200 -1.034126 -0.737542 -0.801895 1.622157 1.802918 0.696069 0.537947 0.052630 0.059343 0.005900 0.000000 0.000000
130 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.091747 -0.226608 0.381632 1.422385 1.579469 0.293156 -0.520425 0.242622 0.079941 0.080580 0.014894 0.000000 0.000000
135 N12 digital_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.109242 0.210012 -1.023716 -0.702254 -0.645211 -0.524133 0.729328 0.109290 0.077536 0.090346 0.019617 1.200425 1.187491
136 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.674562 14.124581 -0.826665 0.033247 2.434065 1.786312 -0.141965 0.909284 0.076754 0.088837 0.017548 1.203462 1.204815
137 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.079293 11.514746 19.152879 15.864766 22.749394 14.074417 -0.912488 -1.068595 0.780365 0.550581 0.529408 3.856257 3.343532
138 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.206078 0.389185 17.711132 -0.905882 20.141949 -1.245892 -0.927277 -0.264778 0.791338 0.582746 0.516809 4.211425 3.561608
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.362550 27.174695 30.946421 32.496176 27.580425 25.625017 -0.073296 -0.099785 0.038401 0.040500 0.001520 0.827616 0.832724
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.569833 3.863638 -0.689497 7.690181 0.775866 1.795674 3.331989 6.146356 0.819303 0.605610 0.507090 -0.000000 -0.000000
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 29.851257 32.683078 1.885854 32.714852 25.903865 25.608677 0.199815 0.249606 0.506237 0.040600 0.224867 -0.000000 -0.000000
143 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.586639 -0.826270 1.426261 -0.191591 6.175496 5.407548 5.081687 5.060673 0.812469 0.634838 0.488907 0.000000 0.000000
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.259886 -1.022981 1.565350 -0.238973 0.197887 -0.077626 0.378124 0.555174 0.816067 0.624668 0.507171 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.909271 28.688939 32.099714 33.120493 30.887450 29.005885 5.932486 6.099743 0.034610 0.036034 -0.000184 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.003751 30.620970 31.896010 33.713304 27.730667 25.605155 1.328546 1.423087 0.044870 0.045564 0.001047 0.000000 0.000000
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.114823 25.658233 31.039055 32.273727 27.658898 25.814621 0.575619 0.636319 0.038138 0.040990 0.000417 1.296360 1.289411
156 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.423114 23.031817 0.603902 3.056723 0.094292 16.056795 0.150680 20.459276 0.048691 0.074278 0.005197 0.965397 0.959155
157 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.353620 -1.236827 -0.399449 2.117800 0.178263 -0.092951 -0.367711 -0.596954 0.064626 0.055857 0.005718 26.751854 38.578375
158 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.181370 -1.354802 31.795661 -1.032208 27.653164 -0.783046 -0.022249 -0.119075 0.036204 0.060725 0.052388 0.858003 0.891002
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.347503 26.599889 31.553474 32.572746 27.721921 25.689793 0.434135 0.611726 0.040086 0.041172 0.002058 1.287974 1.247732
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.402250 49.596129 -0.623880 2.486033 -0.540379 2.228813 0.165087 -0.335924 0.804479 0.504089 0.480247 5.833701 7.225373
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.679762 0.096300 -0.950607 -0.724383 1.338571 0.240417 -0.357816 0.069699 0.810919 0.608562 0.513472 1.577125 1.252830
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.343298 -0.307203 0.020743 -0.395088 -0.680691 -0.564057 0.289178 1.276085 0.807988 0.620198 0.498930 1.565560 1.155008
164 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.058802 -0.981195 -0.861187 -0.340072 6.735090 6.745734 5.618963 4.653924 0.809042 0.615159 0.508707 5.339574 5.879677
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.493219 1.738053 5.437149 -0.757442 5.975951 4.032588 3.011392 2.324062 0.810185 0.616012 0.503141 6.103234 5.387951
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 38.385079 25.393313 1.760350 0.732524 9.033796 7.761535 14.077906 25.104297 0.676239 0.496926 0.337351 0.000000 0.000000
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 40.314047 22.318657 13.295627 16.730786 27.723292 24.873296 33.623156 16.516081 0.639101 0.460509 0.344704 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.603297 15.828272 16.753776 19.001941 22.826023 24.468412 4.272567 3.955369 0.780563 0.536659 0.531433 0.000000 0.000000
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.252810 14.597722 18.691877 17.871482 26.075564 23.949916 4.352035 4.144401 0.772067 0.518874 0.544288 0.000000 0.000000
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.725816 12.926708 18.999958 17.118648 22.147661 17.439482 -0.519779 -1.086413 0.767344 0.516311 0.550964 0.000000 0.000000
176 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.053400 -0.970229 -0.993976 0.039915 0.017221 0.218181 -0.333459 0.758886 0.042558 0.061761 0.004064 0.000000 0.000000
177 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.914444 0.805824 0.441596 1.370120 -0.379607 0.534565 0.499822 0.382017 0.061813 0.058221 0.006430 0.969674 0.971127
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.810462 -1.391017 0.574081 -0.588770 -0.970130 -0.331225 -0.428166 -0.726091 0.067541 0.055492 0.008738 1.261735 1.260058
179 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.085908 -0.299432 -0.512978 0.181104 3.644161 -0.750996 0.201771 -0.809213 0.073354 0.074408 0.018079 1.190762 1.193227
180 N13 RF_maintenance 100.00% 0.00% 89.25% 0.00% 100.00% 0.00% 0.512016 20.991490 -0.454296 30.386859 -0.391963 19.574806 -0.655855 0.056705 0.800358 0.295547 0.611455 17.302808 2.948787
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.307427 63.940896 32.096094 4.769822 27.692186 27.145282 0.348970 1.696262 0.042438 0.313306 0.123987 1.286542 3.680199
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.996922 2.553797 16.956193 7.642397 18.667460 3.760572 -0.877808 4.617942 0.791741 0.587390 0.529140 7.738032 6.047356
183 N13 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
184 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.307998 -0.132668 0.486581 0.589347 6.144993 6.249628 7.712168 5.727910 0.800460 0.608109 0.503486 5.778522 5.262750
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.087182 0.174708 6.976654 1.078551 3.851301 3.446951 9.080563 2.026399 0.799005 0.604430 0.507401 5.309364 5.709149
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.569670 -0.251399 3.376303 2.079235 1.724119 0.709157 2.128241 1.379171 0.797806 0.595162 0.505395 1.489413 1.296515
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.173013 0.868696 0.177305 -0.001760 4.892599 4.474083 5.792006 3.773466 0.798384 0.596527 0.507239 0.000000 0.000000
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.278984 3.589165 0.429375 0.480582 9.910374 9.566571 5.244084 5.503051 0.787163 0.550351 0.540937 0.000000 0.000000
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 57.356112 32.073902 2.860385 33.203276 23.758611 30.046612 53.663661 4.426345 0.648337 0.041528 0.359514 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.366604 0.399387 -0.652871 -0.300949 9.521015 9.194698 6.401928 7.858468 0.782766 0.521643 0.572090 0.000000 0.000000
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 23.547018 22.664310 10.957421 0.406519 12.972280 5.985990 4.079399 5.429195 0.791260 0.524965 0.543489 7.554663 3.849273
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 20.696986 21.259775 4.418166 7.564147 5.973616 7.729504 4.544514 4.626343 0.778074 0.542163 0.531479 3.605243 2.824392
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 24.903731 22.401989 13.229423 10.442460 15.448835 10.307941 1.159175 1.261010 0.768843 0.535857 0.523041 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% 43.877997 43.698782 inf inf 3041.919122 3551.064460 2222.847033 2934.810266 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.420887 21.695435 6.479094 1.255757 6.191974 3.139554 -0.109553 10.434819 0.774069 0.481459 0.559663 4.296859 2.879089
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 30.341455 30.110734 20.413671 20.033604 25.559865 23.069909 -1.065310 -1.139767 0.731026 0.481556 0.522700 3.210815 2.479832
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% 43.549257 43.288469 inf inf 4152.077441 4151.844675 3494.666335 3494.408459 nan nan nan 0.000000 0.000000
320 N03 dish_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
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.767937 4.063391 10.949555 9.675501 12.311117 10.128865 5.664368 5.415483 0.099166 0.069863 0.044363 0.000000 0.000000
323 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.305288 7.877768 0.638114 13.316634 10.537411 11.042100 12.808055 -0.027634 0.093291 0.069259 0.040229 0.000000 0.000000
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.028732 6.106203 14.817773 9.166080 15.748800 8.133010 0.188846 -0.193160 0.113123 0.071410 0.051414 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 10.343006 4.244757 4.283973 9.110174 9.165721 7.556255 1.618245 -0.617443 0.087114 0.069453 0.034685 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.819835 4.330907 -0.108748 8.640041 4.329807 5.283253 -0.177247 -0.659704 0.083744 0.070502 0.038571 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 30, 31, 32, 33, 36, 40, 41, 42, 50, 51, 52, 53, 54, 55, 56, 57, 68, 69, 70, 71, 72, 73, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [37, 38, 45, 46, 65, 66, 67, 81, 83, 98, 100, 116, 162, 163]

golden_ants: [37, 38, 45, 46, 65, 66, 67, 81, 83, 98, 100, 116, 162, 163]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H6C_Notebooks/_rtp_summary_/rtp_summary_table_2459825.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.dev9+gea58d1b
In [ ]: