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 = "2460007"
data_path = "/mnt/sn1/2460007"
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-3-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/2460007/zen.2460007.21268.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 1852 ant_metrics files matching glob /mnt/sn1/2460007/zen.2460007.?????.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/2460007/zen.2460007.?????.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 2460007
Date 3-3-2023
LST Range 5.279 -- 15.247 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1852
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 107 / 198 (54.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 148 / 198 (74.7%)
Redcal Done? ❌
Never Flagged Antennas 50 / 198 (25.3%)
A Priori Good Antennas Flagged 72 / 93 total a priori good antennas:
3, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29, 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, 140, 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 29 / 105 total a priori bad antennas:
22, 35, 43, 46, 48, 49, 50, 61, 62, 64, 73,
74, 82, 89, 90, 126, 135, 137, 139, 220, 222,
223, 237, 238, 239, 241, 320, 325, 333
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_2460007.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% 10.511609 14.457762 11.170376 12.030477 5.858751 7.187026 1.581698 2.256676 0.028809 0.030893 0.002751
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.155996 0.482376 5.423504 -1.321101 -0.724388 0.162483 1.779121 0.095864 0.536784 0.585802 0.379636
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 1.743572 1.471130 0.655695 0.443363 0.497568 1.516503 0.678595 0.543773 0.580260 0.581810 0.362588
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% 236.913659 236.886601 inf inf 2557.266674 2613.707432 7000.303204 7409.513405 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% 10.764807 14.176340 10.561994 11.400954 5.863838 7.190721 0.852385 1.221061 0.027638 0.026257 0.001747
16 N01 digital_ok 100.00% 100.00% 0.00% 0.00% 10.778180 -0.693338 11.136699 1.116891 5.859862 2.032185 1.484705 2.927536 0.032327 0.594071 0.459411
17 N01 digital_ok 100.00% 0.00% 100.00% 0.00% 1.198291 13.585021 0.924339 12.028409 0.721549 7.216366 1.326852 1.705612 0.589140 0.042934 0.506772
18 N01 RF_maintenance 100.00% 100.00% 52.11% 0.00% 11.430409 16.811268 11.119392 0.231300 5.943673 3.244689 1.477660 15.052429 0.029774 0.217628 0.163232
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% nan nan inf inf nan nan nan nan nan nan nan
22 N06 not_connected 0.00% 0.00% 0.00% 0.00% -0.708822 -0.345084 0.033926 -0.299280 0.544884 0.669080 -0.250131 -1.217716 0.564452 0.577098 0.345153
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 10.075866 13.532035 11.178367 11.824065 5.939832 7.247336 3.452270 2.811575 0.035573 0.039474 0.005745
28 N01 RF_maintenance 100.00% 0.00% 82.72% 0.00% 8.134090 23.927734 0.428379 3.677396 4.665250 3.813288 4.189043 17.859481 0.353182 0.158171 0.250977
29 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 10.823295 13.965539 10.763695 11.413016 5.925715 7.225755 1.499319 1.099917 0.029573 0.037266 0.007877
30 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.842919 0.169093 1.233277 -1.178544 1.987163 0.381090 2.115149 -0.355382 0.591791 0.614666 0.368512
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% 12.380325 15.159709 5.487744 6.014276 5.901113 7.191883 1.745795 1.358184 0.035129 0.047114 0.008593
35 N06 not_connected 0.00% 0.00% 0.00% 0.00% 0.704828 -0.697557 1.154988 -1.440929 0.203058 -0.867097 -2.037086 -0.316060 0.576605 0.575411 0.336321
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 7.206913 8.210306 1.226203 1.103589 0.673251 1.947535 0.168519 1.057571 0.583522 0.591285 0.370528
37 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 0.153723 22.835383 -0.252966 14.067736 -0.598848 7.192238 -1.145833 4.055146 0.595432 0.033856 0.474845
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.780984 0.038991 -1.451025 3.055092 -0.054424 0.430548 1.333463 10.011777 0.597966 0.587872 0.361974
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.413695 0.114160 -0.155570 0.964959 -0.863204 0.984655 -1.511152 0.789754 0.613402 0.616541 0.362362
44 N05 digital_ok 0.00% 0.00% 0.00% 0.00% -1.529555 0.294395 -0.778364 -0.192682 -1.022465 0.865543 -1.093270 -0.374094 0.614642 0.629650 0.360269
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 0.645473 4.165253 0.595246 1.072729 -0.165191 1.809530 0.454588 21.143998 0.606905 0.613997 0.345021
46 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.762823 -0.315877 -0.494144 -1.216032 -0.061709 -0.470350 -0.225560 -0.756101 0.609696 0.631512 0.358378
47 N06 not_connected 100.00% 100.00% 100.00% 0.00% 11.642099 14.795222 5.390109 5.620175 5.899391 7.146127 3.534032 1.048624 0.031749 0.057956 0.018934
48 N06 not_connected 0.00% 0.00% 0.00% 0.00% 0.012414 0.911010 -0.545265 1.400825 1.348095 1.414839 -0.625062 -2.060348 0.576114 0.600212 0.345266
49 N06 not_connected 0.00% 0.00% 0.00% 0.00% -0.288213 -0.148196 -0.517230 -0.033926 -0.662794 -0.418319 0.073730 0.029131 0.538625 0.579120 0.344720
50 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.675081 0.937810 0.046788 2.094994 -0.066587 1.486716 -0.107614 0.171590 0.585509 0.589373 0.365196
51 N03 dish_maintenance 100.00% 0.00% 0.00% 0.00% 8.016692 1.758469 0.151539 0.159264 1.822893 1.940729 28.512872 0.176687 0.580467 0.603547 0.363043
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 7.256796 5.805655 0.380889 0.401400 1.391269 1.320192 2.215766 0.678018 0.600524 0.612488 0.361845
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.945090 1.680976 -0.142879 -0.946750 1.405311 0.612386 10.756200 7.069552 0.602583 0.618328 0.369442
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% 10.097350 13.884434 11.072431 11.945933 5.863293 7.166982 2.116365 1.729968 0.037899 0.037314 0.002561
59 N05 RF_maintenance 100.00% 100.00% 0.00% 0.00% 11.020730 1.015466 10.604294 1.133445 5.765589 1.873778 0.957536 10.922323 0.050746 0.627911 0.501346
60 N05 RF_maintenance 100.00% 0.00% 98.81% 0.00% 0.406703 13.817860 -0.235116 11.975844 0.258377 7.168053 6.577181 3.394598 0.617427 0.082156 0.500756
61 N06 not_connected 0.00% 0.00% 0.00% 0.00% 2.229650 -0.189226 0.209782 -0.993823 0.454506 -1.121726 -0.380975 0.670386 0.558740 0.599095 0.339364
62 N06 not_connected 0.00% 0.00% 0.00% 0.00% -0.353165 0.713598 -0.729415 0.833901 -1.097359 0.211570 0.868287 -1.179522 0.562971 0.601467 0.344994
63 N06 not_connected 100.00% 0.00% 100.00% 0.00% 1.168041 14.341855 -0.597034 6.044413 -0.278469 7.254026 -0.363013 3.704975 0.567430 0.047213 0.438903
64 N06 not_connected 0.00% 0.00% 0.00% 0.00% -0.146909 0.127729 -1.175037 -0.431134 -0.879407 -1.105404 3.075179 0.363492 0.555789 0.558600 0.335174
65 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 23.637347 22.587889 14.271669 14.513646 6.012330 7.262833 5.908707 7.513667 0.022668 0.028116 0.005723
66 N03 digital_ok 100.00% 0.00% 0.00% 100.00% 1.014261 0.403471 -1.356767 4.091930 1.731271 0.910923 -0.396468 2.103736 0.237519 0.223276 -0.278811
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.420594 -0.824066 -1.305371 1.230493 -0.572754 1.820926 4.720157 1.767630 0.606031 0.612200 0.356568
68 N03 dish_maintenance 100.00% 100.00% 0.00% 0.00% 25.548874 0.252541 14.415723 0.612275 5.877109 0.469022 6.677548 -1.002236 0.034608 0.618874 0.487461
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% nan nan inf inf nan nan nan nan 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.366130 0.815378 -1.155291 -0.567975 0.212143 -0.583985 -0.262430 -0.545498 0.633683 0.646099 0.349260
74 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.487656 0.445009 -0.223207 -0.268683 -0.683698 1.026788 -1.443063 3.711735 0.635114 0.646954 0.343818
77 N06 not_connected 100.00% 0.00% 0.00% 0.00% 55.692079 23.022030 0.729340 -0.604763 3.989576 1.690233 0.641210 -0.871874 0.322199 0.486889 0.263778
78 N06 not_connected 100.00% 0.00% 0.00% 0.00% 28.624995 0.609036 -0.427888 1.134935 1.490187 0.593774 0.752058 0.217228 0.424283 0.603542 0.342303
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.555901 14.696190 0.406468 10.541307 0.439647 6.966058 0.050728 2.413755 0.559793 0.040570 0.424723
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 3.228943 0.907379 -0.771412 -0.389867 -0.078112 -0.990163 -0.474529 -0.338937 0.591627 0.602840 0.361469
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.221052 0.216611 0.547746 0.935711 0.544250 0.392744 -0.243398 1.260877 0.593467 0.599011 0.352642
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.538879 0.130672 0.677350 1.291967 0.207027 -0.057314 1.110750 0.409815 0.617870 0.630907 0.339564
89 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.675050 0.323052 0.509266 1.308032 -0.326067 -0.090378 -0.293074 0.027102 0.625152 0.643781 0.337491
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 0.082598 -0.546201 -0.962227 -0.694085 -0.502154 -0.958154 -0.225841 2.899854 0.633599 0.655391 0.339048
91 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.664973 0.020807 0.846351 0.727568 -0.022779 0.427935 0.021434 0.102329 0.616077 0.647849 0.338432
92 N10 RF_maintenance 100.00% 100.00% 0.00% 0.00% 10.600793 0.281086 11.063786 0.586948 5.956730 1.557546 0.990822 0.999872 0.036723 0.643679 0.411905
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 10.968131 14.058676 11.206071 12.052463 5.844114 7.142346 3.437637 2.882310 0.030798 0.024953 0.002699
94 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 11.550834 14.315467 11.321820 11.841350 5.967509 7.180785 2.152081 1.466328 0.025273 0.025312 0.001205
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.257789 0.302880 0.500898 1.357316 0.895019 0.627852 -0.113027 -0.021434 0.624568 0.639032 0.339308
106 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 1.089475 -0.672478 -0.616004 -0.057902 -0.190517 -0.457425 -0.029274 -0.224353 0.634434 0.643018 0.328988
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 4.457831 1.125610 -0.487905 -0.821792 0.965665 0.085804 3.302791 3.984069 0.629384 0.659671 0.329509
108 N09 RF_maintenance 100.00% 100.00% 0.00% 0.00% 10.701005 40.302564 11.117206 1.511384 5.907180 3.698566 2.501799 1.508797 0.034787 0.327667 0.180132
109 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 10.456155 13.902558 11.157248 11.703475 5.945752 7.237270 1.172997 2.627673 0.058502 0.035395 0.014301
110 N10 RF_maintenance 100.00% 0.00% 0.00% 0.00% 13.925970 11.513900 6.713123 0.150262 7.134377 -0.040513 2.745780 -0.282844 0.539501 0.596001 0.311864
111 N10 digital_ok 100.00% 0.00% 99.89% 0.00% 29.515473 13.752625 1.412460 11.797773 3.465357 7.226208 7.269946 3.055323 0.487475 0.065698 0.318774
112 N10 digital_ok 100.00% 59.02% 97.89% 0.00% 2.263813 13.420060 7.949091 11.871889 0.318391 6.985902 0.661062 1.338822 0.204804 0.081784 -0.099219
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% 11.489903 15.384148 11.242973 12.316199 5.821545 7.173995 1.990690 4.958562 0.028246 0.032440 0.002882
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.302598 1.488168 0.236845 0.917002 0.117416 0.909170 -0.224382 0.475405 0.596616 0.610423 0.358085
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% 10.806368 0.209316 11.399323 1.041406 5.806747 1.006688 1.315995 0.864260 0.044321 0.657592 0.461344
125 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 3.090368 0.688874 1.052913 1.340877 0.755896 0.316134 6.448698 1.836113 0.635576 0.651404 0.324998
126 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 1.102610 0.871371 -0.617201 1.371403 0.458568 0.745833 1.675582 0.401703 0.644064 0.653295 0.327024
127 N10 digital_ok 100.00% 100.00% 0.00% 0.00% 10.251778 0.187251 11.054129 0.721505 5.946470 1.511571 0.950703 0.641135 0.035147 0.653599 0.413904
128 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 0.247439 -0.508475 -1.237070 -0.527120 0.144871 -0.403475 0.130927 5.052435 0.627688 0.641394 0.354064
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 0.00% 0.00% 0.00% 0.00% -0.394943 -1.149003 -1.124239 -1.402857 2.790127 0.761222 0.743383 -0.052331 0.567638 0.592277 0.368841
136 N12 digital_ok 100.00% 100.00% 0.00% 0.00% 9.782288 0.079443 10.733317 -0.436067 5.942460 0.176834 2.319944 -0.131541 0.041632 0.593316 0.408745
137 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.423028 -0.579042 0.397703 -1.347780 1.278856 -0.210138 1.886774 1.784745 0.582563 0.608966 0.359918
139 N13 RF_maintenance 0.00% 0.00% 0.00% 0.00% 1.093423 1.277197 1.256811 -1.266976 0.207992 -0.867891 -1.697641 -0.816002 0.601567 0.602243 0.346531
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 0.496684 -1.164851 -0.608657 -0.519553 0.502690 -0.854821 5.273536 3.095580 0.614821 0.634945 0.350568
141 N13 digital_ok 0.00% 0.00% 0.00% 0.00% -0.739288 -0.780088 -0.049429 0.315397 1.026211 -0.607711 0.144136 -1.402238 0.620532 0.642482 0.347692
142 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 1.963894 13.905329 -0.529303 11.983786 1.598572 7.197182 14.908117 2.614054 0.631055 0.050222 0.487323
143 N14 RF_maintenance 100.00% 98.97% 100.00% 0.00% 11.328995 13.862043 11.001428 11.951281 5.500872 7.200084 0.987078 2.406151 0.110678 0.030783 0.061075
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.556422 1.250939 -0.921260 2.355460 0.229028 0.228283 -0.680401 0.373989 0.648071 0.660169 0.331476
145 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.063525 -0.424110 2.041776 0.747810 0.113373 1.092028 0.662941 -1.631584 0.642647 0.663885 0.337033
146 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.327708 0.259185 -1.116187 -0.671632 -1.084220 -1.188720 -0.606175 0.968645 0.617180 0.637978 0.334836
147 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
148 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 212.011606 212.925453 inf inf 2961.810167 2934.317601 9091.279863 8954.383041 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% nan nan inf inf nan nan nan nan nan nan nan
151 N16 digital_ok 100.00% 0.00% 0.00% 0.00% 22.249245 1.004558 -0.582451 0.973176 1.838740 -0.856171 0.289275 -0.037282 0.433893 0.535583 0.325050
155 N12 RF_maintenance 100.00% 100.00% 0.00% 0.00% 10.172024 -0.971821 10.892966 -0.903725 5.956299 0.349095 3.103625 0.947645 0.043627 0.599327 0.424109
156 N12 RF_maintenance 100.00% 0.00% 100.00% 0.00% 2.965735 13.671104 8.847547 11.746241 1.790078 7.248976 2.789567 3.117283 0.444488 0.040631 0.324123
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.732346 -0.094787 0.355963 1.101256 0.255285 1.691881 0.047753 0.433877 0.590860 0.610690 0.360445
158 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 0.426463 -0.484681 0.078900 0.156228 1.733002 1.708277 4.642664 20.139160 0.603494 0.623926 0.359954
159 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.640833 24.973713 -1.171098 -0.580437 -1.007901 2.574406 -0.107475 2.203997 0.578905 0.499345 0.317967
160 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.414358 -0.768116 -0.201093 -0.379582 0.093791 1.363937 -0.435530 1.264478 0.619582 0.642651 0.349011
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.181081 29.653625 0.331654 0.036767 0.575957 0.479387 -0.069224 1.003892 0.628635 0.527425 0.305029
162 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -1.132052 -1.336411 -0.175791 -1.326036 -0.018557 0.445713 5.440242 -0.283057 0.644645 0.663210 0.339669
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.727579 1.525139 0.140363 0.793632 0.379188 1.810617 0.281155 1.297281 0.650699 0.666634 0.336991
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.442116 0.639794 0.139384 1.772803 0.928993 1.339091 0.274719 1.693750 0.649686 0.660886 0.327052
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 20.348416 0.316771 -0.607248 -0.536325 2.364874 0.429965 8.208828 -0.337521 0.559708 0.661535 0.335193
166 N14 digital_ok 0.00% 0.00% 0.00% 0.00% -0.807858 -0.012414 0.979842 0.471054 0.805327 -0.682681 0.596099 -1.607394 0.641024 0.655157 0.330960
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% 0.704615 1.363341 -1.386094 -0.035930 -1.027113 -0.691119 -0.397544 0.729971 0.537697 0.535394 0.343289
173 N16 digital_ok 100.00% 100.00% 100.00% 0.00% 12.804316 14.381802 4.831704 5.651822 5.974283 7.242260 4.618868 7.013848 0.036451 0.043852 0.005083
179 N12 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.417230 -0.871215 -0.727202 0.614154 0.397060 23.968216 -0.422161 4.294948 0.601624 0.622041 0.355764
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% -0.031573 14.624835 -1.246466 12.124655 0.286862 7.146688 19.185366 3.346261 0.621890 0.058668 0.489481
181 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 1.219113 0.382263 1.108072 0.893974 -0.032608 1.063823 0.084641 6.322291 0.629872 0.648957 0.348442
182 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 0.052333 13.607097 -0.953733 11.687916 -0.379283 7.247762 6.169762 2.937926 0.643421 0.052210 0.467949
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% -1.264534 -0.025304 -0.301547 0.508408 0.539253 0.249535 0.648752 -0.035711 0.638467 0.656282 0.329244
184 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 22.327925 -0.196036 6.568084 -0.924053 6.307820 0.352960 9.707683 -0.313974 0.495831 0.664187 0.343202
185 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 4.702331 -0.344047 3.501874 0.619244 3.032795 -0.278888 -2.045957 -0.822685 0.619700 0.659137 0.345607
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 2.260218 -0.858822 0.272134 -0.519823 -0.579014 -0.679901 -0.820897 -0.830562 0.628358 0.657517 0.343115
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 8.628244 -0.927953 10.362123 -0.457864 4.364568 0.459002 1.173957 0.158842 0.304840 0.640587 0.425921
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.405238 6.053036 2.555117 4.100374 2.588291 5.793548 -0.652411 -3.565568 0.548206 0.531918 0.367154
193 N16 digital_ok 100.00% 0.00% 0.00% 0.00% 6.819803 0.396337 4.467118 0.805886 4.645739 0.728104 -3.583585 -0.404128 0.515605 0.556041 0.381673
200 N18 RF_maintenance 100.00% 100.00% 34.99% 0.00% 12.369456 36.887456 5.260505 -0.065491 5.959597 3.371479 2.542194 10.929699 0.042390 0.248937 0.160545
201 N18 RF_maintenance 100.00% 0.00% 0.00% 0.00% 2.940710 4.424696 2.830090 3.560749 1.697218 4.906320 -1.495720 -3.023945 0.610179 0.614456 0.338744
202 N18 digital_ok 100.00% 0.00% 0.00% 0.00% 0.538893 2.784483 1.353361 -1.343219 0.484591 -0.234650 -1.470049 24.629612 0.627611 0.623523 0.326118
204 N19 RF_maintenance 100.00% 0.00% 0.00% 0.00% 9.782420 13.975582 1.463748 -0.974904 0.446794 0.706373 20.501409 1.516528 0.638029 0.656756 0.341130
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 9.102422 0.838792 3.860037 -0.897917 3.841639 -0.786882 83.398686 4.639703 0.389744 0.628242 0.411495
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% -0.528354 6.078724 -0.919299 3.109981 5.928701 1.506230 -0.350540 0.427047 0.590366 0.512547 0.349011
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% -0.803810 2.006387 -0.893939 -0.294105 -0.987915 1.609166 7.002045 -0.186229 0.594110 0.591101 0.340767
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% -1.180335 -0.918696 0.253941 -0.691290 -0.924852 -0.790938 3.270795 -1.262921 0.614359 0.620041 0.333009
221 N18 RF_ok 100.00% 0.00% 0.00% 0.00% 1.458650 -0.338061 -1.366030 -1.018919 0.943582 -1.068974 9.919862 -0.450742 0.599773 0.629263 0.335971
222 N18 RF_ok 0.00% 0.00% 0.00% 0.00% -0.090969 -0.265938 -0.373643 -0.147214 -0.784053 -0.832719 2.181015 -1.443065 0.613507 0.634012 0.338547
223 N19 RF_ok 0.00% 0.00% 0.00% 0.00% -0.787062 -0.664138 -1.114936 0.180858 -1.128616 -0.591890 0.877537 1.615155 0.599234 0.630654 0.342337
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 7.116086 5.544405 4.716371 4.053585 4.975050 5.641431 -3.641760 -3.046208 0.578038 0.594895 0.346516
225 N19 RF_ok 100.00% 0.00% 82.13% 0.00% -0.490464 13.918360 0.556905 5.808059 -0.772222 6.955020 -1.279221 2.365040 0.601872 0.155206 0.484199
226 N19 RF_ok 100.00% 0.00% 0.00% 0.00% -0.424844 19.997539 -0.722614 0.321641 -1.175862 3.662212 -0.954283 -0.448402 0.580239 0.493447 0.332182
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.374678 -0.229533 0.360021 -1.285448 -0.760294 -0.328990 0.145005 -0.817259 0.549631 0.598019 0.349440
238 N18 RF_ok 0.00% 0.00% 0.00% 0.00% 0.254948 -0.202403 1.127378 0.574746 0.022779 -0.580966 -1.930258 -1.976724 0.601106 0.614883 0.344426
239 N18 RF_ok 0.00% 0.00% 0.00% 0.00% -0.841091 -0.673932 0.238629 0.270974 -0.287368 -0.414706 -0.680511 0.477846 0.606278 0.617674 0.344583
240 N19 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.251121 0.133696 -0.565836 -1.224771 -0.813424 -1.191407 10.253314 4.682052 0.597193 0.613314 0.345414
241 N19 RF_ok 0.00% 0.00% 0.00% 0.00% -0.964851 -1.145166 -0.547440 -0.132895 -1.036416 -0.877602 1.074198 -0.743863 0.594207 0.613868 0.357505
242 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 22.466329 0.259340 -0.356817 0.918641 1.415566 0.620055 -1.060617 -0.265929 0.457508 0.601256 0.359217
243 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 20.576456 -0.919178 0.752056 -1.168526 1.983611 -0.613492 -1.001724 0.117241 0.450578 0.577986 0.360896
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 0.00% 0.00% 0.00% 0.00% 3.532055 1.088114 2.280317 0.850327 1.135362 0.319133 -0.780451 0.514864 0.484740 0.499877 0.360334
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.234663 -0.967714 0.944350 -1.289118 0.176166 -1.172996 -1.653573 0.786507 0.496408 0.498131 0.351106
329 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 1.784586 -0.079457 -1.163615 -1.278365 -0.906129 -0.974344 4.665784 0.051594 0.462080 0.483332 0.342173
333 N12 dish_maintenance 0.00% 0.00% 0.00% 0.00% 3.193395 3.617395 -0.662156 -1.118054 -1.041242 -0.535382 1.103649 0.544815 0.443476 0.461557 0.322490
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 31, 32, 34, 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, 125, 127, 128, 131, 132, 133, 134, 136, 140, 142, 143, 147, 148, 149, 150, 151, 155, 156, 158, 159, 161, 162, 165, 167, 168, 169, 170, 173, 179, 180, 181, 182, 184, 185, 187, 189, 190, 191, 192, 193, 200, 201, 202, 204, 205, 206, 207, 208, 209, 210, 211, 221, 224, 225, 226, 227, 228, 229, 240, 242, 243, 244, 245, 246, 261, 262, 324, 329]

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

golden_ants: [5, 30, 44, 83, 88, 91, 105, 106, 118, 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_2460007.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 [ ]: