Пример #1
0
    def setLevel1(self, datafile, source=''):
        """
        """
        self.setSource(source)

        self.teleLon = self.datafile['hk/antenna0/tracker/siteActual'][
            0, 0] / (60.**2 * 1000.)
        self.teleLat = self.datafile['hk/antenna0/tracker/siteActual'][
            0, 1] / (60.**2 * 1000.)

        self.datafile = datafile

        self.attributes = self.datafile['comap'].attrs

        self.tsamp = float(self.attributes['tsamp'].decode())
        self.obsid = self.attributes['obsid'].decode()
        self.source = self.attributes['source'].decode()

        # load but do not read yet.
        self.x = self.datafile['spectrometer/pixel_pointing/pixel_ra']
        self.y = self.datafile['spectrometer/pixel_pointing/pixel_dec']
        self.utc = self.datafile['spectrometer/MJD']
        sunra, sundec, sundist = Coordinates.getPlanetPosition('Sun',
                                                               self.teleLon,
                                                               self.teleLat,
                                                               self.utc[:],
                                                               returnall=True)
        sunra, sundec = Coordinates.precess(sunra, sundec, self.utc[:])
        pa = Coordinates.pa(sunra, sundec, self.utc, self.teleLon,
                            self.teleLat)
        for i in range(self.x.shape[0]):
            self.x[i, :], self.y[i, :] = Coordinates.Rotate(
                self.x[i, :], self.y[i, :], sunra, sundec, -pa)

        self.xCoordinateName = r'$\Delta$A'
        self.yCoordinateName = r'$\Delta$E'

        self.el = self.datafile['spectrometer/pixel_pointing/pixel_el']

        self.tod_bavg = self.datafile['spectrometer/band_average']
        self.features = self.datafile['spectrometer/features'][:]
        self.mask = np.ones(self.features.size).astype(int)
        self.mask[self.featureBits(self.features.astype(float), 13)] = 0
        self.mask[self.features == 0] = 0
        self.mask = self.mask.astype(int)

        # If we don't spe
        self.setCrval()

        self.setWCS(self.crval, self.cdelt, self.crpix, self.ctype)
Пример #2
0
    def MakeMap(self, tod, ra, dec, mjd, el):
        #takes a 1D tod array and makes a simple map

        #produce arrays for mapping
        npix = self.naxis[0] * self.naxis[1]

        pixbins = np.arange(0, npix + 1).astype(int)

        nHorns, nSBs, nChans, nSamples = tod.shape
        rms = Filtering.calcRMS(tod)

        maps = np.zeros((nHorns, nSBs, nChans, self.naxis[0], self.naxis[1]))
        for i in range(nHorns):

            good = (np.isnan(ra[i, :]) == False) & (np.isnan(tod[i, 0, 0])
                                                    == False)
            pa = Coordinates.pa(ra[i, good], dec[i, good], mjd[good], self.lon,
                                self.lat)
            x, y = Coordinates.Rotate(ra[i, good], dec[i, good], self.x0,
                                      self.y0, -pa)

            nbins = 10
            xbins = np.linspace(np.min(x), np.max(x), nbins + 1)
            xmids = (xbins[1:] + xbins[:-1]) / 2.
            xbw, _ = np.histogram(x, xbins)
            ybw, _ = np.histogram(y, xbins)

            todAvg = np.nanmean(np.nanmean(tod[i, ...], axis=0), axis=0)
            fitx0, fity0 = self.initialPeak(todAvg[good], x, y)
            r = np.sqrt((x - fitx0)**2 + (y - fity0)**2)
            close = (r < 6. / 60.)

            pix = ang2pixWCS(self.wcs, x, y).astype('int')
            mask = np.where((pix != -1))[0]

            h, b = np.histogram(pix,
                                pixbins,
                                weights=(pix != -1).astype(float))
            self.hits = np.reshape(h, (self.naxis[0], self.naxis[1]))

            for j in range(nSBs):
                for k in range(1):  #nChans):
                    todmap = tod[i, j, k, good]

                    if self.filtertod:
                        txbw, _ = np.histogram(x, xbins, weights=todmap)
                        tybw, _ = np.histogram(y, xbins, weights=todmap)
                        fb = txbw / xbw
                        gd = np.isfinite(fb)
                        pmdl = np.poly1d(np.polyfit(xmids[gd], fb[gd], 1))
                        todmap -= pmdl(x)
                        fb = tybw / ybw
                        gd = np.isfinite(fb)
                        pmdl = np.poly1d(np.polyfit(xmids[gd], fb[gd], 1))
                        todmap -= pmdl(y)

                    w, b = np.histogram(pix[mask],
                                        pixbins,
                                        weights=todmap[mask])
                    #                    w, b = np.histogram(pix[:], pixbins, weights=tod[i,j,k,:])
                    m = np.reshape(w, (self.naxis[0], self.naxis[1]))
                    maps[i, j, k, ...] = m / self.hits

        return maps