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 = "2459865"
data_path = "/mnt/sn1/2459865"
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-12-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/2459865/zen.2459865.25276.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/2459865/zen.2459865.?????.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/2459865/zen.2459865.?????.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 2459865
Date 10-12-2022
LST Range 20.913 -- 6.934 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 N09
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 71 / 180 (39.4%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 148 / 180 (82.2%)
Redcal Done? ❌
Never Flagged Antennas 23 / 180 (12.8%)
A Priori Good Antennas Flagged 76 / 98 total a priori good antennas:
3, 7, 10, 15, 17, 19, 20, 21, 29, 30, 31, 37,
42, 45, 46, 51, 54, 55, 56, 65, 66, 67, 68,
71, 72, 73, 84, 86, 88, 91, 93, 94, 98, 99,
101, 103, 105, 106, 107, 108, 109, 111, 117,
118, 121, 122, 123, 124, 128, 140, 141, 142,
143, 147, 156, 158, 160, 161, 162, 164, 165,
167, 169, 170, 176, 178, 179, 181, 183, 184,
185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 1 / 82 total a priori bad antennas:
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_2459865.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.410978 -0.186479 3.268034 5.004698 0.460621 -0.316748 0.572737 4.504696 0.711817 0.699413 0.363734
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 2.773217 4.412321 1.824017 -0.199646 0.256370 -0.023405 0.938860 0.589956 0.724454 0.699711 0.361595
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -0.799625 -0.638106 -1.157246 0.447150 1.420421 2.350119 0.675958 0.358973 0.730407 0.705219 0.356743
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 0.143061 -1.321779 11.356302 7.417229 1.147497 0.635850 2.440373 9.701686 0.717784 0.700003 0.358150
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 2.395354 1.391440 18.600494 21.867051 0.222936 0.662294 8.789474 2.903037 0.724756 0.692208 0.363200
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 1.119908 -0.786549 -0.877930 0.139326 1.735447 -0.590388 1.490691 2.363273 0.723888 0.696597 0.367599
10 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 7.589261 0.521942 14.039909 13.052654 6.202671 3.435899 4.189152 1.309642 0.712793 0.692876 0.377276
15 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 2.117690 1.468082 5.143753 7.819212 0.182597 -1.048629 4.329423 2.554061 0.732417 0.706648 0.357778
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -1.456716 1.436148 -1.259163 0.622404 -0.200366 0.697524 1.523594 2.957048 0.740741 0.708220 0.358585
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 0.040147 1.501720 10.589864 7.700370 0.666343 -0.124387 2.926420 1.623311 0.725578 0.709959 0.350759
18 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% -0.056444 15.959453 1.422859 1.946354 -0.706229 6.486690 0.695315 21.231068 0.727661 0.516491 0.420510
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 2.228874 -0.648260 0.110592 -0.893922 0.295017 4.152896 8.627921 6.869811 0.726517 0.713100 0.358435
20 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 0.768039 5.121387 12.264599 47.794108 0.554835 13.462175 3.423049 7.907615 0.733993 0.683949 0.379084
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 1.410722 0.289666 -0.876000 -0.248364 0.991496 0.943980 1.698231 7.207218 0.719233 0.700489 0.362227
22 N06 not_connected 100.00% 0.00% 0.00% 0.00% 49.419683 27.542090 6.974083 23.207398 5.147654 16.507924 9.040095 5.766451 0.518621 0.627976 0.294467
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 18.146644 20.487109 64.267410 65.768370 15.674992 24.015627 15.624123 12.944328 0.031069 0.035339 0.002844
28 N01 RF_maintenance 100.00% 0.00% 68.64% 0.00% 24.657272 46.497054 8.246842 5.376358 10.847397 18.369052 15.933727 25.404317 0.394453 0.181247 0.238779
29 N01 digital_ok 100.00% 0.00% 0.00% 0.00% -0.971203 0.065415 8.298982 5.806993 -0.616478 -1.271183 0.554501 2.914943 0.730476 0.709695 0.345860
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 1.004908 -0.574047 0.274650 -1.092353 -0.215993 -0.789811 9.748402 0.381663 0.731777 0.718853 0.346930
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 0.656707 2.751231 6.164125 -0.658249 0.959133 2.275578 2.776702 5.632381 0.745790 0.715852 0.357276
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 2.012407 41.340523 1.440347 5.605064 -0.711879 13.446474 1.925953 19.748635 0.725006 0.649958 0.329800
33 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.866377 26.809381 8.234844 11.620753 -0.441467 10.459907 4.534929 16.703583 0.723775 0.523109 0.444399
34 N06 not_connected 100.00% 100.00% 0.00% 0.00% 21.093035 5.793511 25.011636 23.147563 15.663070 1.244766 14.653784 3.777182 0.039204 0.680750 0.512092
35 N06 not_connected 100.00% 0.00% 0.00% 0.00% 5.967997 3.516952 2.374233 8.918071 4.742289 4.751411 4.923008 1.409489 0.632033 0.665105 0.383684
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 14.800719 13.932980 0.887162 0.851410 2.212603 3.235887 1.631069 0.202479 0.728954 0.704005 0.371166
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.469776 0.600503 10.505802 11.149718 -1.242030 0.692167 1.774145 4.071597 0.733608 0.709674 0.368421
38 N03 digital_ok 0.00% 0.00% 0.00% 0.00% -0.240715 -0.367509 -0.466585 -1.139526 1.734511 0.815374 2.960270 0.394665 0.740193 0.716400 0.367095
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.818044 -0.015059 0.013455 -1.028894 1.386122 -0.803969 -0.505659 -0.933213 0.734550 0.711982 0.358074
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.811883 1.767554 0.219241 1.182837 0.237784 -0.588013 -0.358379 -0.037246 0.737312 0.712479 0.349960
42 N04 digital_ok 100.00% 0.00% 0.00% 0.00% -0.261525 1.974646 6.054942 7.584273 -0.883473 -0.463252 0.160774 0.606782 0.741925 0.721997 0.354740
43 N05 digital_maintenance 100.00% 100.00% 0.00% 0.00% 16.916118 5.120316 63.524402 4.288722 15.787720 0.223445 15.356300 1.223817 0.036700 0.715581 0.468307
44 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 5.407649 3.070249 -0.414167 -0.397333 2.499991 -0.054108 11.994124 1.445886 0.726161 0.719826 0.342557
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% -0.394062 5.058606 -0.973553 0.879410 1.377579 3.673567 -0.272328 13.695917 0.738845 0.704300 0.351911
46 N05 digital_ok 100.00% 0.00% 100.00% 0.00% -0.338680 21.239155 3.265823 66.007686 1.134403 23.927005 1.236468 13.567267 0.730388 0.034444 0.502351
47 N06 not_connected 100.00% 100.00% 0.00% 0.00% 19.759527 6.505795 23.779118 15.940248 15.771018 3.803390 14.743785 4.757614 0.036288 0.682043 0.514339
48 N06 not_connected 100.00% 0.00% 0.00% 0.00% 4.914315 3.896774 29.589316 36.936844 3.915458 6.198334 6.856215 5.697046 0.701028 0.691663 0.382486
49 N06 not_connected 100.00% 0.00% 0.00% 0.00% 2.566837 2.343867 22.926811 30.490103 2.887474 6.537051 5.745669 4.302264 0.689121 0.676772 0.378213
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 6.887068 7.983878 -0.215811 1.857365 2.038505 3.985288 5.043860 8.057398 0.719970 0.690504 0.357293
51 N03 digital_ok 100.00% 100.00% 0.00% 0.00% 39.887016 1.963801 83.370786 -0.758585 14.993711 2.641879 19.270406 3.772879 0.036237 0.710540 0.439612
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 11.928119 11.609312 2.409311 4.733024 1.863523 -0.379570 0.319563 -0.312210 0.739696 0.715915 0.358874
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.260901 3.641177 -0.798937 -0.506659 -0.631029 0.002298 1.712391 1.727755 0.743593 0.722417 0.358051
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 18.154920 21.842821 64.327068 67.481600 15.768925 24.046624 15.394824 12.166941 0.041021 0.041137 0.001868
55 N04 digital_ok 100.00% 0.00% 100.00% 0.00% 3.720371 23.004075 2.581324 66.768984 3.498736 23.940410 2.968158 13.332733 0.732678 0.032706 0.489077
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 3.743791 2.848984 -0.323788 -0.785207 3.828379 1.894950 0.505175 5.800812 0.735818 0.722016 0.340687
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 52.593419 0.283118 27.624937 -0.921565 12.072345 0.955807 5.928052 -0.621169 0.580626 0.722245 0.339667
58 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 17.537205 21.707485 64.035749 67.170204 15.886938 24.141765 15.903296 12.970215 0.034536 0.032095 0.001832
59 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 2.807123 5.688323 1.976418 7.185232 4.132449 0.720188 25.722339 5.814846 0.730204 0.710645 0.344659
60 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 18.913481 21.316751 64.170074 66.966103 15.752407 24.054602 15.486927 13.182711 0.026796 0.026244 0.001340
61 N06 not_connected 100.00% 0.00% 0.00% 0.00% 7.781605 7.396063 7.566583 0.427907 2.063686 5.736321 2.528999 3.728004 0.693067 0.659187 0.356558
62 N06 not_connected 100.00% 0.00% 0.00% 0.00% 3.539884 3.193007 24.045263 33.032616 2.810967 7.314240 6.010273 5.430701 0.704302 0.694873 0.369401
63 N06 not_connected 100.00% 0.00% 100.00% 0.00% 1.063458 22.091662 25.289852 26.013601 1.865219 23.952256 5.801977 13.227904 0.689820 0.041474 0.560777
64 N06 not_connected 100.00% 0.00% 0.00% 0.00% 5.426291 3.233104 14.067047 27.580121 2.793868 4.494744 12.071213 3.920985 0.660902 0.661159 0.385225
65 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 312.240616 312.123834 inf inf 9226.235800 9289.369548 6466.646081 6664.051160 nan nan nan
66 N03 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
67 N03 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
68 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 5.963777 45.415006 1.486076 90.290773 0.090603 23.020678 1.782197 16.377668 0.732982 0.029636 0.423433
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.790426 -0.776351 -0.922563 0.493256 1.764032 2.167722 -0.835815 -0.868431 0.737259 0.720036 0.346778
70 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 1.632355 0.400996 0.378447 0.634613 -0.002298 -0.243703 -0.110392 0.036634 0.739725 0.723462 0.348184
71 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 12.037257 0.057079 2.796300 1.369075 0.601514 1.540400 0.039691 -0.602230 0.747512 0.724505 0.348493
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 6.232059 -0.165684 6.953786 1.009924 1.824911 1.430123 1.712135 -0.129850 0.728942 0.718343 0.342667
73 N05 digital_ok 100.00% 100.00% 100.00% 0.00% 16.750460 20.133962 63.025956 64.916240 15.569656 23.954742 15.964103 12.179502 0.026829 0.026613 0.001223
74 N05 digital_maintenance 100.00% 100.00% 12.89% 0.00% 19.211306 18.781893 66.390840 65.400352 16.161450 21.417475 15.569973 18.100534 0.029060 0.343552 0.203777
75 N05 digital_maintenance 100.00% 0.00% 100.00% 0.00% 14.827380 22.039832 55.019746 67.795928 14.323690 24.259274 5.904876 13.555564 0.561057 0.038287 0.380635
77 N06 not_connected 100.00% 0.00% 0.00% 0.00% 40.216850 42.852898 25.966523 20.685443 7.148437 13.002825 18.007204 9.526709 0.604998 0.536282 0.201729
78 N06 not_connected 100.00% 0.00% 0.00% 0.00% 53.474007 2.021570 19.454424 24.712108 10.314455 2.634704 7.687408 4.152159 0.530545 0.677261 0.347782
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.374988 -0.873253 -1.023995 3.268103 1.092612 3.715410 -0.519244 -0.433562 0.703642 0.684620 0.367551
82 N07 RF_maintenance 100.00% 0.00% 95.81% 0.00% 0.130935 21.320614 -0.845552 55.723641 1.879644 24.624006 -0.242434 11.623472 0.708542 0.078717 0.553477
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.905892 -0.059078 -0.858351 0.127193 -1.059792 1.466444 -0.889089 -0.036634 0.724272 0.706233 0.355492
84 N08 digital_ok 100.00% 0.00% 100.00% 0.00% 11.669852 37.492017 9.338373 86.947648 -1.164363 23.048946 1.217956 14.219285 0.732000 0.037516 0.548087
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.561951 -0.101089 -1.026139 -0.571605 -0.860538 -0.368622 -1.037386 -0.973089 0.735625 0.711748 0.352085
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 2.902238 14.643742 0.681264 0.842179 3.989052 3.296399 0.333831 17.631682 0.726581 0.672531 0.350220
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 8.477466 12.585158 10.097113 7.872844 2.423993 2.768389 1.549691 1.457033 0.747385 0.725625 0.347348
88 N09 digital_ok 0.00% 100.00% 100.00% 0.00% 1.163459 1.144206 1.536903 -0.500066 0.193267 0.239758 -0.452564 -0.999089 0.070935 0.075048 0.010555
89 N09 RF_maintenance 0.00% 100.00% 100.00% 0.00% 1.480224 -0.022863 0.158862 -0.021474 0.399642 -0.535243 -0.861694 -0.801804 0.064814 0.068386 0.007363
90 N09 RF_maintenance 0.00% 100.00% 100.00% 0.00% 0.001261 -0.202671 -0.505702 0.632880 -0.446727 -0.439951 -0.101956 1.120324 0.068384 0.075246 0.009895
91 N09 digital_ok 0.00% 100.00% 100.00% 0.00% 0.020399 0.232369 -1.006553 0.561828 -0.134120 -0.454631 2.291684 0.537692 0.086520 0.084577 0.019638
92 N10 RF_maintenance 100.00% 0.32% 19.44% 0.00% 64.577915 73.324574 8.168829 9.521535 11.469669 20.470921 11.102028 13.327301 0.332419 0.280257 0.106588
93 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 3.305334 1.032804 13.521049 -0.944431 2.394829 -0.690860 4.848215 -0.537622 0.727343 0.714407 0.356017
94 N10 digital_ok 100.00% 0.00% 0.00% 0.00% -0.116162 -0.555316 8.958335 8.523613 0.452393 2.501455 3.148919 2.329760 0.724239 0.701754 0.359788
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 7.008732 -0.659762 6.649010 8.669371 2.340875 1.954363 2.525448 2.548842 0.671516 0.671780 0.365789
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 1.101630 -0.782188 6.510379 -0.830385 2.709403 3.118926 2.271182 -0.659734 0.697093 0.692245 0.364818
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.470208 -0.290852 0.503484 -1.141294 1.604331 -0.904037 0.172065 -1.031410 0.715927 0.696904 0.358205
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 12.538998 15.390432 3.335462 3.331101 -0.489988 -0.990696 0.421314 -0.498779 0.737681 0.714802 0.352233
102 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 16.327725 22.039178 58.597996 63.377087 15.601571 24.203350 10.080356 14.301508 0.395809 0.037389 0.294381
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 38.606971 39.229374 74.619618 77.036339 16.198168 24.281199 19.180447 16.705722 0.025924 0.026926 0.001952
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 12.490181 90.463877 3.485262 61.451690 0.092436 -0.276834 0.064163 5.452266 0.739548 0.662976 0.380953
105 N09 digital_ok 0.00% 100.00% 100.00% 0.00% -0.782134 -0.306817 0.173938 -0.013455 -0.025857 -0.237075 -0.735587 -1.007288 0.072228 0.075974 0.011898
106 N09 digital_ok 0.00% 100.00% 100.00% 0.00% 0.447169 1.249061 2.292907 1.415091 1.140746 0.493287 -0.154084 -0.422799 0.062178 0.063741 0.006936
107 N09 digital_ok 0.00% 100.00% 100.00% 0.00% 1.203042 -0.867472 0.414383 -0.389149 0.743387 -0.696044 2.266373 1.625769 0.048531 0.058421 0.004184
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 2.101065 3.983709 35.348526 -0.495335 31.595942 -0.404255 6.014178 1.397316 0.091888 0.070487 0.019772
109 N10 digital_ok 100.00% 0.00% 100.00% 0.00% 0.114231 21.257402 6.828723 64.942374 -0.441143 23.979571 2.485624 12.847290 0.735656 0.032821 0.441543
110 N10 RF_maintenance 100.00% 0.00% 100.00% 0.00% 0.864109 43.173719 -0.879324 88.421673 -1.276685 23.198651 -0.461035 13.799492 0.748845 0.029754 0.442647
111 N10 digital_ok 100.00% 0.00% 100.00% 0.00% 0.962592 20.736982 0.280699 65.661523 -0.798273 23.959887 1.135714 12.997039 0.735943 0.033425 0.443097
112 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.085617 0.025138 -0.838496 -0.284525 0.424078 -0.652937 0.637020 -0.875611 0.725266 0.708125 0.367088
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.305247 0.857448 -0.797210 1.789402 0.180949 1.414201 1.040460 0.355277 0.693064 0.681635 0.368465
117 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 19.965871 24.165186 64.698272 69.251265 15.957774 24.077408 14.960387 13.676201 0.027591 0.029572 0.002066
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 0.875083 1.575641 2.590460 5.081858 1.575501 0.443328 2.060971 2.142141 0.718023 0.701669 0.357714
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.145194 2.319853 8.659055 7.418553 -0.882689 23.909379 1.287259 1.401434 0.727620 0.691228 0.358903
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 4.714358 38.798925 3.545703 86.788397 -0.373768 23.541797 0.631447 16.819701 0.734226 0.032390 0.556484
121 N08 digital_ok 100.00% 0.32% 0.00% 0.00% 4.294253 9.000576 -0.033432 1.044468 0.677837 0.227640 30.825966 13.118022 0.739075 0.719431 0.356555
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 13.618712 12.095130 3.015457 1.931379 4.403501 -0.849036 0.377194 -0.779535 0.744031 0.722437 0.352405
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 10.484155 14.887343 1.681503 2.024749 -1.403429 1.332755 0.122655 -0.279302 0.740471 0.721293 0.353651
124 N09 digital_ok 0.00% 100.00% 100.00% 0.00% -0.782375 0.087105 0.940228 0.070942 -1.101027 -0.792848 -0.114330 -0.550135 0.069923 0.075316 0.009529
125 N09 RF_maintenance 0.00% 100.00% 100.00% 0.00% 0.145810 -0.110020 0.271198 -0.714369 -0.697621 -0.109043 -0.642313 -1.054430 0.064923 0.071085 0.007236
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 12.063440 -0.523646 5.063610 7.000088 23.006781 0.407084 7.132194 0.503479 0.077776 0.077247 0.014226
127 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.767056 0.710875 -0.345484 -0.838247 -0.799769 0.516782 0.317265 1.376457 0.737745 0.719288 0.363092
128 N10 digital_ok 100.00% 0.00% 0.00% 0.00% -0.125575 12.261137 1.603172 0.529971 -0.334980 2.705105 -0.407826 -0.345259 0.736170 0.700308 0.358928
129 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 1.270997 -0.883876 2.688669 2.724743 -0.995219 -0.321142 -0.069244 1.391218 0.732667 0.709299 0.362873
130 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 1.769560 0.975787 -0.216329 -0.807221 0.783056 0.150988 -0.402083 0.955363 0.722651 0.705234 0.363120
135 N12 digital_maintenance 100.00% 0.00% 100.00% 0.00% -1.592339 21.395059 5.353980 67.425188 1.426248 24.245576 3.807679 12.459428 0.690546 0.035108 0.427886
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 5.880729 2.833421 5.238229 0.665646 1.219615 -0.573309 2.004031 0.185005 0.683596 0.677654 0.361770
137 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.836069 -1.625207 6.943727 -0.859269 2.728205 -1.386548 1.990912 -0.280594 0.693292 0.685948 0.362358
138 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.361544 0.066121 0.318819 2.079863 -0.914480 0.098395 6.711490 -0.042875 0.721278 0.701245 0.364044
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 389.586034 389.288862 inf inf 12362.710772 12362.006846 4871.130655 4869.943263 nan nan nan
141 N13 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
142 N13 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
143 N14 digital_ok 100.00% 100.00% 0.00% 0.00% 18.621564 -1.211406 65.238719 -0.995011 16.130099 -0.462686 14.364299 -0.597832 0.037274 0.720294 0.473898
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.312564 -0.094931 -1.096297 1.857754 1.002292 -0.974105 -0.395355 0.134691 0.730726 0.717579 0.365558
145 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% -1.624774 1.235267 19.828902 16.760337 -0.274060 27.841576 3.710749 2.733722 0.731994 0.698013 0.366361
147 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 30.727891 0.818958 2.954453 4.581722 9.674634 -0.956650 39.328558 0.136885 0.687598 0.709296 0.352268
148 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 17.915621 22.049025 63.211345 66.409543 15.559926 23.897742 14.406547 12.099677 0.029897 0.030071 0.000410
149 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% -0.912428 2.619270 4.197247 42.275619 0.443935 8.270922 0.210536 7.072187 0.738547 0.713837 0.374261
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 19.357600 21.273230 64.268673 66.762996 15.710081 24.075097 15.399520 13.230644 0.026044 0.027991 0.000911
151 N16 not_connected 100.00% 0.00% 0.00% 0.00% 47.695216 4.957156 20.364059 -0.330021 7.072673 5.627174 7.560690 0.286703 0.571902 0.642866 0.353867
152 N16 not_connected 100.00% 0.00% 0.00% 0.00% 4.334784 4.143853 10.897733 16.061746 1.104533 2.282955 9.789567 1.921835 0.669995 0.666649 0.390015
153 N16 not_connected 100.00% 100.00% 0.00% 0.00% 19.232138 3.252789 23.400697 18.462638 15.838345 0.104739 14.693831 1.230902 0.038011 0.665390 0.518122
154 N16 not_connected 100.00% 0.00% 0.00% 0.00% -0.078073 0.517514 25.700871 25.318691 3.644571 3.258961 4.082005 1.945105 0.669159 0.660590 0.399863
155 N12 digital_maintenance 100.00% 100.00% 0.00% 0.00% 17.576932 -1.321268 61.858298 2.203530 15.575212 4.343903 14.594819 5.284492 0.052847 0.676614 0.440920
156 N12 digital_ok 100.00% 22.61% 0.00% 0.00% 14.866021 -0.318011 61.821080 1.093546 13.951006 -0.605079 10.748886 0.479327 0.319794 0.687291 0.450511
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.541477 -0.300975 -0.029222 0.534078 -0.775443 0.332628 0.648202 0.431532 0.709286 0.691887 0.366585
158 N12 digital_ok 100.00% 0.00% 0.00% 0.00% -0.826609 0.058882 10.607540 1.220987 1.107992 0.933626 3.457567 21.006328 0.723963 0.700457 0.372045
160 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 0.312203 -1.341035 19.603159 20.147794 -0.872196 1.826320 4.849955 3.693565 0.732683 0.710679 0.362063
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.741785 45.291111 2.425434 7.921193 -0.765099 5.749869 0.552622 5.214926 0.728205 0.583279 0.328866
162 N13 digital_ok 100.00% 64.12% 0.00% 0.00% 18.089032 1.152707 63.346217 5.609318 18.048312 1.856372 14.043230 1.484156 0.183841 0.710757 0.486545
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.118860 -0.869564 1.221559 -1.039737 -1.054437 0.315011 0.149419 0.265384 0.734022 0.706707 0.365342
164 N14 digital_ok 100.00% 0.00% 0.00% 0.00% -0.860128 0.074889 11.166336 13.079620 3.340929 0.942319 2.730638 2.710090 0.732802 0.716536 0.368378
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 52.938875 79.265774 6.617200 9.931614 10.899739 13.925329 17.677812 29.180852 0.587982 0.542378 0.161846
168 N15 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.001261 -0.233538 -0.117814 1.405918 0.035376 -0.464293 -0.673024 0.406813 0.733010 0.711958 0.369086
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 20.089911 21.370238 63.603213 65.252169 15.566859 24.002741 15.439200 12.312023 0.030905 0.032795 0.001394
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 9.893106 54.947007 20.529057 7.140560 19.591279 12.215864 5.080210 3.746717 0.691113 0.608173 0.352901
171 N16 not_connected 100.00% 0.00% 0.00% 0.00% 3.816222 8.846026 13.330809 0.074793 3.046104 7.519515 3.361318 1.802151 0.676784 0.608303 0.382168
173 N16 not_connected 100.00% 100.00% 100.00% 0.00% 21.432748 22.883609 20.517455 23.416186 15.499775 23.912639 16.796374 15.484782 0.034368 0.037600 0.003742
176 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 0.262619 -0.353558 3.888895 3.233300 0.365043 0.666660 6.263123 9.450850 0.693750 0.673548 0.379291
177 N12 digital_ok 0.00% 0.00% 0.00% 0.00% -1.135080 -0.775151 0.247104 1.311624 -1.026500 0.565806 1.644839 2.257907 0.707319 0.687241 0.379435
178 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 4.856054 -0.692300 15.804351 3.859419 -0.247519 2.267505 6.639687 2.134869 0.693189 0.687083 0.370951
179 N12 digital_ok 100.00% 100.00% 92.59% 0.00% 19.987803 23.538384 65.705589 70.482139 16.158703 24.117079 14.566584 12.089824 0.045486 0.096622 0.043449
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% -1.112729 22.388619 0.328185 67.835651 1.695596 24.145428 0.409158 13.087611 0.726808 0.050308 0.481303
181 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 0.121722 -0.390653 17.407561 4.782063 -0.751261 1.287153 3.079019 3.885266 0.738177 0.710036 0.368560
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 4.425080 4.667166 38.918968 49.601166 3.516162 13.376455 10.353295 14.412288 0.674125 0.695628 0.374908
183 N13 digital_ok 100.00% 100.00% 0.00% 0.00% 18.958346 0.263651 63.165988 -1.052111 15.520363 1.064084 14.270055 -0.411798 0.035624 0.703895 0.453784
184 N14 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
185 N14 digital_ok 100.00% 100.00% 0.00% 0.00% 17.412741 -0.389414 64.476401 21.056675 15.777191 -0.258020 14.505986 2.932815 0.033367 0.691324 0.430699
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 0.295460 -0.425815 35.549501 28.054201 0.943449 3.594719 6.265070 4.418040 0.679157 0.679150 0.358364
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 4.133839 1.526890 34.534298 33.848901 23.091588 4.004546 5.919163 5.589523 0.671102 0.664004 0.359172
189 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
190 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
191 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
192 N16 not_connected 100.00% 0.00% 0.00% 0.00% 3.046449 9.829265 45.656724 60.610908 8.793135 21.481491 9.679307 9.484637 0.694541 0.645649 0.408455
193 N16 not_connected 100.00% 0.00% 0.00% 0.00% 9.320221 1.284298 60.352554 34.623085 13.359738 4.464874 11.986071 6.096808 0.659481 0.669782 0.416906
200 N18 RF_maintenance 100.00% 100.00% 54.51% 0.00% 21.062411 58.669921 23.397008 28.492759 15.471161 19.712014 15.118092 16.639725 0.045070 0.223633 0.140495
201 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 9.817329 8.486971 60.853040 57.543081 13.710244 19.063642 12.291626 9.488666 0.680731 0.659222 0.381172
202 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 3.338863 8.300885 28.664946 0.132800 1.612036 8.013256 9.051371 3.926771 0.711243 0.632754 0.387675
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 21.775230 24.678245 21.800617 24.158569 15.620928 23.890229 15.890719 13.752412 0.032836 0.039574 0.000735
219 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 9.621525 5.822364 61.888793 51.276287 14.398347 13.834009 12.250620 8.192849 0.655996 0.670700 0.398043
220 N18 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
221 N18 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
222 N18 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
237 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 7.391073 5.542760 1.355147 16.213611 4.891083 2.883292 2.090433 2.706877 0.654555 0.650986 0.385139
238 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 1.135410 1.988997 31.695492 29.192023 3.670594 6.207988 6.074403 3.835485 0.706617 0.671871 0.388266
239 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 2.287324 6.438178 18.651456 -0.040061 1.726416 6.627002 7.282783 6.590429 0.698339 0.621022 0.397663
320 N03 dish_maintenance 100.00% 0.00% 100.00% 0.00% 2.704637 21.853580 -0.714130 41.022159 2.743257 24.001026 6.833051 13.299164 0.708666 0.044278 0.462717
321 N02 not_connected 100.00% 0.00% 0.00% 0.00% 1.917771 1.412037 19.499959 22.427040 4.655566 4.677432 5.732354 4.543580 0.637209 0.599162 0.391218
322 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 4.054416 3.886987 24.402280 39.990465 3.492801 8.894972 3.356052 4.982397 0.619394 0.582690 0.404953
323 N02 not_connected 100.00% 0.00% 0.00% 0.00% 41.040905 3.186878 6.454160 39.354589 10.620881 8.100766 13.487387 6.256933 0.406699 0.565475 0.366533
324 N04 not_connected 100.00% 0.00% 0.00% 0.00% 3.487215 4.642891 32.009662 36.969940 3.186709 7.379789 5.623747 3.971680 0.622359 0.587461 0.384455
325 N09 dish_ok 100.00% 100.00% 100.00% 0.00% 1.595713 0.085209 32.603372 16.713085 3.220332 2.398601 3.795246 2.037144 0.091421 0.088484 0.036848
329 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 9.254010 0.712371 0.280443 23.328991 5.138069 4.519047 6.104088 2.163810 0.546637 0.589613 0.394937
333 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 10.185603 4.935607 1.320811 14.736230 5.010393 4.351718 5.073333 1.690711 0.533897 0.574030 0.389541
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, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 71, 72, 73, 74, 75, 77, 78, 82, 84, 86, 87, 88, 89, 90, 91, 92, 93, 94, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 128, 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, 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, 38, 40, 41, 53, 69, 70, 81, 83, 85, 100, 112, 116, 127, 129, 130, 144, 157, 163, 168, 177]

golden_ants: [5, 9, 16, 38, 40, 41, 53, 69, 70, 81, 83, 85, 100, 112, 116, 127, 129, 130, 144, 157, 163, 177]
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_2459865.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 [ ]: