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 = "2460010"
data_path = "/mnt/sn1/2460010"
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: 3-6-2023
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_Notebooks/blob/main/antenna_report/antenna_{ant}_report.html'

Load Auto Metrics¶

In [6]:
use_auto_metrics = False

# find the auto_metrics file
glob_str = os.path.join(data_path, f'zen.{JD}*.auto_metrics.h5')
auto_metrics_file = sorted(glob.glob(glob_str))

# if it exists, load and extract relevant information
if len(auto_metrics_file) > 0:
    auto_metrics_file = auto_metrics_file[0]
    print(f'Found auto_metrics results file at {auto_metrics_file}.')
    
    auto_metrics = load_metric_file(auto_metrics_file)
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
    auto_ex_ants = auto_metrics['ex_ants']['r2_ex_ants']
    
    use_auto_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping auto_metrics.')
Found auto_metrics results file at /mnt/sn1/2460010/zen.2460010.21275.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 1851 ant_metrics files matching glob /mnt/sn1/2460010/zen.2460010.?????.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/2460010/zen.2460010.?????.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 2460010
Date 3-6-2023
LST Range 5.478 -- 15.440 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1851
Total Number of Antennas 198
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 10
dish_ok: 1
RF_maintenance: 50
RF_ok: 19
digital_ok: 93
not_connected: 25
Commanded Signal Source None
Antennas in Commanded State (reported) 0 / 198 (0.0%)
Antennas in Commanded State (observed) 0 / 198 (0.0%)
Cross-Polarized Antennas 66
Total Number of Nodes 19
Nodes Registering 0s N02, N04, N08, N11, N15, N20
Nodes Not Correlating
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 110 / 198 (55.6%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 153 / 198 (77.3%)
Redcal Done? ❌
Never Flagged Antennas 45 / 198 (22.7%)
A Priori Good Antennas Flagged 73 / 93 total a priori good antennas:
3, 5, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29,
30, 31, 37, 38, 40, 41, 42, 45, 53, 54, 55,
56, 65, 66, 67, 69, 70, 71, 72, 81, 85, 86,
93, 94, 101, 103, 107, 109, 111, 112, 121,
122, 123, 124, 127, 128, 136, 147, 148, 149,
150, 151, 158, 161, 162, 165, 167, 168, 169,
170, 173, 181, 182, 184, 187, 189, 190, 191,
192, 193, 202
A Priori Bad Antennas Not Flagged 25 / 105 total a priori bad antennas:
22, 43, 46, 48, 49, 50, 61, 62, 64, 73, 74,
82, 89, 90, 125, 126, 137, 139, 179, 220, 222,
237, 238, 241, 325
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H6C_Notebooks/_rtp_summary_/array_health_table_2460010.csv

Build DataFrame¶

In [20]:
# build dataframe
to_show = {'Ant': [f'<a href="{ant_to_report_url(ant)}" target="_blank">{ant}</a>' for ant in ants],
           'Node': [f'N{nodes[ant]:02}' for ant in ants], 
           'A Priori Status': [a_priori_statuses[ant] for ant in ants]}
           #'Worst Metric': worst_metrics, 'Worst Modified Z-Score': worst_zs}
df = pd.DataFrame(to_show)

# create bar chart columns for flagging percentages:
bar_cols = {}
if use_auto_metrics:
    bar_cols['Auto Metrics Flags'] = [float(ant in auto_ex_ants) for ant in ants]
if use_ant_metrics:
    if np.sum(list(a_priori_flag_frac.values())) > 0:  # only include this col if there are any a priori flags
        bar_cols['A Priori Flag Fraction in Ant Metrics'] = [a_priori_flag_frac[ant] for ant in ants]
    for ap in antpols:
        bar_cols[f'Dead Fraction in Ant Metrics ({ap})'] = [dead_ant_frac[ap][ant] for ant in ants]
    bar_cols['Crossed Fraction in Ant Metrics'] = [crossed_ant_frac[ant] for ant in ants]
if use_redcal:
    bar_cols['Flag Fraction Before Redcal'] = [redcal_prior_flag_frac[ant] for ant in ants]
    bar_cols['Flagged By Redcal chi^2 Fraction'] = [redcal_flagged_frac[ant] for ant in ants]  
for col in bar_cols:
    df[col] = bar_cols[col]

# add auto_metrics
if use_auto_metrics:
    for label, modz in all_modzs.items():
        df[label] = modz
z_score_cols = [col for col in df.columns if 'Modified Z-Score' in col]        
        
# add ant_metrics
ant_metrics_cols = {}
if use_ant_metrics:
    for ap in antpols:
        ant_metrics_cols[f'Average Dead Ant Metric ({ap})'] = [average_dead_metrics[ap][ant] for ant in ants]
    ant_metrics_cols['Average Crossed Ant Metric'] = [average_crossed_metrics[ant] for ant in ants]
    for col in ant_metrics_cols:
        df[col] = ant_metrics_cols[col]   

# add redcal chisq
redcal_cols = []
if use_redcal:
    for ap in antpols:
        col_title = f'Median chi^2 Per Antenna ({ap})'
        df[col_title] = [cspa[ant, ap] for ant in ants]
        redcal_cols.append(col_title)

# sort by node number and then by antenna number within nodes
df.sort_values(['Node', 'Ant'], ascending=True)

# style dataframe
table = df.style.hide_index()\
          .applymap(lambda val: f'background-color: {status_colors[val]}' if val in status_colors else '', subset=['A Priori Status']) \
          .background_gradient(cmap='viridis', vmax=mean_round_modz_cut * 3, vmin=0, axis=None, subset=z_score_cols) \
          .background_gradient(cmap='bwr_r', vmin=dead_cut-.25, vmax=dead_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .background_gradient(cmap='bwr_r', vmin=crossed_cut-.25, vmax=crossed_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .background_gradient(cmap='plasma', vmax=4, vmin=1, axis=None, subset=redcal_cols) \
          .applymap(lambda val: 'font-weight: bold' if val < dead_cut else '', subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val < crossed_cut else '', subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .applymap(lambda val: 'color: red' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .bar(subset=list(bar_cols.keys()), vmin=0, vmax=1) \
          .format({col: '{:,.4f}'.format for col in z_score_cols}) \
          .format({col: '{:,.4f}'.format for col in ant_metrics_cols}) \
          .format({col: '{:,.2%}'.format for col in bar_cols}) \
          .applymap(lambda val: 'font-weight: bold', subset=['Ant']) \
          .set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])])

Table 2: RTP Per-Antenna Metrics Summary Table¶

This admittedly very busy table incorporates summary information about all antennas in the array. Its columns depend on what information is available when the notebook is run (i.e. whether auto_metrics, ant_metrics, and/or redcal is done). These can be divided into 5 sections:

Basic Antenna Info: antenna number, node, and its a priori status.

Flag Fractions: Fraction of the night that an antenna was flagged for various reasons. Note that auto_metrics flags antennas for the whole night, so it'll be 0% or 100%.

auto_metrics Details: If auto_metrics is included, this section shows the modified Z-score signifying how much of an outlier each antenna and polarization is in each of four categories: bandpass shape, overall power, temporal variability, and temporal discontinuities. Bold red text indicates that this is a reason for flagging the antenna. It is reproduced from the auto_metrics_inspect.ipynb nightly notebook, so check that out for more details on the precise metrics.

ant_metrics Details: If ant_metrics is included, this section shows the average correlation-based metrics for antennas over the whole night. Low "dead ant" metrics (nominally below 0.4) indicate antennas not correlating with the rest of the array. Negative "crossed ant" metrics indicate antennas that show stronger correlations in their cross-pols than their same-pols, indicating that the two polarizations are probably swapped. Bold text indicates that the average is below the threshold for flagging.

redcal chi^2 Details: If redcal is included, this shows the median chi^2 per antenna. This would be 1 in an ideal array. Antennas are thrown out when they they are outliers in their median chi^2, usually greater than 4-sigma outliers in modified Z-score.

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric
3 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 12.636325 17.079683 11.703031 12.692505 9.135963 10.435400 1.292592 1.916768 0.027208 0.025128 0.002014
4 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 12.816206 16.565421 11.996553 12.745061 9.111335 10.384372 2.925061 2.412861 0.025302 0.024952 0.001231
5 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 13.488245 16.850211 11.628662 12.378587 9.245041 10.495218 0.967962 0.739061 0.025696 0.025314 0.001268
7 N02 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
8 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
9 N02 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
10 N02 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
15 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 12.914253 16.739013 11.056971 12.025127 9.142260 10.444459 0.564368 0.834591 0.027273 0.025670 0.001875
16 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 12.948752 17.022073 11.668219 12.656695 9.131458 10.402257 1.196046 1.279433 0.025460 0.024917 0.001304
17 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 12.733164 15.964800 11.671006 12.695756 9.159305 10.459872 0.935069 1.345197 0.025496 0.024852 0.001293
18 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 13.716646 17.627679 11.660477 12.641219 9.237743 10.489350 1.263101 1.227752 0.026786 0.024944 0.002075
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
20 N02 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
21 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 277.487452 276.313586 inf inf 3695.177086 3725.900561 7174.254078 7051.767204 nan nan nan
22 N06 not_connected 0.00% 0.00% 0.00% 0.00% -0.561086 -0.135987 0.357510 -0.240208 0.185328 0.719420 -0.464638 -1.090686 0.553754 0.563515 0.352620
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 12.158499 16.009008 11.723447 12.479410 9.225372 10.495912 3.046621 2.419538 0.025787 0.025528 0.001372
28 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 12.678511 17.208576 11.459459 12.445742 9.230687 10.530177 0.777621 3.362556 0.025855 0.025570 0.001341
29 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 12.973054 16.492027 11.280038 12.039815 9.211891 10.490235 1.231543 0.702894 0.031116 0.038031 0.007403
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 1.776075 0.256912 1.793240 -1.405017 4.148553 0.549608 4.792192 -0.375865 0.566041 0.593247 0.384069
31 N02 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
34 N06 not_connected 100.00% 100.00% 100.00% 0.00% 14.759578 17.818179 5.665560 6.296436 9.194798 10.461404 1.442091 1.105934 0.036817 0.046553 0.007588
35 N06 not_connected 100.00% 0.00% 0.00% 0.00% 0.056622 -0.241203 0.873546 -1.244274 5.501422 -1.174332 -0.639667 0.116633 0.567762 0.566877 0.346009
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 9.645383 9.382311 0.980091 0.936170 2.086414 2.701966 0.233632 0.604378 0.573932 0.574857 0.382649
37 N03 digital_ok 100.00% 0.00% 100.00% 0.00% -0.254295 29.947996 -0.358637 15.679791 0.117451 10.367762 -0.769669 4.725862 0.584148 0.032814 0.469232
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.911332 0.519506 -1.209381 3.220055 0.147808 0.584123 1.719204 10.593939 0.584152 0.569596 0.375985
40 N04 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
41 N04 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
42 N04 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
43 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.754919 0.165684 -0.613353 0.861747 -1.251985 0.971065 -0.678889 1.014883 0.595595 0.600185 0.376473
44 N05 digital_ok 0.00% 0.00% 0.00% 0.00% -1.243045 0.728065 -1.026435 0.370614 -0.581837 0.861056 -0.840035 -0.336685 0.602894 0.613374 0.372931
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 0.768963 3.780175 0.404656 0.899189 0.170373 1.125128 0.415675 15.671441 0.594899 0.600412 0.358168
46 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% -1.200784 -0.609174 -0.709848 -0.927384 0.003082 -0.489850 -0.278430 -0.758965 0.599006 0.620696 0.369068
47 N06 not_connected 100.00% 100.00% 100.00% 0.00% 13.791034 17.414576 5.557232 5.873762 9.188485 10.406447 3.350081 0.648838 0.032321 0.054866 0.017273
48 N06 not_connected 0.00% 0.00% 0.00% 0.00% 0.248738 1.470273 -0.027998 1.789164 -0.606643 1.975844 -0.670092 -2.325235 0.567632 0.590682 0.353457
49 N06 not_connected 0.00% 0.00% 0.00% 0.00% -0.267964 -0.088430 -0.103352 -0.399148 -0.349593 -0.639004 -0.008957 1.820962 0.527948 0.569670 0.353369
50 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.800968 0.992214 -0.159808 2.033677 0.135200 1.562952 -0.045913 -0.061556 0.573439 0.572618 0.378135
51 N03 dish_maintenance 100.00% 0.00% 0.00% 0.00% 4.247230 1.881748 -0.325029 0.175193 2.365456 2.914956 65.722287 1.784760 0.580959 0.587213 0.374252
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 8.396187 6.745224 0.165117 0.210331 2.100312 2.016197 2.914364 0.403687 0.588225 0.596538 0.373721
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.869316 1.961368 -0.454604 -0.234076 1.943441 0.443309 8.619757 13.127177 0.588038 0.601249 0.381770
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
56 N04 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
57 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
58 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% 12.127645 16.367200 11.598586 12.599065 9.134081 10.407917 1.934309 1.420221 0.039599 0.038581 0.003129
59 N05 RF_maintenance 100.00% 100.00% 0.00% 0.00% 13.486081 0.959985 11.657472 1.358244 9.054679 1.910156 0.924985 11.632408 0.048798 0.620386 0.499297
60 N05 RF_maintenance 100.00% 0.00% 100.00% 0.00% 0.986951 16.295916 -0.519363 12.636289 0.053648 10.391835 0.858339 2.982025 0.604323 0.076003 0.500611
61 N06 not_connected 0.00% 0.00% 0.00% 0.00% 2.745315 0.305324 0.096685 -1.257799 0.335988 -1.785113 -0.219052 0.707135 0.546662 0.589221 0.349363
62 N06 not_connected 0.00% 0.00% 0.00% 0.00% 0.249815 1.463969 -0.682988 1.278062 -0.269886 0.367853 0.385358 -1.535396 0.549451 0.593291 0.355539
63 N06 not_connected 100.00% 0.00% 100.00% 0.00% 2.193348 16.925356 -0.193591 6.331602 0.118921 10.524525 -0.349590 3.163422 0.556898 0.048281 0.435083
64 N06 not_connected 0.00% 0.00% 0.00% 0.00% 0.161009 0.222102 -0.744915 -0.679634 -0.731866 -1.533479 0.348217 0.074598 0.545371 0.550306 0.344748
65 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 28.705253 27.072601 15.052712 15.379989 9.265841 10.470842 5.662304 7.158898 0.022823 0.029369 0.006785
66 N03 digital_ok 100.00% 0.00% 0.00% 100.00% 0.721926 0.033851 -1.265837 5.090665 3.190727 1.214474 -0.454407 1.057411 0.208793 0.189188 -0.280400
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.646834 -0.892762 -1.244243 1.784722 -0.088103 2.315614 5.979338 1.935872 0.594089 0.596226 0.369701
68 N03 dish_maintenance 100.00% 100.00% 0.00% 0.00% 30.811276 0.880085 15.178392 1.076284 9.103918 -0.533691 6.730417 -0.702008 0.035831 0.603211 0.487716
69 N04 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
70 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 289.520448 289.114997 inf inf 4915.878287 4914.668668 11454.538449 11451.113805 nan nan nan
71 N04 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
73 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.345260 0.880123 -1.429964 -0.030978 0.164453 0.823775 -0.405684 -0.007937 0.621821 0.633657 0.360197
74 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.759641 0.212965 0.244970 -0.406206 -0.507923 1.029080 -1.325728 1.877848 0.625487 0.641020 0.356599
77 N06 not_connected 100.00% 0.00% 0.00% 0.00% 66.469759 28.203584 0.882812 -0.403991 5.708339 3.190450 5.539575 -0.204894 0.300842 0.469930 0.264432
78 N06 not_connected 100.00% 0.00% 0.00% 0.00% 34.206203 1.185195 -0.288807 1.560427 3.008441 0.852399 1.162613 -0.119571 0.412843 0.595546 0.351340
79 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
80 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
81 N07 digital_ok 100.00% 0.00% 100.00% 0.00% -0.615673 17.244803 0.125535 11.075355 -0.077463 10.254055 0.198781 2.262793 0.544570 0.041349 0.421864
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 3.375811 0.881898 -1.104850 -0.043532 0.283871 -1.491447 -0.474810 -0.375181 0.579401 0.585510 0.373137
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.409289 0.057232 0.214960 0.725333 0.434044 0.214612 -0.268192 0.722359 0.582581 0.583372 0.365971
84 N08 RF_maintenance 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% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
86 N08 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
88 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.931474 0.883512 0.420753 1.251519 -0.045509 -0.213880 2.913803 0.705287 0.601241 0.623089 0.352806
89 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 1.435546 0.133095 0.273961 1.197879 -0.003082 0.273426 -0.386010 -0.001577 0.620033 0.635786 0.350004
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.316462 -0.456619 -0.610932 -0.320358 -0.439415 -1.686127 0.219429 2.194665 0.622556 0.649148 0.349247
91 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.716514 0.043743 0.611311 0.622014 -0.198433 0.032824 0.170712 0.001577 0.609181 0.639811 0.349731
92 N10 RF_maintenance 100.00% 100.00% 0.00% 0.00% 12.846566 -0.099655 11.603324 0.449844 9.266480 1.604988 0.709140 0.978551 0.038773 0.635675 0.415432
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 13.142400 16.627284 11.737518 12.710213 9.128091 10.391299 3.295156 2.529069 0.032553 0.025045 0.003482
94 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 14.028649 16.902566 11.885555 12.490995 9.169562 10.430245 5.231034 1.089246 0.025330 0.025593 0.001287
95 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
96 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
97 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
105 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.194285 -0.043743 -0.597747 0.559336 0.687700 0.136328 -0.295977 -0.275035 0.615491 0.630710 0.353796
106 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 1.242178 1.208567 -0.820561 -0.217211 -0.435615 -0.374915 -0.099994 0.103017 0.624948 0.643315 0.344535
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 3.271531 1.071760 -0.839617 -1.076880 0.423607 -0.137548 5.703289 4.808700 0.626485 0.651968 0.340663
108 N09 RF_maintenance 100.00% 100.00% 0.00% 0.00% 12.850678 48.141163 11.649937 1.311062 9.198791 3.615271 2.516486 2.022441 0.037032 0.318379 0.180791
109 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 12.562977 16.395096 11.699649 12.350500 9.217657 10.487813 0.926951 2.349056 0.059671 0.036738 0.015149
110 N10 RF_maintenance 100.00% 0.00% 0.00% 0.00% 28.711605 4.820384 7.172651 -0.124669 7.428669 -0.313801 1.223560 -0.353054 0.478427 0.613954 0.338058
111 N10 digital_ok 100.00% 0.00% 100.00% 0.00% 29.560410 16.263132 0.926023 12.451144 7.479170 10.466561 20.902736 2.627917 0.497524 0.060312 0.346350
112 N10 digital_ok 100.00% 67.96% 99.95% 0.05% 2.102793 15.864249 8.208828 12.527756 0.804776 10.151558 0.354483 1.029584 0.182982 0.069767 -0.110766
113 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
114 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
115 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
117 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 13.769217 18.206894 11.772828 12.992465 9.102019 10.401394 1.785818 4.340324 0.029769 0.033593 0.002756
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.659240 1.740125 0.008477 0.784371 -0.142602 1.425971 0.087695 0.520309 0.584230 0.591663 0.370525
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
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% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
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 100.00% 100.00% 0.00% 0.00% 12.936352 0.757422 11.935282 0.885191 9.083989 0.889665 1.021777 0.883070 0.045567 0.645380 0.461694
125 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.955577 0.731029 0.735714 1.251840 0.684258 0.149276 1.923459 0.617476 0.631823 0.648144 0.339831
126 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.901749 1.231948 -0.719651 1.275070 0.408791 0.517777 1.490207 0.655921 0.635858 0.653690 0.342018
127 N10 digital_ok 100.00% 100.00% 0.00% 0.00% 12.326247 0.320795 11.594189 0.621872 9.236775 1.854998 0.673676 1.040375 0.036889 0.647306 0.419829
128 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 0.160070 -0.202268 -1.403582 -0.110935 -0.129759 -0.340701 0.272739 5.650725 0.619623 0.633177 0.362642
131 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
132 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
133 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
134 N11 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
135 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
136 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
137 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.543263 -0.682090 -0.008477 -1.405501 0.893879 -0.258155 0.585511 1.059566 0.571077 0.589727 0.372517
139 N13 RF_maintenance 0.00% 0.00% 0.00% 0.00% 1.925354 0.117805 1.795583 -0.961552 1.047707 -1.536251 -1.020665 0.835952 0.591604 0.595921 0.361522
140 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.666892 -1.230869 -0.783812 -0.238306 -0.203891 -1.672915 2.794948 2.659053 0.606867 0.625030 0.362577
141 N13 digital_ok 0.00% 0.00% 0.00% 0.00% -1.141086 -0.533366 -0.434899 0.681828 1.360511 -0.644881 1.127098 -1.199566 0.612273 0.633449 0.358781
142 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 1.598858 16.415597 -0.909338 12.644154 1.454927 10.437468 16.591985 2.299314 0.622660 0.050143 0.486996
143 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 13.675179 16.346315 11.495968 12.606512 8.659699 10.545119 0.737931 2.030996 0.106078 0.033043 0.058797
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -1.111610 1.502905 -1.284756 0.875830 -0.762234 2.171002 -0.664860 0.342592 0.642757 0.658787 0.343637
145 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.137127 -0.412347 2.111929 0.669986 0.355849 2.973565 0.082237 -1.130861 0.634079 0.659967 0.345286
146 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.124050 -0.405700 -0.764983 -0.678996 -1.039636 -1.656264 -0.706227 -0.763511 0.609777 0.634656 0.345161
147 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 274.962954 275.366918 inf inf 3687.501036 3643.137364 7401.830326 7240.243937 nan nan nan
148 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
149 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
150 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 249.086396 247.018904 inf inf 4730.655750 4749.000249 10762.206230 10835.430746 nan nan nan
151 N16 digital_ok 100.00% 0.00% 0.00% 0.00% 26.732534 1.474662 -0.244659 0.811560 2.644069 -1.330325 6.231025 0.147443 0.417726 0.527053 0.334832
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
156 N12 RF_maintenance 100.00% 0.00% 100.00% 0.00% 5.506056 16.172977 9.901403 12.402633 5.626617 10.528639 1.419846 2.571678 0.382088 0.041836 0.281488
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.752587 -0.135477 0.074179 0.944274 0.237751 1.147853 0.069813 0.061817 0.578100 0.591987 0.375227
158 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 0.469387 -0.446093 -0.340658 -0.130959 1.150709 1.666446 3.746367 15.291150 0.591952 0.608558 0.373896
159 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.977053 31.444934 -1.364795 -0.456159 -0.907776 2.343627 -0.094193 1.374721 0.567638 0.461441 0.321422
160 N13 digital_ok 0.00% 0.00% 0.00% 0.00% -0.109416 -1.197700 -0.462651 -0.669874 -0.012362 1.634938 -0.479907 0.684338 0.608872 0.631727 0.362141
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.343970 35.592460 0.051416 -0.125271 0.707570 0.870812 -0.183762 0.944278 0.618286 0.514154 0.315547
162 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.800053 -1.381174 0.028154 -0.969189 -0.007563 0.135195 10.061457 -0.300985 0.637196 0.656373 0.350217
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.616205 1.630455 -0.133157 0.601735 0.370280 2.327465 -0.209012 0.981277 0.643990 0.660605 0.348244
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.572073 0.293734 -0.024578 1.639321 0.642391 2.336583 0.005140 0.958393 0.643674 0.651410 0.336510
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 24.952890 0.289853 -0.607218 -0.723740 5.972181 0.392210 15.324653 -0.226707 0.542401 0.656199 0.344273
166 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -1.062197 0.281855 0.808943 0.871245 0.843970 -0.695027 0.051952 -1.675519 0.631518 0.648975 0.338339
167 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
168 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
170 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
171 N16 digital_ok 0.00% 0.00% 0.00% 0.00% 1.264164 2.089051 -1.262038 -0.114421 -0.856429 -0.866736 -0.315692 1.073001 0.528203 0.524905 0.351989
173 N16 digital_ok 100.00% 100.00% 100.00% 0.00% 15.287174 17.496224 4.979861 5.922431 9.297669 10.558469 4.088243 7.370575 0.038278 0.043745 0.003902
179 N12 RF_maintenance 0.00% 0.00% 0.00% 0.00% 3.325924 -0.332148 -0.773909 0.131659 2.494343 0.582295 -0.428009 2.742253 0.583684 0.612481 0.373042
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 0.113065 17.158305 -1.274062 12.787128 0.508178 10.377942 13.983847 3.120817 0.612282 0.059604 0.486900
181 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 1.193386 0.371139 1.186751 0.829141 1.228559 1.015644 0.061586 6.487380 0.619320 0.639253 0.361809
182 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 0.030122 16.094191 0.792119 12.333323 -0.773136 10.520258 -0.628582 2.703597 0.636029 0.053421 0.473697
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% -0.417210 0.610287 0.141608 1.098715 0.868232 0.634491 0.085523 0.094090 0.631181 0.649372 0.338865
184 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 25.637907 -0.400022 7.638850 -1.153165 7.327005 1.086168 3.022283 -0.349914 0.456665 0.659429 0.362890
185 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 5.918399 -0.030533 4.143954 1.000865 5.097286 -0.453203 -2.821219 -0.535996 0.616066 0.656191 0.351891
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.808094 -0.905199 0.769407 -0.230856 -0.896519 -1.538972 -0.942079 -0.862024 0.641784 0.652242 0.349638
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 0.353583 -0.629137 -1.268881 0.014520 -0.048490 -0.006215 6.477424 -0.321018 0.621401 0.634189 0.351667
189 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
190 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
191 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
192 N16 digital_ok 100.00% 0.00% 0.00% 0.00% 2.135953 7.638250 2.428742 4.704242 1.691577 8.521682 -0.026169 -3.871227 0.541673 0.525553 0.374960
193 N16 digital_ok 100.00% 0.00% 0.00% 0.00% 8.366739 0.840664 5.160918 1.186848 7.456007 1.023163 -3.833818 0.303457 0.506439 0.547749 0.388743
200 N18 RF_maintenance 100.00% 100.00% 45.33% 0.00% 14.724395 43.801795 5.434195 0.059559 9.273286 5.050899 2.526299 6.277483 0.044979 0.238167 0.150082
201 N18 RF_maintenance 100.00% 0.00% 0.00% 0.00% 3.901140 5.733540 3.433658 4.132067 3.509576 7.162827 -1.882645 -3.280906 0.603349 0.607655 0.346341
202 N18 digital_ok 100.00% 0.00% 0.00% 0.00% 0.943931 0.915634 1.865845 -1.354845 1.355928 -0.189916 -1.489862 45.409473 0.621730 0.624665 0.338972
204 N19 RF_maintenance 100.00% 0.00% 0.00% 0.00% 10.652974 16.408093 1.380507 -0.952993 0.250468 0.504899 20.579433 1.722007 0.629001 0.652751 0.349899
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 10.789468 -1.221962 3.840738 -0.559276 5.998298 -0.859612 38.764517 3.653891 0.388549 0.632613 0.428965
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 0.762762 6.248900 -0.156561 3.205538 0.920869 2.019638 0.009307 0.692012 0.565379 0.509306 0.341376
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% -0.541462 1.799011 -0.483878 -0.537459 -0.776835 -1.078592 6.062141 -0.224537 0.585806 0.584992 0.350655
208 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
209 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
210 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
211 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
220 N18 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.997529 -0.877796 0.753394 -0.345508 -0.407132 -1.484907 2.275375 -1.176869 0.607376 0.612321 0.343601
221 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 0.321638 -0.173798 -0.852160 -0.694948 0.519929 -1.791116 6.660066 -0.662869 0.598870 0.623382 0.345305
222 N18 RF_ok 0.00% 0.00% 0.00% 0.00% -0.171470 -0.080931 0.170261 0.163821 -0.539203 -0.901808 1.929127 -1.497268 0.611220 0.629670 0.347975
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% -1.572680 3.213398 -1.457458 2.515851 -1.141909 0.979279 0.677109 5.453007 0.599945 0.545770 0.358243
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 8.705674 7.049152 5.430747 4.659091 7.852455 8.235631 -3.897109 -3.404443 0.570303 0.590186 0.350105
225 N19 RF_ok 100.00% 0.00% 86.87% 0.00% -0.163450 16.293191 1.091891 6.078314 -0.470613 10.056215 -1.338605 2.102635 0.595493 0.149104 0.486078
226 N19 RF_ok 100.00% 0.00% 0.00% 0.00% -0.248167 22.849689 -0.263975 0.746285 -1.009278 3.788066 -0.867575 -0.395730 0.571404 0.498382 0.342164
227 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
228 N20 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
229 N20 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
237 N18 RF_ok 0.00% 0.00% 0.00% 0.00% 2.967127 -0.254745 0.174462 -1.387461 -0.854154 -0.366056 0.913599 -0.833388 0.539981 0.588969 0.362028
238 N18 RF_ok 0.00% 0.00% 0.00% 0.00% 0.196099 -0.115052 1.230646 0.626947 0.104941 -0.766423 -1.665664 -1.764158 0.599019 0.607249 0.356102
239 N18 RF_ok 100.00% 0.00% 0.00% 0.00% -0.669739 -0.953901 0.670754 -0.056103 -0.143005 -1.461109 0.389930 4.458608 0.599063 0.607839 0.353768
240 N19 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.524780 0.448727 -0.520646 -0.901511 0.199521 -1.554250 4.197045 3.669261 0.572051 0.606315 0.362698
241 N19 RF_ok 0.00% 0.00% 0.00% 0.00% -0.110705 -1.035079 -0.070434 0.245942 -0.664723 -1.128617 0.603342 -1.191638 0.584451 0.606815 0.368934
242 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 26.390229 0.864543 -0.010475 1.332659 2.971012 0.628283 -0.788434 -0.391097 0.447601 0.594478 0.370360
243 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 20.387735 -0.794347 1.586901 -1.452470 5.864437 -1.188514 21.242586 -0.114385 0.464441 0.569757 0.372736
244 N20 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
245 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
246 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
261 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
262 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
320 N03 dish_maintenance 100.00% 0.00% 0.00% 0.00% 4.647290 1.532213 2.914092 1.357422 2.690614 0.729024 -1.076098 0.389286 0.476932 0.489713 0.364586
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
325 N09 dish_ok 0.00% 0.00% 0.00% 0.00% 1.915009 -0.745333 1.469076 -1.452232 1.144797 -1.251929 -1.519068 0.003649 0.488007 0.485986 0.359969
329 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 1.978572 0.425664 0.339475 -0.466017 1.703799 -1.266825 4.565827 0.053409 0.459208 0.471419 0.346628
333 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 4.257827 3.139857 -0.982429 -1.331950 -0.929052 -1.136950 1.506394 1.160638 0.438543 0.457578 0.334323
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 40, 41, 42, 45, 47, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 63, 65, 66, 67, 68, 69, 70, 71, 72, 77, 78, 79, 80, 81, 84, 85, 86, 87, 92, 93, 94, 95, 96, 97, 101, 102, 103, 104, 107, 108, 109, 110, 111, 112, 113, 114, 115, 117, 120, 121, 122, 123, 124, 127, 128, 131, 132, 133, 134, 135, 136, 142, 143, 147, 148, 149, 150, 151, 155, 156, 158, 159, 161, 162, 165, 167, 168, 169, 170, 173, 180, 181, 182, 184, 185, 187, 189, 190, 191, 192, 193, 200, 201, 202, 204, 205, 206, 207, 208, 209, 210, 211, 221, 223, 224, 225, 226, 227, 228, 229, 239, 240, 242, 243, 244, 245, 246, 261, 262, 320, 324, 329, 333]

unflagged_ants: [22, 43, 44, 46, 48, 49, 50, 61, 62, 64, 73, 74, 82, 83, 88, 89, 90, 91, 105, 106, 118, 125, 126, 137, 139, 140, 141, 144, 145, 146, 157, 160, 163, 164, 166, 171, 179, 183, 186, 220, 222, 237, 238, 241, 325]

golden_ants: [44, 83, 88, 91, 105, 106, 118, 140, 141, 144, 145, 146, 157, 160, 163, 164, 166, 171, 183, 186]
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_2460010.csv
In [24]:
# Load antenna positions
data_list = sorted(glob.glob(os.path.join(data_path, f'zen.{JD}.?????.sum.uvh5')))
hd = io.HERAData(data_list[len(data_list) // 2])

# Figure out where to draw the nodes
node_centers = {}
for node in sorted(set(list(nodes.values()))):
    if np.isfinite(node):
        this_node_ants = [ant for ant in ants + unused_ants if nodes[ant] == node]
        if len(this_node_ants) == 1:
            # put the node label just to the west of the lone antenna 
            node_centers[node] = hd.antpos[ant][node] + np.array([-14.6 / 2, 0, 0])
        else:
            # put the node label between the two antennas closest to the node center
            node_centers[node] = np.mean([hd.antpos[ant] for ant in this_node_ants], axis=0)
            closest_two_pos = sorted([hd.antpos[ant] for ant in this_node_ants], 
                                     key=lambda pos: np.linalg.norm(pos - node_centers[node]))[0:2]
            node_centers[node] = np.mean(closest_two_pos, axis=0)
In [25]:
def Plot_Array(ants, unused_ants, outriggers):
    plt.figure(figsize=(16,16))
    
    plt.scatter(np.array([hd.antpos[ant][0] for ant in hd.data_ants if ant in ants]), 
                np.array([hd.antpos[ant][1] for ant in hd.data_ants if ant in ants]), c='w', s=0)

    # connect every antenna to their node
    for ant in ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', zorder=0)

    rc_color = '#0000ff'
    antm_color = '#ffa500'
    autom_color = '#ff1493'

    # Plot 
    unflagged_ants = []
    for i, ant in enumerate(ants):
        ant_has_flag = False
        # plot large blue annuli for redcal flags
        if use_redcal:
            if redcal_flagged_frac[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=7 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=rc_color, alpha=redcal_flagged_frac[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot medium green annuli for ant_metrics flags
        if use_ant_metrics: 
            if ant_metrics_xants_frac_by_ant[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=antm_color, alpha=ant_metrics_xants_frac_by_ant[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot small red annuli for auto_metrics
        if use_auto_metrics:
            if ant in auto_ex_ants:
                ant_has_flag = True                
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, lw=0, color=autom_color)) 
        
        # plot black/white circles with black outlines for antennas
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4 * (2 - 1 * float(not outriggers)), fill=True, color=['w', 'k'][ant_has_flag], ec='k'))
        if not ant_has_flag:
            unflagged_ants.append(ant)

        # label antennas, using apriori statuses if available
        try:
            bgc = matplotlib.colors.to_rgb(status_colors[a_priori_statuses[ant]])
            c = 'black' if (bgc[0]*0.299 + bgc[1]*0.587 + bgc[2]*0.114) > 186 / 256 else 'white'
        except:
            c = 'k'
            bgc='white'
        plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color=c, backgroundcolor=bgc)

    # label nodes
    for node in sorted(set(list(nodes.values()))):
        if not np.isnan(node) and not np.all(np.isnan(node_centers[node])):
            plt.text(node_centers[node][0], node_centers[node][1], str(node), va='center', ha='center', bbox={'color': 'w', 'ec': 'k'})
    
    # build legend 
    legend_objs = []
    legend_labels = []
    
    # use circles for annuli 
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgecolor='k', markerfacecolor='w', markersize=13))
    legend_labels.append(f'{len(unflagged_ants)} / {len(ants)} Total {["Core", "Outrigger"][outriggers]} Antennas Never Flagged')
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='k', markersize=15))
    legend_labels.append(f'{len(ants) - len(unflagged_ants)} Antennas {["Core", "Outrigger"][outriggers]} Flagged for Any Reason')

    if use_auto_metrics:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=autom_color, markersize=15))
        legend_labels.append(f'{len([ant for ant in auto_ex_ants if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas Flagged by Auto Metrics')
    if use_ant_metrics: 
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=antm_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum([frac for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants]), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Ant Metrics\n(alpha indicates fraction of time)')        
    if use_redcal:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=rc_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum(list(redcal_flagged_frac.values())), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in redcal_flagged_frac.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Redcal\n(alpha indicates fraction of time)')

    # use rectangular patches for a priori statuses that appear in the array
    for aps in sorted(list(set(list(a_priori_statuses.values())))):
        if aps != 'Not Found':
            legend_objs.append(plt.Circle((0, 0), radius=7, fill=True, color=status_colors[aps]))
            legend_labels.append(f'A Priori Status:\n{aps} ({[status for ant, status in a_priori_statuses.items() if ant in ants].count(aps)} {["Core", "Outrigger"][outriggers]} Antennas)')

    # label nodes as a white box with black outline
    if len(node_centers) > 0:
        legend_objs.append(matplotlib.patches.Patch(facecolor='w', edgecolor='k'))
        legend_labels.append('Node Number')

    if len(unused_ants) > 0:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='grey', markersize=15, alpha=.2))
        legend_labels.append(f'Anntenna Not In Data')
        
    
    plt.legend(legend_objs, legend_labels, ncol=2, fontsize='large', framealpha=1)
    
    if outriggers:
        pass
    else:
        plt.xlim([-200, 150])
        plt.ylim([-150, 150])        
       
    # set axis equal and label everything
    plt.axis('equal')
    plt.tight_layout()
    plt.title(f'Summary of {["Core", "Outrigger"][outriggers]} Antenna Statuses and Metrics on {JD}', size=20)    
    plt.xlabel("Antenna East-West Position (meters)", size=12)
    plt.ylabel("Antenna North-South Position (meters)", size=12)
    plt.xticks(fontsize=12)
    plt.yticks(fontsize=12)
    xlim = plt.gca().get_xlim()
    ylim = plt.gca().get_ylim()    
        
    # plot unused antennas
    plt.autoscale(False)    
    for ant in unused_ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', alpha=.2, zorder=0)
        
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='w', ec=None, alpha=1, zorder=0))
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='grey', ec=None, alpha=.2, zorder=0))
        if hd.antpos[ant][0] < xlim[1] and hd.antpos[ant][0] > xlim[0]:
            if hd.antpos[ant][1] < ylim[1] and hd.antpos[ant][1] > ylim[0]:
                plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color='k', alpha=.2) 

Figure 1: Array Plot of Flags and A Priori Statuses¶

This plot shows all antennas, which nodes they are connected to, and their a priori statuses (as the highlight text of their antenna numbers). It may also show (depending on what is finished running):

  • Whether they were flagged by auto_metrics (red circle) for bandpass shape, overall power, temporal variability, or temporal discontinuities. This is done in a binary fashion for the whole night.
  • Whether they were flagged by ant_metrics (green circle) as either dead (on either polarization) or crossed, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.
  • Whether they were flagged by redcal (blue circle) for high chi^2, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.

Note that the last fraction does not include antennas that were flagged before going into redcal due to their a priori status, for example.

In [26]:
core_ants = [ant for ant in ants if ant < 320]
outrigger_ants = [ant for ant in ants if ant >= 320]
Plot_Array(ants=core_ants, unused_ants=unused_ants, outriggers=False)
if len(outrigger_ants) > 0:
    Plot_Array(ants=outrigger_ants, unused_ants=sorted(set(unused_ants + core_ants)), outriggers=True)

Metadata¶

In [27]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.5.dev13+gd6c757c
3.2.3.dev121+gc95c57f
In [ ]: