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 = "2459821"
data_path = "/mnt/sn1/2459821"
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
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 8-29-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/2459821/zen.2459821.25309.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 372 ant_metrics files matching glob /mnt/sn1/2459821/zen.2459821.?????.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.')
Found 38 ant_metrics files matching glob /mnt/sn1/2459821/zen.2459821.?????.sum.known_good.omni.calfits

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])
    startTime = Time(startJD,format='jd')
    stopTime = Time(stopJD,format='jd')
    res = session.get_antenna_status(starttime=startTime, stoptime=stopTime)
    fem_switches = {}
    if len(res) == 0:
        femState = None
    else:
        for antpol in res:
            fem_switches[(antpol.antenna_number, antpol.antenna_feed_pol)] = antpol.fem_switch
    femState = (max(set(list(fem_switches.values())), key = list(fem_switches.values()).count)) 
except Exception as e:
    print(e)
    femState = None

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 (femState == "load" or femState == 'noise') and 80000 < stdev <= 4000000 and antCon[ant] is not False:
                antCon[ant] = True
            elif femState == "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'] = femState
to_show['Antennas in Commanded State'] = 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 2459821
Date 8-29-2022
LST Range 18.030 -- 20.030 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 372
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 32
RF_ok: 11
digital_maintenance: 3
digital_ok: 95
not_connected: 3
Commanded Signal Source None
Antennas in Commanded State 0 / 147 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N02, N10, N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 76 / 147 (51.7%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 98 / 147 (66.7%)
Redcal Done? ✅
Redcal Flagged Antennas 10 / 147 (6.8%)
Never Flagged Antennas 22 / 147 (15.0%)
A Priori Good Antennas Flagged 74 / 95 total a priori good antennas:
5, 7, 9, 10, 15, 19, 20, 21, 31, 40, 41, 42,
51, 53, 54, 55, 56, 68, 69, 71, 72, 73, 81,
83, 84, 85, 86, 88, 91, 93, 94, 98, 101, 103,
105, 106, 107, 108, 109, 111, 112, 117, 118,
121, 122, 123, 127, 128, 129, 130, 140, 141,
142, 143, 144, 156, 157, 158, 160, 161, 165,
167, 169, 170, 176, 177, 178, 179, 181, 185,
187, 189, 190, 191
A Priori Bad Antennas Not Flagged 1 / 52 total a priori bad antennas:
90
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_2459821.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 Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction 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 Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.790110 0.626112 -0.519388 -0.884478 0.094252 0.000630 0.080885 0.527779 0.767130 0.573218 0.535248 1.767216 1.518543
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.229064 5.836498 -0.826770 1.826250 -0.170596 0.376123 0.226355 -0.026481 0.780598 0.572810 0.533950 4.525347 4.516854
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.567827 0.353631 -0.829119 4.826176 2.591550 4.590975 3.154238 1.592187 0.783978 0.580991 0.537900 4.335875 3.615486
7 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.956706 -1.013652 0.400197 0.208611 2.519120 3.271757 1.171723 2.045664 0.079395 0.075506 0.016425 1.231435 1.227849
8 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.837586 16.385271 19.839486 20.710003 20.997010 21.419056 2.076390 2.534745 0.109033 0.090271 0.014127 1.175877 1.173862
9 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.381889 -0.133230 0.759731 -0.345375 4.587730 4.962229 5.138116 4.740556 0.083488 0.064651 0.007236 1.188531 1.189037
10 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.340915 -0.535002 -0.918776 0.407885 1.315108 1.897746 2.158590 0.456161 0.088237 0.065812 0.009199 1.246942 1.246313
15 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.232696 2.448186 2.141603 0.687321 1.759942 1.459230 3.502714 6.272577 0.792391 0.587810 0.522264 4.446941 4.267554
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.435090 -0.430572 -0.558437 -0.329077 -0.224925 -0.055251 1.255055 1.291155 0.794277 0.601124 0.521647 2.247563 1.854114
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.152769 1.040737 0.902073 0.651829 1.559360 1.663572 0.598644 0.760157 0.793655 0.594637 0.536703 2.252178 1.950814
18 N01 RF_maintenance 100.00% 0.00% 75.81% 0.00% 100.00% 0.00% 6.139613 6.771156 2.846508 -0.091011 3.271380 3.979864 4.568552 7.828113 0.764391 0.374455 0.595843 4.134880 2.189808
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.077068 12.404947 -0.813193 16.974047 2.142796 15.861820 0.256541 -0.058800 0.063816 0.083963 0.014154 1.217891 1.205675
20 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.751436 1.135390 0.164833 -0.180351 -0.063134 1.463286 -0.024719 -0.502771 0.068264 0.057166 0.004828 1.257354 1.258360
21 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.095526 2.251117 0.735521 1.884665 4.180123 4.648832 2.443842 2.262428 0.072805 0.056396 0.005239 1.275568 1.272628
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.929627 28.594501 44.468147 45.057191 27.900922 27.466158 1.384448 1.515821 0.039220 0.043084 0.002155 1.243437 1.251405
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 16.131419 26.585149 2.251549 3.621088 24.093446 26.791102 0.801877 6.150969 0.468150 0.226625 0.309038 15.230264 3.758670
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.036302 -0.029975 0.230015 -0.401505 -0.408663 -0.037015 -0.435555 0.661435 0.805704 0.615602 0.519950 2.302549 2.071164
30 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.302348 0.355354 -0.139940 -0.829650 3.107132 2.602256 3.550737 1.841631 0.799140 0.608910 0.528352 2.152489 1.915417
31 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.824550 0.193142 -0.759594 0.323972 4.848229 5.480723 3.263589 3.963389 0.079176 0.081127 0.017324 1.198804 1.194659
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 54.116616 7.806622 3.584681 1.914256 8.193912 14.575296 20.277179 65.395526 0.088725 0.079309 0.011096 1.178706 1.182502
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.037376 6.794832 -0.273011 -0.347856 -0.957320 1.109534 -1.412192 1.493045 0.059196 0.097883 0.033802 1.213487 1.213507
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.637985 8.091595 0.246248 -0.264689 1.676658 0.327945 -0.016433 0.110516 0.784437 0.592709 0.523604 4.518257 3.836825
37 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.509179 1.235745 0.109480 0.412723 -0.604660 -0.629687 -0.855800 1.841086 0.795777 0.609519 0.516746 1.897417 1.565018
38 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.879891 -0.455605 -0.455033 -0.839233 -0.018965 -0.217891 -0.362299 -0.453632 0.800606 0.629013 0.512002 1.771450 1.530341
40 N04 digital_ok 0.00% 11.29% 11.29% 0.00% 13.16% 0.00% -0.416533 -0.191610 0.237961 -0.404033 -0.178325 -0.437569 -1.842139 -1.620162 0.727063 0.590723 0.429534 2.043092 1.818467
41 N04 digital_ok 0.00% 11.29% 11.29% 0.00% 13.16% 2.63% -0.805891 -1.535422 2.823473 1.248030 1.720406 -1.193314 -1.785505 -1.325252 0.730007 0.596201 0.435902 2.220949 1.776057
42 N04 digital_ok 0.00% 11.29% 11.29% 0.00% 13.16% 5.26% -0.357206 0.773526 2.178970 0.905260 -0.831677 -0.731175 -1.246652 -1.496491 0.730557 0.589299 0.444203 2.325164 1.957930
45 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.290104 0.824591 -0.712804 0.042628 -0.142679 -1.026664 -1.465789 -0.581420 0.791030 0.585439 0.554046 1.546710 1.427383
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.884027 -0.222600 -0.073356 -0.949405 -0.931486 -1.267051 0.462361 -1.414038 0.785108 0.564417 0.570839 1.478142 1.409617
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.900561 21.650384 -0.881739 0.798025 0.183959 5.437650 2.183359 27.011056 0.785312 0.542262 0.496219 4.826689 4.751246
51 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 364.913230 365.141779 inf inf 685.086276 657.557950 1369.585431 1384.492320 nan nan nan 0.000000 0.000000
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.458586 7.667712 1.106520 -0.038851 1.663133 -0.788239 -0.696761 -0.733707 0.810250 0.646780 0.494616 5.786361 4.396454
53 N03 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 364.908661 365.187850 inf inf 711.512333 699.290323 1430.920903 1447.388300 nan nan nan 0.000000 0.000000
54 N04 digital_ok 100.00% 11.29% 11.29% 0.00% 100.00% 0.00% 1.481911 1.898634 1.325956 1.798883 -1.375839 3.371661 0.215494 24.437464 0.737290 0.600992 0.424712 4.016303 3.281438
55 N04 digital_ok 100.00% 11.29% 11.29% 0.00% 100.00% 0.00% 4.735157 1.429210 -0.556343 1.351625 1.962233 -1.371420 1.102954 -1.478615 0.744539 0.613379 0.430803 4.285845 3.097760
56 N04 digital_ok 0.00% 11.29% 11.29% 0.00% 13.16% 78.95% 0.042519 1.254527 1.153529 1.443870 -0.179334 -0.921990 -1.488008 2.750060 0.736624 0.609935 0.432194 4.287730 3.294573
57 N04 RF_maintenance 100.00% 11.29% 11.29% 0.00% 100.00% 0.00% 35.086668 -1.403747 16.755333 0.567621 7.862217 0.773151 -0.680038 -0.638820 0.614614 0.595188 0.306773 5.974096 3.094289
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.927442 0.601883 0.903663 1.030409 0.002434 0.273569 -0.868955 -0.329530 0.795687 0.606678 0.518735 1.985305 1.709552
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.825096 -0.129023 -0.859593 0.413597 0.007015 1.447572 -0.579707 0.256273 0.802961 0.643726 0.493458 1.881384 1.543367
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.096048 -0.601578 0.449912 -0.446474 0.316888 0.238246 -0.831652 -0.007001 0.812943 0.667862 0.478343 2.012265 1.652193
68 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.045337 0.588888 0.126886 3.680864 1.333265 4.191372 0.460960 2.197101 0.815399 0.677839 0.465526 4.665535 4.559945
69 N04 digital_ok 0.00% 11.29% 11.29% 0.00% 13.16% 68.42% 1.884121 -1.026560 -0.477945 -0.264308 -0.936858 0.689744 -1.388235 -1.432674 0.738271 0.622633 0.416919 3.525956 3.002826
70 N04 RF_maintenance 100.00% 11.29% 11.29% 0.00% 100.00% 0.00% 9.925905 -0.946732 0.373186 -1.024131 -1.203158 -0.961556 1.661898 -0.566188 0.734173 0.619678 0.417451 14.010384 10.543052
71 N04 digital_ok 0.00% 11.29% 11.29% 0.00% 13.16% 86.84% 1.304874 0.024679 -0.804622 -0.105957 -1.074701 -0.861558 -1.234980 -0.247088 0.737655 0.623610 0.409471 16.464063 14.035217
72 N04 digital_ok 0.00% 11.29% 11.29% 0.00% 13.16% 60.53% 3.190428 -0.620855 -0.697152 1.597476 1.412981 -0.410916 2.708131 -0.004376 0.732350 0.606378 0.423281 3.592948 3.023811
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 27.290621 0.228633 43.572254 2.940935 26.205350 0.767154 -1.257721 -0.039447 0.032410 0.639035 0.314098 1.191407 3.171066
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.306040 3.648455 -0.040698 4.199743 -1.075373 2.688631 -0.435743 -1.050026 0.787060 0.601031 0.503001 4.447530 4.486574
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.493997 0.435040 0.987092 2.187279 2.884481 -0.102583 20.197469 6.155035 0.804733 0.631076 0.507844 5.406956 4.026421
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.985497 4.012967 2.259000 4.963449 -0.468798 1.081793 -1.584124 -0.940632 0.811836 0.664463 0.475214 4.809398 4.177107
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.781317 11.608880 0.013626 0.910668 8.287362 -0.456988 86.636426 -0.752886 0.820397 0.679988 0.456822 4.397673 4.491993
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 31.58% 1.014536 1.025853 1.055705 1.851694 -1.152781 -1.002509 -1.613311 -1.564949 0.823555 0.686220 0.472265 1.727762 1.562669
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.691271 5.092450 -0.638134 -0.365434 0.455453 0.863623 -0.889760 -0.682429 0.819199 0.662223 0.472867 4.130827 3.093943
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 44.201039 12.793702 2.607859 1.329686 5.206033 0.062363 1.399728 -1.084867 0.733234 0.683954 0.392452 3.460158 3.288495
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.538377 18.318092 24.050640 21.609624 22.872895 18.755291 -1.227888 -1.060598 0.782622 0.652524 0.493228 3.111868 2.755001
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.713793 0.632156 0.189604 3.721711 -1.233740 -0.429176 -1.781818 -1.210133 0.806006 0.625717 0.525289 3.723826 2.929740
91 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.682401 20.397427 21.884926 22.831025 20.165101 20.706522 -1.844240 -1.276399 0.773526 0.582241 0.545383 3.417669 2.934006
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 48.694807 70.037306 5.568130 6.820625 25.258151 31.111179 1.154361 7.646853 0.095057 0.090050 0.011845 0.961599 0.964016
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.594740 -0.361073 4.132051 0.682433 4.092754 -0.353396 0.713703 0.938130 0.066558 0.079437 0.011032 56.404512 67.580291
94 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.901646 -2.077737 -0.063161 -0.331214 0.219371 2.303752 2.202750 3.636340 0.076105 0.082430 0.013795 1.243352 1.226651
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.855770 16.308091 0.778987 2.386459 -0.849238 6.359523 -0.925050 0.110217 0.789101 0.576569 0.519503 4.939273 5.318684
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.986074 0.588995 3.392306 -0.114231 -0.145021 -0.867669 -1.372675 -0.544197 0.801564 0.617967 0.508863 1.837995 1.592048
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.026317 0.635986 0.633128 -0.030302 -0.852455 -1.328643 -1.522888 -1.350729 0.811704 0.645061 0.502198 1.760594 1.568685
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.573064 11.151555 3.132851 0.087549 -0.373957 -0.926427 -0.218682 0.340727 0.820958 0.666647 0.481588 3.682010 3.582258
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.285640 12.604521 23.604164 29.832956 89.542334 150.012051 88.665670 144.958587 0.755645 0.554085 0.484089 2.753833 2.339866
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.305530 11.353632 0.124776 -0.059159 -0.177453 -0.989580 -0.992119 -1.410499 0.821404 0.682740 0.471453 3.156522 2.879078
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.835822 94.307233 0.786036 13.840404 2.395094 3.432290 4.167846 0.886817 0.828496 0.679049 0.499931 2.916171 2.711966
105 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.433139 9.493277 8.642029 13.342233 4.688339 9.195415 -1.751128 -1.682540 0.823443 0.674320 0.498667 3.000745 2.676439
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.319608 15.195830 20.798735 19.321358 18.371844 16.456705 -1.820613 -1.474694 0.795814 0.633234 0.522317 2.486443 2.210537
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.837513 5.263337 11.521198 0.936271 1.845581 -1.271823 -1.197137 -1.374377 0.781338 0.620997 0.519976 2.736179 2.448341
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.395479 0.207507 0.156551 0.522784 -0.329551 0.467607 1.594097 -0.429207 0.078345 0.075664 0.017452 0.928684 0.940439
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 50.144298 21.629416 3.333955 0.831731 3.599617 8.771377 5.268094 31.991060 0.080745 0.068565 0.007315 1.175546 1.169647
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.125381 0.330890 0.088874 1.216347 -0.150512 2.020574 1.021191 0.016256 0.059494 0.058757 0.005967 0.940668 0.947840
112 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.878141 -0.268183 -0.803311 1.356829 1.232235 0.761421 0.733019 0.011930 0.065251 0.072845 0.011234 1.155287 1.152907
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.913566 3.100476 0.450411 -0.702749 -0.619638 -1.196156 -0.199040 -0.654882 0.783088 0.575745 0.535344 2.021307 1.732127
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.433047 2.873346 4.978774 5.492063 1.759841 1.887078 -1.642215 -1.810884 0.796263 0.598221 0.528297 5.591053 5.203886
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 3.021764 33.366638 2.266414 39.192383 -0.729142 26.038175 -1.170894 -1.227518 0.809158 0.044225 0.466213 4.885820 1.238810
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.594392 2.164349 9.726296 0.384326 5.834557 -0.142136 -1.953054 -1.505796 0.819283 0.636211 0.512745 3.369842 3.049794
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 24.508130 43.719113 4.105077 49.919016 21.838292 26.027940 -0.557104 -0.059166 0.499353 0.045535 0.319998 3.053217 1.204852
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.274988 8.227680 -0.507681 0.460695 -0.670087 -0.006589 1.374529 2.045500 0.820896 0.669528 0.477359 2.811142 2.701657
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.770131 9.148606 1.137084 1.439498 -1.320938 -0.330954 -1.524006 -0.983546 0.824433 0.669937 0.484773 3.330433 2.894288
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.816778 10.511901 -0.219434 -0.000617 -1.279211 -1.376676 -0.689570 -0.119558 0.823664 0.673282 0.488629 3.069736 2.752241
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
127 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.093854 -0.373765 0.094770 -0.543466 0.480916 0.919419 -0.687546 0.075811 0.090746 0.086236 0.024621 0.942334 0.959404
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.441362 1.499013 -0.009171 1.701312 0.522471 1.226257 0.156355 0.305404 0.075099 0.076586 0.013058 1.096221 1.105689
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.055851 -1.323599 -0.821633 -1.021843 0.708146 0.659237 -0.594845 -0.622181 0.053290 0.065353 0.005913 1.204482 1.200551
130 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.835642 -0.427830 0.771968 1.386401 0.985887 1.153811 0.080140 0.578623 0.075645 0.083478 0.014167 1.231072 1.228768
135 N12 digital_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.477998 0.278335 -1.079256 -0.919261 -0.512177 -0.786278 0.619999 0.430089 0.060945 0.062361 0.010345 1.231216 1.229722
136 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.355366 13.650969 -0.534515 0.938458 1.905641 1.329226 0.884991 3.076511 0.057480 0.059186 0.007782 1.239999 1.236833
137 N07 RF_maintenance 100.00% 34.95% 100.00% 0.00% 100.00% 0.00% 23.226057 28.873454 14.656253 38.481437 22.639165 25.859016 1.063325 -0.602923 0.419607 0.044478 0.218071 3.318695 1.288779
138 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.669345 1.709154 21.576130 -0.534402 20.589476 -1.532943 -1.887477 -0.804438 0.785788 0.609379 0.516595 3.501223 3.291127
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.320865 28.246389 43.348983 44.977451 26.242356 25.875684 -1.181718 -0.893017 0.038760 0.042117 0.001497 1.206502 1.201847
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.172455 4.091988 0.222933 9.433504 -0.063330 2.307842 3.936140 7.230794 0.814814 0.636157 0.500211 3.586821 2.819291
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 29.369593 34.592146 3.500386 45.212136 22.077955 26.033175 1.178546 -0.035280 0.506813 0.042438 0.269351 2.346272 1.086743
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 60.53% 7.89% -0.024679 -1.452225 1.105030 1.332077 1.121858 0.140068 -0.525399 -0.545795 0.809077 0.660084 0.488560 0.000000 0.000000
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.642663 -1.180294 1.500539 -0.962247 1.256325 2.710710 4.572441 7.843993 0.807918 0.649757 0.501344 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.043631 28.462165 44.737825 45.797061 27.774969 27.513469 0.873715 1.260107 0.033526 0.034410 -0.000691 0.862240 0.859971
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.645932 31.046237 44.639477 46.625688 28.354356 27.962986 2.777202 3.367765 0.044163 0.045008 0.000541 1.456678 1.451684
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.682211 28.621774 43.484652 44.621657 26.596251 26.166870 -0.461388 -0.153914 0.034054 0.033903 0.000443 1.220436 1.216489
156 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.380920 0.283977 1.489177 -0.499914 -0.146665 -0.575256 1.582405 0.655297 0.047466 0.045286 0.003513 1.242938 1.242353
157 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.846396 -1.090945 -0.051812 3.487126 0.886429 0.224948 0.004376 -0.130612 0.054582 0.050280 0.003592 1.254180 1.251768
158 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.979455 -1.647046 -0.434266 -0.199508 -0.570925 0.378223 0.538367 -0.480650 0.058514 0.052257 0.006165 1.332029 1.334542
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.204993 27.897664 44.120560 45.072411 26.487706 26.131344 -0.595958 -0.075803 0.040533 0.042080 0.002793 1.235754 1.232023
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.142449 55.080117 -0.268602 3.825003 -0.837822 3.639351 -0.045811 1.976110 0.799470 0.541594 0.460101 3.847857 5.524364
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.452133 0.496581 -0.485446 -0.796660 0.051639 -0.002566 1.795527 1.040534 0.803309 0.633936 0.503728 2.150155 1.935886
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.330260 -0.469068 0.009171 -0.968885 0.636495 1.059377 -0.168030 1.948510 0.801822 0.644740 0.495172 2.030322 1.853633
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.149270 -0.615495 -0.798047 -1.003947 -0.006517 0.340616 0.454017 0.363421 0.801948 0.641278 0.506004 2.038266 2.066235
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.593724 2.130562 6.371624 -0.777804 2.907242 -0.598675 0.386952 0.709911 0.798364 0.637910 0.499062 4.710708 5.206753
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 32.833125 25.123647 2.588886 1.568056 6.923516 4.116122 15.456505 9.579117 0.681834 0.520094 0.291638 8.069306 6.929661
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 26.115748 20.851031 17.056415 19.995010 24.389869 22.174873 56.090562 18.695465 0.643410 0.485210 0.339107 5.551685 4.572145
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.201359 19.645146 20.278630 23.023657 20.023150 22.656788 -0.632201 -0.065367 0.759217 0.553003 0.520333 4.524731 3.762367
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.422432 17.965949 22.290156 21.722275 22.511530 21.719395 -0.609682 0.024899 0.749011 0.532509 0.532299 4.115205 3.921890
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.638006 16.328556 22.492394 20.823319 23.430339 20.758669 2.438136 2.734710 0.741710 0.527547 0.537228 4.499841 4.270397
176 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 364.940315 365.150607 inf inf 726.073916 919.716499 1095.723916 1326.666179 nan nan nan 0.000000 0.000000
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 364.937981 365.136427 inf inf 900.722131 893.977991 1328.733752 1354.626752 nan nan nan 0.000000 0.000000
178 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 364.946641 365.227260 inf inf 1298.508856 1832.716395 1713.069290 1668.125361 nan nan nan 0.000000 0.000000
179 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.712995 -0.565067 -0.934483 -0.270213 2.070449 -0.596374 1.609851 -0.615560 0.051957 0.062336 0.012087 1.236261 1.235982
180 N13 RF_maintenance 100.00% 0.00% 75.81% 0.00% 100.00% 0.00% 1.159929 21.652020 0.534510 41.460440 -0.902388 18.380685 -0.842125 -0.697402 0.792382 0.348871 0.607419 17.845348 4.710195
181 N13 digital_ok 100.00% 100.00% 91.94% 0.00% 100.00% 0.00% 29.022402 68.294408 44.780715 5.633038 26.556899 27.137654 -0.438293 3.346911 0.044804 0.319130 0.154450 1.185571 2.753985
182 N13 RF_maintenance 100.00% 0.00% 26.88% 0.00% 100.00% 0.00% 15.752882 6.965426 20.320151 5.563514 18.180795 134.855845 -1.699521 5.069013 0.779566 0.469344 0.539579 5.166188 3.515158
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.393833 -0.620448 0.292975 -0.971366 -1.395605 -1.351023 -0.020465 0.390877 0.798772 0.625908 0.514699 2.126823 1.903308
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.166909 0.582848 -0.222628 0.514934 0.738653 0.961450 -0.065199 0.098312 0.798389 0.634138 0.503361 2.226005 1.821203
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.726201 0.005011 2.400320 1.060728 0.885007 0.708647 -0.149530 4.884297 0.798035 0.626628 0.509744 3.937090 4.205261
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.444130 0.296774 3.727228 2.137764 1.276179 0.514683 2.438387 2.824401 0.786765 0.613946 0.502812 1.793658 1.665576
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 7.89% 1.206200 1.435063 0.144469 1.134729 0.476210 -0.111952 3.291840 -0.171370 0.785705 0.614433 0.503705 1.238275 1.042021
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.719574 5.342904 0.753408 -0.363291 3.586654 3.880793 3.477883 3.905682 0.768696 0.568238 0.526985 6.546456 6.572079
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 34.559561 31.040336 1.951426 45.739592 9.330736 27.687229 32.528138 1.300725 0.682422 0.042586 0.439431 5.545904 1.719189
191 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 7.89% -0.094876 0.472031 -0.899449 -0.848784 -0.109131 -0.000630 0.973495 1.048226 0.759431 0.536597 0.555796 1.184525 1.037685
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 25.875335 24.170786 13.380935 1.052902 12.273808 4.650655 1.983857 4.033966 0.773904 0.553685 0.525783 5.579622 3.604033
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 22.001821 23.592593 1.274262 9.457207 3.873586 7.662171 5.114122 3.229174 0.752366 0.565028 0.513697 3.050127 2.825174
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 28.047283 25.490722 15.927167 13.245873 14.844564 11.669550 -0.018707 0.193344 0.748437 0.553568 0.507347 5.839193 4.970695
220 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
221 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
222 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 47.221673 47.133451 inf inf 2471.240779 2904.293725 1608.166298 2195.018595 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 22.924252 26.307396 7.887223 15.136018 5.463106 12.418022 -0.880558 -1.616570 0.760543 0.552436 0.531116 3.543463 2.900312
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 35.008721 35.380132 24.286033 24.133100 24.589424 23.277788 -2.018706 -1.740933 0.712749 0.502997 0.510685 2.685336 2.477383
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 47.220001 47.235467 inf inf 3412.023252 3411.982985 2628.970678 2629.161475 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 364.943933 365.171203 inf inf 658.697371 531.761392 1542.976773 1318.906591 nan nan nan 0.000000 0.000000
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.792353 7.958784 13.612914 12.544873 12.118183 9.823380 2.931057 2.935396 0.100863 0.073480 0.046045 0.000000 0.000000
323 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.334985 11.778273 1.141691 16.591115 6.834692 11.950357 3.161086 -1.323860 0.096937 0.074028 0.041809 0.000000 0.000000
324 N04 not_connected 100.00% 11.29% 67.74% 0.00% 100.00% 0.00% 14.192791 9.218391 17.647032 11.866696 14.793004 9.283814 -0.048729 2.628200 0.604627 0.344101 0.458955 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.569404 7.515213 5.036788 11.909916 6.747299 9.657402 1.260001 -0.413150 0.071980 0.058073 0.025703 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.829118 7.409733 0.149302 11.063250 1.600177 7.414333 -0.524969 -0.131289 0.070999 0.059649 0.028495 0.000000 0.000000
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, 7, 8, 9, 10, 15, 18, 19, 20, 21, 27, 28, 31, 32, 33, 36, 40, 41, 42, 50, 51, 52, 53, 54, 55, 56, 57, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 185, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [3, 16, 17, 29, 30, 37, 38, 45, 46, 65, 66, 67, 99, 100, 116, 162, 163, 164, 183, 184, 186]

golden_ants: [3, 16, 17, 29, 30, 37, 38, 45, 46, 65, 66, 67, 99, 100, 116, 162, 163, 164, 183, 184, 186]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H6C_Notebooks/_rtp_summary_/rtp_summary_table_2459821.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.3.dev44+g7d4aa18
3.1.4.dev3+g68bd8c3
In [ ]: