def initialPeak(self, tod, x, y): rms = Filtering.calcRMS(tod) r = np.sqrt((x)**2 + (y)**2) close = (r < 10) tod -= Filtering.estimateBackground(tod, rms, close) dx, dy = 1. / 60., 1. / 60. Dx, Dy = 1., 1. npix = int(Dx / dx) xpix, ypix = np.arange(npix + 1), np.arange(npix + 1) xpix = xpix * dx - Dx / 2. ypix = ypix * dy - Dy / 2. m = np.histogram2d(x, y, xpix, weights=tod)[0] / np.histogram2d( x, y, xpix)[0] m = median_filter(m, 3) xmax, ymax = np.unravel_index(np.nanargmax(m), m.shape) return xpix[xmax], ypix[ymax]
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