Skip to content

Commit

Permalink
update stations
Browse files Browse the repository at this point in the history
  • Loading branch information
jurjen93 committed Nov 13, 2023
1 parent 8d26074 commit bffb185
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions h5_helpers/selfcal_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import re
import tables
from glob import glob
from scipy.stats import circstd, linregress, circmean
from scipy.stats import circstd, linregress
import numpy as np
import matplotlib.pyplot as plt
from argparse import ArgumentParser
Expand All @@ -25,14 +25,16 @@


class SelfcalQuality:
def __init__(self, folder: str = None, remote_only: bool = False, international_only: bool = False):
def __init__(self, folder: str = None, remote_only: bool = False, international_only: bool = False, dutch_only: bool = False):
"""
Determine quality of selfcal from facetselfcal.py
:param folder: path to where selfcal ran
:param dutch_only: consider dutch stations only for amp/phase stability
:param remote_only: consider remote stations only for amp/phase stability
:param international_only: consider international stations only for amp/phase stability
"""

# selfcal folder
self.folder = folder
# merged selfcal h5parms
Expand All @@ -59,6 +61,7 @@ def __init__(self, folder: str = None, remote_only: bool = False, international_
# for phase/amp evolution
self.remote_only = remote_only
self.international_only = international_only
self.dutch_only = dutch_only

self.textfile = open('selfcal_performance.csv', 'w')
self.writer = csv.writer(self.textfile)
Expand Down Expand Up @@ -189,16 +192,24 @@ def get_solution_scores(self, h5_1: str = None, h5_2: str = None):
vals2 = F.root.sol000.phase000.val[:]
weights2 = F.root.sol000.phase000.weight[:]

if self.remote_only and not self.international_only:

if self.dutch_only:
stations = [i for i, station in enumerate(H.root.sol000.antenna[:]['name']) if
('CS' in self.make_utf8(station))]
vals1 = np.take(vals1, stations, axis=axes.index('ant'))
weights1 = np.take(weights1, stations, axis=axes.index('ant'))
if h5_2 is not None:
vals2 = np.take(vals2, stations, axis=axes.index('ant'))
weights2 = np.take(weights2, stations, axis=axes.index('ant'))
elif self.remote_only:
stations = [i for i, station in enumerate(H.root.sol000.antenna[:]['name']) if
('RS' in self.make_utf8(station))]
vals1 = np.take(vals1, stations, axis=axes.index('ant'))
weights1 = np.take(weights1, stations, axis=axes.index('ant'))
if h5_2 is not None:
vals2 = np.take(vals2, stations, axis=axes.index('ant'))
weights2 = np.take(weights2, stations, axis=axes.index('ant'))

elif self.international_only and not self.remote_only:
elif self.international_only:
stations = [i for i, station in enumerate(H.root.sol000.antenna[:]['name']) if
not ('RS' in self.make_utf8(station)
or 'CS' in self.make_utf8(station)
Expand All @@ -221,12 +232,7 @@ def get_solution_scores(self, h5_1: str = None, h5_2: str = None):
if h5_2 is not None:
vals2 = F.root.sol000.amplitude000.val[:]

if self.remote_only and not self.international_only:
vals1 = np.take(vals1, stations, axis=axes.index('ant'))
if h5_2 is not None:
vals2 = np.take(vals2, stations, axis=axes.index('ant'))

elif self.international_only and not self.remote_only:
if self.remote_only or self.dutch_only or self.international_only:
vals1 = np.take(vals1, stations, axis=axes.index('ant'))
if h5_2 is not None:
vals2 = np.take(vals2, stations, axis=axes.index('ant'))
Expand Down Expand Up @@ -276,7 +282,9 @@ def solution_stability(self):
total_amp_scores = np.append(total_amp_scores, [amp_scores], axis=0)

# plot
if self.remote_only:
if self.dutch_only:
plotname = f'selfcal_stability_dutch_{self.sourcename}.png'
elif self.remote_only:
plotname = f'selfcal_stability_remote_{self.sourcename}.png'
elif self.international_only:
plotname = f'selfcal_stability_international_{self.sourcename}.png'
Expand Down Expand Up @@ -415,6 +423,7 @@ def parse_args():
"""
parser = ArgumentParser(description='Determine selfcal quality')
parser.add_argument('--selfcal_folder', default='.')
parser.add_argument('--dutch_only', action='store_true', help='Only Dutch stations are considered', default=None)
parser.add_argument('--remote_only', action='store_true', help='Only remote stations are considered', default=None)
parser.add_argument('--international_only', action='store_true', help='Only international stations are considered',
default=None)
Expand Down

0 comments on commit bffb185

Please sign in to comment.