Skip to content

Commit ee3b80b

Browse files
committed
fixes to integration-based searches to used masked_array. also changed iteration range for make_bisp
1 parent d1343d7 commit ee3b80b

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

tpipe.py

+14-32
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
except ImportError:
2424
try:
2525
# as a backup, casa stuff can be imported if running casapy
26+
# from casac import casac; # Recommended by Sanjay B. (Don't ask me why this is so! :)
27+
# ms = casac.ms();
2628
from casa import ms
2729
from casa import quanta as qa
2830
print 'Imported CASA'
@@ -1090,11 +1092,10 @@ def read(self, file, nints, nskip, spw, selectpol, scan, datacol):
10901092
self.m0 = n.zeros(self.nints)
10911093

10921094
self.rawdata = newda
1093-
self.flags = flags
1095+
self.flags = n.invert(flags) # tests show that MS has opposite flag convention as Miriad! using complement of MS flag in tpipe.
10941096
print 'Shape of raw data, time:'
10951097
print self.rawdata.shape, self.reltime.shape
10961098

1097-
10981099
class SimulationReader(Reader):
10991100
""" Class for simulating visibility data for transients analysis.
11001101
"""
@@ -1197,7 +1198,7 @@ def prep(self):
11971198
# using 0 as flag
11981199
# self.data = n.ma.masked_array(self.rawdata[:self.nints,:, self.chans,:], self.rawdata[:self.nints,:, self.chans,:] == 0j)
11991200
# using standard flags
1200-
self.data = n.ma.masked_array(self.rawdata[:self.nints,:, self.chans,:], self.flags[:self.nints,:, self.chans,:] == 0)
1201+
self.data = n.ma.masked_array(self.rawdata[:self.nints,:, self.chans,:], self.flags[:self.nints,:, self.chans,:] == 0) # mask of True for flagged data (flags=0 in tpipe, which is flags=False in Miriad and flags=True in MS)
12011202
self.dataph = (self.data.mean(axis=3).mean(axis=1)).real #dataph is summed and detected to form TP beam at phase center, multi-pol
12021203
self.min = self.dataph.min()
12031204
self.max = self.dataph.max()
@@ -1255,8 +1256,6 @@ def tracksub(self, tbin, bgwindow = 0):
12551256
twidth = self.twidth
12561257

12571258
dataon = data[trackon[0], :, trackon[1]]
1258-
truearron = n.ones( n.shape(dataon) )
1259-
falsearron = 1e-5*n.ones( n.shape(dataon) ) # small weight to keep n.average from giving NaN
12601259

12611260
# set up bg track
12621261
if bgwindow:
@@ -1269,23 +1268,17 @@ def tracksub(self, tbin, bgwindow = 0):
12691268
trackoff = (trackoff[0] + list(n.array(track_t)+k), list(trackoff[1]) + list(track_c))
12701269

12711270
dataoff = data[trackoff[0], :, trackoff[1]]
1272-
truearroff = n.ones( n.shape(dataoff) )
1273-
falsearroff = 1e-5*n.ones( n.shape(dataoff) ) # small weight to keep n.average from giving NaN
12741271

1275-
datadiffarr = n.zeros((len(self.chans), self.nbl, self.npol),dtype='complex')
1272+
datadiffarr = n.ma.zeros((len(self.chans), self.nbl, self.npol),dtype='complex')
12761273

12771274
# compress time axis, then subtract on and off tracks
12781275
for ch in n.unique(trackon[1]):
12791276
indon = n.where(trackon[1] == ch)
1280-
weightarr = n.where(dataon[indon] != 0j, truearron[indon], falsearron[indon])
1281-
meanon = n.average(dataon[indon], axis=0, weights=weightarr)
1282-
# meanon = dataon[indon].mean(axis=0) # include all zeros
1277+
meanon = dataon[indon].mean(axis=0) # include all zeros
12831278

12841279
if bgwindow:
12851280
indoff = n.where(trackoff[1] == ch)
1286-
weightarr = n.where(dataoff[indoff] != 0j, truearroff[indoff], falsearroff[indoff])
1287-
meanoff = n.average(dataoff[indoff], axis=0, weights=weightarr)
1288-
# meanoff = dataoff[indoff].mean(axis=0) # include all zeros
1281+
meanoff = dataoff[indoff].mean(axis=0) # include all zeros
12891282

12901283
datadiffarr[ch] = meanon - meanoff
12911284
zeros = n.where( (meanon == 0j) | (meanoff == 0j) ) # find baselines and pols with zeros for meanon or meanoff
@@ -1323,29 +1316,18 @@ def make_bispectra(self, bgwindow=4):
13231316
"""
13241317

13251318
bisp = lambda d, ij, jk, ki: d[:,ij] * d[:,jk] * n.conj(d[:,ki]) # bispectrum for pol data
1326-
# bisp = lambda d, ij, jk, ki: n.complex(d[ij] * d[jk] * n.conj(d[ki])) # without pol axis
13271319

1328-
triples = self.make_triples()
1329-
meanbl = self.data.mean(axis=3).mean(axis=2).mean(axis=0) # find non-zero bls
1330-
self.triples = triples[(meanbl[triples][:,0] != 0j) & (meanbl[triples][:,1] != 0j) & (meanbl[triples][:,2] != 0j)] # take triples with non-zero bls
1320+
self.triples = self.make_triples()
1321+
self.bispectra = n.ma.zeros((len(self.data), len(self.triples)), dtype='complex')
13311322

1332-
self.bispectra = n.zeros((len(self.data), len(self.triples)), dtype='complex')
1333-
truearr = n.ones( (self.npol, self.nbl, len(self.chans)))
1334-
falsearr = n.zeros( (self.npol, self.nbl, len(self.chans)))
1335-
1336-
for i in xrange((bgwindow/2)+self.twidth, len(self.data)-( (bgwindow/2)+self.twidth )):
1323+
for i in xrange((bgwindow/2)+self.twidth, len(self.data)-( (bgwindow/2)+2*self.twidth )):
13371324
# for i in xrange((bgwindow/2)+self.twidth, len(self.data)-( (bgwindow/2)+self.twidth ), max(1,self.twidth)): # leaves gaps in data
13381325
diff = self.tracksub(i, bgwindow=bgwindow)
13391326

13401327
if len(n.shape(diff)) == 1: # no track
13411328
continue
13421329

1343-
weightarr = n.where(diff != 0j, truearr, falsearr) # ignore zeros in mean across channels # bit of a hack
1344-
1345-
try:
1346-
diffmean = n.average(diff, axis=2, weights=weightarr)
1347-
except ZeroDivisionError:
1348-
diffmean = n.mean(diff, axis=2) # if all zeros, just make mean # bit of a hack
1330+
diffmean = n.mean(diff, axis=2) # if all zeros, just make mean # bit of a hack
13491331

13501332
for trip in xrange(len(self.triples)):
13511333
ij, jk, ki = self.triples[trip]
@@ -1483,7 +1465,7 @@ def prep(self):
14831465
# using 0 as flag
14841466
# self.data = n.ma.masked_array(self.rawdata[:self.nints,:, self.chans,:], self.rawdata[:self.nints,:, self.chans,:] == 0j)
14851467
# using standard flags
1486-
self.data = n.ma.masked_array(self.rawdata[:self.nints,:, self.chans,:], self.flags[:self.nints,:, self.chans,:] == 0)
1468+
self.data = n.ma.masked_array(self.rawdata[:self.nints,:, self.chans,:], self.flags[:self.nints,:, self.chans,:] == 0) # mask of True for flagged data (flags=0 in tpipe, which is flags=False in Miriad and flags=True in MS)
14871469
self.dataph = (self.data.mean(axis=3).mean(axis=1)).real #dataph is summed and detected to form TP beam at phase center, multi-pol
14881470
self.min = self.dataph.min()
14891471
self.max = self.dataph.max()
@@ -1634,7 +1616,7 @@ def make_bispectra(self, bgwindow=4):
16341616
twidth = n.round(self.twidths[d])
16351617
dmwidth = int(n.round(n.max(self.dmtrack0[d][0]) - n.min(self.dmtrack0[d][0])))
16361618

1637-
for i in xrange((bgwindow/2)+twidth, len(self.data)-( (bgwindow/2)+twidth+dmwidth )): # dmwidth avoided at end, others are split on front and back side of time iteration
1619+
for i in xrange((bgwindow/2)+twidth, len(self.data)-( (bgwindow/2)+2*twidth+dmwidth )): # dmwidth avoided at end, others are split on front and back side of time iteration
16381620
# for i in xrange((bgwindow/2)+twidth, len(self.data)-( (bgwindow/2)+twidth+dmwidth ), max(1,twidth/2)): # can step by twidth/2, but messes up data products
16391621
diff = self.tracksub(d, i, bgwindow=bgwindow)
16401622

@@ -1891,7 +1873,7 @@ def prep(self, deleteraw=False):
18911873
# using 0 as flag
18921874
# self.data = n.ma.masked_array(self.rawdata[:self.nints,:, self.chans,:], self.rawdata[:self.nints,:, self.chans,:] == 0j)
18931875
# using standard flags
1894-
self.data = n.ma.masked_array(self.rawdata[:self.nints,:, self.chans,:], self.flags[:self.nints,:, self.chans,:] == 0)
1876+
self.data = n.ma.masked_array(self.rawdata[:self.nints,:, self.chans,:], self.flags[:self.nints,:, self.chans,:] == 0) # mask of True for flagged data (flags=0 in tpipe, which is flags=False in Miriad and flags=True in MS)
18951877
self.dataph = (self.data.mean(axis=3).mean(axis=1)).real #dataph is summed and detected to form TP beam at phase center, multi-pol
18961878
self.min = self.dataph.min()
18971879
self.max = self.dataph.max()

0 commit comments

Comments
 (0)