Skip to content

Commit

Permalink
Merge pull request #219 from HERA-Team/rparams_backwards_compat
Browse files Browse the repository at this point in the history
Makes r_params backwards compatible for UVPSpec
  • Loading branch information
nkern committed Aug 29, 2019
2 parents 849bd7d + 01fbd33 commit b35a830
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Binary file added hera_pspec/data/test_uvp.h5
Binary file not shown.
21 changes: 11 additions & 10 deletions hera_pspec/pspecdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def __init__(self, dsets=[], wgts=None, dsets_std=None, labels=None,
self.spw_range = None
self.spw_Nfreqs = None
self.spw_Ndlys = None
self.r_params = {} #r_params is a dictionary that stores parameters for
#parametric R matrices.
# r_params is a dictionary that stores parameters for
# parametric R matrices.
self.r_params = {}
self.cov_regularization = 0.
# set data weighting to identity by default
# and taper to none by default
Expand Down Expand Up @@ -831,11 +832,11 @@ def R(self, key):
# Note that we multiply sqrtY inside of the pinv
#to apply flagging weights before taking psuedo inverse.
self._R[Rkey] = sqrtT.T * np.linalg.pinv(sqrtY.T * \
dspec.sinc_downweight_mat_inv(nchan = self.spw_Nfreqs,
df = np.median(np.diff(self.freqs)),
filter_centers = r_params['filter_centers'],
filter_widths = r_params['filter_widths'],
filter_factors = r_params['filter_factors'])* sqrtY) * sqrtT
dspec.sinc_downweight_mat_inv(nchan=self.spw_Nfreqs,
df=np.median(np.diff(self.freqs)),
filter_centers=r_params['filter_centers'],
filter_widths=r_params['filter_widths'],
filter_factors=r_params['filter_factors']) * sqrtY) * sqrtT

return self._R[Rkey]

Expand Down Expand Up @@ -2065,7 +2066,7 @@ def pspec(self, bls1, bls2, dsets, pols, n_dlys=None,
input_data_weight='identity', norm='I', taper='none',
sampling=False, little_h=True, spw_ranges=None,
baseline_tol=1.0, store_cov=False, verbose=True,
exact_norm=False, history='', r_params = None):
exact_norm=False, history='', r_params=None):
"""
Estimate the delay power spectrum from a pair of datasets contained in
this object, using the optimal quadratic estimator of arXiv:1502.06016.
Expand Down Expand Up @@ -2461,8 +2462,8 @@ def pspec(self, bls1, bls2, dsets, pols, n_dlys=None,
if not key2 in r_params:
raise ValueError("No r_param dictionary supplied"
" for baseline %s"%(str(key2)))
self.set_r_param(key1,r_params[key1])
self.set_r_param(key2,r_params[key2])
self.set_r_param(key1, r_params[key1])
self.set_r_param(key2, r_params[key2])

# Build Fisher matrix
if input_data_weight == 'identity':
Expand Down
7 changes: 7 additions & 0 deletions hera_pspec/tests/test_uvpspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,3 +722,10 @@ def test_conj_blpair():
blpair = uvputils._conj_blpair(101102103104, which='both')
nt.assert_equal(blpair, 102101104103)
nt.assert_raises(ValueError, uvputils._conj_blpair, 102101103104, which='foo')

def test_compatibility_read():
# test read in of a static test file dated 8/2019
uvp = uvpspec.UVPSpec()
uvp.read_hdf5(os.path.join(DATA_PATH, 'test_uvp.h5'))
# assert check does not fail
uvp.check()
4 changes: 2 additions & 2 deletions hera_pspec/uvpspec_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def _select(uvp, spws=None, bls=None, only_pairs_in_bls=False, blpairs=None,
if store_cov:
uvp.cov_array = cov

#select r_params based on new bl_array
# select r_params based on new bl_array
blp_keys = uvp.get_all_keys()
blkeys = []
for blpkey in blp_keys:
Expand All @@ -756,7 +756,7 @@ def _select(uvp, spws=None, bls=None, only_pairs_in_bls=False, blpairs=None,
if not key2 in blkeys:
blkeys += [key2,]
new_r_params = {}
if not uvp.r_params == '':
if hasattr(uvp, 'r_params') and uvp.r_params != '':
r_params = uvp.get_r_params()
for rpkey in r_params:
if rpkey in blkeys:
Expand Down

0 comments on commit b35a830

Please sign in to comment.