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 = "2459869"
data_path = "/mnt/sn1/2459869"
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: 10-16-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/2459869/zen.2459869.25299.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 1862 ant_metrics files matching glob /mnt/sn1/2459869/zen.2459869.?????.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/2459869/zen.2459869.?????.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 2459869
Date 10-16-2022
LST Range 21.181 -- 7.203 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1862
Total Number of Antennas 180
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
dish_ok: 1
RF_maintenance: 35
RF_ok: 9
digital_maintenance: 11
digital_ok: 98
not_connected: 23
Commanded Signal Source None
Antennas in Commanded State (reported) 0 / 180 (0.0%)
Antennas in Commanded State (observed) 0 / 180 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 16
Nodes Registering 0s
Nodes Not Correlating
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 63 / 180 (35.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 148 / 180 (82.2%)
Redcal Done? ❌
Never Flagged Antennas 32 / 180 (17.8%)
A Priori Good Antennas Flagged 70 / 98 total a priori good antennas:
3, 7, 10, 19, 20, 21, 30, 37, 38, 46, 51, 53,
54, 55, 66, 67, 68, 71, 72, 73, 81, 83, 84,
85, 86, 88, 93, 98, 99, 101, 103, 106, 107,
108, 109, 111, 116, 117, 121, 122, 123, 128,
130, 140, 141, 142, 143, 147, 156, 158, 160,
161, 162, 164, 165, 167, 169, 170, 176, 177,
178, 179, 183, 184, 185, 186, 187, 189, 190,
191
A Priori Bad Antennas Not Flagged 4 / 82 total a priori bad antennas:
4, 89, 125, 168
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_2459869.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% 0.00% 0.00% 0.00% 6.930981 -1.310114 -0.253800 -0.687988 0.502643 -0.172940 0.714890 1.252775 0.697615 0.697668 0.389161
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 2.604096 3.650656 2.182912 -0.477967 0.264371 -0.357760 1.288720 0.237152 0.705706 0.695633 0.381179
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -0.491547 0.852537 -0.858202 2.157363 0.182244 0.290134 0.788408 -0.452315 0.716995 0.699648 0.380378
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% -1.754387 -1.619463 -0.249917 1.565089 1.410585 5.516240 10.439987 10.574691 0.711458 0.698904 0.385218
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 6.727404 7.344309 31.438967 33.077401 9.563067 15.876078 3.080147 0.939347 0.694112 0.666644 0.381527
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% -0.558190 -2.065583 0.559082 0.132503 -0.026491 -0.364238 1.339077 1.959007 0.704979 0.692265 0.388596
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 0.00% 0.00% 0.00% 0.00% 2.317890 1.064608 1.086227 -0.552847 -0.115870 -0.144020 3.977415 0.838507 0.714443 0.703892 0.380244
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -0.694798 0.029567 0.818200 -0.544527 0.525960 0.119873 1.723637 0.030106 0.717836 0.702892 0.374394
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.022952 0.634813 -0.685707 0.588077 -0.452469 -0.077815 0.271806 -0.860089 0.715849 0.706482 0.372858
18 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
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 100.00% 0.00% 0.00% 0.00% 1.990086 -0.213555 -0.086821 0.289838 1.529237 3.649573 1.275067 5.975267 0.703758 0.690953 0.384630
22 N06 not_connected 100.00% 0.00% 0.00% 0.00% 46.249035 17.538706 3.421536 11.733708 6.085381 5.223617 5.814081 2.279497 0.476102 0.638541 0.325356
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
28 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -1.490701 -1.210825 -0.247737 0.450251 -0.904452 -1.358012 -0.600456 3.038837 0.720513 0.707768 0.368746
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% -0.521325 -1.370417 5.005668 -0.957314 -0.257075 -0.823459 3.257247 -0.733759 0.722011 0.712120 0.372065
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.317454 -0.397711 0.857268 2.212556 2.249177 2.912764 1.087695 1.661878 0.727929 0.708759 0.382465
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 36.989794 32.819746 7.036576 3.234976 4.905379 7.969451 7.196549 11.265560 0.590942 0.628183 0.229386
33 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% -0.557370 24.401272 -0.393012 0.838014 -0.221691 6.147772 1.124115 28.499969 0.711527 0.524598 0.457688
34 N06 not_connected 100.00% 100.00% 0.00% 0.00% 21.676462 4.483883 20.536920 12.144492 15.815336 7.188358 5.443951 0.298107 0.044151 0.675341 0.558549
35 N06 not_connected 100.00% 0.00% 0.00% 0.00% 7.351658 0.749918 27.956649 6.844665 105.005856 3.320661 0.036228 -0.123950 0.660712 0.668362 0.394014
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 14.298482 14.492245 0.539042 0.453894 1.899902 2.457172 1.109633 0.961099 0.712865 0.702509 0.387524
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.594183 1.671758 0.460855 3.117824 0.559683 -0.245193 -0.103607 8.376906 0.717011 0.708391 0.388811
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 1.172227 1.270407 -0.441333 -0.373861 1.985781 1.662417 7.098950 2.638421 0.720711 0.712829 0.388551
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% -0.074548 0.462800 -0.583743 -0.778900 0.026491 -0.358400 -0.563603 -1.284077 0.716304 0.708332 0.378601
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.139443 0.060327 2.504379 1.228319 0.621957 -1.451686 -0.562993 -0.776615 0.722217 0.709492 0.368281
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% -0.654184 1.774379 -0.804080 0.775407 -0.407230 -0.952792 -0.462426 -1.145862 0.729848 0.721226 0.377173
43 N05 digital_maintenance 100.00% 100.00% 0.00% 0.00% 17.890085 1.048137 46.749769 -0.201501 15.824792 -0.039126 6.166719 1.562777 0.043179 0.718740 0.514932
44 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 2.675575 2.083470 0.306083 0.000943 1.528513 -0.115950 6.602807 2.431756 0.712636 0.715191 0.361916
45 N05 digital_ok 0.00% 0.00% 0.00% 0.00% -0.705106 2.618768 -0.487550 -0.161815 -0.418137 3.393057 -0.296784 3.513717 0.722121 0.702921 0.370612
46 N05 digital_ok 100.00% 0.00% 100.00% 0.00% -0.999033 20.439385 -0.846857 47.929930 1.477371 22.968677 0.257614 6.622644 0.715386 0.038729 0.538370
47 N06 not_connected 100.00% 100.00% 0.00% 0.00% 20.422495 4.106188 19.636209 9.869993 15.869224 2.951387 5.433947 3.470719 0.039956 0.678260 0.557672
48 N06 not_connected 100.00% 0.00% 0.00% 0.00% 3.948259 4.122899 19.904095 23.289976 4.812475 6.758486 1.197509 0.149540 0.688156 0.689036 0.396582
49 N06 not_connected 100.00% 0.00% 0.00% 0.00% 2.252340 3.700069 9.631435 22.755178 3.239013 8.327422 0.846034 0.405740 0.661306 0.674967 0.396211
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 5.068435 8.112057 -0.092545 0.384152 2.690231 7.484506 10.112667 18.713548 0.698497 0.681583 0.368295
51 N03 digital_ok 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% 11.679740 12.006224 0.262476 0.229509 3.108189 -1.408645 0.893570 0.098387 0.720778 0.714580 0.377752
53 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 385.564689 385.701286 inf inf 8587.583800 8879.051588 7408.160355 8298.692078 nan nan nan
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 19.062449 20.810559 47.261983 48.802131 15.840640 23.042329 6.644102 4.494176 0.048526 0.048207 0.001823
55 N04 digital_ok 100.00% 0.00% 100.00% 0.00% 4.423807 21.967812 1.660055 48.417563 7.886884 22.946310 3.027169 6.551655 0.717097 0.035623 0.521031
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.956100 1.065678 0.588375 0.414066 0.245578 0.319994 -0.450393 1.730727 0.724170 0.720027 0.356983
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 52.461980 0.330247 19.507780 -0.641789 7.806302 -0.618800 2.651301 0.431627 0.566928 0.722957 0.358870
58 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 18.350077 20.351257 47.023105 48.569540 15.930409 23.191376 7.259771 6.278522 0.039059 0.035809 0.002249
59 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 5.707640 19.783236 1.122080 3.766662 4.933800 2.503379 10.224295 9.139321 0.711480 0.680312 0.355663
60 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 19.878927 19.903850 47.181922 48.486274 15.846430 23.124246 6.397901 6.677787 0.027948 0.027833 0.001590
61 N06 not_connected 100.00% 0.00% 0.00% 0.00% 7.064380 4.680274 1.089311 -0.140438 3.714887 4.738528 0.486616 4.651390 0.669468 0.663816 0.369344
62 N06 not_connected 100.00% 0.00% 0.00% 0.00% 3.014785 4.777214 16.044826 22.612182 3.903547 8.647672 1.104392 0.154313 0.692388 0.694366 0.385033
63 N06 not_connected 100.00% 0.00% 100.00% 0.00% 15.046937 20.610361 15.139662 20.684715 3.849704 22.991216 1.346033 6.448661 0.636760 0.044437 0.562017
64 N06 not_connected 100.00% 0.00% 0.00% 0.00% 3.619261 2.601231 9.901452 18.380288 3.092845 5.260303 0.982665 -0.057618 0.646968 0.659551 0.400529
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 1.514961 1.133417 0.987185 0.965158 2.953845 2.006821 0.885028 1.369042 0.704810 0.698621 0.392670
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.229468 3.380016 8.425181 6.472110 0.383076 0.218441 0.678267 4.188046 0.708861 0.707597 0.387743
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.445458 0.352502 8.896811 5.329517 0.022319 -0.444832 1.267553 1.547002 0.712237 0.711178 0.379451
68 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 4.026868 44.415998 1.053125 64.598780 0.431926 22.084486 0.943716 13.594231 0.714728 0.032099 0.476549
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.044521 -1.537581 0.483385 -0.954043 1.821085 2.290087 0.282966 -0.135488 0.718887 0.719485 0.373739
70 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.473374 -1.059044 1.322642 2.051205 0.608612 -0.261643 -0.705060 -0.740017 0.727573 0.725652 0.371535
71 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 11.602251 0.243268 2.906336 1.801122 3.179037 1.177414 0.176364 -0.125422 0.736289 0.725555 0.363572
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 6.492644 -0.218124 1.957208 1.494457 2.900805 0.213170 1.039930 -0.554745 0.718286 0.719146 0.357595
73 N05 digital_ok 100.00% 100.00% 100.00% 0.00% 17.895244 19.248063 46.510286 47.166293 15.724823 22.929247 7.317139 4.517667 0.027094 0.027144 0.001227
74 N05 digital_maintenance 100.00% 100.00% 0.00% 0.00% 19.620448 16.433989 48.487595 46.540645 16.122339 20.315351 6.796229 20.315836 0.032417 0.371042 0.238309
75 N05 digital_maintenance 100.00% 0.00% 100.00% 0.00% 12.260863 20.847008 11.228710 48.918489 4.193957 23.244857 6.161294 6.830817 0.698732 0.048811 0.524358
77 N06 not_connected 100.00% 0.00% 0.00% 0.00% 37.347455 37.955594 16.394163 13.498049 7.578182 13.087120 6.987858 2.191756 0.580026 0.537738 0.191219
78 N06 not_connected 100.00% 0.00% 0.00% 0.00% 51.842239 1.176483 12.287622 16.094443 8.969338 3.566012 1.700402 2.591477 0.511658 0.675010 0.369177
81 N07 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
82 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
83 N07 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
84 N08 digital_ok 100.00% 0.00% 100.00% 0.00% 10.639442 39.380203 5.955230 62.496277 -1.063288 22.177391 -0.138290 9.026196 0.713030 0.042787 0.604296
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% 32.922565 12.846919 5.935019 0.326740 25.522703 2.012452 47.896734 0.655226 0.632121 0.731329 0.355392
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
89 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 1.855431 0.969831 -0.403443 0.411687 -0.596254 -0.857053 -0.764976 -1.201690 0.727252 0.719580 0.361059
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
91 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 1.072862 0.120143 -0.190044 -0.463554 0.101404 -0.941602 0.793922 -0.480814 0.723219 0.724301 0.371476
92 N10 RF_maintenance 100.00% 0.00% 16.17% 0.00% 65.173952 72.396930 5.699484 6.983538 12.785152 18.775223 3.948591 8.280432 0.310240 0.254212 0.094892
93 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 4.475263 -0.443217 7.938087 -0.033721 4.060312 -0.378855 4.660471 -1.016847 0.714046 0.716043 0.378483
94 N10 digital_ok 0.00% 0.00% 0.00% 0.00% -1.209173 -2.037541 0.067895 -0.491656 -0.112103 2.610187 1.060201 0.237317 0.717979 0.710487 0.384546
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 1.767975 8.417263 -0.588777 1.200336 0.498880 3.079188 2.413454 3.596971 0.683795 0.679184 0.386833
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 6.115521 0.062992 0.344688 1.418471 0.039219 4.904891 1.810404 0.043984 0.687275 0.689742 0.385553
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.178173 -1.317690 1.772522 -0.875779 -0.114881 -0.964983 -0.063565 -0.706394 0.699630 0.699456 0.382197
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 11.770080 15.636141 1.425764 1.075160 -0.520854 -1.304966 0.056322 -0.781156 0.718893 0.716358 0.377266
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% 100.00% 100.00% 0.00% 39.773209 39.948010 54.069626 55.116548 16.057931 23.158621 13.854256 13.112784 0.027483 0.027890 0.002002
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 11.503090 91.596221 4.684259 45.502150 1.028277 5.902738 -0.249116 1.227496 0.726519 0.659003 0.398018
105 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 0.447189 0.513383 -0.074828 0.538181 3.114895 -1.025044 -0.112667 -1.176418 0.729134 0.721496 0.360106
106 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 0.458726 2.240673 4.909002 2.467887 2.417078 -0.129253 0.163713 -0.830187 0.716343 0.716784 0.362459
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 digital_ok 100.00% 0.00% 0.00% 0.00% 14.037467 4.788360 43.271055 0.806095 9.388921 0.150980 4.101393 0.304946 0.446678 0.723588 0.495067
109 N10 digital_ok 100.00% 0.00% 100.00% 0.00% -0.577171 20.329675 1.484581 47.188873 -0.692103 22.976358 -0.125178 5.480149 0.727865 0.036229 0.488411
110 N10 RF_maintenance 100.00% 0.00% 100.00% 0.00% 0.369395 41.921092 -0.013539 63.113122 0.415380 22.298713 0.417732 8.124043 0.732708 0.033665 0.490851
111 N10 digital_ok 100.00% 0.00% 100.00% 0.00% -0.432658 20.160188 1.230610 47.705631 -0.862050 22.958408 -0.042121 6.399496 0.719390 0.036144 0.487181
112 N10 digital_ok 0.00% 0.00% 0.00% 0.00% -0.061693 -0.647421 -0.869130 1.739606 0.330979 0.322769 0.353000 -1.177335 0.707929 0.708032 0.390642
116 N07 digital_ok 100.00% 0.00% 0.00% 0.00% -0.593702 1.640142 0.467299 -0.718383 5.196341 1.313063 6.312531 1.140350 0.673544 0.680940 0.390019
117 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 20.613325 22.766893 47.429931 50.045702 15.979712 23.100610 5.994377 7.863425 0.027790 0.032552 0.004200
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.305220 1.702625 -0.272597 1.334434 1.070269 2.666313 0.601186 0.643921 0.699054 0.702376 0.382184
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.810958 4.067083 6.399231 14.413806 -0.489302 7.464507 -0.070667 0.582147 0.710887 0.673020 0.382838
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 4.797873 38.761279 -0.231946 62.189503 -0.071273 22.573622 0.000454 13.116683 0.715848 0.036651 0.608296
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 4.254009 8.916506 0.388384 0.554576 1.719915 -0.480397 33.070113 18.579897 0.724354 0.722388 0.376930
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 12.903796 12.292526 0.478006 0.777370 5.034311 -1.305668 0.060548 -0.964432 0.732548 0.727173 0.371992
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 10.059381 14.958908 0.964126 1.458700 -0.462569 0.342020 -0.273226 -0.033198 0.731974 0.727505 0.368699
124 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 0.094401 3.236401 -0.525141 -0.201210 -0.633665 -0.727503 0.360725 -0.203057 0.732704 0.722735 0.367960
125 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.174535 0.348249 -0.666880 1.093384 -0.715317 -0.794266 -0.466860 -1.174621 0.722652 0.718146 0.364793
126 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 50.069848 0.276187 3.762804 0.034499 7.610162 -0.416470 5.452317 -0.697796 0.606220 0.719214 0.354717
127 N10 digital_ok 0.00% 0.00% 0.00% 0.00% -0.034128 -0.022952 -0.245967 0.450158 1.015625 0.863859 -0.317444 -0.471694 0.729022 0.726805 0.376817
128 N10 digital_ok 100.00% 0.00% 0.00% 0.00% -1.461667 8.948507 5.165129 0.663342 -0.078170 2.278574 -0.216657 -0.755945 0.723016 0.706286 0.372507
129 N10 digital_ok 0.00% 0.00% 0.00% 0.00% -0.088067 -1.139256 -0.857148 -0.593794 0.061415 -0.743376 -0.436734 0.760272 0.720414 0.714916 0.384361
130 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 1.992908 -0.392726 -0.467107 -0.142348 0.943701 1.119489 -0.086964 5.028953 0.703710 0.705572 0.383674
135 N12 digital_maintenance 100.00% 0.00% 100.00% 0.00% -2.013755 20.241530 -0.864344 48.692772 1.060042 23.250300 2.991588 5.114406 0.676297 0.041051 0.483441
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 7.407884 1.331837 0.082849 0.605332 0.864779 5.093526 1.463177 1.831253 0.668414 0.679850 0.386274
137 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.611334 -0.511943 0.500623 3.775010 2.343828 6.234849 1.923157 0.788991 0.686194 0.682524 0.384659
138 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.598703 -0.271716 0.619853 1.511812 7.587927 -1.400601 3.497521 -0.465183 0.702921 0.702231 0.389337
140 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 6.583727 21.593530 31.912201 48.111599 10.133132 22.830059 2.313259 6.301059 0.697455 0.056233 0.497052
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -1.861263 8.752114 2.106817 35.061945 0.469728 17.142954 0.150687 0.671451 0.718458 0.696692 0.367398
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 2.163070 20.110744 0.130913 48.417289 3.839584 23.086065 1.095198 5.508557 0.717211 0.051332 0.515542
143 N14 digital_ok 100.00% 100.00% 0.00% 0.00% 19.409760 -1.827309 47.698685 0.152092 16.068645 -0.535178 4.694321 -0.810027 0.040062 0.728614 0.539983
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.911434 -0.357354 -0.682101 2.129941 0.976255 1.793590 -0.306803 1.395512 0.726850 0.723688 0.370828
145 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% -1.884007 6.072281 -0.598863 33.778296 8.092809 12.551133 0.490580 1.938450 0.724680 0.631493 0.392817
147 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 34.025874 -0.151849 2.832113 2.756120 6.926693 -1.331880 8.304915 -0.527080 0.662678 0.715125 0.365946
148 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 18.806729 21.045436 46.638875 48.218058 15.686521 22.887554 4.782177 4.334031 0.033431 0.032616 0.001021
149 N15 RF_maintenance 100.00% 19.60% 0.00% 0.00% -0.602005 5.162098 -0.455172 28.290392 99.937511 11.075726 2.822341 0.593574 0.608105 0.716792 0.402923
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 20.184019 20.296504 47.239342 48.341116 15.825354 23.102266 6.861780 6.282650 0.025894 0.028750 0.001330
151 N16 not_connected 100.00% 0.00% 0.00% 0.00% 43.681399 2.063088 13.019625 -0.182718 7.131518 4.854742 1.384402 -0.061808 0.552560 0.652601 0.380502
152 N16 not_connected 100.00% 0.00% 0.00% 0.00% 3.039365 2.336172 6.495836 10.521888 14.908232 3.083713 12.506338 0.203172 0.656514 0.670593 0.411745
153 N16 not_connected 100.00% 100.00% 0.00% 0.00% 19.792580 1.283045 19.349459 8.647361 15.928893 2.600220 5.480769 -0.563627 0.041769 0.661974 0.561772
154 N16 not_connected 100.00% 0.00% 0.00% 0.00% 0.346852 0.780062 17.457968 16.666499 4.144727 3.741881 0.164490 0.234113 0.653654 0.660156 0.417108
155 N12 digital_maintenance 100.00% 100.00% 0.00% 0.00% 18.567878 0.580335 45.686983 -0.816156 15.707056 7.119883 5.131036 3.672807 0.066728 0.681366 0.510587
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 14.193461 0.652830 44.376928 1.927923 13.652969 0.082139 4.176421 1.340305 0.366145 0.688301 0.459954
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% -0.373357 -0.368492 -0.067895 -0.728607 -0.568059 -0.303317 0.631128 -0.086363 0.690703 0.691735 0.391561
158 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 0.734960 -1.511108 1.420851 2.941476 1.410984 1.176062 4.414968 22.909660 0.704037 0.702681 0.396346
160 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.876032 -1.134980 1.068324 4.887257 -0.623377 0.017922 1.166805 -0.117162 0.713072 0.708824 0.375985
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.895836 45.936963 0.288621 5.216791 -0.647766 6.213847 0.205687 2.407092 0.716475 0.588833 0.336630
162 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 5.322720 2.456138 5.846182 18.356504 35.048572 19.443452 0.833921 1.406584 0.711293 0.696214 0.367094
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.549183 -2.228124 0.438508 -0.698836 -1.058133 0.828561 0.241660 0.077981 0.726762 0.712415 0.374669
164 N14 digital_ok 100.00% 0.00% 0.00% 0.00% -0.676779 -0.212093 5.586356 2.854748 10.832261 -0.322067 0.619432 1.651385 0.718109 0.722673 0.376079
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 30.599964 1.421536 35.106575 2.697602 10.102120 -1.099269 2.414322 -0.341850 0.455905 0.721545 0.407113
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 47.958119 14.310445 9.855049 43.723339 7.213168 19.287228 2.977651 2.116081 0.579082 0.379502 0.327790
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 86.251176 64.446872 8.135487 5.491994 25.955697 12.302980 84.723287 27.295288 0.489772 0.543542 0.169864
168 N15 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.886074 -0.732762 -0.812242 2.194487 0.270901 -0.717958 -0.030106 0.744378 0.722569 0.715684 0.384895
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 20.710030 20.458568 46.899886 47.364429 15.695782 22.974928 7.114515 4.901820 0.035171 0.039535 0.002346
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 3.465243 20.621554 -0.140959 6.573448 12.250503 9.396401 1.111189 3.334731 0.709516 0.677571 0.385932
171 N16 not_connected 100.00% 0.00% 0.00% 0.00% 2.657319 4.703965 8.637600 -0.051622 2.296967 4.122188 0.853848 0.000073 0.666054 0.628063 0.387313
173 N16 not_connected 100.00% 100.00% 100.00% 0.00% 22.391893 21.584573 17.638787 18.914244 15.713573 22.951032 7.801794 11.537321 0.040236 0.044362 0.005581
176 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
178 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
179 N12 digital_ok 100.00% 100.00% 99.19% 0.00% 20.498835 22.023647 47.958813 50.696707 16.096421 23.197487 5.176464 4.794833 0.050078 0.064920 0.013741
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% -1.591307 21.290162 -0.670099 49.013095 1.340842 23.192042 0.888791 6.364524 0.711688 0.056013 0.518939
181 N13 digital_ok 0.00% 0.00% 0.00% 0.00% -0.493863 -2.008465 0.189381 -1.040701 -0.749544 1.551918 -0.099169 3.281023 0.720298 0.708316 0.377959
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 3.941969 7.667735 26.502919 32.493300 3.633391 14.697279 6.787332 1.725235 0.671921 0.698872 0.388484
183 N13 digital_ok 100.00% 100.00% 0.00% 0.00% 19.767425 -1.253357 46.603901 0.266674 15.682881 -0.652262 4.626785 -0.338105 0.041441 0.709659 0.505637
184 N14 digital_ok 100.00% 72.45% 100.00% 0.00% 18.750437 20.798273 47.239224 48.493509 16.192713 23.066945 4.991797 4.597935 0.173102 0.044003 0.105313
185 N14 digital_ok 100.00% 100.00% 0.00% 0.00% 18.250348 -1.836404 47.364109 13.399043 15.891034 -0.490837 4.918985 0.066105 0.038984 0.701053 0.498486
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 1.787950 2.739587 6.407084 10.442952 11.020865 0.244956 0.568612 0.777636 0.718209 0.719350 0.381607
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 4.515100 4.286055 8.547958 25.259604 46.361963 9.376173 1.623545 2.154794 0.701816 0.711968 0.390624
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 1.685937 2.394510 1.844505 5.771667 -0.532177 1.893108 0.293839 0.233245 0.706222 0.704250 0.391886
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 73.839503 20.450793 6.490574 48.837030 12.450324 23.274610 43.282906 6.673234 0.509537 0.035407 0.366532
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 0.704200 -0.211268 0.690995 5.632981 0.580844 -0.363467 17.489447 2.675117 0.696009 0.698358 0.405501
192 N16 not_connected 100.00% 0.00% 0.00% 0.00% 10.041034 11.522239 37.665764 39.047975 20.208607 21.115516 1.701045 -0.069582 0.661441 0.650981 0.407233
193 N16 not_connected 100.00% 0.00% 0.00% 0.00% 10.718363 1.790995 38.168686 21.759365 13.947540 4.536181 0.880332 0.951069 0.641677 0.673368 0.429025
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_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
202 N18 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 22.510187 23.302482 18.419183 19.417861 15.732045 22.915483 7.309277 6.884025 0.034505 0.043606 0.001888
219 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 11.083591 7.737288 39.232315 32.933830 14.585293 14.597242 0.741092 -0.061867 0.644567 0.673820 0.405682
220 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 6.663228 8.353853 32.213955 32.927186 10.125863 15.262997 1.979772 -0.132429 0.698038 0.676860 0.391399
221 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 4.393606 1.746210 2.043612 14.361434 4.049348 2.385499 3.912026 0.712754 0.670231 0.679463 0.390953
222 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 8.035410 8.814805 33.659158 33.310590 11.661505 15.441023 2.146069 0.131450 0.692010 0.677208 0.393933
237 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 5.289273 3.263948 0.943607 11.398616 2.842305 2.565647 1.174745 0.156602 0.652088 0.658463 0.399044
238 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 2.045262 0.446301 20.880062 20.856355 4.610630 8.174366 0.459601 -0.246713 0.698780 0.677470 0.395712
239 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 1.602513 8.189436 17.236249 33.381244 1.418352 15.800755 0.694478 0.109506 0.694243 0.666696 0.398786
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
321 N02 not_connected 100.00% 0.00% 0.00% 0.00% 1.888743 2.181660 13.463526 15.724020 4.318066 4.985708 6.469786 4.025937 0.620894 0.597708 0.412195
322 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 3.488235 5.150253 16.408470 27.034825 3.590925 11.044544 1.852908 0.450134 0.608623 0.588161 0.406662
323 N02 not_connected 100.00% 0.00% 0.00% 0.00% 40.822198 3.659978 2.878289 24.618649 8.974173 8.841995 5.056553 1.144913 0.405398 0.583890 0.370309
324 N04 not_connected 100.00% 0.00% 0.00% 0.00% 3.042232 5.181539 20.609424 24.299572 3.388147 8.498967 0.933029 -0.218965 0.608884 0.588670 0.394171
325 N09 dish_ok 100.00% 0.00% 0.00% 0.00% 2.022240 0.043539 21.091256 10.734301 4.782004 2.979263 -0.079794 0.834693 0.641113 0.603437 0.402121
329 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 2.209985 0.091391 14.219708 15.845911 5.538534 5.419682 1.343784 0.112362 0.602650 0.597793 0.402600
333 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 7.186001 1.810595 -0.227490 10.366872 4.021876 2.873590 5.312867 2.824617 0.555314 0.583125 0.397155
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, 7, 8, 10, 18, 19, 20, 21, 22, 27, 28, 30, 32, 33, 34, 35, 36, 37, 38, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, 71, 72, 73, 74, 75, 77, 78, 81, 82, 83, 84, 85, 86, 87, 88, 90, 92, 93, 98, 99, 101, 102, 103, 104, 106, 107, 108, 109, 110, 111, 116, 117, 119, 120, 121, 122, 123, 126, 128, 130, 135, 136, 137, 138, 140, 141, 142, 143, 145, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 158, 160, 161, 162, 164, 165, 166, 167, 169, 170, 171, 173, 176, 177, 178, 179, 180, 182, 183, 184, 185, 186, 187, 189, 190, 191, 192, 193, 200, 201, 202, 203, 219, 220, 221, 222, 237, 238, 239, 320, 321, 322, 323, 324, 325, 329, 333]

unflagged_ants: [4, 5, 9, 15, 16, 17, 29, 31, 40, 41, 42, 45, 56, 65, 69, 70, 89, 91, 94, 100, 105, 112, 118, 124, 125, 127, 129, 144, 157, 163, 168, 181]

golden_ants: [5, 9, 15, 16, 17, 29, 31, 40, 41, 42, 45, 56, 65, 69, 70, 91, 94, 100, 105, 112, 118, 124, 127, 129, 144, 157, 163, 181]
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_2459869.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.4.dev20+g17344e9
3.1.5.dev171+gc8e6162
In [ ]: