def estimate_atmosphere(tod, region_cut, srate, fknee, alpha): model = gapfill.gapfill_joneig(tod, region_cut, inplace=False) ft = fft.rfft(model) freq = fft.rfftfreq(model.shape[-1]) * srate flt = 1 / (1 + (freq / fknee)**alpha) ft *= flt fft.ifft(ft, model, normalize=True) return model
def estimate_atmosphere(tod, region_cut, srate, fknee, alpha): model = gapfill.gapfill_joneig(tod, region_cut, inplace=False) ft = fft.rfft(model) freq = fft.rfftfreq(model.shape[-1])*srate flt = 1/(1+(freq/fknee)**alpha) ft *= flt fft.ifft(ft, model, normalize=True) return model
with bench.show("ivar"): tod = d.tod del d.tod tod -= np.mean(tod,1)[:,None] tod = tod.astype(dtype) diff = tod[:,1:]-tod[:,:-1] diff = diff[:,:diff.shape[-1]/csize*csize].reshape(d.ndet,-1,csize) ivar = 1/(np.median(np.mean(diff**2,-1),-1)/2**0.5) del diff # Generate planet cut with bench.show("planet cut"): planet_cut = cuts.avoidance_cut(d.boresight, d.point_offset, d.site, args.planet, R) # Subtract atmospheric model with bench.show("atm model"): model= gapfill.gapfill_joneig(tod, planet_cut, inplace=False) # Estimate noise level asens = np.sum(ivar)**-0.5 / d.srate**0.5 print asens with bench.show("smooth"): ft = fft.rfft(model) freq = fft.rfftfreq(model.shape[-1])*d.srate flt = 1/(1+(freq/model_fknee)**model_alpha) ft *= flt fft.ifft(ft, model, normalize=True) del ft, flt, freq with bench.show("atm subtract"): tod -= model del model tod = tod.astype(dtype, copy=False) # Should now be reasonably clean of correlated noise.
rhs = enmap.zeros((ncomp, ) + shape, area.wcs, dtype) div = enmap.zeros((ncomp, ncomp) + shape, area.wcs, dtype) hits = enmap.zeros((ncomp, ncomp) + shape, area.wcs, dtype) junk = np.zeros(pcut.njunk, dtype) # Generate planet cut. with bench.show("planet cut"): planet_cut = cuts.avoidance_cut(d.boresight, d.point_offset, d.site, args.planet, R) if args.sim: if args.noiseless: tod_orig = tod.copy() with bench.show("inject"): pmap.forward(tod, area) # Compute atmospheric model with bench.show("atm model"): model = smooth(gapfill.gapfill_joneig(tod, planet_cut, inplace=False), d.srate) if args.sim and args.noiseless: model -= smooth( gapfill.gapfill_joneig(tod_orig, planet_cut, inplace=False), d.srate) tod -= tod_orig del tod_orig with bench.show("atm subtract"): tod -= model del model tod = tod.astype(dtype, copy=False) # Should now be reasonably clean of correlated noise. # Proceed to make simple binned map with bench.show("rhs"): tod *= ivar[:, None]
def calc_model_joneig(tod, cut, srate=400): return smooth(gapfill.gapfill_joneig(tod, cut, inplace=False), srate)
with bench.show("ivar"): tod = d.tod del d.tod tod -= np.mean(tod,1)[:,None] tod = tod.astype(dtype) diff = tod[:,1:]-tod[:,:-1] diff = diff[:,:diff.shape[-1]//csize*csize].reshape(d.ndet,-1,csize) ivar = 1/(np.median(np.mean(diff**2,-1),-1)/2**0.5) del diff # Generate planet cut with bench.show("planet cut"): planet_cut = cuts.avoidance_cut(d.boresight, d.point_offset, d.site, args.planet, R) # Subtract atmospheric model with bench.show("atm model"): model= gapfill.gapfill_joneig(tod, planet_cut, inplace=False) # Estimate noise level asens = np.sum(ivar)**-0.5 / d.srate**0.5 print(asens) with bench.show("smooth"): ft = fft.rfft(model) freq = fft.rfftfreq(model.shape[-1])*d.srate flt = 1/(1+(freq/model_fknee)**model_alpha) ft *= flt fft.ifft(ft, model, normalize=True) del ft, flt, freq with bench.show("atm subtract"): tod -= model del model tod = tod.astype(dtype, copy=False) # Should now be reasonably clean of correlated noise, so we can from now on use
pmap = pmat.PmatMap(scan, area, sys=sys) pcut = pmat.PmatCut(scan) rhs = enmap.zeros((ncomp,)+shape, area.wcs, dtype) div = enmap.zeros((ncomp,ncomp)+shape, area.wcs, dtype) junk = np.zeros(pcut.njunk, dtype) # Generate planet cut with bench.show("planet cut"): planet_cut = cuts.avoidance_cut(d.boresight, d.point_offset, d.site, args.planet, R) if args.sim: if args.noiseless: tod_orig = tod.copy() with bench.show("inject"): pmap.forward(tod, area) # Compute atmospheric model with bench.show("atm model"): model = smooth(gapfill.gapfill_joneig(tod, planet_cut, inplace=False), d.srate) if args.sim and args.noiseless: model -= smooth(gapfill.gapfill_joneig(tod_orig, planet_cut, inplace=False), d.srate) tod -= tod_orig del tod_orig with bench.show("atm subtract"): tod -= model del model tod = tod.astype(dtype, copy=False) # Should now be reasonably clean of correlated noise. # Proceed to make simple binned map with bench.show("rhs"): tod *= ivar[:,None] pcut.backward(tod, junk) pmap.backward(tod, rhs) with bench.show("hits"):
if bleh: sim_rhs = np.zeros(len(inject_params)) sim_div = np.zeros(len(inject_params)) for si, scan in zip(myinds, myscans): L.debug("Processing %s" % scan.id) # Read the tod tod = scan.get_samples().astype(dtype) tod = utils.deslope(tod) if args.mapsub: # Subtract the reference map. If the reference map is not source free, # then this could reintroduce strong point sources that were cut earlier. # To avoid this we do another round of gapfilling signal.forward(scan, tod, refmap, tmul=1, mmul=-1) gapfill.gapfill_joneig(tod, scan.cut, inplace=True) # Inject simulated signal if requested if args.inject: dmjd = scan.mjd0 - mjd0 earth_pos = -ephemeris.ephem_vec("Sun", scan.mjd0)[:, 0] # Set the position and amplitude uK of each simulated source sim_srcs = np.zeros([len(inject_params), 8]) # TODO: inject and analyze with no displacement to see if interpolation is the # cause of the low bias in amplitude. sim_srcs[:, :2] = inject_params[:, 1::-1] * utils.degree if not args.static: sim_srcs[:, :2] = planet9.displace_pos( sim_srcs[:, :2].T, earth_pos, inject_params.T[2], inject_params.T[4:2:-1] * ym * dmjd).T #print "params", inject_params[:,5]