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 = "2460097"
data_path = "/mnt/sn1/2460097"
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: 6-1-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/2460097/zen.2460097.42114.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 361 ant_metrics files matching glob /mnt/sn1/2460097/zen.2460097.?????.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/2460097/zen.2460097.?????.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 'startTime' 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 2460097
Date 6-1-2023
LST Range 16.210 -- 18.151 hours
X-Engine Status ❌ ❌ ✅ ❌ ✅ ❌ ❌ ❌
Number of Files 361
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: 94
not_connected: 24
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 40, 42, 70, 112
Total Number of Nodes 19
Nodes Registering 0s N01, N15, N20
Nodes Not Correlating
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 77 / 198 (38.9%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 85 / 198 (42.9%)
Redcal Done? ❌
Never Flagged Antennas 111 / 198 (56.1%)
A Priori Good Antennas Flagged 42 / 94 total a priori good antennas:
5, 15, 16, 17, 29, 30, 37, 38, 40, 42, 55,
62, 66, 70, 81, 83, 86, 93, 94, 109, 111, 112,
118, 121, 124, 127, 136, 147, 148, 149, 150,
160, 166, 167, 168, 169, 170, 182, 184, 189,
190, 191
A Priori Bad Antennas Not Flagged 59 / 104 total a priori bad antennas:
8, 22, 32, 35, 36, 43, 46, 48, 49, 50, 52,
57, 63, 64, 73, 74, 77, 78, 79, 80, 87, 89,
90, 95, 96, 97, 102, 108, 110, 113, 114, 115,
120, 126, 132, 133, 134, 135, 139, 159, 179,
185, 201, 206, 220, 221, 222, 223, 224, 237,
238, 239, 241, 242, 243, 320, 324, 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_2460097.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
4 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
5 N01 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
7 N02 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.702805 0.679819 0.360647
8 N02 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.686113 0.653900 0.341183
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.709884 0.687018 0.351201
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.701409 0.682093 0.349003
15 N01 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
16 N01 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
17 N01 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
18 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
19 N02 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.726948 0.689794 0.361230
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.729142 0.708279 0.351128
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.722076 0.700054 0.352235
22 N06 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.702530 0.679536 0.353499
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
28 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
29 N01 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
30 N01 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.740915 0.725007 0.359408
32 N02 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.709854 0.707696 0.209161
34 N06 not_connected 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.119209 0.700038 0.461095
35 N06 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.706751 0.690724 0.353242
36 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.683122 0.644951 0.332558
37 N03 digital_ok 100.00% 0.00% 100.00% 0.00% nan nan nan nan nan nan nan nan 0.700002 0.091849 0.535151
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.707572 0.679089 0.347533
40 N04 digital_ok 100.00% 0.00% 0.00% 100.00% nan nan nan nan nan nan nan nan 0.375144 0.369306 -0.283738
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.739629 0.717958 0.366859
42 N04 digital_ok 0.00% 0.00% 0.00% 100.00% nan nan nan nan nan nan nan nan 0.381394 0.374602 -0.292140
43 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.758924 0.740395 0.364617
44 N05 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.751637 0.739540 0.362014
45 N05 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.759725 0.742660 0.365935
46 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.750318 0.732852 0.370042
47 N06 not_connected 100.00% 0.00% 48.48% 0.00% nan nan nan nan nan nan nan nan 0.469285 0.232290 0.277021
48 N06 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.721718 0.700741 0.350922
49 N06 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.718449 0.691103 0.359454
50 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.684645 0.650142 0.339443
51 N03 dish_maintenance 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.701184 0.671766 0.335792
52 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.718194 0.687601 0.348376
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.732680 0.705902 0.354889
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.489456 0.526135 0.164331
55 N04 digital_ok 100.00% 0.00% 100.00% 0.00% nan nan nan nan nan nan nan nan 0.401690 0.100730 0.178351
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.761527 0.743236 0.362622
57 N04 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.769758 0.751905 0.365073
58 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan 0.102319 0.106610 0.001786
59 N05 RF_maintenance 100.00% 67.59% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.178158 0.753620 0.522264
60 N05 RF_maintenance 100.00% 0.00% 1.66% 0.00% nan nan nan nan nan nan nan nan 0.759016 0.335965 0.502728
61 N06 not_connected 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.072642 0.729368 0.493687
62 N06 digital_ok 100.00% 0.00% 54.57% 0.00% nan nan nan nan nan nan nan nan 0.727408 0.203722 0.494169
63 N06 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.727162 0.675323 0.368893
64 N06 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.714634 0.689580 0.353414
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.692226 0.657531 0.348474
66 N03 digital_ok 100.00% 0.00% 97.23% 0.00% nan nan nan nan nan nan nan nan 0.371177 0.172912 0.117510
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.725472 0.695315 0.347520
68 N03 dish_maintenance 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.079626 0.707731 0.545277
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.753370 0.724839 0.352480
70 N04 digital_ok 0.00% 0.00% 0.00% 100.00% nan nan nan nan nan nan nan nan 0.417603 0.402682 -0.275240
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.768010 0.757143 0.348295
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.777455 0.763323 0.354792
73 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.778155 0.762545 0.354008
74 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.763642 0.759323 0.362432
77 N06 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.731132 0.723536 0.335641
78 N06 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.708090 0.709053 0.293178
79 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.725970 0.703778 0.357095
80 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.704584 0.666983 0.357929
81 N07 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan 0.031776 0.030859 0.013718
82 N07 RF_maintenance 100.00% 95.29% 73.13% 0.00% nan nan nan nan nan nan nan nan 0.024775 0.034494 0.014122
83 N07 digital_ok 100.00% 90.86% 88.92% 0.00% nan nan nan nan nan nan nan nan 0.024721 0.030299 0.011114
84 N08 RF_maintenance 100.00% 0.00% 95.01% 0.00% nan nan nan nan nan nan nan nan 0.722020 0.175888 0.406480
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.755489 0.733861 0.352045
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.772293 0.751304 0.343545
87 N08 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.727579 0.765980 0.292621
88 N09 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.780803 0.766599 0.349197
89 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.786635 0.772086 0.361415
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.775991 0.770392 0.362505
91 N09 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.778727 0.763836 0.383730
92 N10 RF_maintenance 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.089018 0.753099 0.485756
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan 0.073136 0.048201 0.012105
94 N10 digital_ok 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.055372 0.683748 0.446828
95 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.721137 0.703671 0.357375
96 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.703717 0.644839 0.305321
97 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.697346 0.674476 0.345242
101 N08 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.743778 0.717809 0.352823
102 N08 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.753689 0.733317 0.350006
103 N08 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.764364 0.750516 0.340565
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.779469 0.763490 0.351747
105 N09 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.775718 0.763701 0.346539
106 N09 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.784133 0.771071 0.355690
107 N09 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.781612 0.763752 0.346288
108 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.763976 0.764240 0.369122
109 N10 digital_ok 100.00% 6.37% 100.00% 0.00% nan nan nan nan nan nan nan nan 0.334774 0.091664 0.187482
110 N10 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.723502 0.748860 0.294644
111 N10 digital_ok 100.00% 0.00% 0.28% 54.29% nan nan nan nan nan nan nan nan 0.388366 0.245914 -0.137436
112 N10 digital_ok 100.00% 0.00% 0.00% 100.00% nan nan nan nan nan nan nan nan 0.379971 0.356487 -0.276965
113 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.692706 0.667078 0.344755
114 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.677868 0.678796 0.329464
115 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.683013 0.657691 0.337532
117 N07 RF_maintenance 100.00% 71.47% 86.98% 0.00% nan nan nan nan nan nan nan nan 0.037878 0.029163 0.017970
118 N07 digital_ok 100.00% 67.87% 67.87% 0.00% nan nan nan nan nan nan nan nan 0.033153 0.031696 0.015896
120 N08 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.755464 0.733229 0.353199
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.750437 0.750127 0.345948
122 N08 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.774329 0.756761 0.347113
123 N08 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.762342 0.751226 0.345218
124 N09 digital_ok 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.110663 0.771049 0.468952
125 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.775395 0.763355 0.335923
126 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.777493 0.766983 0.374920
127 N10 digital_ok 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.083811 0.752145 0.486667
128 N10 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.756077 0.745735 0.386490
131 N11 not_connected 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.709629 0.523372 0.386106
132 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.702073 0.685151 0.347056
133 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.680858 0.658501 0.330760
134 N11 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.650045 0.618406 0.327818
135 N12 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.655014 0.632061 0.338234
136 N12 digital_ok 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.114962 0.655723 0.432358
137 N07 RF_maintenance 100.00% 74.52% 83.10% 0.00% nan nan nan nan nan nan nan nan 0.026931 0.023311 0.009707
139 N13 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.724735 0.710511 0.353091
140 N13 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.756901 0.740490 0.347280
141 N13 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.766856 0.748281 0.353633
142 N13 RF_maintenance 100.00% 0.00% 99.72% 0.00% nan nan nan nan nan nan nan nan 0.772809 0.137633 0.554934
143 N14 RF_maintenance 100.00% 0.00% 100.00% 0.00% nan nan nan nan nan nan nan nan 0.354640 0.074366 0.237325
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.782944 0.770361 0.366560
145 N14 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.779269 0.760355 0.366162
146 N14 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.759086 0.744713 0.375352
147 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
148 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
149 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
150 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
151 N16 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.654500 0.682313 0.298236
155 N12 RF_maintenance 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.119611 0.647286 0.434586
156 N12 RF_maintenance 100.00% 0.00% 100.00% 0.00% nan nan nan nan nan nan nan nan 0.687441 0.107184 0.491159
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.710195 0.686446 0.354577
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.721541 0.698244 0.360895
159 N13 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.726898 0.652701 0.325916
160 N13 digital_ok 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.108359 0.730261 0.534681
161 N13 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.764258 0.667718 0.315114
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.764928 0.747628 0.352704
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.771657 0.752624 0.356541
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.768491 0.748486 0.356500
165 N14 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.731067 0.751694 0.312557
166 N14 digital_ok 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.093963 0.734270 0.508805
167 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
168 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
170 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
171 N16 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.692439 0.675589 0.347167
172 N16 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.670537 0.653089 0.336737
173 N16 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.624117 0.603533 0.311825
179 N12 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.734050 0.701374 0.364990
180 N13 RF_maintenance 100.00% 0.00% 99.72% 0.00% nan nan nan nan nan nan nan nan 0.732729 0.144120 0.536793
181 N13 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.750840 0.728195 0.363892
182 N13 digital_ok 100.00% 0.00% 99.72% 0.00% nan nan nan nan nan nan nan nan 0.755062 0.136793 0.508818
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.757466 0.733532 0.339726
184 N14 digital_ok 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.575712 0.740722 0.356951
185 N14 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.755824 0.741892 0.356701
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.741259 0.729043 0.358168
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.745935 0.733409 0.371115
189 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
190 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
191 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
192 N16 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.647856 0.615491 0.337217
193 N16 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.627846 0.603857 0.319116
200 N18 RF_maintenance 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.111195 0.696811 0.511848
201 N18 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.722489 0.688548 0.363079
202 N18 digital_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.737162 0.723143 0.353552
204 N19 RF_maintenance 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.739617 0.721538 0.349078
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.699124 0.719455 0.346576
206 N19 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.721388 0.702480 0.356410
207 N19 RF_ok 100.00% 100.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.091567 0.705601 0.554691
208 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
209 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
210 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
211 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
220 N18 RF_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.720361 0.700088 0.354043
221 N18 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.723241 0.703067 0.344586
222 N18 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.724396 0.700136 0.346964
223 N19 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.720357 0.698831 0.346583
224 N19 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.688302 0.661764 0.346883
225 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
226 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
227 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
228 N20 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
229 N20 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
237 N18 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.703829 0.673959 0.350506
238 N18 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.705297 0.677860 0.352576
239 N18 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.710629 0.682000 0.356310
240 N19 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
241 N19 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.706165 0.675338 0.362649
242 N19 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.644711 0.662879 0.321784
243 N19 RF_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.641744 0.657896 0.328449
244 N20 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
245 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
246 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
261 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
262 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan nan nan nan
320 N03 dish_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.572596 0.489845 0.256324
324 N04 not_connected 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.533391 0.474101 0.234824
325 N09 dish_ok 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.598564 0.538800 0.287918
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan nan nan nan nan nan nan 0.096557 0.088767 0.006788
333 N12 dish_maintenance 0.00% 0.00% 0.00% 0.00% nan nan nan nan nan nan nan nan 0.537919 0.474929 0.233301
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: [4, 5, 15, 16, 17, 18, 27, 28, 29, 30, 34, 37, 38, 40, 42, 47, 51, 55, 58, 59, 60, 61, 62, 66, 68, 70, 81, 82, 83, 84, 86, 92, 93, 94, 104, 109, 111, 112, 117, 118, 121, 124, 125, 127, 131, 136, 137, 142, 143, 147, 148, 149, 150, 155, 156, 160, 166, 167, 168, 169, 170, 180, 182, 184, 189, 190, 191, 200, 204, 205, 207, 208, 209, 210, 211, 225, 226, 227, 228, 229, 240, 244, 245, 246, 261, 262, 329]

unflagged_ants: [7, 8, 9, 10, 19, 20, 21, 22, 31, 32, 35, 36, 41, 43, 44, 45, 46, 48, 49, 50, 52, 53, 54, 56, 57, 63, 64, 65, 67, 69, 71, 72, 73, 74, 77, 78, 79, 80, 85, 87, 88, 89, 90, 91, 95, 96, 97, 101, 102, 103, 105, 106, 107, 108, 110, 113, 114, 115, 120, 122, 123, 126, 128, 132, 133, 134, 135, 139, 140, 141, 144, 145, 146, 151, 157, 158, 159, 161, 162, 163, 164, 165, 171, 172, 173, 179, 181, 183, 185, 186, 187, 192, 193, 201, 202, 206, 220, 221, 222, 223, 224, 237, 238, 239, 241, 242, 243, 320, 324, 325, 333]

golden_ants: [7, 9, 10, 19, 20, 21, 31, 41, 44, 45, 53, 54, 56, 65, 67, 69, 71, 72, 85, 88, 91, 101, 103, 105, 106, 107, 122, 123, 128, 140, 141, 144, 145, 146, 151, 157, 158, 161, 162, 163, 164, 165, 171, 172, 173, 181, 183, 186, 187, 192, 193, 202]
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_2460097.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.1.1.dev3+gb291d34
3.2.3.dev158+gd5cadd5
In [ ]: