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 = "2459872"
data_path = "/mnt/sn1/2459872"
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-19-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/2459872/zen.2459872.25283.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 1729 ant_metrics files matching glob /mnt/sn1/2459872/zen.2459872.?????.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/2459872/zen.2459872.?????.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 2459872
Date 10-19-2022
LST Range 21.375 -- 7.087 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1729
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, N14
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 67 / 180 (37.2%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 152 / 180 (84.4%)
Redcal Done? ❌
Never Flagged Antennas 23 / 180 (12.8%)
A Priori Good Antennas Flagged 77 / 98 total a priori good antennas:
3, 7, 10, 19, 20, 21, 29, 30, 31, 37, 38, 45,
46, 51, 53, 54, 55, 66, 67, 68, 69, 71, 72,
73, 81, 84, 86, 88, 91, 93, 94, 98, 101, 103,
105, 106, 107, 108, 109, 111, 116, 117, 121,
122, 123, 124, 128, 140, 141, 142, 143, 144,
147, 156, 158, 160, 161, 162, 163, 164, 165,
167, 169, 170, 176, 177, 178, 179, 181, 183,
184, 185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 2 / 82 total a priori bad antennas:
4, 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_2459872.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% 5.581840 -1.200733 -0.009490 -0.694702 0.137870 1.230715 0.140941 6.267416 0.679948 0.674186 0.399774
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 1.581190 2.576973 1.442150 0.239758 0.764694 1.349761 0.464448 -1.063192 0.687670 0.676406 0.390986
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -0.389511 0.133225 -0.688801 1.520017 0.826925 1.301304 -0.189694 -0.964600 0.697254 0.676619 0.384463
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% -1.883117 -1.023694 -0.055153 0.534560 0.854061 4.007650 2.976216 15.384557 0.693119 0.677452 0.391332
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.026765 1.343353 1.874468 0.323743 -0.129959 -0.130775 11.719325 0.406965 0.687324 0.661610 0.384117
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% -0.424912 -2.072585 -0.737505 -0.037775 1.357881 0.020205 -0.180310 0.083036 0.689741 0.669938 0.398604
10 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 14.941749 -1.324934 15.492035 6.465504 6.784154 4.030585 2.489400 0.040769 0.655869 0.666987 0.407275
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.972636 0.122663 0.430099 -0.161439 -0.042660 -0.109632 3.153529 1.182077 0.696426 0.682788 0.391859
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -0.723829 1.197435 0.037775 -0.391368 -0.350097 0.760889 1.184102 2.845222 0.699066 0.676607 0.381495
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% -0.740949 0.475939 -0.610234 0.437047 0.077817 -0.064647 0.428657 0.640450 0.697327 0.687742 0.383434
18 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 3.593799 16.209210 0.838194 1.399281 3.561545 10.585978 23.359350 32.103685 0.680890 0.464535 0.426489
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 2.987803 -0.890365 -0.251246 14.150299 1.322431 4.171528 1.692583 8.238465 0.692874 0.673680 0.387658
20 N02 digital_ok 100.00% 0.00% 0.00% 0.00% -1.376906 3.931998 0.734843 18.126876 1.839133 3.563383 6.883542 -1.341797 0.700221 0.677996 0.388809
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 1.140650 0.379574 -0.580895 -0.690350 2.155714 0.901916 1.656018 8.585262 0.687747 0.671688 0.396376
22 N06 not_connected 100.00% 0.00% 0.00% 0.00% 44.851870 15.924735 5.797265 20.727300 10.683878 7.720557 7.117031 0.683581 0.464519 0.612943 0.341304
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 16.656437 18.255533 58.209717 59.456149 20.196889 31.466069 4.558123 2.724159 0.031309 0.035141 0.002653
28 N01 RF_maintenance 100.00% 0.00% 86.47% 0.00% 20.758168 41.195499 6.645667 5.009888 15.681370 28.361097 10.675709 21.082077 0.359946 0.157486 0.220197
29 N01 digital_ok 100.00% 0.00% 0.00% 0.00% -1.423547 -0.616819 -0.183061 0.278398 -0.537008 1.290449 -0.028996 4.862523 0.699833 0.683915 0.377010
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 0.784523 -1.417095 -0.342252 -0.936020 2.221220 -0.697535 23.287042 0.732172 0.694714 0.689115 0.379061
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 0.268651 -0.009894 0.416057 -0.722202 1.662229 5.134349 1.983310 6.070690 0.711255 0.690049 0.389069
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 12.164180 35.579038 2.128401 5.153518 3.642582 18.710458 1.643028 12.554568 0.652717 0.605827 0.321198
33 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.041689 19.837989 -0.233449 1.413097 -0.035067 7.910802 1.762108 30.926621 0.693365 0.493416 0.463153
34 N06 not_connected 100.00% 100.00% 0.00% 0.00% 19.089155 3.977429 23.225304 21.116001 20.105184 4.422955 2.051963 -1.175149 0.039272 0.658343 0.477640
35 N06 not_connected 100.00% 0.00% 0.00% 0.00% 3.234401 1.436761 2.055404 12.812705 6.749173 5.567204 2.090392 -0.370887 0.608192 0.636531 0.406148
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 13.289750 12.545622 0.942205 0.808689 2.416892 4.418416 0.569188 0.348563 0.698203 0.680227 0.395237
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.042369 1.211382 3.267852 4.635457 -0.897387 1.546418 -0.107441 7.379075 0.703260 0.686062 0.397241
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.035263 0.203533 -0.566818 -0.756497 0.614801 0.960280 9.028718 2.499108 0.707390 0.691553 0.396999
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% -0.127288 -0.046646 -0.071280 -0.827248 0.732854 -0.970387 -0.670918 -1.114030 0.698769 0.683507 0.391557
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.212841 0.960808 1.689681 1.593372 0.761448 -1.378420 -0.680531 -1.033429 0.700947 0.683799 0.376909
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% -0.667308 1.249248 -0.631084 1.607971 -0.689939 -0.605408 -0.559004 -1.185797 0.709502 0.697110 0.389477
43 N05 digital_maintenance 100.00% 100.00% 0.00% 0.00% 15.569373 2.506482 57.548069 -0.457654 20.208991 1.173368 3.115776 2.672329 0.036890 0.691895 0.451042
44 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 5.494963 1.391322 3.430018 4.106251 4.293955 1.482931 12.055293 6.298480 0.684354 0.691275 0.376204
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% -0.877981 3.237719 -0.738537 0.257658 -0.550515 4.841874 0.192712 19.395391 0.702361 0.674418 0.383531
46 N05 digital_ok 100.00% 0.00% 100.00% 0.00% -0.889088 18.939026 -0.775860 59.691551 0.325536 31.361824 -0.015595 4.127723 0.697161 0.034162 0.476112
47 N06 not_connected 100.00% 100.00% 0.00% 0.00% 17.940188 4.170154 22.090979 14.624336 20.183266 4.813185 1.936363 3.268872 0.036669 0.656950 0.478789
48 N06 not_connected 100.00% 0.00% 0.00% 0.00% 2.890417 2.983824 26.990840 32.593799 4.093628 9.190044 -1.414443 -2.821963 0.673308 0.670651 0.406249
49 N06 not_connected 100.00% 0.00% 0.00% 0.00% 1.902554 2.359300 13.309900 30.855915 3.517858 9.966930 1.668656 -0.646678 0.640129 0.653889 0.407475
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 4.811668 6.128542 -0.167927 1.072760 4.655160 9.810893 7.644982 14.934135 0.687126 0.664391 0.375253
51 N03 digital_ok 100.00% 100.00% 0.00% 0.00% 35.960297 1.641516 75.401362 -0.276740 19.727176 2.075108 14.005782 8.012479 0.035329 0.689730 0.438651
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 10.850316 10.404175 1.220495 0.513822 4.006294 -0.323807 0.987034 0.349901 0.709340 0.693491 0.383752
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.662861 4.176090 -0.216725 0.376146 -0.125905 0.160881 5.009311 7.509264 0.710982 0.697674 0.390963
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 16.603940 19.279125 58.246313 60.940949 20.260188 31.431396 3.758357 1.598008 0.042040 0.041759 0.001380
55 N04 digital_ok 100.00% 0.00% 100.00% 0.00% 2.991218 20.363154 -0.203684 60.341744 11.604867 31.319880 3.177266 3.868378 0.697821 0.032762 0.458390
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% -0.003466 1.268775 -0.219242 -0.645276 0.352014 2.524628 -0.237829 3.733012 0.701152 0.694294 0.373102
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 48.027185 -0.963956 27.877894 2.937702 11.136190 2.193500 2.621071 0.459425 0.525352 0.694918 0.380029
58 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 16.047053 19.074026 57.961308 60.663289 20.320935 31.533339 4.647622 3.475849 0.034718 0.032515 0.001781
59 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 22.222934 12.594723 5.966079 0.790190 6.588111 6.326885 3.849571 7.493918 0.658891 0.665986 0.367010
60 N05 digital_maintenance 100.00% 100.00% 100.00% 0.00% 17.344520 18.630527 58.121283 60.501321 20.216716 31.494694 3.337174 3.903816 0.027305 0.026531 0.001360
61 N06 not_connected 100.00% 0.00% 0.00% 0.00% 5.758440 5.420754 6.411152 0.518888 5.202835 9.136454 -0.167365 3.585088 0.655751 0.630055 0.381565
62 N06 not_connected 100.00% 0.00% 0.00% 0.00% 2.418064 2.961102 21.889624 29.944435 3.107528 9.487560 0.275318 -1.834684 0.675199 0.673882 0.395096
63 N06 not_connected 100.00% 0.00% 100.00% 0.00% 14.206063 19.144210 22.297570 24.025526 5.414039 31.380635 1.141289 4.238294 0.621391 0.039664 0.474249
64 N06 not_connected 100.00% 0.00% 0.00% 0.00% 3.244775 1.592003 14.004069 24.973224 2.662522 5.943211 0.692625 -1.637516 0.626794 0.636595 0.407476
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.962999 0.477812 -0.335063 1.662313 2.348528 3.196247 -0.534976 -0.810731 0.692891 0.676944 0.394418
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.294728 2.235330 13.769253 7.895910 2.018765 1.503383 -0.229902 0.304493 0.695134 0.685932 0.389774
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.992320 -0.187228 6.286450 3.777967 0.692280 1.036883 1.462013 3.078607 0.700749 0.688517 0.381243
68 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 3.699765 39.967945 0.781103 81.317068 0.304467 30.252649 0.880183 13.973483 0.699931 0.028882 0.414219
69 N04 digital_ok 100.00% 0.00% 0.00% 0.00% -0.064784 -1.296232 -0.825276 0.109883 0.513616 4.357248 -0.163149 0.049820 0.703256 0.693697 0.383170
70 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.732942 -0.690655 1.265628 1.757729 -0.380159 -0.379989 0.016150 -0.941599 0.707290 0.698616 0.386551
71 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 11.231388 -0.373657 2.425898 1.421250 1.591643 0.245353 -0.289010 0.007875 0.714577 0.697020 0.385265
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 5.279100 -0.709092 1.473758 1.151099 2.235957 0.453938 0.939462 -0.782870 0.690841 0.689575 0.379595
73 N05 digital_ok 100.00% 100.00% 100.00% 0.00% 15.502857 17.607630 57.150700 58.669871 20.141560 31.450948 4.463765 1.276676 0.026888 0.026757 0.001226
74 N05 digital_maintenance 100.00% 100.00% 2.37% 0.00% 17.195677 16.283072 60.003146 58.703034 20.484309 27.815506 3.984127 19.808568 0.029576 0.308143 0.181495
75 N05 digital_maintenance 100.00% 0.00% 100.00% 0.00% 11.187351 19.357381 18.789440 61.184736 2.568852 31.597250 5.121333 4.659987 0.664638 0.042355 0.454538
77 N06 not_connected 100.00% 0.00% 0.00% 0.00% 36.515380 37.596262 22.871335 19.047765 9.269598 18.475706 9.507674 -0.022066 0.559534 0.507195 0.201584
78 N06 not_connected 100.00% 0.00% 0.00% 0.00% 51.039712 0.634174 17.017913 22.254174 10.943608 4.596458 -0.774765 0.962124 0.486745 0.651662 0.378874
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% -0.185603 -0.559246 0.028005 8.249262 0.740493 21.396372 0.092786 0.074943 0.669520 0.652527 0.386676
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 3.192733 0.256441 -0.218897 8.135817 -0.407216 1.607186 -0.229081 -0.583910 0.683438 0.666866 0.386988
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.713523 -0.506684 -0.104799 0.697404 0.183793 0.995007 -0.801274 0.092885 0.693198 0.682029 0.379316
84 N08 digital_ok 100.00% 0.00% 100.00% 0.00% 9.513197 35.675589 7.884588 78.560729 -1.142230 30.345737 -0.412898 7.320080 0.697865 0.036721 0.503101
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.624583 0.313855 -0.768575 -0.569090 -0.568257 -1.111018 -0.788950 -1.174948 0.700921 0.683743 0.384378
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 3.439939 6.717273 1.996221 0.938053 4.523365 5.283753 0.457002 31.499337 0.690325 0.653710 0.378282
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 6.731028 11.700772 0.056417 1.090428 4.348875 5.641997 -0.073007 0.855614 0.712025 0.702190 0.382592
88 N09 digital_ok 0.00% 100.00% 100.00% 0.00% 1.080970 1.175370 0.341665 -0.210585 -0.299507 0.370505 -0.490984 -0.889739 0.069789 0.067000 0.011894
89 N09 RF_maintenance 0.00% 100.00% 100.00% 0.00% 1.392589 0.155634 -0.095851 0.165404 0.014998 -0.627437 -0.693606 -0.911499 0.061011 0.061172 0.006996
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 0.406437 -0.275029 -0.391330 1.098217 -0.578197 0.009697 0.843640 4.704938 0.067558 0.068496 0.010382
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
92 N10 RF_maintenance 100.00% 0.00% 19.38% 0.00% 56.882955 63.141478 7.367980 8.576001 17.798881 25.003528 0.288597 9.021944 0.292858 0.237235 0.093896
93 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 3.987181 0.648262 8.788648 -0.556870 2.002727 0.089065 7.335766 -0.604832 0.696309 0.688343 0.390109
94 N10 digital_ok 100.00% 0.00% 0.00% 0.00% -1.137115 -1.554145 -0.822828 -0.938121 0.284669 5.391474 2.650985 1.994656 0.699070 0.679131 0.393277
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 1.822173 10.718369 0.642813 0.651080 0.495539 4.401667 1.176424 4.525675 0.667066 0.648119 0.381691
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.563599 -0.948671 0.777952 -0.793655 2.820383 0.726471 3.447831 -1.038286 0.671618 0.666215 0.385478
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.302900 -1.094473 -0.140586 2.192697 2.988311 -0.053663 0.533504 0.128765 0.684615 0.671100 0.378679
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 10.993080 13.687883 3.228854 2.285801 -0.393436 -0.857020 0.397174 -0.866736 0.708591 0.688915 0.376354
102 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 7.452678 19.110283 40.324957 57.286973 18.549813 31.611357 2.352168 6.416428 0.593074 0.038590 0.444635
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 34.895157 36.486229 67.359332 69.466345 20.343957 31.273405 14.249161 12.337780 0.026029 0.026847 0.001815
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 10.385124 84.347357 4.096689 56.359645 0.182597 1.060001 0.118540 -0.070261 0.705829 0.619915 0.420916
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
106 N09 digital_ok 0.00% 100.00% 100.00% 0.00% 0.299261 1.211731 2.938411 1.410282 0.989671 -0.168083 0.482754 -0.532475 0.060799 0.058696 0.006141
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 3.876351 1.845269 1.345202 4.961444 0.272771 0.666784 1.214833 3.193961 0.050053 0.057610 0.004690
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
109 N10 digital_ok 100.00% 0.00% 100.00% 0.00% -0.776653 18.830219 0.894047 58.728245 -0.753222 31.409151 -0.036638 2.828887 0.700211 0.032676 0.425606
110 N10 RF_maintenance 100.00% 0.00% 100.00% 0.00% 0.516474 37.807816 0.047943 79.566450 -0.059834 30.406958 0.507476 6.564690 0.717314 0.029573 0.431688
111 N10 digital_ok 100.00% 0.00% 100.00% 0.00% -0.209774 18.636126 0.049019 59.380000 -0.939110 31.378461 -0.415245 3.413001 0.704137 0.032730 0.427792
112 N10 digital_ok 0.00% 0.00% 0.00% 0.00% -0.365372 -0.704301 -0.884618 0.767575 0.245072 -0.165912 0.678064 -0.946682 0.692251 0.681667 0.395550
116 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 0.162232 0.788788 -0.228342 -0.382754 5.764377 2.819552 8.805244 0.321032 0.662242 0.653436 0.389205
117 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 18.070655 21.011849 58.544031 62.553406 20.302254 31.515391 2.719774 5.381285 0.027846 0.029811 0.002168
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.324637 1.039269 1.317156 0.525443 -0.434325 -0.014998 0.375184 0.765623 0.686415 0.674912 0.381620
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.917468 3.697646 4.260165 21.512966 -0.813749 9.649091 0.518637 1.967077 0.698578 0.637636 0.393935
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 3.806895 34.986560 -0.352078 78.292530 2.640045 30.769973 1.578655 12.716187 0.702816 0.032057 0.518239
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 3.342499 7.825693 0.023338 0.973732 1.072665 2.000141 58.391872 22.919001 0.711560 0.690785 0.383873
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 12.316104 10.593117 0.920668 1.464548 6.048875 -0.860174 -0.136828 -0.942766 0.714405 0.690742 0.387965
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 9.469198 13.850278 1.477072 1.906658 -1.438637 0.410113 0.070616 -0.085472 0.708087 0.692714 0.393407
124 N09 digital_ok 0.00% 100.00% 100.00% 0.00% -0.737176 2.989907 0.640975 -0.157528 -1.005645 -1.072268 0.665979 -0.224246 0.066975 0.065348 0.009644
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 0.147294 2.823534 0.719219 -0.247098 -0.158301 5.859184 -0.094378 0.662999 0.061564 0.063335 0.007092
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 1.691773 -0.343786 7.824673 1.337401 4.160697 10.295420 3.237085 11.743837 0.068447 0.067974 0.011856
127 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.003466 -0.302547 -0.691351 -0.660180 -0.090160 1.407546 0.037965 1.590016 0.701829 0.691048 0.403266
128 N10 digital_ok 100.00% 0.00% 0.00% 0.00% -1.098811 8.320593 5.671047 3.054517 -0.120874 2.619515 -0.343899 -0.676776 0.702043 0.673604 0.388798
129 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.208611 -1.714229 1.872415 1.751466 -0.450357 -0.356769 -0.435230 0.437675 0.703090 0.687321 0.394294
130 N10 digital_ok 0.00% 0.00% 0.00% 0.00% -0.031813 -0.411153 0.044999 -0.163426 0.673682 0.919802 0.055889 2.896285 0.691456 0.681811 0.389462
135 N12 digital_maintenance 100.00% 0.00% 100.00% 0.00% -1.838870 18.825335 -0.608082 60.855711 1.640896 31.559871 0.736033 1.903458 0.661503 0.035871 0.414040
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 5.727092 1.064171 0.094460 0.336431 1.346600 -0.230975 0.235489 -0.629970 0.650804 0.649689 0.387413
137 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.859203 -1.186119 -0.438895 -0.953165 3.818488 -0.153680 2.525496 -0.371447 0.667330 0.656963 0.387914
138 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.144065 -0.759111 4.747503 5.820744 -1.272168 -0.268058 11.600287 -0.541535 0.687143 0.670746 0.391210
140 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 5.396563 19.906600 44.208684 59.902235 10.386404 31.312721 -0.767696 3.888491 0.690891 0.047454 0.435734
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -1.701754 7.203534 2.059629 48.232479 1.282239 22.716784 0.369746 -3.953972 0.700125 0.666147 0.380799
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 1.899978 18.709123 1.313284 60.435100 3.910792 31.510610 1.296402 2.765253 0.692809 0.043673 0.443813
143 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 16.997774 -1.905831 58.980908 -1.072139 20.401323 -0.529907 0.946196 -1.010555 0.027236 0.065935 0.038960
144 N14 digital_ok 100.00% 100.00% 100.00% 0.00% -1.407704 -0.876833 0.181630 12.461338 0.827748 -0.319487 -0.187343 -0.544560 0.055569 0.069457 0.005700
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% -2.048935 3.293275 1.513506 30.780550 5.234541 11.163776 0.603257 1.236474 0.061800 0.083714 0.008747
147 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 28.418748 28.757652 12.853094 13.821896 15.583956 24.465945 3.122545 1.267076 0.339137 0.338787 0.155081
148 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% -1.077223 -0.400311 18.456118 7.429677 1.732095 -0.687423 1.045702 -0.079604 0.683958 0.685917 0.397245
149 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% -1.075135 1.920307 12.241984 34.530982 -0.717964 10.517593 -0.668730 -2.190238 0.704817 0.691794 0.398262
150 N15 RF_maintenance 100.00% 100.00% 0.35% 0.00% 17.740148 3.946074 58.168013 40.631914 20.169271 14.975952 3.878118 -3.081391 0.043384 0.303969 0.053557
151 N16 not_connected 100.00% 0.00% 0.00% 0.00% 42.442221 2.522212 18.502769 -0.261522 9.815852 6.663020 2.246282 -0.632148 0.527277 0.616835 0.381886
152 N16 not_connected 100.00% 0.00% 0.00% 0.00% 2.828666 2.330103 8.574336 14.546219 3.341590 3.199030 23.325912 -0.897890 0.630031 0.642617 0.416833
153 N16 not_connected 100.00% 100.00% 0.00% 0.00% 17.356714 1.436190 21.762538 16.113526 20.261589 1.899324 2.026988 -0.868229 0.037611 0.638310 0.477435
154 N16 not_connected 100.00% 0.00% 0.00% 0.00% -0.727670 -0.037126 23.409786 22.905701 2.700899 4.590182 0.072730 -0.964171 0.633313 0.634988 0.421126
155 N12 digital_maintenance 100.00% 100.00% 0.00% 0.00% 16.118478 -0.433931 56.046231 0.216101 20.049737 6.408440 1.613277 6.754656 0.054342 0.653064 0.437464
156 N12 digital_ok 100.00% 19.03% 0.00% 0.00% 13.723407 -0.084761 55.860112 1.734972 18.200240 0.451953 2.326791 0.620195 0.274699 0.658447 0.468253
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% -0.071473 -0.681673 -0.393077 -0.452743 -0.661560 1.130423 -0.016150 0.400889 0.676568 0.661629 0.393996
158 N12 digital_ok 100.00% 0.00% 0.00% 0.00% -0.743460 -1.136742 0.776723 2.673289 1.838190 1.260347 8.345099 51.619394 0.689483 0.672349 0.399102
160 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.808150 -0.591573 2.246116 4.886148 -1.133526 0.807805 3.012795 2.950607 0.698667 0.675234 0.378643
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.717818 40.923244 0.649895 8.542731 -1.109456 10.144708 0.467301 1.864222 0.699282 0.546187 0.355618
162 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 2.096900 -0.205160 14.131599 0.606075 4.246631 25.528566 0.842842 2.046209 0.702247 0.677965 0.389777
163 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 0.047346 -1.963330 1.453014 -1.084029 -1.326889 1.162265 0.274893 2.322477 0.053481 0.061124 0.004946
164 N14 digital_ok 100.00% 100.00% 100.00% 0.00% -0.941805 -0.670685 2.860727 2.973587 10.080216 1.669232 2.245763 2.244915 0.057684 0.056540 0.006408
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 28.060555 0.608893 42.759083 3.507752 12.574337 -0.458056 0.250584 -0.864814 0.068375 0.059731 0.020527
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 45.094975 16.397228 9.676573 56.720032 8.018428 28.162309 7.200051 0.322581 0.068580 0.055740 0.028403
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% -0.614122 -1.516679 14.060708 2.229525 1.388300 2.662896 -0.383499 11.105001 0.706571 0.680144 0.408875
168 N15 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.939770 -0.608161 -0.899956 2.154713 -0.675299 -0.623205 -0.437151 0.795185 0.700416 0.683344 0.401693
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 2.507067 3.776517 32.345219 39.544335 3.475349 15.236993 -2.284035 -3.578627 0.706486 0.671963 0.403868
170 N15 digital_ok 100.00% 98.03% 0.00% 0.00% 17.704333 -1.565364 59.270428 13.748579 19.997233 15.522253 1.970644 4.188314 0.044054 0.690185 0.474461
171 N16 not_connected 100.00% 0.00% 0.00% 0.00% 1.884049 4.912056 12.365147 1.845614 3.484387 8.313352 -0.162875 -0.207770 0.643570 0.598445 0.394617
173 N16 not_connected 100.00% 100.00% 100.00% 0.00% 19.747766 20.106015 19.305091 21.717678 20.030987 31.314491 5.329557 9.953802 0.033962 0.037614 0.004067
176 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
178 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
179 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 18.011298 20.530983 59.357132 63.614644 20.421754 31.505970 1.678718 1.936885 0.043453 0.051996 0.008976
180 N13 RF_maintenance 100.00% 100.00% 100.00% 0.00% 17.138455 19.740914 58.759070 61.271108 20.305044 31.538726 1.332319 3.472727 0.045971 0.048050 0.004686
181 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.018353 -1.346505 1.181897 -0.519237 -0.193386 0.409003 0.126646 7.568573 0.706209 0.677424 0.389439
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 3.817135 6.016879 33.436687 44.371273 5.401869 18.445144 16.464819 -0.967126 0.643284 0.673132 0.400590
183 N13 digital_ok 100.00% 100.00% 0.00% 0.00% 17.296950 -0.842462 57.265711 1.535817 20.103975 -0.650372 0.783095 -0.122058 0.039866 0.671670 0.438508
184 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 16.673496 19.298634 58.384156 60.445388 20.265188 31.353900 1.612315 1.523035 0.038067 0.026781 0.007769
185 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 15.952726 -1.445340 58.363180 18.378364 20.202111 1.151916 1.203521 -0.269410 0.029523 0.070800 0.034438
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 1.572280 2.069397 8.022136 14.724686 12.141593 2.672621 2.956121 1.649107 0.055242 0.060404 0.004876
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 4.095046 2.738505 5.739493 33.745266 47.138810 10.770507 2.630931 2.137904 0.065849 0.074647 0.013449
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 1.233026 1.921585 1.791117 4.927383 -0.427782 1.884999 0.576010 0.313217 0.683412 0.672861 0.403601
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 66.773207 19.010254 8.782718 61.080520 15.512081 31.618105 9.834849 4.267021 0.498020 0.032905 0.310841
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% -0.067545 0.011606 21.417979 0.111234 1.089199 -0.530232 15.937204 1.086330 0.661360 0.670115 0.418509
192 N16 not_connected 100.00% 0.00% 0.00% 0.00% 3.042283 10.162324 40.521856 54.304319 7.831531 28.614331 0.003253 -5.388654 0.664742 0.630042 0.418142
193 N16 not_connected 100.00% 0.00% 0.00% 0.00% 9.746468 1.485439 54.002276 33.056434 17.536889 9.472775 -4.822167 -0.433612 0.625141 0.648992 0.428469
200 N18 RF_maintenance 100.00% 100.00% 51.76% 0.00% 19.102158 53.066130 21.854934 25.176764 20.030080 26.786575 3.135264 11.700760 0.045003 0.210740 0.124137
201 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 10.012614 8.648305 53.864256 50.974694 17.413068 25.110381 -4.692485 -4.276643 0.660628 0.640939 0.388871
202 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 2.247662 4.894672 25.535166 2.025448 2.037701 8.455494 4.144539 5.439813 0.682028 0.616207 0.403695
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 19.897515 21.585980 20.405282 22.368058 20.095170 31.279635 4.361251 5.026846 0.033491 0.039063 0.000664
219 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 9.761923 6.345507 54.591885 45.507823 18.170929 19.524715 -4.978920 -3.859054 0.632924 0.652474 0.407890
220 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 5.243410 6.714009 44.912478 45.177079 11.724637 19.823239 -0.144094 -4.214205 0.682707 0.654858 0.404359
221 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 5.115584 1.596899 2.842817 20.530578 5.767832 3.620212 3.759026 0.726841 0.634385 0.649604 0.407065
222 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 6.429426 7.304684 46.631213 45.899747 13.515639 20.549485 -0.360090 -4.320116 0.668729 0.651725 0.406328
237 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 5.386578 3.400451 1.804017 14.885738 5.134501 4.667869 -0.010244 -0.901469 0.622084 0.628042 0.408834
238 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 0.596022 0.318735 28.598615 26.782402 4.709814 7.641948 -1.521315 -2.255472 0.678606 0.649408 0.410534
239 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 0.684593 4.606071 18.336753 40.898064 18.465153 15.851079 7.829737 -2.638588 0.665857 0.648008 0.407709
320 N03 dish_maintenance 100.00% 0.00% 100.00% 0.00% 1.248293 19.589852 1.008485 37.418271 1.355172 31.424963 17.197343 4.190022 0.678524 0.043846 0.445746
321 N02 not_connected 100.00% 0.00% 0.00% 0.00% 1.345551 1.362712 18.126762 20.796832 4.607492 7.093395 5.217486 3.742255 0.601804 0.578050 0.412207
322 N05 digital_maintenance 100.00% 0.00% 0.00% 0.00% 2.605574 3.624834 22.328664 36.177682 3.763485 12.602855 1.460728 -1.933364 0.591080 0.573792 0.407291
323 N02 not_connected 100.00% 0.00% 0.00% 0.00% 37.636012 2.169478 4.042223 32.815891 12.050035 10.821906 10.612335 -0.235932 0.376271 0.565034 0.378929
324 N04 not_connected 100.00% 0.00% 0.00% 0.00% 1.892687 3.745717 29.032997 33.216672 4.666880 10.382856 -0.490921 -2.294134 0.590675 0.567256 0.396288
325 N09 dish_ok 100.00% 100.00% 100.00% 0.00% 0.903932 -0.608459 29.387491 15.064014 4.651499 4.272403 -1.290326 0.501111 0.077324 0.075086 0.028732
329 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 3.582309 -0.514280 12.703168 21.200147 3.770335 5.028010 3.796884 -0.582682 0.565284 0.573978 0.403399
333 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 5.263380 2.345930 5.090433 13.777097 4.478874 5.360007 2.351716 -0.106941 0.547741 0.555727 0.395847
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 7, 8, 10, 18, 19, 20, 21, 22, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, 69, 71, 72, 73, 74, 75, 77, 78, 81, 82, 84, 86, 87, 88, 89, 90, 91, 92, 93, 94, 98, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 116, 117, 119, 120, 121, 122, 123, 124, 125, 126, 128, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 158, 160, 161, 162, 163, 164, 165, 166, 167, 169, 170, 171, 173, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 192, 193, 200, 201, 202, 203, 219, 220, 221, 222, 237, 238, 239, 320, 321, 322, 323, 324, 325, 329, 333]

unflagged_ants: [4, 5, 9, 15, 16, 17, 40, 41, 42, 56, 65, 70, 83, 85, 99, 100, 112, 118, 127, 129, 130, 157, 168]

golden_ants: [5, 9, 15, 16, 17, 40, 41, 42, 56, 65, 70, 83, 85, 99, 100, 112, 118, 127, 129, 130, 157]
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_2459872.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.dev44+g3962204
3.1.5.dev171+gc8e6162
In [ ]: