def __init__(self, shape, wcs, pattern, offset, site, pad=2.0 * utils.degree): """This unskew operation assumes that equal spacing in dec corresponds to equal spacing in time, and that shifts in RA can be done in units of whole pixels. This is an approximation relative to UnskewCurved, but it is several times faster, uses less memory, and causes less smoothing.""" ndec, nra = shape[-2:] info = calc_az_sweep(pattern, offset, site, pad=pad) sweep_ra, sweep_dec = info.sweep_cel # For each pixel in dec (that we hit for this scanning pattern), we # want to know how far we have been displaced in ra. # First get the dec of each pixel center. ysweep, xsweep = enmap.sky2pix(shape, wcs, [sweep_dec, sweep_ra]) y1 = max(int(np.min(ysweep)), 0) y2 = min(int(np.max(ysweep)) + 1, shape[-2]) # Make fft-friendly ny = y2 - y1 ny2 = fft.fft_len(ny, "above", [2, 3, 5, 7]) y1 = max(y1 - (ny2 - ny) / 2, 0) y2 = min(y1 + ny2, shape[-2]) y = np.arange(y1, y2) dec, _ = enmap.pix2sky(shape, wcs, [y, y * 0]) # Then interpolate the ra values corresponding to those decs. # InterpolatedUnivariateSpline broken. Returns nan even when # interpolating. So we will use UnivariateSpline spline = scipy.interpolate.UnivariateSpline(sweep_dec, sweep_ra) ra = spline(dec) dra = ra - ra[len(ra) / 2] y, x = np.round(enmap.sky2pix(shape, wcs, [dec, ra])) dx = x - x[len(x) / 2] # It's also useful to be able to go from normal map index to # position in y and dx inv_y = np.zeros(shape[-2], dtype=int) - 1 inv_y[y.astype(int)] = np.arange(len(y)) # Compute the azimuth step size based on the total azimuth sweep. daz = (pattern[2] - pattern[1] + 2 * pad) / len(y) # Build the geometry of the unskewed system ushape, uwcs = enmap.geometry(pos=[0, 0], shape=[len(y), shape[-1]], res=[daz, enmap.pixshape(shape, wcs)[1]], proj="car") # And store the result self.y = y.astype(int) self.dx = np.round(dx).astype(int) self.dx_raw = dx self.inv_y = inv_y self.ushape = ushape self.uwcs = uwcs
def __init__(self, shape, wcs, pattern, offset, site, pad=2.0 * utils.degree, order=0, subsample=2.0): """Build an unskew operator that uses spline interpolation along an azimuth sweep to straighten out the scanning motion for one scanning pattern. Relatively slow, and leads to some smoothing due to the interpolation, but does not assume that dec changes with a constant speed during a sweep.""" # Find the unskew transformation for this pattern. # We basically want dec->az and ra->ra0, with az spacing # similar to el spacing. ndec, nra = shape[-2:] info = calc_az_sweep(pattern, offset, site, pad=pad, subsample=subsample) sweep_ra, sweep_dec = info.sweep_cel #(sweep_ra, sweep_dec), naz, daz = calc_az_sweep(pattern, offset, site, pad=pad, subsample=subsample) # We want to be able to go from (y,x) to (ra,dec), with # dec = dec[y] # ra = ra[y]-ra[0]+x # Precompute the pixel mapping. This will have the full witdh in ra, # but will be smaller in dec due to the limited az range. raw_dec, raw_ra = enmap.posmap(shape, wcs) skew_pos = np.zeros((2, info.naz, nra)) skew_pos[0] = sweep_dec[:, None] skew_pos[1] = (sweep_ra - sweep_ra[0])[:, None] + raw_ra[None, ndec / 2, :] skew_pix = enmap.sky2pix(shape, wcs, skew_pos).astype(dtype) # Build geometry for the unskewed system ushape, uwcs = enmap.geometry( pos=[0, 0], shape=[info.naz, nra], res=[np.abs(info.daz), enmap.pixshape(shape, wcs)[1]], proj="car") # Save self.order = order self.shape = shape self.wcs = wcs self.pattern = pattern self.site = site self.skew_pix = skew_pix # External interface self.ushape = ushape self.uwcs = uwcs
def __init__(self, shape, wcs, pattern, offset, site, pad=2.0*utils.degree): """This unskew operation assumes that equal spacing in dec corresponds to equal spacing in time, and that shifts in RA can be done in units of whole pixels. This is an approximation relative to UnskewCurved, but it is several times faster, uses less memory, and causes less smoothing.""" ndec, nra = shape[-2:] info = calc_az_sweep(pattern, offset, site, pad=pad) sweep_ra, sweep_dec = info.sweep_cel # For each pixel in dec (that we hit for this scanning pattern), we # want to know how far we have been displaced in ra. # First get the dec of each pixel center. ysweep, xsweep = enmap.sky2pix(shape, wcs, [sweep_dec,sweep_ra]) y1 = max(int(np.min(ysweep)),0) y2 = min(int(np.max(ysweep))+1,shape[-2]) # Make fft-friendly ny = y2-y1 ny2 = fft.fft_len(ny, "above", [2,3,5,7]) y1 = max(y1-(ny2-ny)/2,0) y2 = min(y1+ny2,shape[-2]) y = np.arange(y1,y2) dec, _ = enmap.pix2sky(shape, wcs, [y,y*0]) # Then interpolate the ra values corresponding to those decs. # InterpolatedUnivariateSpline broken. Returns nan even when # interpolating. So we will use UnivariateSpline spline = scipy.interpolate.UnivariateSpline(sweep_dec, sweep_ra) ra = spline(dec) dra = ra - ra[len(ra)/2] y, x = np.round(enmap.sky2pix(shape, wcs, [dec,ra])) dx = x-x[len(x)/2] # It's also useful to be able to go from normal map index to # position in y and dx inv_y = np.zeros(shape[-2],dtype=int)-1 inv_y[y.astype(int)]= np.arange(len(y)) # Compute the azimuth step size based on the total azimuth sweep. daz = (pattern[2]-pattern[1]+2*pad)/len(y) # Build the geometry of the unskewed system ushape, uwcs = enmap.geometry(pos=[0,0], shape=[len(y),shape[-1]], res=[daz,enmap.pixshape(shape,wcs)[1]], proj="car") # And store the result self.y = y.astype(int) self.dx = np.round(dx).astype(int) self.dx_raw = dx self.inv_y = inv_y self.ushape = ushape self.uwcs = uwcs
def __init__(self, shape, wcs, groups=None): # Symbolic self.l1x, self.l1y, self.l2x, self.l2y, self.l1, self.l2 = get_ells() self.Lx, self.Ly, self.L = get_Ls() if groups is None: groups = [self.Lx * self.Lx, self.Ly * self.Ly, self.Lx * self.Ly] self._default_groups = groups self.integrands = {} self.ul1s = {} self.ul2s = {} self.ogroups = {} self.ogroup_weights = {} self.ogroup_symbols = {} self.l1funcs = [] self.l2funcs = [] # Diagnostic self.nfft = 0 self.nifft = 0 # Numeric self.shape, self.wcs = shape, wcs self.modlmap = enmap.modlmap(shape, wcs) self.lymap, self.lxmap = enmap.lmap(shape, wcs) self.pixarea = np.prod(enmap.pixshape(shape, wcs))
def __init__(self, shape, wcs, gradCut=None, kBeamX=None, kBeamY=None): ''' templateFT is a template liteMap FFT object ''' self.Ny, self.Nx = shape[-2:] self.lxMap, self.lyMap, self.modLMap, self.thetaMap, self.lx, self.ly = fmaps.get_ft_attributes_enmap( shape, wcs) self.lxHatMap = self.lxMap * np.nan_to_num(1. / self.modLMap) self.lyHatMap = self.lyMap * np.nan_to_num(1. / self.modLMap) if kBeamX is not None: self.kBeamX = kBeamX else: self.kBeamX = 1. if kBeamY is not None: self.kBeamY = kBeamY else: self.kBeamY = 1. self.uClNow2d = {} self.uClFid2d = {} self.lClFid2d = {} self.noiseXX2d = {} self.noiseYY2d = {} if gradCut is not None: self.gradCut = gradCut else: self.gradCut = self.modLMap.max() self.Nlkk = {} self.pixScaleY, self.pixScaleX = enmap.pixshape(shape, wcs)
fkmaps = fftfast.fft(measured, axes=[-2, -1]) if deconvolve_beam: fkmaps = np.nan_to_num(fkmaps / kbeam_dat) if maxlike and cluster: polcomb = "TT" fkmapsdc = np.nan_to_num(fkmaps / kbeam_dat) maps = enmap.samewcs( fftfast.ifft(fkmapsdc * fMaskCMB_T, normalize=True, axes=[-2, -1]).real, measured) #kappa_model = init_kappa_model k = 0 io.quickPlot2d(maps, out_dir + "map_iter_" + str(k).zfill(3) + ".png") from scipy.integrate import simps Ny, Nx = shape_dat[-2:] pixScaleY, pixScaleX = enmap.pixshape(shape_dat, wcs_dat) Ukappa = init_kappa_model Uft = fftfast.fft(Ukappa, axes=[-2, -1]) Upower = np.real(Uft * Uft.conjugate()) Nl2d = qest_maxlike.N.Nlkk[polcomb] area = Nx * Ny * pixScaleX * pixScaleY Upower = Upower * area / (Nx * Ny)**2 wfilter = np.nan_to_num(Upower / Nl2d) #wfilter = np.nan_to_num(1./(qest_maxlike.N.Nlkk[polcomb])) # print wfilter.max() #wfilter = np.nan_to_num(qest_maxlike.N.clkk2d/(qest_maxlike.N.clkk2d+qest_maxlike.N.Nlkk[polcomb])) wfilter[wfilter > 1.e90] = 0. wfilter = wfilter / wfilter.max() wfilter[wfilter <= 0.] = 0. #io.quickPlot2d(np.fft.fftshift(wfilter),out_dir+"bwf2d.png")
offset_array = np.mean(offsets, 0) offset_det = offsets - offset_array ndet = len(offsets) if args.unskew == "curved": U = UnskewCurved(rhs.shape, rhs.wcs, pattern, offset_array, site, order=args.order) elif args.unskew == "shift": U = UnskewShift(rhs.shape, rhs.wcs, pattern, offset_array, site) else: raise ValueError(args.unskew) scale = calc_scale(inspec.size, srate, speed, enmap.pixshape(U.ushape, U.uwcs)[0]) # Set up the inv noise matrix N. This should take a 2d ft of the # map as input, though it actually only cares about the y direction. N = NmatUncorr2(U.ushape, inspec, scale) # Set up the weight matrix W if args.cmode > 0: offset_upos = calc_offset_upos(pattern, offset_array, offset_det, site, rhs, U) corrfun = calc_cmode_corrfun(U.ushape, U.uwcs, offset_upos, corrfun_smoothing) W = WeightMat(U.ushape, corrfun, 4) #ndet) else: W = None
def get_ft_attributes_enmap(shape, wcs): Ny, Nx = shape[-2:] pixScaleY, pixScaleX = enmap.pixshape(shape, wcs) return get_ft_attributes(Ny, Nx, pixScaleY, pixScaleX)
def simple_flipper_template_from_enmap(shape, wcs): Ny, Nx = shape[-2:] pixScaleY, pixScaleX = enmap.pixshape(shape, wcs) return simple_flipper_template(Ny, Nx, pixScaleY, pixScaleX)
def __init__(self, shape, wcs, pattern, offset, site, pad=2.0*utils.degree, order=0, subsample=2.0): """Build an unskew operator that uses spline interpolation along an azimuth sweep to straighten out the scanning motion for one scanning pattern. Relatively slow, and leads to some smoothing due to the interpolation, but does not assume that dec changes with a constant speed during a sweep.""" # Find the unskew transformation for this pattern. # We basically want dec->az and ra->ra0, with az spacing # similar to el spacing. ndec, nra = shape[-2:] info = calc_az_sweep(pattern, offset, site, pad=pad, subsample=subsample) sweep_ra, sweep_dec = info.sweep_cel #(sweep_ra, sweep_dec), naz, daz = calc_az_sweep(pattern, offset, site, pad=pad, subsample=subsample) # We want to be able to go from (y,x) to (ra,dec), with # dec = dec[y] # ra = ra[y]-ra[0]+x # Precompute the pixel mapping. This will have the full witdh in ra, # but will be smaller in dec due to the limited az range. raw_dec, raw_ra = enmap.posmap(shape, wcs) skew_pos = np.zeros((2, info.naz, nra)) skew_pos[0] = sweep_dec[:,None] skew_pos[1] = (sweep_ra-sweep_ra[0])[:,None] + raw_ra[None,ndec/2,:] skew_pix = enmap.sky2pix(shape, wcs, skew_pos).astype(dtype) # Build geometry for the unskewed system ushape, uwcs = enmap.geometry(pos=[0,0], shape=[info.naz, nra], res=[np.abs(info.daz), enmap.pixshape(shape,wcs)[1]], proj="car") # Save self.order = order self.shape = shape self.wcs = wcs self.pattern = pattern self.site = site self.skew_pix = skew_pix # External interface self.ushape = ushape self.uwcs = uwcs
rhs = enmap.ndmap(rhs, wcs) hits = enmap.ndmap(hits, wcs) rhs = prepare(rhs) hits = prepare(hits, hitmap=True) # Turn offsets into an average array offset and detector offsets relative to that, # and use the array offset to set up the Unskew matrix. offset_array = np.mean(offsets,0) offset_det = offsets - offset_array ndet = len(offsets) if args.unskew == "curved": U = UnskewCurved(rhs.shape, rhs.wcs, pattern, offset_array, site, order=args.order) elif args.unskew == "shift": U = UnskewShift(rhs.shape, rhs.wcs, pattern, offset_array, site) else: raise ValueError(args.unskew) scale = calc_scale(inspec.size, srate, speed, enmap.pixshape(U.ushape, U.uwcs)[0]) # Set up the inv noise matrix N. This should take a 2d ft of the # map as input, though it actually only cares about the y direction. N = NmatUncorr2(U.ushape, inspec, scale) # Set up the weight matrix W if args.cmode > 0: offset_upos = calc_offset_upos(pattern, offset_array, offset_det, site, rhs, U) corrfun = calc_cmode_corrfun(U.ushape, U.uwcs, offset_upos, corrfun_smoothing) W = WeightMat(U.ushape, corrfun, 4)#ndet) else: W = None # The H in our equation is related to the hitcount, but isn't exactly it. # normalize_hits approximates it using the hitcounts. H = normalize_hits(hits)