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

Load Auto Metrics¶

In [6]:
use_auto_metrics = False

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

# if it exists, load and extract relevant information
if len(auto_metrics_file) > 0:
    auto_metrics_file = auto_metrics_file[0]
    print(f'Found auto_metrics results file at {auto_metrics_file}.')
    
    auto_metrics = load_metric_file(auto_metrics_file)
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
    auto_ex_ants = auto_metrics['ex_ants']['r2_ex_ants']
    
    use_auto_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping auto_metrics.')
Found auto_metrics results file at /mnt/sn1/2459921/zen.2459921.21318.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 1850 ant_metrics files matching glob /mnt/sn1/2459921/zen.2459921.?????.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/2459921/zen.2459921.?????.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 2459921
Date 12-7-2022
LST Range 23.640 -- 9.597 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1850
Total Number of Antennas 201
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 7
dish_ok: 1
RF_maintenance: 54
RF_ok: 19
digital_ok: 96
not_connected: 24
Commanded Signal Source None
Antennas in Commanded State (reported) 0 / 201 (0.0%)
Antennas in Commanded State (observed) 0 / 201 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 18
Nodes Registering 0s N05, N19, N20
Nodes Not Correlating N14
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 123 / 201 (61.2%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 161 / 201 (80.1%)
Redcal Done? ❌
Never Flagged Antennas 39 / 201 (19.4%)
A Priori Good Antennas Flagged 72 / 96 total a priori good antennas:
3, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29, 30,
31, 37, 38, 42, 44, 45, 51, 53, 54, 55, 56,
68, 70, 71, 72, 81, 86, 88, 93, 94, 100, 101,
103, 106, 107, 109, 111, 118, 121, 122, 123,
124, 127, 128, 136, 140, 143, 144, 146, 147,
148, 149, 157, 158, 161, 163, 164, 165, 167,
170, 181, 182, 183, 184, 185, 186, 187, 189,
191, 202
A Priori Bad Antennas Not Flagged 15 / 105 total a priori bad antennas:
22, 35, 48, 62, 79, 82, 95, 115, 120, 132,
137, 179, 238, 324, 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_2459921.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% 0.00% 0.00% 9.116331 0.030485 8.217076 0.569062 11.403367 1.338207 0.612211 3.875191 0.033312 0.676026 0.575314
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.223638 1.206216 4.959576 2.180460 39.098254 7.107627 152.377778 58.182789 0.587007 0.659844 0.432523
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.452325 0.292454 -0.431164 0.062346 -0.348828 2.086244 0.831697 -0.065568 0.663176 0.674898 0.409859
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% -1.298952 -1.044725 0.465090 3.017584 -0.117814 0.150677 12.906325 11.990002 0.652875 0.655234 0.410648
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.568610 -1.369310 -1.170677 -0.015973 0.121470 1.195991 4.591164 2.230484 0.656478 0.666291 0.415412
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 3.489162 -0.503467 6.681284 0.262390 4.998198 1.431947 -0.187390 -0.484077 0.482405 0.665817 0.486409
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% 0.00% 0.00% 9.490763 0.325342 8.159932 1.201872 11.433201 1.421172 0.111983 3.252346 0.032902 0.677777 0.558839
16 N01 digital_ok 100.00% 100.00% 0.00% 0.00% 9.375366 -1.407257 8.186810 0.622828 11.394502 2.279478 0.396935 2.473265 0.033415 0.678462 0.556804
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% -0.559254 0.950190 -0.320812 0.166131 0.751526 1.274897 7.857045 5.958485 0.663740 0.677907 0.409084
18 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
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% 0.00% 0.00% 0.00% -0.149920 0.508559 -0.526655 4.093962 0.843111 0.549168 0.606700 0.042741 0.644859 0.627564 0.415479
22 N06 not_connected 0.00% 0.00% 0.00% 0.00% -0.681738 -0.732492 0.143210 -0.701529 0.075283 -0.613727 -1.109193 -1.242129 0.625326 0.641913 0.416659
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
28 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
29 N01 digital_ok 100.00% 100.00% 100.00% 0.00% 9.364719 10.409914 7.854137 8.813650 11.513687 11.422446 0.370533 0.114677 0.029581 0.035401 0.005958
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% -0.928368 -0.211767 0.460916 0.449368 2.020047 0.935878 7.259354 0.394593 0.655305 0.677977 0.412694
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 0.203459 -1.066886 0.514218 1.002869 1.736036 0.391202 0.887167 4.405942 0.669386 0.676047 0.421433
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 3.708797 23.663176 -0.720792 2.283795 -0.719022 3.448178 2.974812 11.674041 0.631961 0.558338 0.381454
34 N06 not_connected 100.00% 100.00% 0.00% 0.00% 10.749547 -0.833953 3.208379 -0.376850 11.461589 0.231479 0.585080 -0.518075 0.044400 0.660562 0.520904
35 N06 not_connected 0.00% 0.00% 0.00% 0.00% 0.343695 -0.323686 0.766472 -1.862587 -0.822805 -1.356919 0.023099 0.071607 0.635429 0.633224 0.408714
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 8.383361 7.441328 -0.382489 0.356259 1.487073 3.324330 0.192997 2.655474 0.677764 0.681921 0.396393
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.859091 0.152496 -1.684142 1.279873 1.598277 2.451785 -0.474208 5.792569 0.691265 0.692466 0.404940
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% -0.219493 -0.043293 -0.487640 0.392261 0.801880 2.752832 4.627174 1.424831 0.690333 0.696893 0.408572
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.246382 0.711993 -0.533821 0.469802 -0.169071 0.405288 -0.710905 -0.058446 0.677497 0.683969 0.403438
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.545652 0.237689 -0.792636 -0.056319 1.941881 0.212796 -0.639472 1.077328 0.676102 0.683589 0.398001
42 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 9.894640 10.893729 8.454585 9.624529 11.254788 11.267417 0.118046 1.018765 0.032204 0.030520 0.002597
43 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
44 N05 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
45 N05 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
46 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
47 N06 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
48 N06 not_connected 0.00% 0.00% 0.00% 0.00% -0.410558 0.362404 0.218096 0.736564 -1.472586 0.225586 -0.620723 -2.171634 0.635829 0.662302 0.417982
49 N06 not_connected 100.00% 0.00% 0.00% 0.00% -0.050919 -0.263255 -1.615325 -1.594354 -0.313387 -1.324453 0.140147 10.125016 0.587265 0.627787 0.404395
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 0.409674 23.135576 -0.400279 1.376901 1.515627 1.672444 8.594679 27.441761 0.672345 0.608612 0.362167
51 N03 digital_ok 100.00% 100.00% 0.00% 0.00% 21.564397 0.371390 10.673443 0.393218 11.687944 4.694491 8.071258 4.651645 0.041157 0.697445 0.551162
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 6.919117 6.161657 -0.993307 0.434362 1.802342 2.038199 1.064767 1.178047 0.695939 0.702373 0.389440
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 0.457109 2.484893 -0.548290 0.212303 1.955875 3.217908 2.660266 6.042678 0.698818 0.704402 0.401403
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 9.137092 10.599765 8.238478 9.390696 11.474703 11.394105 1.472220 0.741851 0.032873 0.031121 0.001886
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% 0.00% 100.00% 0.00% -0.224391 11.339220 -0.242673 9.498115 -0.157662 11.329025 0.822071 0.608083 0.675419 0.039387 0.537630
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 21.604785 1.757584 5.365127 1.034649 6.046934 2.035294 15.370191 1.734355 0.478812 0.681000 0.430766
58 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
59 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
60 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
61 N06 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
62 N06 not_connected 0.00% 0.00% 0.00% 0.00% 0.308438 0.364012 -1.306965 0.186588 -1.460282 -0.949242 0.636782 -0.883839 0.603685 0.659649 0.417718
63 N06 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
64 N06 not_connected 100.00% 100.00% 100.00% 0.00% 194.338117 194.089060 inf inf 6364.226069 6346.872421 6385.700343 6354.179622 nan nan nan
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.003701 0.286958 -0.249955 0.884507 1.868908 2.212875 2.663047 1.211415 0.670740 0.688329 0.407127
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.154996 1.383169 1.746744 1.749637 3.245169 0.843583 -0.501208 0.621012 0.680590 0.696677 0.393888
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% -0.775210 -1.067075 1.347326 1.833201 -0.474805 0.725911 0.269103 2.333109 0.685135 0.698011 0.384858
68 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 0.283334 24.265801 -0.013619 12.292302 0.440837 11.282840 3.461729 8.698387 0.697932 0.032664 0.549816
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.162987 -0.345578 -0.346951 0.638574 0.344696 1.909556 -0.569406 -0.131548 0.694098 0.702185 0.383518
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% 0.00% 100.00% 0.00% 1.675317 11.405329 0.024439 9.645307 0.014248 11.274471 4.761220 0.724649 0.671799 0.036046 0.538097
73 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
74 N05 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
77 N06 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
78 N06 not_connected 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
79 N11 not_connected 0.00% 0.00% 0.00% 0.00% 0.782617 -0.826191 -1.592104 -0.978386 -1.708519 -2.288180 0.659479 -1.247829 0.618756 0.653838 0.411016
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.852364 11.052439 -0.664308 8.037916 -0.925009 11.212080 -0.421673 1.420021 0.645446 0.037264 0.483108
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 2.012257 -0.684327 -0.306758 1.884190 -0.508312 -0.888061 -0.727550 -0.105542 0.668417 0.669488 0.387635
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.565291 -0.279387 -0.543226 0.229022 0.089091 -0.091045 -0.843207 0.588928 0.681704 0.692109 0.383320
84 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 182.661073 42.744457 52.607913 25.509381 186.505576 40.656541 2400.131123 640.690336 0.016582 0.016214 0.002177
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% -0.095969 0.161691 0.295254 0.591258 -0.814209 -0.032784 -0.448432 -0.487402 0.690741 0.698661 0.386597
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 1.061789 -0.293772 0.187738 0.814039 4.715177 -1.007008 0.266557 18.262022 0.683642 0.692602 0.380936
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 5.084760 6.481591 -1.093192 -0.071205 1.065549 0.723434 0.470417 2.796551 0.694381 0.705331 0.392725
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
89 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
91 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.732166 -0.689247 -0.288993 0.187415 -1.042393 -0.325766 0.379721 0.601156 0.645480 0.671994 0.423477
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
94 N10 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
95 N11 not_connected 0.00% 0.00% 0.00% 0.00% 0.984751 -1.274753 -1.386009 -0.147791 -0.833420 -1.925523 0.233026 1.226187 0.626483 0.665731 0.417951
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% 0.00% 0.00% 0.00% 0.737498 2.268896 -0.385250 -0.297791 0.148910 0.042574 3.163253 11.894982 0.568866 0.611122 0.402529
98 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 1.055407 0.324592 -0.526432 0.162898 0.004868 1.328789 0.443344 1.591268 0.639833 0.656689 0.400984
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.105487 -0.832671 0.267701 0.249249 -0.623071 2.325542 2.178013 -0.530997 0.648815 0.674719 0.404536
100 N07 digital_ok 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% 0.00% 0.00% 0.00% 7.462360 7.017644 -1.013445 0.986999 0.401402 2.324565 0.954116 0.663226 0.698195 0.699535 0.385286
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% -1.514081 0.889237 -1.043847 2.008183 0.395453 1.053287 0.990644 9.341469 0.703397 0.691597 0.379265
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 2.698528 4.820828 4.183614 -0.216405 3.493005 2.413986 6.822064 10.797349 0.664030 0.706295 0.390694
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 1.843518 56.462564 5.469692 6.302681 2.352555 1.126839 -0.100568 1.688112 0.638413 0.674075 0.392592
105 N09 digital_ok 0.00% 0.00% 0.00% 0.00% -0.189710 -0.363646 -0.398228 0.707538 0.597364 0.148832 -0.380575 -0.023099 0.680801 0.687960 0.392829
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
108 N09 RF_maintenance 100.00% 100.00% 0.00% 0.00% 9.247790 8.722482 8.172975 -0.426052 11.486933 7.724631 1.303746 4.815788 0.039046 0.355859 0.234180
109 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 9.046889 10.310797 8.207080 9.073002 11.575551 11.454421 0.127506 1.401731 0.028760 0.034623 0.002282
110 N10 RF_maintenance 100.00% 0.00% 100.00% 0.00% 0.698914 22.850554 -0.484418 12.060982 1.767708 11.169641 4.533503 3.817891 0.667386 0.032921 0.481518
111 N10 digital_ok 100.00% 0.00% 100.00% 0.00% 0.263883 10.206665 -0.222363 9.163413 -0.019442 11.468809 -0.149805 1.727921 0.664787 0.036730 0.483793
112 N10 digital_ok 0.00% 0.00% 0.00% 0.00% -0.479898 1.313705 -0.436697 0.112929 0.542370 2.880791 0.224370 -0.495102 0.659322 0.666613 0.415299
113 N11 not_connected 100.00% 100.00% 100.00% 0.00% 11.018884 11.422605 2.858783 4.066392 11.317304 11.305923 1.152068 0.347399 0.035391 0.030978 0.003137
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 0.00% 0.00% 0.00% 0.00% 0.349112 1.190726 1.002074 1.167083 -0.314324 0.898823 -1.955503 -1.481898 0.618423 0.645518 0.428522
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% -0.342771 -0.467020 -0.714683 0.611373 0.505379 0.376276 -0.122248 0.228515 0.631003 0.645105 0.402663
117 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 10.004549 11.701333 8.281424 9.614312 11.342322 11.387196 0.752986 3.408601 0.027677 0.031593 0.002314
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% -0.222746 1.023590 -0.777511 0.471047 0.112226 1.321916 2.382494 4.662691 0.667124 0.680168 0.397740
119 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
120 N08 RF_maintenance 0.00% 0.00% 0.00% 0.00% 2.380095 2.214500 1.827492 1.158136 0.468671 0.563266 0.770232 -2.087681 0.680318 0.698276 0.378121
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 2.086581 3.648460 -1.731041 1.849931 1.452199 42.893609 17.900559 15.693577 0.702300 0.697902 0.379378
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 7.600321 5.848564 0.697131 0.723026 2.534717 1.465390 0.014253 -0.491984 0.700119 0.702106 0.385349
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 6.443155 8.325592 -0.008386 0.866823 0.724815 1.907191 -0.337277 0.284026 0.695299 0.702707 0.400791
124 N09 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
127 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 0.103321 0.375919 -0.279243 0.358344 2.500676 2.151974 2.302486 4.934111 0.661971 0.686056 0.434317
128 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 8.766478 9.894038 8.280531 9.285100 11.320313 11.335039 -0.046887 0.431204 0.030680 0.026739 0.002629
129 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.781923 -1.214810 0.056319 0.887664 0.031822 1.155783 0.193861 1.317814 0.663380 0.679474 0.424659
130 N10 digital_ok 0.00% 0.00% 0.00% 0.00% -0.055085 0.667243 -0.538351 0.352696 -0.263092 1.161237 1.434928 2.376538 0.652704 0.673284 0.410293
131 N11 not_connected 100.00% 0.00% 91.03% 0.00% 3.349504 11.350840 2.813290 4.219110 4.465639 11.163673 -2.791117 -0.422815 0.647206 0.132584 0.494527
132 N11 not_connected 0.00% 0.00% 0.00% 0.00% -0.077088 1.369794 -1.843127 -1.524894 -0.198383 -1.617511 1.708704 -0.281424 0.601812 0.630818 0.408142
133 N11 not_connected 100.00% 100.00% 0.00% 0.00% 10.526476 -0.443225 2.843330 -1.283068 11.449771 -2.106264 1.143422 -0.555264 0.074134 0.626577 0.506590
135 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
136 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
137 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.304302 -0.796728 -0.547147 -1.021271 2.003872 -0.425031 0.347456 0.682317 0.644634 0.665056 0.407556
138 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
139 N13 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 0.359416 -0.578034 -1.600717 -1.104370 -0.720253 -0.447102 4.353346 3.652451 0.693650 0.701619 0.383594
141 N13 digital_ok 0.00% 0.00% 0.00% 0.00% -1.493339 -1.000521 -0.955689 -0.232078 1.528653 -2.611126 2.337765 -0.596792 0.693352 0.701617 0.383154
142 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 1.899609 10.203134 -1.277193 9.319541 3.424757 11.411022 19.668848 1.361803 0.687596 0.049107 0.598679
143 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 9.339800 10.684581 8.348212 9.310813 11.238837 11.255705 -0.117471 0.778057 0.025489 0.025330 0.001363
144 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 8.803345 9.167651 8.173235 9.170827 11.459685 11.385438 0.512455 0.934913 0.026607 0.025261 0.001737
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 9.315098 10.768074 8.243099 9.361485 11.388536 11.362585 0.219710 2.861523 0.025536 0.024934 0.001430
146 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 10.321655 10.805892 2.867503 3.881424 11.396342 11.329789 -0.078650 -0.245584 0.029670 0.029443 0.001465
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% nan nan inf inf nan nan nan nan nan nan nan
149 N15 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
150 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 0.987786 -0.143992 1.089670 -0.144608 -0.538388 -1.863111 -1.750283 -0.347226 0.665054 0.678375 0.426658
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
156 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
157 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
158 N12 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
159 N13 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
160 N13 digital_ok 0.00% 0.00% 0.00% 0.00% -0.555633 -0.805948 -0.904169 -0.647452 -0.238151 2.409261 0.393302 1.003644 0.685335 0.682099 0.392143
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.932951 26.285124 -0.703836 -0.650382 0.132697 0.822445 -0.459431 1.541216 0.685318 0.552443 0.359586
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 1.088461 -0.363686 1.757020 0.300506 0.223846 -1.751757 -0.388733 -0.933068 0.685656 0.688982 0.400477
163 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 8.968688 9.666102 8.094771 9.172872 11.553172 11.422154 0.294117 0.812716 0.027659 0.025296 0.002272
164 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 9.541163 10.596813 8.153118 9.367593 11.348825 11.316166 0.249658 1.278248 0.025713 0.025326 0.001472
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 9.604230 9.693794 7.786566 8.874473 11.543414 11.386659 -0.040912 0.528287 0.027134 0.025647 0.001940
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 9.155826 9.196987 7.978522 8.911399 11.596615 11.434977 0.155279 1.079689 0.025872 0.025572 0.001367
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% -0.185912 -1.203097 -1.287790 3.425238 1.334061 -0.076104 -0.331333 4.411541 0.670436 0.655546 0.432735
168 N15 digital_ok 0.00% 0.00% 0.00% 0.00% -0.834897 -0.924169 -0.431347 -0.371853 2.061519 1.206718 -0.666664 1.071500 0.664279 0.682321 0.426982
169 N15 digital_ok 0.00% 0.00% 0.00% 0.00% -0.623975 1.893684 -1.427786 -1.653973 1.186947 -0.419842 -0.760619 -0.866033 0.670712 0.670986 0.417731
170 N15 digital_ok 100.00% 100.00% 0.00% 0.00% 9.832287 -0.433676 8.399316 -0.918087 11.298483 -0.122635 0.504739 0.142365 0.039102 0.681001 0.573272
179 N12 RF_maintenance 0.00% 0.00% 0.00% 0.00% -0.201658 -0.256000 1.187833 2.241717 -0.004868 1.949152 -0.281318 0.030974 0.650904 0.651000 0.407118
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% -0.071169 11.001338 -0.741951 9.444784 1.009651 11.365866 19.487961 1.980048 0.677561 0.058896 0.590858
181 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 0.632761 -0.024274 -0.757472 0.277897 0.281904 1.357226 -0.523610 5.119010 0.685795 0.673935 0.406878
182 N13 digital_ok 100.00% 0.00% 0.00% 0.00% -0.187002 3.720972 -0.810286 2.188881 -0.408597 3.856451 13.190916 -0.631151 0.687361 0.670212 0.417501
183 N13 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
184 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 9.379371 10.574682 8.303397 9.320865 11.472662 11.391570 0.327017 0.724423 0.025335 0.024925 0.001281
185 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 9.041019 9.925159 7.982516 9.046365 11.610690 11.388537 0.041080 0.523620 0.026993 0.025400 0.001912
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 8.735244 10.789738 8.264557 9.240417 11.449911 11.356460 0.829115 0.413020 0.027340 0.025445 0.001996
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 9.347000 10.049271 8.013578 9.191944 11.567916 11.408159 0.546099 0.409363 0.025769 0.025073 0.001336
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 8.565562 8.328740 0.303401 -0.363760 3.348945 9.746831 0.604910 0.862718 0.347102 0.367419 0.174589
190 N15 digital_ok 0.00% 0.00% 0.00% 0.00% -1.161798 -1.432892 -1.216969 -0.531367 0.463717 -1.128563 -0.733698 -1.400057 0.661626 0.677693 0.429511
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% -1.667607 0.447294 0.503807 -0.402869 0.759059 1.531716 13.783012 1.350250 0.642853 0.664011 0.433978
200 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
201 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
202 N18 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
205 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
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
219 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
220 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 1.400512 1.010661 -0.343809 -1.056769 -1.152290 -1.659136 4.690649 1.005224 nan nan nan
221 N18 RF_ok 0.00% 100.00% 100.00% 0.00% 3.452233 1.831331 -0.917093 -1.145077 -0.311403 -2.215248 1.230154 0.247502 nan nan nan
222 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 2.363942 3.296663 0.143644 -0.239028 -0.973826 45.642915 4.475877 1.101674 nan nan nan
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
225 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
226 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
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 100.00% 0.00% 0.00% 0.00% 5.464790 1.883044 0.890247 -1.803430 3.735181 -0.829470 2.320234 0.949755 0.508309 0.617757 0.458736
238 N18 RF_ok 0.00% 0.00% 0.00% 0.00% 0.579398 -0.003701 1.161199 0.149401 -0.048460 -0.208217 -1.341062 2.297557 0.638026 0.626770 0.431251
239 N18 RF_ok 100.00% 0.00% 0.00% 0.00% -0.320036 -0.440617 -0.260164 -0.583420 -1.610785 -1.039008 1.192365 9.846107 0.627083 0.633019 0.426896
240 N19 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
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 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
261 N20 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
262 N20 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
320 N03 dish_maintenance 100.00% 0.00% 100.00% 0.00% -0.537056 11.085110 -0.832629 6.009105 -0.467276 11.422699 9.012484 2.422301 0.664017 0.051738 0.539493
324 N04 not_connected 0.00% 0.00% 0.00% 0.00% 0.851342 1.950108 0.765379 0.560088 0.284111 0.218800 0.505504 -0.724845 0.538901 0.553752 0.405356
325 N09 dish_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
329 N12 dish_maintenance 100.00% 0.00% 0.00% 0.00% 2.276628 -0.618245 -1.607868 -1.157163 0.308280 -1.086157 5.471545 0.831589 0.491404 0.555758 0.409728
333 N12 dish_maintenance 0.00% 0.00% 0.00% 0.00% 2.748651 0.902070 -1.247531 -1.631755 -1.045391 -0.306050 0.807581 1.304152 0.494466 0.538915 0.403634
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, 30, 31, 32, 34, 36, 37, 38, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 63, 64, 68, 70, 71, 72, 73, 74, 77, 78, 80, 81, 84, 86, 87, 88, 89, 90, 92, 93, 94, 96, 97, 100, 101, 102, 103, 104, 106, 107, 108, 109, 110, 111, 113, 114, 117, 118, 119, 121, 122, 123, 124, 125, 126, 127, 128, 131, 133, 135, 136, 138, 139, 140, 142, 143, 144, 145, 146, 147, 148, 149, 155, 156, 157, 158, 159, 161, 163, 164, 165, 166, 167, 170, 180, 181, 182, 183, 184, 185, 186, 187, 189, 191, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 211, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 237, 239, 240, 241, 242, 243, 244, 245, 246, 261, 262, 320, 325, 329]

unflagged_ants: [5, 22, 35, 40, 41, 48, 62, 65, 66, 67, 69, 79, 82, 83, 85, 91, 95, 98, 99, 105, 112, 115, 116, 120, 129, 130, 132, 137, 141, 150, 160, 162, 168, 169, 179, 190, 238, 324, 333]

golden_ants: [5, 40, 41, 65, 66, 67, 69, 83, 85, 91, 98, 99, 105, 112, 116, 129, 130, 141, 150, 160, 162, 168, 169, 190]
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_2459921.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.dev11+g87299d5
3.1.5.dev171+gc8e6162
In [ ]: