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 = "2459959"
data_path = "/mnt/sn1/2459959"
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, TimeDelta
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 1-14-2023
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/2459959/zen.2459959.21302.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 1850 ant_metrics files matching glob /mnt/sn1/2459959/zen.2459959.?????.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.')
No files found matching glob /mnt/sn1/2459959/zen.2459959.?????.sum.known_good.omni.calfits. Skipping redcal chisq.

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])
    start_time = Time(startJD,format='jd')
    stop_time = Time(stopJD,format='jd')

    # get initial state by looking for commands up to 3 hours before the starttime
    # this logic can be improved after an upcoming hera_mc PR
    # which will return the most recent command before a particular time.
    search_start_time = start_time - TimeDelta(3*3600, format="sec")
    initial_command_res = session.get_array_signal_source(starttime=search_start_time, stoptime=start_time)
    if len(initial_command_res) == 0:
        initial_source = "Unknown"
    elif len(command_res) == 1:
        initial_source = initial_command_res[0].source
    else:
        # multiple commands
        times = []
        sources = []
        for obj in command_res:
            times.append(obj.time)
            sources.append(obj.source)
        initial_source = sources[np.argmax(times)]
    
    # check for any changes during observing
    command_res = session.get_array_signal_source(starttime=start_time, stoptime=stop_time)
    if len(command_res) == 0:
        # still nothing, set it to None
        obs_source = None
    else:
        obs_source_times = []
        obs_source = []
        for obj in command_res:
            obs_source_times.append(obj.time)
            obs_source.append(obj.source)

    if obs_source is not None:
        command_source = [initial_source] + obs_source
    else:
        command_source = initial_source
    
    res = session.get_antenna_status(starttime=startTime, stoptime=stopTime)
    fem_switches = {}
    right_rep_ant = []
    if len(res) > 0:
        for obj in res:
            if obj.antenna_number not in fem_switches.keys():
                fem_switches[obj.antenna_number] = {}
            fem_switches[obj.antenna_number][obj.antenna_feed_pol] = obj.fem_switch
        for ant, pol_dict in fem_switches.items():
            if pol_dict['e'] == initial_source and pol_dict['n'] == initial_source:
                right_rep_ant.append(ant)
except Exception as e:
    print(e)
    initial_source = None
    command_source = None
    right_rep_ant = []
name 'command_res' is not defined

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 (initial_source == 'digital_noise_same' or initial_source == 'digital_noise_different') and med < 10:
                antCon[ant] = True
            elif (initial_source == "load" or initial_source == 'noise') and 80000 < stdev <= 4000000 and antCon[ant] is not False:
                antCon[ant] = True
            elif initial_source == "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'] = ', '.join(command_source if hasattr(command_source, '__iter__') else [str(command_source)])
to_show['Antennas in Commanded State (reported)'] = f'{len(right_rep_ant)} / {len(ants)} ({len(right_rep_ant) / len(ants):.1%})'
to_show['Antennas in Commanded State (observed)'] = 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 2459959
Date 1-14-2023
LST Range 2.133 -- 12.090 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1850
Total Number of Antennas 196
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 9
dish_ok: 1
RF_maintenance: 50
RF_ok: 19
digital_ok: 93
not_connected: 24
Commanded Signal Source None
Antennas in Commanded State (reported) 0 / 196 (0.0%)
Antennas in Commanded State (observed) 0 / 196 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 19
Nodes Registering 0s N14
Nodes Not Correlating
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 112 / 196 (57.1%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 153 / 196 (78.1%)
Redcal Done? ❌
Never Flagged Antennas 43 / 196 (21.9%)
A Priori Good Antennas Flagged 72 / 93 total a priori good antennas:
3, 7, 9, 10, 15, 16, 17, 19, 20, 29, 37, 38,
40, 41, 42, 45, 53, 54, 55, 56, 65, 66, 67,
71, 72, 81, 85, 86, 88, 94, 101, 103, 106,
107, 109, 111, 121, 122, 123, 128, 136, 140,
143, 144, 146, 150, 151, 157, 158, 160, 161,
162, 163, 164, 165, 167, 168, 169, 170, 173,
181, 182, 184, 185, 186, 187, 189, 190, 191,
192, 193, 202
A Priori Bad Antennas Not Flagged 22 / 103 total a priori bad antennas:
8, 48, 61, 62, 89, 114, 115, 120, 132, 137,
139, 205, 211, 220, 222, 229, 237, 238, 239,
245, 324, 325
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_2459959.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 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
3 N01 digital_ok 100.00% 100.00% 0.00% 0.00% 10.774674 14.187950 11.063438 -1.436634 9.285285 4.059777 0.050158 6.475106 0.033267 0.350718 0.280285
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.398452 0.693926 1.158283 1.026156 23.920325 8.190721 16.117231 4.567039 0.610791 0.630329 0.390471
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.496435 0.315254 0.535419 0.548758 0.329067 2.527200 0.415658 1.349808 0.621909 0.630600 0.377699
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% -1.112737 0.139486 -1.123444 -0.177907 0.436031 0.429582 9.372485 6.050705 0.627062 0.642166 0.376180
8 N02 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.433363 -1.356623 -0.569494 0.220367 -0.066352 0.475932 2.870364 0.941869 0.627529 0.640279 0.373801
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 4.448203 -1.022276 9.242266 -0.407650 5.993544 0.263130 -0.448164 0.201559 0.453258 0.638658 0.447227
10 N02 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
15 N01 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
16 N01 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
17 N01 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
18 N01 RF_maintenance 100.00% 100.00% 43.35% 0.00% 11.718688 21.768583 10.972121 -1.092112 9.432931 7.647797 -0.028714 13.564018 0.030180 0.255809 0.199581
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
20 N02 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.499579 -0.441823 -0.533358 0.365357 0.912285 1.767698 -0.313972 0.281677 0.619681 0.631768 0.374828
22 N06 not_connected 100.00% 100.00% 100.00% 0.00% 297.721725 297.550949 inf inf 4531.120834 4529.641405 6347.043460 6260.897555 nan nan nan
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 10.418411 12.690365 11.048147 11.554724 9.399474 10.709010 1.072596 1.412702 0.036004 0.038413 0.004996
28 N01 RF_maintenance 100.00% 0.00% 84.11% 0.00% 12.806959 28.175804 -1.452386 1.124094 5.395963 8.145507 3.124978 18.106586 0.369892 0.177829 0.255098
29 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 11.129109 13.254400 10.569679 11.083536 9.388115 10.674711 -0.019320 0.435673 0.030132 0.034844 0.005209
30 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -0.800412 0.008838 0.457658 0.832222 1.680877 -0.003658 2.920627 0.291678 0.631366 0.648898 0.372374
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 1.533064 -0.848561 1.668007 1.103783 1.561670 -0.625964 -0.179712 1.652986 0.643770 0.644295 0.371082
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% -1.082088 24.996494 -0.045304 3.350925 0.005889 3.004485 1.231832 8.307842 0.632666 0.546588 0.360229
34 N06 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
35 N06 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
36 N03 RF_maintenance 100.00% 100.00% 100.00% 0.00% 28.075653 28.325362 14.765205 14.719451 9.486190 10.615764 2.276120 3.022099 0.031910 0.029760 0.002232
37 N03 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
38 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 248.888583 248.741200 inf inf 3565.544956 3691.689536 4267.341509 4611.730214 nan nan nan
40 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 10.400825 0.668962 10.603734 0.709392 9.335576 -0.380578 0.011352 -0.457471 0.037860 0.635418 0.506709
41 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 1.173184 0.233601 -0.510657 -0.503714 2.346821 0.261824 -0.443777 6.235785 0.638087 0.646062 0.366933
42 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 11.675592 13.871765 11.407482 12.182610 9.088378 10.402389 -0.179886 1.039760 0.027449 0.027184 0.001630
43 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
44 N05 digital_ok 0.00% 0.00% 0.00% 0.00% -1.818698 -0.231409 -0.709140 -0.494632 -0.044249 0.003658 -1.289518 -0.665573 0.648863 0.662450 0.374695
45 N05 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
46 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
47 N06 not_connected 100.00% 100.00% 100.00% 0.00% 12.001051 14.302651 4.368454 4.511819 9.305718 10.578391 0.109626 0.195295 0.030872 0.048961 0.013437
48 N06 not_connected 0.00% 0.00% 0.00% 0.00% -0.507001 0.827812 0.380222 2.170535 -0.991422 1.958773 -0.734663 -1.661121 0.620252 0.639426 0.381769
49 N06 not_connected 100.00% 0.00% 0.00% 0.00% -0.457688 -0.673714 -0.433711 -1.367805 0.934188 -0.895702 -0.010668 4.909453 0.565627 0.606410 0.373039
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.665764 20.374119 0.309815 1.750377 1.716611 4.774139 10.664761 46.003765 0.598815 0.543277 0.369847
51 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 10.448720 8.282262 -0.188868 0.760703 1.336891 0.386883 0.556763 1.259973 0.625992 0.632529 0.388227
53 N03 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 10.714337 13.388790 11.069651 11.827959 9.323475 10.609505 0.686489 0.757530 0.027338 0.026741 0.001654
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 11.082079 13.561628 10.417122 11.031413 9.334480 10.609309 -0.161317 1.497393 0.028781 0.031784 0.002999
56 N04 digital_ok 100.00% 0.00% 100.00% 0.00% -0.764956 14.362771 0.709150 11.989033 -0.398560 10.516254 -0.013707 0.763739 0.644280 0.037862 0.525754
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 23.869008 0.563448 7.205471 0.844059 6.071940 1.809105 35.533603 0.832312 0.472353 0.654638 0.397013
58 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% 10.359116 13.161641 10.949429 11.712086 9.284140 10.612826 0.494375 0.853995 0.035277 0.034546 0.002242
59 N05 RF_maintenance 100.00% 100.00% 0.00% 0.00% 11.324375 0.624709 10.454973 2.502873 9.085094 0.884347 0.033696 7.135233 0.046793 0.638753 0.518411
60 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
61 N06 not_connected 0.00% 0.00% 0.00% 0.00% 2.211820 -0.209117 -0.960960 -1.573427 0.521112 -1.250152 -0.908017 0.054616 0.590049 0.620138 0.370588
62 N06 not_connected 0.00% 0.00% 0.00% 0.00% 0.390154 0.001709 -0.759583 1.110874 -0.590941 -0.783477 1.803876 -0.482653 0.581526 0.637073 0.384419
63 N06 not_connected 100.00% 0.00% 100.00% 0.00% -0.162027 13.584203 -0.363916 4.956777 0.619152 10.743317 -0.715259 1.970161 0.618373 0.047067 0.481842
64 N06 not_connected 100.00% 0.00% 0.00% 0.00% -0.207754 0.170180 -1.419187 -1.051575 -0.572234 -0.604821 5.759480 1.565206 0.598278 0.590009 0.354112
65 N03 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
66 N03 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
67 N03 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
68 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.744333 -1.169937 0.248466 1.193365 -0.320720 0.777920 -0.889946 -0.503602 0.636073 0.647047 0.369080
70 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.630227 -0.705020 0.110004 0.419156 1.198512 1.211437 0.181535 0.520309 0.644787 0.653470 0.363499
71 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 10.051118 -0.688458 0.958616 1.119310 0.825006 -0.630822 0.315109 -0.141109 0.657453 0.653162 0.359526
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 11.303808 14.454920 11.536148 12.200503 9.151354 10.439118 0.001917 0.825201 0.026675 0.025762 0.001624
73 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
74 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
77 N06 not_connected 100.00% 0.00% 0.00% 0.00% 69.566621 0.632516 0.602408 -0.469560 5.131550 -0.586689 9.234741 -0.940732 0.332612 0.628676 0.432387
78 N06 not_connected 100.00% 0.00% 0.00% 0.00% 39.673599 -0.514434 -0.627853 1.156736 1.807201 -0.142741 0.144701 0.366243 0.447661 0.641857 0.366701
79 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
80 N11 not_connected 100.00% 0.00% 98.70% 0.00% -1.470190 14.961182 -0.374926 4.884673 1.133919 10.609820 9.096759 1.252710 0.602406 0.049651 0.470282
81 N07 digital_ok 100.00% 0.00% 100.00% 0.00% -0.312963 14.120744 0.378864 10.168827 0.102196 10.278596 0.461952 1.256818 0.581354 0.039217 0.447356
82 N07 RF_maintenance 100.00% 0.00% 80.43% 0.00% 2.235306 20.965412 8.159591 17.360643 -0.590677 7.897117 -0.543632 5.662908 0.574543 0.194600 0.428527
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.284552 0.103371 -0.341412 -0.172720 0.594173 -0.748467 -0.417321 0.400113 0.613694 0.627540 0.383547
84 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 75.714977 49.034934 39.448574 34.097959 25.123436 26.852875 497.486008 440.835892 0.016124 0.016196 0.000905
85 N08 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
86 N08 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 8.625376 8.527859 -0.684790 -0.194152 -0.187702 1.130105 0.016822 1.704431 0.655222 0.668737 0.359783
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 289.596456 289.493651 inf inf 3903.352270 3877.034211 4821.256867 4759.091004 nan nan nan
89 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 1.505249 0.650028 0.014673 1.046086 -0.176272 -0.628802 -0.591369 -0.253748 0.638248 0.650126 0.366814
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 249.176047 249.363075 inf inf 3536.634678 3550.925385 4159.810647 4100.160891 nan nan nan
91 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.213611 -0.175610 -0.170708 -0.372385 -0.848158 -0.852402 0.148310 -0.060325 0.629327 0.654202 0.385650
92 N10 RF_maintenance 100.00% 0.00% 24.49% 0.00% 39.742424 46.964824 0.828563 1.715823 4.576746 4.132377 -0.202526 4.532301 0.296224 0.260305 0.083690
93 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 1.463536 -0.179812 2.476992 -1.068072 0.103048 0.283966 1.510648 -0.428138 0.638916 0.660507 0.376672
94 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 11.832591 13.561977 11.236194 11.582534 9.369490 10.628488 0.179635 0.646914 0.031491 0.026348 0.002613
95 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
96 N11 not_connected 100.00% 100.00% 100.00% 0.00% 12.255415 14.513316 4.429279 5.140564 9.158535 10.472738 0.070621 0.821282 0.033953 0.039206 0.002558
97 N11 not_connected 100.00% 0.00% 0.00% 0.00% 0.285900 6.285990 -0.098206 1.449879 0.634746 4.154701 0.276261 5.213804 0.568121 0.549769 0.333971
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 11.287409 10.776955 -0.368036 1.666727 0.272728 0.965240 0.290783 0.755217 0.638594 0.645362 0.374140
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 2.995675 6.636012 5.591662 -1.606825 2.595549 0.529592 5.006734 4.510266 0.611629 0.660873 0.369221
104 N08 RF_maintenance 100.00% 0.11% 0.00% 0.00% 11.404069 68.948577 -1.357448 8.301307 1.452702 2.457185 2.429250 5.034432 0.653301 0.629119 0.355981
105 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.271786 -0.001709 -0.219897 0.264801 0.349218 -0.667337 -0.568501 -0.180287 0.647342 0.654655 0.359619
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
108 N09 RF_maintenance 100.00% 100.00% 2.43% 0.00% 10.876620 46.840281 10.988369 1.162739 9.383320 4.815483 0.739587 3.406118 0.034504 0.292224 0.166827
109 N10 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
111 N10 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
112 N10 digital_ok 0.00% 0.00% 0.00% 0.00% -1.873185 -0.512222 0.471044 0.632199 0.376887 2.459426 -0.171284 -0.645488 0.646034 0.658412 0.378857
113 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
114 N11 not_connected 0.00% 0.00% 0.00% 0.00% 0.015432 0.303273 -1.248902 -0.515905 0.106542 -0.681644 -0.105060 0.186899 0.600262 0.631475 0.367162
115 N11 not_connected 0.00% 0.00% 0.00% 0.00% -1.734346 -1.160123 -1.270594 -0.795370 -0.104329 -1.007172 -0.691795 0.158350 0.588180 0.614759 0.372975
117 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 11.788649 14.804450 11.164869 12.134130 9.206328 10.639914 0.457248 2.714670 0.028018 0.031315 0.002465
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.591367 1.328033 -0.230318 0.842856 -0.039047 -0.493828 -0.206648 0.902221 0.605367 0.628387 0.383822
120 N08 RF_maintenance 0.00% 0.00% 0.00% 0.00% 3.111441 1.989838 3.272728 -0.800802 -0.067221 0.819493 1.248447 0.626914 0.622904 0.655063 0.371977
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 3.529562 4.335387 -0.331538 6.662632 1.678138 0.022248 18.706577 11.165246 0.650246 0.635482 0.352151
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 11.237239 8.397905 0.217626 1.381422 0.718263 1.127266 -0.004757 -0.401776 0.654342 0.661151 0.362968
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 9.232524 11.375269 1.097272 1.223437 0.529316 -0.313499 -0.744183 -0.293493 0.654573 0.665460 0.376211
124 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.471116 -0.172034 0.036817 0.928863 -0.240893 -0.525757 0.076133 0.064955 0.647719 0.655048 0.375103
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
127 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.311256 0.289844 0.975183 0.692929 1.550477 0.720600 -0.194571 0.688576 0.644507 0.662398 0.383222
128 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 10.393681 12.149303 10.530578 11.086527 9.215881 10.517167 -0.396157 0.499096 0.030863 0.029313 0.001144
131 N11 not_connected 100.00% 0.00% 0.00% 0.00% -1.400555 12.899187 -0.301146 4.773602 -0.008108 9.097985 -0.783518 0.290633 0.631513 0.328004 0.414368
132 N11 not_connected 0.00% 0.00% 0.00% 0.00% -0.862332 1.932010 -1.233599 -1.709828 1.355651 -0.560882 0.657721 0.175162 0.606652 0.616128 0.353624
133 N11 not_connected 100.00% 96.27% 0.00% 0.00% 12.642496 -0.736606 4.120960 -1.724169 9.364664 -1.100773 0.681637 -0.587786 0.078187 0.612438 0.454734
135 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
136 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
137 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.296345 -0.514840 0.654977 -1.800755 1.790274 -0.310769 -0.054616 -0.236038 0.583684 0.622556 0.390666
139 N13 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.022441 -1.106143 1.702925 -1.226896 0.623584 -0.835721 -1.146913 -0.099222 0.624809 0.625869 0.363421
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.191677 0.108292 -1.090839 -0.345513 0.253795 -0.210287 4.636066 3.585102 0.638694 0.660511 0.364161
141 N13 digital_ok 0.00% 0.00% 0.00% 0.00% -1.595790 -0.617920 0.079980 0.656053 2.274402 -1.016170 -0.062289 -0.687128 0.640576 0.663401 0.365669
142 N13 RF_maintenance 100.00% 0.00% 99.89% 0.00% 0.888500 13.116044 -0.189707 11.745110 4.582439 10.635794 32.075594 1.234945 0.638335 0.049290 0.528513
143 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
144 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
146 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
147 N15 digital_ok 0.00% 0.00% 0.00% 0.00% -0.801557 -2.135298 1.339128 2.719532 -0.475596 -0.960782 -0.612352 0.905346 0.642705 0.649169 0.369836
148 N15 digital_ok 0.00% 0.00% 0.00% 0.00% -1.048376 0.737050 -0.308662 -0.400477 2.432779 1.616285 -0.748357 -0.672150 0.655897 0.670458 0.377843
149 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 0.141792 -1.072308 -1.261154 -1.814932 -0.146248 1.426226 0.324972 0.676831 0.654444 0.669466 0.377423
150 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
151 N16 digital_ok 100.00% 0.00% 0.00% 0.00% 29.936185 1.124712 -0.336090 0.655310 5.232502 -0.113136 2.228722 -0.186175 0.507569 0.590404 0.324285
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
156 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
157 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
158 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
159 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% -0.240853 19.159316 -1.860052 -1.302738 -0.071501 5.603562 -0.722753 39.481633 0.589240 0.555178 0.342058
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
161 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 289.512804 289.961434 inf inf 3401.611575 3379.314657 4149.008975 4092.632429 nan nan nan
162 N13 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
163 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
164 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
167 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
168 N15 digital_ok 100.00% 0.00% 0.70% 0.00% -1.375778 -1.326733 0.637317 0.059128 1.556847 16.753929 -0.888847 3.313175 0.650570 0.635358 0.385064
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 0.202264 10.788799 -0.786650 -1.540081 0.567753 6.108208 -0.860903 13.802099 0.658789 0.632341 0.366175
170 N15 digital_ok 100.00% 100.00% 0.00% 0.00% 11.741783 -0.937446 11.402150 -1.312534 9.179851 0.147850 1.117725 1.042822 0.043026 0.669949 0.515258
171 N16 digital_ok 0.00% 0.00% 0.00% 0.00% 0.297309 2.776070 -1.844028 -0.034312 -0.863735 2.175087 -0.565550 1.219802 0.594172 0.576538 0.342907
173 N16 digital_ok 100.00% 100.00% 100.00% 0.00% 13.278035 14.272151 3.798455 4.526991 9.483549 10.706081 1.911458 3.636367 0.040687 0.044415 0.004116
179 N12 RF_maintenance 100.00% 0.00% 0.00% 0.00% -0.142616 -0.490224 -0.315766 -0.210520 -0.083998 3.976322 -0.202155 5.963073 0.614445 0.631365 0.377279
180 N13 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
182 N13 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.779047 0.672321 -0.758004 0.110419 1.411999 0.010973 0.979648 0.970396 0.631715 0.640199 0.375617
184 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
185 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
189 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
190 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
191 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
192 N16 digital_ok 100.00% 0.00% 0.00% 0.00% 7.564633 8.169387 5.947087 5.810320 6.807470 8.075470 -2.566699 -1.998998 0.600733 0.614821 0.364249
193 N16 digital_ok 100.00% 0.00% 0.00% 0.00% 8.363135 -0.119365 6.051156 1.435260 7.061105 1.834279 -2.538380 0.817948 0.585213 0.620942 0.393688
200 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
201 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
202 N18 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
205 N19 RF_ok 0.00% 0.00% 0.00% 0.00% 2.500597 2.773903 -0.110008 -0.326970 -0.973395 -0.660888 -0.934025 2.625816 0.619894 0.603735 0.362837
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 4.013354 1.089911 3.335940 -1.093545 10.063804 -0.493005 -0.968987 5.115469 0.630802 0.622584 0.366528
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
208 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% 9.154135 12.514713 10.289774 12.063325 8.771633 10.622697 10.818101 46.104378 0.035385 0.035868 -0.000064
209 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% 8.017376 9.582259 10.045797 10.258363 9.325566 10.823452 8.165935 8.764839 0.044772 0.042193 0.003634
210 N20 dish_maintenance 100.00% 0.00% 0.00% 0.00% 15.958758 13.750307 -1.150264 -0.963511 -0.597520 -0.398243 -0.893259 0.746614 0.641072 0.646641 0.366276
211 N20 RF_ok 0.00% 0.00% 0.00% 0.00% 0.578286 -1.517514 -1.696746 -0.172967 -0.952129 -0.839054 1.913185 0.937226 0.588435 0.619880 0.366236
220 N18 RF_maintenance 0.00% 0.00% 0.00% 0.00% -1.902982 -1.245526 0.355418 -0.334041 -0.579109 0.646557 2.344164 -0.928535 0.614158 0.623974 0.377816
221 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 0.539400 -0.806224 -1.846478 -0.913012 -0.062462 -0.630011 7.308097 -0.443853 0.591945 0.628139 0.382714
222 N18 RF_ok 0.00% 0.00% 0.00% 0.00% 0.164919 -0.676661 -0.652862 -0.302433 0.301139 3.717963 0.869191 -0.973605 0.604872 0.635021 0.377701
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 275.934610 275.618566 inf inf 3261.090656 3265.550194 3548.959923 3652.490684 nan nan nan
225 N19 RF_ok 100.00% 0.00% 87.62% 0.00% 1.372293 13.389803 0.702710 4.736372 -0.581835 10.480437 -1.062890 1.125884 0.632532 0.156281 0.484970
226 N19 RF_ok 100.00% 0.00% 0.00% 0.00% -0.183155 12.622393 -0.055375 1.682968 -1.220388 3.305209 -0.756850 -0.465252 0.626639 0.596369 0.357525
227 N20 RF_ok 100.00% 0.00% 0.00% 0.00% 1.749752 -0.049423 -1.753936 -0.034798 -0.051616 -0.455721 8.775654 0.515849 0.591187 0.629287 0.363055
228 N20 RF_maintenance 100.00% 0.00% 0.00% 0.00% 8.921256 21.007239 -0.993644 -0.484532 1.341546 5.022394 31.271203 47.118670 0.550888 0.534729 0.312162
229 N20 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.344969 -0.025667 1.680545 1.518732 -0.243831 0.815739 1.208692 -1.227948 0.614221 0.629828 0.375260
237 N18 RF_ok 0.00% 0.00% 0.00% 0.00% 2.336741 -0.327410 -0.009748 -1.832632 0.124228 -0.863080 -0.836934 -0.660834 0.542346 0.604050 0.390398
238 N18 RF_ok 0.00% 0.00% 0.00% 0.00% -1.117180 -0.638750 0.895326 0.042415 -0.644987 0.108304 -1.328957 -1.166282 0.612674 0.627113 0.384350
239 N18 RF_ok 0.00% 0.00% 0.00% 0.00% -1.542101 -2.284297 -0.347166 -0.134127 -0.884895 -0.036908 1.537368 0.917463 0.609962 0.631741 0.384098
240 N19 RF_maintenance 100.00% 0.00% 0.00% 0.00% 38.774928 64.471317 -0.670786 0.942978 2.716691 5.872332 11.838712 13.436068 0.450519 0.392153 0.206393
241 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 2.130578 4.555583 -1.271426 0.605573 -0.445469 0.882848 3.778174 11.717799 0.604187 0.582993 0.368583
242 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 40.404192 1.197898 -0.201906 1.409283 6.255852 1.098416 15.665173 0.033348 0.465295 0.639859 0.396032
243 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 60.604824 2.630928 1.173549 -1.770525 5.482773 -0.924078 -1.216529 0.856933 0.357187 0.612698 0.411333
244 N20 RF_maintenance 100.00% 0.00% 0.00% 0.00% 5.168833 1.843139 1.533208 -0.967034 3.343340 0.187134 2.358852 5.852458 0.492149 0.593158 0.370157
245 N20 RF_ok 0.00% 0.00% 0.00% 0.00% 0.052816 2.025178 0.009748 -1.332050 -0.957807 -0.340196 -1.019227 0.306532 0.603422 0.606309 0.364974
246 N20 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
261 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
262 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% 289.227210 289.168017 inf inf 3411.310697 3436.988438 4186.826472 4289.051206 nan nan nan
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
324 N04 not_connected 0.00% 0.00% 0.00% 0.00% 1.186537 2.378531 1.228645 1.710258 0.516783 1.495622 1.966261 1.471488 0.504358 0.523597 0.360194
325 N09 dish_ok 0.00% 0.00% 0.00% 0.00% 0.450368 -1.662065 1.358486 -1.625932 0.818380 0.396000 -1.138813 0.472031 0.541704 0.540949 0.373204
329 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 1.955699 -1.394002 -1.385454 -1.301247 -0.039252 -0.092872 3.758929 0.661467 0.485465 0.524686 0.362120
333 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 3.530128 5.236656 -0.617529 -1.706900 0.051368 0.316837 0.139282 0.620516 0.466614 0.498384 0.343924
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, 7, 9, 10, 15, 16, 17, 18, 19, 20, 22, 27, 28, 29, 32, 34, 35, 36, 37, 38, 40, 41, 42, 43, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 63, 64, 65, 66, 67, 68, 71, 72, 73, 74, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 90, 92, 94, 95, 96, 97, 101, 102, 103, 104, 106, 107, 108, 109, 110, 111, 113, 117, 121, 122, 123, 125, 126, 128, 131, 133, 135, 136, 140, 142, 143, 144, 145, 146, 150, 151, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 173, 179, 180, 181, 182, 184, 185, 186, 187, 189, 190, 191, 192, 193, 200, 201, 202, 206, 207, 208, 209, 210, 221, 223, 224, 225, 226, 227, 228, 240, 241, 242, 243, 244, 246, 261, 262, 320, 329, 333]

unflagged_ants: [5, 8, 21, 30, 31, 44, 48, 61, 62, 69, 70, 83, 89, 91, 93, 105, 112, 114, 115, 118, 120, 124, 127, 132, 137, 139, 141, 147, 148, 149, 171, 183, 205, 211, 220, 222, 229, 237, 238, 239, 245, 324, 325]

golden_ants: [5, 21, 30, 31, 44, 69, 70, 83, 91, 93, 105, 112, 118, 124, 127, 141, 147, 148, 149, 171, 183]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H6C_Notebooks/_rtp_summary_/rtp_summary_table_2459959.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.5.dev13+gd6c757c
3.3.dev3+gb08b74d
In [ ]: