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 = "2459868"
data_path = "/mnt/sn1/2459868"
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-15-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/2459868/zen.2459868.25282.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/2459868/zen.2459868.?????.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/2459868/zen.2459868.?????.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 2459868
Date 10-15-2022
LST Range 21.111 -- 7.133 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 58 / 180 (32.2%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 154 / 180 (85.6%)
Redcal Done? ❌
Never Flagged Antennas 26 / 180 (14.4%)
A Priori Good Antennas Flagged 76 / 98 total a priori good antennas:
3, 7, 10, 15, 17, 19, 20, 21, 29, 30, 31, 37,
38, 45, 46, 51, 53, 54, 55, 56, 66, 67, 68,
71, 72, 73, 81, 84, 85, 86, 93, 94, 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, 181, 183, 184,
185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 4 / 82 total a priori bad antennas:
89, 125, 137, 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_2459868.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% 8.296715 -1.016827 -0.105207 -0.228810 -0.091806 0.342855 0.055194 6.156703 0.678193 0.670799 0.405521
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 2.392898 5.243593 3.277361 -0.162765 0.523184 -0.437096 3.023589 -0.545674 0.689091 0.669099 0.402347
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.121427 -0.048211 -0.896003 1.818188 0.276441 1.042751 -0.276150 -1.411940 0.696828 0.673634 0.398130
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% -0.794141 -1.852378 0.615812 0.977852 0.321609 -0.055454 3.075866 28.050111 0.689777 0.675372 0.400205
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.188991 1.796528 1.435795 0.128742 -0.467648 -0.607723 12.027355 1.169021 0.685824 0.658401 0.392925
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.205267 -1.685876 0.264140 0.066335 -0.055765 -1.064027 0.265437 1.354017 0.686590 0.665679 0.404707
10 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 23.410832 -0.313683 3.543999 2.645545 4.401208 2.972902 2.795277 1.206921 0.668231 0.660286 0.408421
15 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 1.868418 0.837690 1.858008 -0.801198 -0.219265 -0.206345 7.988179 10.801114 0.699558 0.679219 0.398955
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -0.422411 1.090735 -0.865019 -0.602967 -0.502261 0.329920 3.798340 3.574743 0.701073 0.676706 0.394739
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% -0.334175 1.271760 -0.239639 0.525727 0.954738 -0.288303 6.589433 3.615738 0.697518 0.684400 0.391770
18 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 7.478493 21.433128 1.789509 1.432369 3.035352 7.019081 32.552572 49.891176 0.678532 0.453592 0.445586
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 1.959936 -0.978129 0.769624 1.894856 0.009830 27.688494 23.027561 26.524295 0.689726 0.684956 0.400379
20 N02 digital_ok 100.00% 0.00% 0.00% 0.00% -0.895722 5.437480 0.165625 21.979635 0.202769 1.546127 2.853143 -1.382958 0.697027 0.670681 0.398592
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 1.892664 1.194323 -0.902443 -0.984708 0.252428 -0.040218 1.866703 10.448967 0.682766 0.666514 0.401581
22 N06 not_connected 100.00% 0.00% 0.00% 0.00% 52.638190 17.428418 6.011980 23.429689 5.094809 5.770260 13.123284 23.232929 0.450322 0.608411 0.336617
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 20.567864 22.716616 71.548779 72.234008 10.827541 17.146143 7.113676 4.419824 0.032969 0.037779 0.003222
28 N01 RF_maintenance 100.00% 0.00% 87.59% 0.00% 25.450275 49.122340 9.091916 5.826895 8.261257 17.044936 10.475097 36.296293 0.352919 0.151288 0.226752
29 N01 digital_ok 100.00% 0.00% 0.00% 0.00% -1.578922 -0.521890 -1.098237 0.130392 -1.063250 0.383160 0.234388 9.353205 0.703889 0.681374 0.386498
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 0.053476 -1.131520 1.108063 -1.274548 26.474534 -1.200500 23.227067 1.468838 0.696871 0.686532 0.388906
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 0.128890 2.007089 1.240347 0.126934 -0.213465 3.156097 4.846149 5.711516 0.711289 0.683333 0.399735
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 22.383363 35.433211 6.464819 5.166920 15.538428 16.293584 18.588584 96.698230 0.612870 0.614216 0.289693
33 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.108798 24.386704 -0.932270 1.578524 -1.129884 7.601618 5.704235 53.332911 0.689343 0.486892 0.473702
34 N06 not_connected 100.00% 100.00% 0.00% 0.00% 23.497547 5.465284 29.874297 22.499324 10.816703 1.753541 3.223499 -1.207246 0.041842 0.652165 0.534887
35 N06 not_connected 100.00% 0.00% 0.00% 0.00% 4.834215 2.540069 2.431988 10.215228 7.754186 3.299059 7.842010 0.035813 0.597829 0.635022 0.422232
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 16.152142 14.573125 1.211722 0.799232 0.996266 1.694226 1.896962 1.037172 0.695872 0.679045 0.408278
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.742060 1.461002 -0.508733 0.541422 1.768758 -0.101448 0.118596 14.273030 0.701617 0.686146 0.406518
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.509126 0.209950 -1.093322 -1.110452 0.394698 0.698240 11.651816 3.818534 0.705833 0.690981 0.404810
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.256759 0.684353 -1.116696 -1.052649 0.738119 -1.401782 -0.680536 -1.290563 0.700962 0.684056 0.393842
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.288260 0.838042 1.574053 1.836984 0.858598 -1.196501 -0.668445 0.521377 0.707834 0.686556 0.384839
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% -0.630064 1.433750 0.274643 1.938481 -0.885464 -0.980777 0.394663 -0.292444 0.714161 0.695289 0.394715
43 N05 digital_maintenance 100.00% 100.00% 0.00% 0.00% 19.340845 1.967850 70.729441 -0.830048 10.864956 -0.733798 4.708628 3.669914 0.039290 0.692004 0.500003
44 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 56.724739 2.515693 6.439467 4.740083 5.741582 0.389021 42.386621 15.519064 0.602149 0.689351 0.364751
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 digital_ok 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% 0.00% 0.00% 22.192855 6.012976 28.505254 16.673891 10.858139 2.596095 3.019204 6.733639 0.038671 0.651546 0.536665
48 N06 not_connected 100.00% 0.00% 0.00% 0.00% 4.020999 4.346947 30.984705 38.096328 2.333233 4.183318 -1.289881 -4.048758 0.666922 0.664904 0.414486
49 N06 not_connected 100.00% 0.00% 0.00% 0.00% 2.720815 2.733142 9.732585 32.256470 1.974577 4.793052 1.219594 -0.715860 0.635858 0.649881 0.419282
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 2.483507 43.065358 -0.502210 6.136225 1.311400 7.011675 7.041064 50.666982 0.688319 0.586872 0.370456
51 N03 digital_ok 100.00% 100.00% 0.00% 0.00% 43.930187 1.880828 92.086614 0.234854 10.455207 3.330935 22.337514 12.852773 0.037399 0.686655 0.488740
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 12.762442 11.502583 0.718358 0.354933 3.170952 -0.864707 1.950766 0.746702 0.705782 0.692682 0.391976
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 1.108767 4.507535 -0.885406 0.518652 -0.494869 0.375751 6.458056 11.523238 0.711094 0.699545 0.397638
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 20.616646 23.980159 71.583892 73.992197 10.874684 17.142676 5.646646 2.448243 0.044393 0.044437 0.001632
55 N04 digital_ok 100.00% 0.00% 100.00% 0.00% 4.058430 25.191118 1.448087 73.278173 7.069325 17.092242 9.992352 6.604083 0.700968 0.035043 0.503784
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 0.449265 1.516659 0.627440 -0.538532 0.622425 1.894469 1.952212 19.548051 0.707870 0.695714 0.374539
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 57.139856 0.217640 32.130971 -0.820618 4.708712 0.595309 4.955229 1.166883 0.539559 0.696877 0.373699
58 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 19.913826 23.660412 71.220454 73.638130 10.944404 17.236357 7.210589 5.565003 0.036337 0.033425 0.001828
59 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 40.582475 7.807995 6.103741 -0.114460 4.488019 3.739598 15.919398 28.000630 0.634544 0.678300 0.373462
60 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 21.446232 23.188865 71.419188 73.451265 10.873098 17.169837 5.101590 6.324870 0.027324 0.026996 0.001477
61 N06 not_connected 100.00% 0.00% 0.00% 0.00% 7.283106 7.020095 5.295222 0.280366 2.236562 4.028282 1.031400 6.574727 0.648761 0.628228 0.387634
62 N06 not_connected 100.00% 0.00% 0.00% 0.00% 3.048414 4.353997 24.905520 35.288954 1.411684 5.597175 0.802807 -2.499621 0.669830 0.668129 0.404033
63 N06 not_connected 100.00% 0.00% 100.00% 0.00% 1.449726 23.767748 24.980101 30.041278 0.593395 17.095811 0.465842 6.355544 0.652764 0.043478 0.583153
64 N06 not_connected 100.00% 0.00% 0.00% 0.00% 4.417820 2.668104 15.045796 29.078433 3.020114 3.368893 3.188595 -2.309898 0.625316 0.633662 0.420534
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 1.459564 1.013365 0.645511 1.942672 1.453552 1.254466 -0.280633 -0.440638 0.686220 0.677180 0.415560
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.047924 2.541619 15.558148 9.377368 1.964364 -0.209414 0.371135 2.345490 0.691079 0.684869 0.408279
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.946622 -0.141198 8.575256 4.607533 -0.217253 0.063417 2.418120 4.863871 0.696868 0.689081 0.396931
68 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 4.744442 48.871981 2.247543 98.381875 0.152377 16.430924 1.710824 21.292642 0.697707 0.030903 0.459880
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.444950 -0.664629 -0.284305 -0.098799 1.432359 1.313675 0.035438 0.338916 0.703982 0.697250 0.387686
70 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 1.023856 0.080795 0.703470 1.838417 0.055765 -0.353632 0.289357 0.595640 0.710133 0.702976 0.384627
71 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 12.592779 -0.143079 3.969399 2.364782 0.127152 0.925846 0.626032 0.754839 0.720269 0.702208 0.380295
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 6.129744 -0.638166 2.765472 1.876204 1.588163 0.644046 7.326231 -0.211137 0.702134 0.695600 0.373651
73 N05 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
74 N05 digital_maintenance 100.00% 100.00% 0.00% 0.00% 21.304909 20.108455 73.607070 70.985115 11.047709 15.270606 5.945543 43.750675 0.031004 0.317763 0.208613
75 N05 digital_maintenance 100.00% 0.00% 100.00% 0.00% 14.346831 24.097205 17.397890 74.249961 5.319025 17.271944 27.903217 7.090421 0.672575 0.044749 0.516720
77 N06 not_connected 100.00% 0.00% 0.00% 0.00% 41.972064 44.416995 25.919093 21.237595 4.664554 9.316459 27.377798 4.954844 0.556801 0.499875 0.211846
78 N06 not_connected 100.00% 0.00% 0.00% 0.00% 59.970547 1.523328 19.131307 25.796779 6.244468 2.386340 2.354195 -0.289606 0.481069 0.649168 0.381436
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% -0.013759 -0.563636 -1.021288 8.986686 0.620130 22.711814 0.114617 -0.325814 0.662030 0.648532 0.408905
82 N07 RF_maintenance 100.00% 0.00% 32.81% 0.00% 1.465197 0.997946 -0.320395 20.766093 1.464788 85.834680 0.310416 2.241166 0.671044 0.473314 0.491881
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.398539 -0.540490 -0.929126 0.518011 -0.625517 -0.279819 -0.855400 0.923997 0.688987 0.681690 0.397039
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
85 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 0.740771 1.132935 4.103263 4.282653 -1.374338 -0.237597 -0.378538 -0.773230 0.700235 0.687045 0.393766
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 2.947864 14.764934 10.071302 5.585892 5.544370 1.527458 1.308524 41.493723 0.690103 0.647117 0.381052
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 6.792552 12.768516 0.071963 0.788359 1.468071 1.928713 5.094611 2.532076 0.710752 0.710211 0.381234
88 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 1.608036 1.267678 1.697657 0.422715 -0.880094 1.274695 -0.387081 -1.107474 0.703385 0.696415 0.376938
89 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 1.981387 -0.089938 -0.900662 0.219853 0.482825 -0.468472 -0.777028 -0.947980 0.709772 0.695234 0.380844
90 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.445806 0.284917 -0.022870 1.257792 -0.960806 0.023864 1.209035 8.434297 0.704361 0.691859 0.378771
91 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 1.305864 -1.054144 -0.162139 0.217321 -0.208178 -0.665356 2.617569 -0.109586 0.698129 0.697733 0.393365
92 N10 RF_maintenance 100.00% 3.17% 25.40% 0.00% 68.285277 76.852203 8.601872 10.406761 9.177231 15.757058 0.793271 10.681727 0.277639 0.234073 0.095913
93 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 4.312155 1.230206 11.136995 -0.749146 2.900263 -0.494306 12.909060 -0.904805 0.686976 0.686448 0.401482
94 N10 digital_ok 100.00% 0.00% 0.00% 0.00% -1.148650 -1.504798 -0.895117 -1.342711 0.809609 4.662832 5.426549 7.801611 0.689224 0.678401 0.408679
98 N07 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
99 N07 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.121038 -1.049795 1.279013 -1.143802 1.290059 -1.176659 0.857181 -0.911985 0.680849 0.670331 0.398755
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 12.782474 15.787263 2.789701 2.667903 0.259247 -1.167517 0.571296 -0.657073 0.703021 0.689020 0.393005
102 N08 RF_maintenance 100.00% 6.55% 100.00% 0.00% 18.523990 24.883868 69.311622 73.817269 8.995979 17.196365 3.054421 11.130770 0.329887 0.039174 0.261393
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 42.272051 44.345322 82.340803 84.036502 11.121309 17.182386 21.862331 19.658650 0.027022 0.027788 0.001984
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 12.623174 100.750502 5.526161 67.507395 1.096543 1.346890 0.416211 0.204330 0.709865 0.631339 0.420939
105 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.033521 -0.685355 0.066749 0.506661 0.142622 -0.327067 -0.035438 -1.133466 0.708505 0.695495 0.377962
106 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 0.526825 1.262297 5.203437 2.271930 2.673172 0.309458 1.107947 -0.309746 0.699238 0.690694 0.379499
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 3.077846 -0.811556 0.235631 4.863548 -0.372047 -0.780444 3.102030 5.329099 0.701632 0.696555 0.377832
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 11.942251 4.692032 60.637772 0.403338 5.885892 0.228934 2.438590 2.346957 0.512401 0.696426 0.468356
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% -0.240190 0.061460 -0.880922 1.179100 -0.493679 0.580761 2.997311 -0.845115 0.684395 0.678761 0.413240
116 N07 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
117 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 22.304365 26.017723 71.870193 75.851339 10.943874 17.145700 4.221099 9.615364 0.027514 0.031857 0.003585
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.568621 1.255103 -1.151287 0.549411 1.541955 0.624965 1.599071 1.666342 0.679936 0.673608 0.403063
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.788213 5.051819 9.114863 20.294041 -1.482480 13.615965 0.045233 1.999133 0.693021 0.640399 0.402709
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 5.123365 42.737019 -0.446641 94.646588 1.458224 16.780726 4.709616 20.323857 0.700212 0.034426 0.581481
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 14.690091 12.959975 0.895303 1.584106 2.428285 -1.450877 0.290597 -1.087334 0.716551 0.699789 0.389750
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
124 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.477373 0.033521 -0.259312 0.121616 0.146318 -0.886837 0.834770 0.166906 0.715179 0.702979 0.385898
125 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.643062 0.987327 -0.596667 -0.066335 -0.703829 -0.115757 -0.436702 -1.143637 0.707329 0.690676 0.378846
126 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 55.534580 -0.492811 6.536564 0.936181 7.257356 -1.063985 18.726981 -0.698447 0.587024 0.690995 0.369640
127 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.507295 0.159172 -0.560037 -0.643932 0.584093 0.373203 0.469756 3.387492 0.703920 0.697698 0.396414
128 N10 digital_ok 100.00% 0.00% 0.00% 0.00% -1.038612 11.395659 7.809225 3.547169 0.176399 2.699547 0.007347 -0.404079 0.696957 0.673763 0.397904
129 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.814030 -1.581360 -0.972687 -0.620397 -0.651649 -0.534522 -0.558057 -0.515609 0.695227 0.686279 0.410059
130 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 1.749598 0.503984 -0.708584 -0.701057 0.920505 -0.273153 0.503147 6.286309 0.680724 0.676823 0.408030
135 N12 digital_maintenance 100.00% 0.00% 100.00% 0.00% -1.944416 23.419514 0.369492 73.871752 0.247176 17.269039 0.700559 3.254473 0.652432 0.037781 0.477273
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 5.567589 2.524923 0.510359 0.410526 0.357332 -0.778060 0.504281 -0.499000 0.645178 0.646051 0.409558
137 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 1.161929 -1.424107 1.398424 -0.246002 1.910739 3.113201 1.409928 -0.116467 0.664277 0.654192 0.408703
138 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.662161 -0.860335 1.093386 2.415694 -1.253480 -0.587034 14.242851 -0.421198 0.683077 0.670646 0.411667
140 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 6.694058 24.726407 50.568205 72.776705 6.274635 17.013296 -0.721916 6.585192 0.687723 0.048823 0.508426
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -2.105454 8.966119 1.747326 56.387994 0.301233 12.199325 1.056394 -6.496790 0.699713 0.671549 0.386733
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 2.386029 23.267216 1.629178 73.369344 1.061218 17.149026 2.111522 4.392249 0.697789 0.046686 0.515642
143 N14 digital_ok 100.00% 100.00% 0.00% 0.00% 21.021881 -1.975863 72.374785 -1.280365 11.023393 -0.107960 1.598041 -1.164510 0.037721 0.698928 0.517893
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -1.020841 -0.185530 -1.278241 -0.807249 -0.849144 0.625878 -0.510939 1.871489 0.708914 0.696700 0.388983
145 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% -2.129127 3.813391 0.413327 37.347730 3.075640 19.319958 0.779226 2.169530 0.706979 0.642813 0.400222
147 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
148 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
149 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 21.867615 23.473369 71.526221 73.246728 10.856529 17.177260 5.831566 6.081510 0.025854 0.028195 0.001171
151 N16 not_connected 100.00% 0.00% 0.00% 0.00% 50.298098 3.976242 19.079990 -0.412111 5.009941 4.211675 3.843028 -0.456801 0.524792 0.614821 0.393005
152 N16 not_connected 100.00% 0.00% 0.00% 0.00% 3.217057 3.461758 9.543604 17.043388 0.926596 1.711917 19.923912 -1.467115 0.630433 0.640058 0.427947
153 N16 not_connected 100.00% 100.00% 0.00% 0.00% 21.453192 2.295431 28.100379 17.531905 10.903811 1.528027 3.282867 -1.370814 0.040362 0.634907 0.536700
154 N16 not_connected 100.00% 0.00% 0.00% 0.00% -0.414787 0.430772 26.914131 26.504147 1.187925 2.297351 -1.070529 -1.236617 0.632356 0.633338 0.433802
155 N12 digital_maintenance 100.00% 100.00% 0.00% 0.00% 20.052181 -1.215886 69.018009 -0.154400 10.754234 2.081636 2.835587 7.787500 0.047487 0.648589 0.489348
156 N12 digital_ok 100.00% 30.34% 0.00% 0.00% 17.012701 -0.388718 68.640614 2.023053 9.768649 0.235325 4.533086 1.745971 0.269453 0.657292 0.478716
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% -0.118012 -0.069567 0.449233 -0.162490 -0.831571 0.683626 -0.130973 0.643089 0.669292 0.660545 0.414052
158 N12 digital_ok 100.00% 0.00% 0.00% 0.00% -0.440059 -0.715355 0.371746 2.220548 1.579262 0.432191 7.374366 66.128780 0.683874 0.672175 0.417456
160 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.927893 -0.934988 2.411898 5.481968 -0.496004 0.548782 2.482476 4.068226 0.696007 0.681309 0.395009
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.730773 49.951335 -0.227386 9.006257 -0.853778 4.992799 0.197361 5.062141 0.699508 0.551413 0.358926
162 N13 digital_ok 100.00% 70.41% 0.00% 0.00% 20.310736 0.532503 70.408832 16.041293 10.224511 37.465318 3.362857 3.403474 0.161353 0.675088 0.495962
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.688839 -1.937442 0.775620 -1.244764 -1.119164 0.451605 0.516307 2.322388 0.708990 0.683995 0.394647
164 N14 digital_ok 100.00% 0.00% 0.00% 0.00% -0.813332 -0.912375 1.657973 3.561281 10.198822 -0.308138 1.889298 2.735819 0.703035 0.692448 0.392362
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 33.641879 0.482070 52.818323 4.155348 6.606349 -1.081202 0.557796 -1.156441 0.425427 0.692631 0.416808
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 53.087676 13.991602 12.601340 63.174404 3.896473 8.464133 9.982213 -0.126480 0.556890 0.407710 0.325484
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 84.764888 74.465085 10.997144 8.949065 18.189888 9.617820 139.704980 85.620678 0.472690 0.503439 0.172815
168 N15 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.925728 -1.384467 -0.414664 2.415466 -0.794458 0.095135 -0.503360 2.884891 0.698050 0.690074 0.408909
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 22.369292 23.585237 70.876766 71.663613 10.768399 17.114544 6.447330 3.212496 0.033034 0.036165 0.002018
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 36.964576 54.842383 3.970834 7.568327 19.885349 12.266356 7.227314 29.035805 0.601475 0.574584 0.322988
171 N16 not_connected 100.00% 0.00% 0.00% 0.00% 3.025237 6.695055 13.259288 1.374835 0.804435 3.966367 0.132027 0.238495 0.639092 0.593039 0.403864
173 N16 not_connected 100.00% 100.00% 100.00% 0.00% 24.316535 24.868718 25.209515 27.266349 10.716171 17.049818 8.729845 14.818265 0.036108 0.040497 0.004701
176 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 389.855492 390.318100 inf inf 7950.066361 7331.066870 18020.907095 15933.948173 nan nan nan
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 385.548715 386.261843 inf inf 7416.894623 7291.802814 15685.287203 15489.964516 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% 100.00% 0.00% 22.270817 25.360969 72.841791 77.064083 11.100580 17.144648 4.393412 4.889494 0.045746 0.063656 0.016876
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% -1.426475 24.590734 -0.781573 74.345981 0.233013 17.218584 0.700221 5.731783 0.692647 0.051492 0.524564
181 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 0.001751 -1.074135 -0.012069 -1.024353 0.830003 0.756779 0.955994 11.396743 0.703618 0.681356 0.395665
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 5.298850 6.800134 42.978242 51.709383 1.820901 10.535610 11.158975 22.113419 0.641422 0.678042 0.408010
183 N13 digital_ok 100.00% 100.00% 0.00% 0.00% 21.115458 -0.133576 66.394147 6.392803 10.778689 -0.791185 0.870762 -0.434550 0.041024 0.682265 0.500312
184 N14 digital_ok 100.00% 62.67% 100.00% 0.00% 19.770115 23.970926 71.053215 73.392975 8.734553 17.072017 2.407822 2.669103 0.186417 0.039488 0.121523
185 N14 digital_ok 100.00% 100.00% 0.00% 0.00% 19.797288 -1.039997 71.693141 21.869987 10.866157 0.033299 1.990136 -0.274174 0.038008 0.667318 0.481542
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 2.327709 2.504524 5.310387 16.198558 2.085367 -1.064282 4.245645 2.298570 0.702779 0.693122 0.399902
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 5.005559 3.703514 2.949514 39.774169 45.543596 5.894010 1.630907 0.200299 0.691364 0.687049 0.409139
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 1.786843 3.021844 3.040971 -0.393798 -0.613039 10.465915 8.229610 18.758938 0.681946 0.674076 0.411852
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 84.831493 23.594314 11.281403 74.114247 10.281194 17.303647 82.251096 6.981084 0.472672 0.034097 0.334816
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 0.843987 1.486795 1.348159 4.713770 -0.458455 1.532847 28.189838 17.545721 0.673268 0.664260 0.421384
192 N16 not_connected 100.00% 0.00% 0.00% 0.00% 6.979715 12.355897 52.403580 63.223207 17.897349 15.726621 -4.466429 -8.084488 0.654881 0.625943 0.425457
193 N16 not_connected 100.00% 0.00% 0.00% 0.00% 11.895061 2.483904 62.012592 38.535546 9.660038 5.135769 -7.336948 -1.007841 0.625382 0.646312 0.440850
200 N18 RF_maintenance 100.00% 100.00% 74.38% 0.00% 23.537277 63.230600 28.252874 29.551919 10.704571 14.651193 5.037306 12.687675 0.047935 0.191181 0.119753
201 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 12.251745 10.681634 61.885678 59.409422 9.521362 14.078982 -7.202218 -6.967270 0.659154 0.641674 0.394899
202 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 3.181216 6.149819 29.369944 2.153864 -0.025493 4.729124 2.714894 8.242498 0.687372 0.624205 0.402510
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 24.429259 26.652699 26.522537 28.064608 10.771902 17.029851 6.872570 7.489175 0.034882 0.041501 0.001023
219 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 11.948755 7.858529 62.935582 53.055764 9.798520 10.598160 -7.608572 -6.004916 0.630371 0.651412 0.416514
220 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 6.818532 8.387036 51.480356 52.735732 6.239453 10.527035 -1.354253 -6.345756 0.684345 0.656196 0.405975
221 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 8.005397 2.693926 2.551482 23.856669 3.042051 1.775659 6.434519 0.157530 0.640138 0.653047 0.407687
222 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 8.279266 9.177753 53.649477 53.455054 7.030111 11.143419 -1.639795 -6.342585 0.675106 0.654183 0.409165
237 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 6.670616 4.671025 0.967685 17.610219 2.931206 3.096917 0.154475 -1.269698 0.624731 0.629014 0.415650
238 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 1.610412 1.094598 32.777994 31.834923 2.587249 4.316445 -2.367460 -3.193721 0.680868 0.652006 0.411607
239 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 1.230458 6.738686 22.665147 2.044879 9.070761 4.578906 5.142431 29.531160 0.675675 0.587266 0.430912
320 N03 dish_maintenance 100.00% 0.00% 100.00% 0.00% 1.832617 24.362345 -0.817558 45.992757 0.062896 17.107899 18.235260 7.803036 0.673739 0.047070 0.513574
321 N02 not_connected 100.00% 0.00% 0.00% 0.00% 2.249024 1.889202 20.390730 24.061146 3.145488 3.065383 10.376338 6.201073 0.597079 0.576788 0.421335
322 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 3.470107 4.933542 25.304340 42.399518 1.294638 7.770337 0.823705 -3.408858 0.590004 0.570982 0.416587
323 N02 not_connected 100.00% 0.00% 0.00% 0.00% 44.590031 4.218564 5.275491 41.498738 5.173933 7.262344 9.582752 -1.600118 0.377169 0.561289 0.375123
324 N04 not_connected 100.00% 0.00% 0.00% 0.00% 3.182892 5.256453 33.172944 38.814478 2.729929 5.270325 -0.132982 -3.422156 0.589076 0.564065 0.405259
325 N09 dish_ok 100.00% 0.00% 0.00% 0.00% 1.894437 -0.030776 33.580393 17.510979 2.711678 1.611812 -2.326842 0.434429 0.621168 0.578097 0.413025
329 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 9.965764 0.284005 7.338753 20.619761 32.418197 2.326592 11.384560 0.570182 0.483243 0.571627 0.420537
333 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 8.683998 3.671197 -0.075784 15.960139 2.884916 5.096820 3.345117 0.688410 0.529014 0.555218 0.407743
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, 8, 10, 15, 17, 18, 19, 20, 21, 22, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, 71, 72, 73, 74, 75, 77, 78, 81, 82, 84, 85, 86, 87, 90, 92, 93, 94, 98, 99, 101, 102, 103, 104, 106, 107, 108, 109, 110, 111, 116, 117, 119, 120, 121, 122, 123, 126, 128, 130, 135, 136, 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, 181, 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: [5, 9, 16, 40, 41, 42, 65, 69, 70, 83, 88, 89, 91, 100, 105, 112, 118, 124, 125, 127, 129, 137, 144, 157, 163, 168]

golden_ants: [5, 9, 16, 40, 41, 42, 65, 69, 70, 83, 88, 91, 100, 105, 112, 118, 124, 127, 129, 144, 157, 163]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H6C_Notebooks/_rtp_summary_/rtp_summary_table_2459868.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 [ ]: