Skip to content

Commit

Permalink
Added folding of covariance matrices and get_cov now addresses folding.
Browse files Browse the repository at this point in the history
  • Loading branch information
EXTERNAL-Ewall-Wice committed Jul 8, 2018
1 parent 25cb579 commit cab8a22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 27 additions & 0 deletions hera_pspec/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ def fold_spectra(uvp):
# get number of dly bins
Ndlys = len(uvp.get_dlys(spw))

# This section could be streamlined considerably since there is a lot of
# code overlap between the even and odd Ndlys cases.

if Ndlys % 2 == 0:
# even number of dlys
left = uvp.data_array[spw][:, 1:Ndlys//2, :][:, ::-1, :]
Expand All @@ -620,13 +623,37 @@ def fold_spectra(uvp):
uvp.data_array[spw][:, :Ndlys//2, :] = 0.0
uvp.nsample_array[spw] *= 2.0

# fold covariance array if it exists.
if hasattr(uvp,'cov_array'):
leftleft = uvp.cov_array[spw][:, 1:Ndlys//2, 1:Ndlys//2, :][:, ::-1, ::-1, :]
leftright = uvp.cov_array[spw][:, 1:Ndlys//2, Ndlys//2+1:, :][:, ::-1, :, :]
rightleft = uvp.cov_array[spw][:, Ndlys//2+1: , 1:Ndlys//2, :][:, :, ::-1, :]
rightright = uvp.cov_array[spw][:, Ndlys//2+1:, Ndlys//2+1:, :]
uvp.cov_array[spw][:, Ndlys//2+1:, Ndlys//2+1:, :] = .25*(leftleft\
+leftright\
+rightleft\
+rightright)
uvp.cov_array[spw][:, :Ndlys/2, :, :] = 0.0
uvp.cov_array[spw][:, :, :Ndlys/2, : :] = 0.0
else:
# odd number of dlys
left = uvp.data_array[spw][:, :Ndlys//2, :][:, ::-1, :]
right = uvp.data_array[spw][:, Ndlys//2+1:, :]
uvp.data_array[spw][:, Ndlys//2+1:, :] = np.mean([left, right], axis=0)
uvp.data_array[spw][:, :Ndlys//2, :] = 0.0
uvp.nsample_array[spw] *= 2.0
# fold covariance array if it exists.
if hasattr(uvp,'cov_array'):
leftleft = uvp.cov_array[spw][:, :Ndlys//2, :Ndlys//2, :][:, ::-1, ::-1, :]
leftright = uvp.cov_array[spw][:, :Ndlys//2, Ndlys//2+1:, :][:, ::-1, :, :]
rightleft = uvp.cov_array[spw][:, Ndlys//2+1: , :Ndlys//2, :][:, :, ::-1, :]
rightright = uvp.cov_array[spw][:, Ndlys//2+1:, Ndlys//2+1:, :]
uvp.cov_array[spw][:, Ndlys//2+1:, Ndlys//2+1:, :] = .25*(leftleft\
+leftright\
+rightleft\
+rightright)
uvp.cov_array[spw][:, :Ndlys/2, :, :] = 0.0
uvp.cov_array[spw][:, :, :Ndlys/2, : :] = 0.0

uvp.folded = True

Expand Down
6 changes: 5 additions & 1 deletion hera_pspec/uvpspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ def get_cov(self,key,*args):
# Need to deal with folded data!
# if data has been folded, return only positive delays
if hasattr(self,'cov_array'):
return self.cov_array[spw][blpairts, :, :, pol]
if self.folded:
Ndlys = self.data_array[spw].shape[1]
return self.cov_array[spw][blpairts, Ndlys//2+1:, Ndlys//2+1:, pol]
else:
return self.cov_array[spw][blpairts, :, :, pol]
else:
raise AttributeError("No covariance array has been calculated.")

Expand Down

0 comments on commit cab8a22

Please sign in to comment.