Пример #1
0
    def bispectrumplot(self, plotcand={}, show=1, save=0):
        """ Produces plot of bispectrum for given candidate.
        """

        if len(plotcand) != 1:
            print 'plotcands should have exactly one beam.'
            return 0

        # collect candidate params
        (ra, dec) = plotcand.keys()[0]
        cand = plotcand[(ra,dec)][0]
        startint = self.startints[0]

        print 'Producing bispectrum plot for beam', ra, dec, ', candidate, ', cand

        self.obs = tpipe.pipe_msdisp2(file=self.datafile, nints=self.nints, nskip=startint, profile='default', selectpol=self.selectpol, scan=self.scan, spw=self.spw, chans=self.chans, dmarr=self.dmarr, datacol='corrected_data')

        # select data for candidate
        self.obs.time_filter(cand[0], self.filtershape, bgwindow=self.bgwindow)
        noiseperbl = self.obs.data.mean(axis=3).mean(axis=2).real.std()   # measure single noise for input to detect_bispectra

        l1 = n.radians(ra); m1 = n.radians(dec)
        if ( (l1 != self.obs.l0[0]) | (m1 != self.obs.m0[0]) ):
            dl = l1 - self.obs.l0[0]; dm = m1 - self.obs.m0[0]  # find phase shift for new location
            self.obs.phaseshift(dl, dm)

        # find candidates
        self.obs.make_bispectra(stokes=self.stokes)
        (candsnr, candstd, cands) = self.obs.detect_bispectra(sigma=self.sigma, Q=noiseperbl, show=show, save=save)
Пример #2
0
    def candplot2(self, plotcands={}, save=0):
        """ Builds summary plots, including phased beam and imaging for each plot candidate.
        This is a "tier 2" plot, since it only uses all interferometric info for a given candidate data location.
        Candidate should be dictionary with keys of beam location and value of a list of 3-element lists (dt, int, dmbin).
        Note: this starts from scratch by reading data to produce a set of plots tailored to each candidate.
        No requirement for do_search and find_candidates to be run first.
        """

        print 'Building Tier 2 candidate plot.'

        if n.array([len(plotcands[beam]) for beam in plotcands.keys()]).sum() == 0:
            print 'No candidates available...'
            return

#        twindow = 128     # number of integrations to read for plots
        figi = 1
        for beam in plotcands.keys():
            if len(plotcands[beam]) == 0:
                continue
            if (n.ndim(plotcands[beam]) != 2) | (n.shape(plotcands[beam])[1] != 3):
                print 'Candidate does not seem to be in proper format. Skipping.'
                continue

            (ra, dec) = beam
            print 'Generating plots for candidate with delaycenter: (%s, %s)' % (str(ra), str(dec))
            for cand in plotcands[beam]:
                (dtind, ii, dmind) = cand
                print 'Candidate at (dtind, ii, dmind) = (%d, %d, %d)' % (dtind, ii, dmind)

                if self.datatype == 'mir':
# older version centered pulse plot in time
#                    obs = tpipe.pipe_mirdisp2(file=self.datafile, nints=twindow, nskip=self.startints[0]+ii-twindow/2, profile='default', dmarr=self.dmarr, chans=self.chans)
                    self.obs = tpipe.pipe_mirdisp2(file=self.datafile, nints=self.nints, nskip=self.startints[0], profile='default', dmarr=self.dmarr, chans=self.chans)
                elif self.datatype == 'ms':
#                    obs = tpipe.pipe_msdisp2(file=self.datafile, nints=twindow, nskip=self.startints[0]+ii-twindow/2, profile='default', selectpol=self.selectpol, scan=self.scan, spw=self.spw, chans=self.chans, dmarr=self.dmarr, datacol='corrected_data')
                    self.obs = tpipe.pipe_msdisp2(file=self.datafile, nints=self.nints, nskip=self.startints[0], profile='default', selectpol=self.selectpol, scan=self.scan, spw=self.spw, chans=self.chans, dmarr=self.dmarr, datacol='corrected_data')
                elif self.datatype == 'sim':
                    print 'For datatype=\'sim\', we have no original data.'
#                    obs = tpipe.pipe_simdisp2(array='vla_d', nints=twindow, profile='default', dmarr=self.dmarr)
#                    obs.add_transient(0., 0., 1., twindow/2)
                    self.obs = tpipe.pipe_simdisp2(array='vla_d', nints=self.nints, profile='default', dmarr=self.dmarr)
                    self.obs.add_transient(0., 0., 1., ii)

                self.obs.time_filter(self.timescales[dtind], self.filtershape, bgwindow=self.bgwindow)    # tophat filter (bgwindow not used)
                noiseperbl = self.obs.data.mean(axis=3).mean(axis=2).real.std()   # measure single noise for input to detect_bispectra

                # shift phase center to candidate
                l1 = n.radians(ra); m1 = n.radians(dec)
                if ( (l1 != self.obs.l0[0]) | (m1 != self.obs.m0[0]) ):
                    dl = l1 - self.obs.l0[0]; dm = m1 - self.obs.m0[0]  # find phase shift for new location (in degrees)
                    self.obs.phaseshift(dl, dm)

                # reproduce bisp candidates
                self.obs.make_bispectra(stokes=self.stokes)
                (candsnr, candstd, cands) = self.obs.detect_bispectra(sigma=self.sigma, Q=noiseperbl, save=0)
                print 'Reproduced bispectrum candidate, ', cands

                # make image of field
#                im = obs.imagetrack(obs.tracksub(dmind, twindow/2), i=twindow/2, pol='i', size=self.size, res=self.res, clean=1, show=0)
                im = self.obs.imagetrack(self.obs.tracksub(dmind, ii), i=ii, pol='i', size=self.size, res=self.res, clean=1, show=0)
                imsize = float(self.size)/self.res
                pixelscale = 1./self.size
                peakm, peakl = n.where(im == im.max())
                dm = -(imsize/2. - peakm[0])*pixelscale   # indexed starting at top...
                dl = -(peakl[0] - imsize/2.)*pixelscale   # indexed starting at left.
                # phase shift to center for spectral analysis
                self.obs.phaseshift(dl, dm)
#                specmod = obs.specmod(dmind, twindow/2)
                specmod = self.obs.specmod(dmind, ii)

                # now plot
                p.figure(figi)

                # text description of candidate
                p.subplot(221, axisbg='white')
                p.title('Candidate @ Tier 2')
                p.xticks([])
                p.yticks([])
                p.text(0.1, 0.8, self.datafile, fontname='sans-serif')
                beamra = n.round(beam, 3)[0]
                beamdec = n.round(beam, 3)[1]
                p.text(0.1, 0.6, 'Beam: ' + str(beamra) + ', ' + str(beamdec) + ', dt: ' + str(self.timescales[cand[0]]), fontname='sans-serif')
                p.text(0.1, 0.4, 'Integration: ' + str(cand[1]) + ', DM: ' + str(self.dmarr[cand[2]]), fontname='sans-serif')
#                ww = n.where([n.all(mastercand == cand) for mastercand in self.masterloc[beam]])[0][0]
                p.text(0.1, 0.2, 'SNR: ' + str(n.round(candsnr, 1)), fontname='sans-serif')

                # image of dispersed visibilities for candidate
                p.subplot(222)
                fov = n.degrees(1./self.res)*3600.       # field of view in arcseconds
                p.imshow(im, aspect='auto', origin='lower', interpolation='nearest', extent=[fov/2, -fov/2, -fov/2, fov/2])
                p.colorbar()
                p.xlabel('RA/l Offset (arcsec)')
                p.ylabel('Dec/m Offset (arcsec)')

                p.subplot(223)
#                spec = obs.dedisperse(dmind).mean(axis=3).mean(axis=1).real[twindow/2]    # stokes I
                spec = self.obs.dedisperse(dmind).mean(axis=3).mean(axis=1).real[ii]    # stokes I
                p.plot(self.obs.freq, spec, '.')
                p.text(0.1, 0.1, 'specmod =' + str(specmod))
                p.xlabel('Frequency (GHz)')
                p.ylabel('Flux density (Jy)')

                p.subplot(224)
                dataph = n.rot90(self.obs.dataph)
                sh = dataph.shape
                im = p.imshow(dataph, aspect='auto', origin='upper', interpolation='nearest', extent=(0, sh[1], 0, sh[0]))
                p.colorbar()
                p.plot(self.obs.dmtrack0[dmind][0], self.obs.dmtrack0[dmind][1],'k.')   # reference dispersed track
                p.xlabel('Integration')
                p.ylabel('Channel')
                if self.datatype == 'mir':   # casapy doesn't get along with recent matplotlib stuff
                    p.tight_layout()

                if save:
                    p.savefig(self.fileroot + '_sc' + str(self.scan) + 'sp' + str(self.spw[0]) + 'i' + str(self.startints[0]) + '_tier1_' + str(figi) + '.png')
                figi += 1
Пример #3
0
    def do_search(self):
        """ Bispectrum transient search over all delay beams.
        """

        self.masterloc = {}           # "location" of candidate: dt, integration (over all data in pipe), dmbin
        self.masterprop = {}          # properties of candidate: snr and std of bispectra for dedispersed trial
        self.masterdata = {}          # data around the candidate: bisp lightcurve and spectrogram
        self.masternoise = {}         # noise per bl as measured by detect_bispectra
        for (ra,dec) in self.delaycenters:
            self.masterloc[(ra,dec)] = []
            self.masterprop[(ra,dec)] = []
            self.masterdata[(ra,dec)] = []
            self.masternoise[(ra,dec)] = []

        for startint in self.startints:
            if self.datatype == 'mir':
                self.obs = tpipe.pipe_mirdisp2(file=self.datafile, nints=self.nints, nskip=startint, profile='default', dmarr=self.dmarr, chans=self.chans)
            elif self.datatype == 'ms':
                self.obs = tpipe.pipe_msdisp2(file=self.datafile, nints=self.nints, nskip=startint, profile='default', selectpol=self.selectpol, scan=self.scan, spw=self.spw, chans=self.chans, dmarr=self.dmarr, datacol='corrected_data')
            elif self.datatype == 'sim':
                self.obs = tpipe.pipe_simdisp2(array='vla_a', nints=self.nints, profile='default', dmarr=self.dmarr, chans=range(64))
#                self.obs.add_transient(0., 0., 1., n.random.randint(self.nints))
            else:
                print 'Unknown datatype!'
                return

            # accumulate running reltime
            if startint == self.startints[0]:
                self.tarr = self.obs.reltime
            else:
                self.tarr = n.append(self.tarr, self.obs.reltime + self.tarr[-1] + self.obs.inttime)

            for dtind in range(len(self.timescales)):

                # after first pass, need to reset the working data so effect of time_filter is as expected
#                if self.timescales.index(dt) > 0:
                if dtind > 0:
                    print 'Resetting data to unfiltered version...'
                    self.obs.prep()

                self.obs.time_filter(self.timescales[dtind], self.filtershape, bgwindow=self.bgwindow)

                for (ra,dec) in self.delaycenters:
                    print
                    print 'Searching int %d, dt %d, and delay beam (ra, dec) = %.3f, %.3f' % (startint, self.timescales[dtind], ra, dec)
                    l1 = n.radians(ra); m1 = n.radians(dec)
                    if ( (l1 != self.obs.l0[0]) | (m1 != self.obs.m0[0]) ):
                        dl = l1 - self.obs.l0[0]; dm = m1 - self.obs.m0[0]  # find phase shift for new location
                        self.obs.phaseshift(dl, dm)

                    # measure single noise for input to detect_bispectra
                    noiseperbl = self.obs.data.mean(axis=3).mean(axis=2).real.std()

                    # find candidates
                    self.obs.make_bispectra(stokes=self.stokes)
# add a way to cut candidates near edges (due to time_filter)?
                    (candsnr, candstd, cands) = self.obs.detect_bispectra(sigma=self.sigma, Q=noiseperbl, save=0)

                    # build master list of candidate location from bispectrum search
                    loclist = self.masterloc[(ra,dec)]
                    proplist = self.masterprop[(ra,dec)]
                    datalist = self.masterdata[(ra,dec)]
                    for i in range(len(cands)):
                        loclist.append( [dtind, (startint-self.startints[0])+cands[i][0], cands[i][1]] )    # candidate location
                        proplist.append( [candsnr[i], candstd[i]] )                  # candidate bisp properties
                        intmin = max(0, cands[i][0] - 64)                            # candidate lightcuve and spectrogram
                        intmax = min(cands[i][0] + 64, self.nints)
                        bamean = self.obs.bispectra.real.mean(axis=2)[cands[i][1], intmin:intmax]     # trim in time to save space
                        bastd = self.obs.bispectra.real.std(axis=2)[cands[i][1], intmin:intmax]
                        spec = self.obs.dataph[intmin:intmax]
                        datalist.append( (bamean, bastd, spec) )

                    self.masterloc[(ra,dec)] = loclist
                    self.masterprop[(ra,dec)] = proplist
                    self.masterdata[(ra,dec)] = datalist
                    self.masternoise[(ra,dec)] = (dtind, self.obs.Q)
                    print '%d candidates found in beam of %s at int %d' % (len(loclist), self.datafile, startint)