Skip to content

Commit

Permalink
Now use uvtools for filtering. Removed redundant code.
Browse files Browse the repository at this point in the history
  • Loading branch information
EXTERNAL-Ewall-Wice committed Jun 21, 2019
1 parent 16c8444 commit 3c33bc9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 57 deletions.
3 changes: 2 additions & 1 deletion hera_pspec/pspecdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ast
import glob
import warnings
import uvtools.dspec as dspec

class PSpecData(object):

Expand Down Expand Up @@ -793,7 +794,7 @@ def R(self, key):
#weights = copy.copy(self.w(key))
#weights = np.mean(weights,axis=1) #weights are calculated by averaging weights matrix in time.
self._R[Rkey] = sqrtT.T * np.linalg.pinv(sqrtY.T * \
utils.sinc_downweight_mat_inv(nchan = self.spw_Nfreqs,
dspec.sinc_downweight_mat_inv(nchan = self.spw_Nfreqs,
df = 1.,
filter_centers = r_params['filter_centers'],
filter_widths = r_params['filter_widths'],
Expand Down
13 changes: 0 additions & 13 deletions hera_pspec/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,6 @@ def test_get_blvec_reds():
red_bl_tag) = utils.get_blvec_reds(uvp, bl_error_tol=1.0, match_bl_lens=True)
nt.assert_equal(len(red_bl_grp), 1)

def test_sinc_downweight_mat_inv():
cmat = utils.sinc_downweight_mat_inv(32, 100e3, filter_centers = [], filter_widths = [], filter_factors = [])
#verify that the inverse cleaning matrix without cleaning windows is the identity!
np.testing.assert_array_equal(cmat, np.identity(32).astype(np.complex128))
#next, test with a single filter window with list and float arguments supplied
cmat1 = utils.sinc_downweight_mat_inv(32, 100e3, filter_centers = 0., filter_widths = 100e-9, filter_factors = 1e-9)
cmat2 = utils.sinc_downweight_mat_inv(32, 100e3, filter_centers = [0.], filter_widths = [100e-9], filter_factors = [1e-9])
x,y = np.meshgrid(np.arange(-16,16), np.arange(-16,16))
cmata = np.identity(32).astype(np.complex128) + 1e9 * np.sinc( (x-y) * 100e3 * 200e-9 ).astype(np.complex128)
np.testing.assert_array_equal(cmat1, cmat2)
#next test that the array is equal to what we expect
np.testing.assert_almost_equal(cmat1, cmata)

def test_job_monitor():
# open empty files
datafiles = ["./{}".format(i) for i in ['a', 'b', 'c', 'd']]
Expand Down
43 changes: 0 additions & 43 deletions hera_pspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,6 @@
from pyuvdata import UVData
from datetime import datetime



def sinc_downweight_mat_inv(nchan, df, filter_centers, filter_widths, filter_factors):
"""
Computes inverse of clean weights for a baseline.
This form of weighting is diagonal in delay-space and down-weights tophat regions
Parameters
----------
nchan: integer
Number of channels on baseline
df: float
channel width (Hz)
filter_centers: float or list
float or list of floats of centers of delay filter windows in nanosec
filter_widths: float or list
float or list of floats of widths of delay filter windows in nanosec
filter_factors: float or list
float or list of floats of filtering factors.
Returns
----------
(nchan, nchan) complex inverse of the tophat filtering matrix assuming that the delay-space covariance is diagonal and zero outside
of the horizon
"""
if isinstance(filter_centers, float):
filter_centers = [filter_centers]
if isinstance(filter_widths, float):
filter_widths = [filter_widths]
if isinstance(filter_factors,float):
filter_factors = [filter_factors]
x = np.arange(-int(nchan/2),int(np.ceil(nchan/2)))
fx, fy = np.meshgrid(x,x)
sdwi_mat = np.identity(fx.shape[0]).astype(np.complex128)
for fc, fw, ff in zip(filter_centers, filter_widths, filter_factors):
if not ff == 0:
sdwi_mat = sdwi_mat + np.sinc( 2. * (fx-fy) * df * fw ).astype(np.complex128)\
* np.exp(-2j * np.pi * (fx-fy) * df * fc) / ff
#multiply by weights matrix.
return sdwi_mat



def cov(d1, w1, d2=None, w2=None, conj_1=False, conj_2=True):
"""
Computes an empirical covariance matrix from data vectors. If d1 is of size
Expand Down

0 comments on commit 3c33bc9

Please sign in to comment.