示例#1
0
def smooth(tod, srate, fknee=10, alpha=10):
    ft = fft.rfft(tod)
    freq = fft.rfftfreq(tod.shape[-1]) * srate
    flt = 1 / (1 + (freq / fknee)**alpha)
    ft *= flt
    fft.ifft(ft, tod, normalize=True)
    return tod
示例#2
0
def smooth(tod, srate):
	ft   = fft.rfft(tod)
	freq = fft.rfftfreq(tod.shape[-1])*srate
	flt  = 1/(1+(freq/model_fknee)**model_alpha)
	ft  *= flt
	fft.ifft(ft, tod, normalize=True)
	return tod
示例#3
0
def smooth(tod, srate, fknee=10, alpha=10):
	ft   = fft.rfft(tod)
	freq = fft.rfftfreq(tod.shape[-1])*srate
	flt  = 1/(1+(freq/fknee)**alpha)
	ft  *= flt
	fft.ifft(ft, tod, normalize=True)
	return tod
示例#4
0
def smooth(tod, srate):
    ft = fft.rfft(tod)
    freq = fft.rfftfreq(tod.shape[-1]) * srate
    flt = 1 / (1 + (freq / model_fknee)**model_alpha)
    ft *= flt
    fft.ifft(ft, tod, normalize=True)
    return tod
示例#5
0
 def __init__(self, shape, inspec, scale):
     freqs = fft.rfftfreq(shape[-2]) * scale
     # Should check units of fourier space here. Should
     # rescaling from samples to az change the value of the
     # spectrum? How much of that is handled by the hitcounts?
     self.spec_full = utils.interpol(inspec, freqs[None])
     self.scale = scale
示例#6
0
	def __init__(self, shape, inspec, scale):
		freqs = fft.rfftfreq(shape[-2]) * scale
		# Should check units of fourier space here. Should
		# rescaling from samples to az change the value of the
		# spectrum? How much of that is handled by the hitcounts?
		self.spec_full = utils.interpol(inspec, freqs[None])
		self.scale = scale
示例#7
0
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
示例#8
0
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
示例#9
0
def broaden_beam_hor(tod, d, ibeam, obeam):
	ft    = fft.rfft(tod)
	k     = 2*np.pi*fft.rfftfreq(d.nsamp, 1/d.srate)
	el    = np.mean(d.boresight[2,::100])
	skyspeed = d.speed*np.cos(el)
	sigma = (obeam**2-ibeam**2)**0.5
	ft *= np.exp(-0.5*(sigma/skyspeed)**2*k**2)
	fft.ifft(ft, tod, normalize=True)
示例#10
0
def broaden_beam_hor(tod, d, ibeam, obeam):
    ft = fft.rfft(tod)
    k = 2 * np.pi * fft.rfftfreq(d.nsamp, 1 / d.srate)
    el = np.mean(d.boresight[2, ::100])
    skyspeed = d.speed * np.cos(el)
    sigma = (obeam**2 - ibeam**2)**0.5
    ft *= np.exp(-0.5 * (sigma / skyspeed)**2 * k**2)
    fft.ifft(ft, tod, normalize=True)
示例#11
0
 def __init__(self, scan, model=None, window=None, filter=None):
     model  = config.get("noise_model", model)
     window = config.get("tod_window", window)*scan.srate
     nmat.apply_window(scan.tod, window)
     self.nmat = nmat_measure.NmatBuildDelayed(model, cut=scan.cut_noiseest, spikes=scan.spikes)
     self.nmat = self.nmat.update(scan.tod, scan.srate)
     nmat.apply_window(scan.tod, window, inverse=True)
     self.model, self.window = model, window
     self.ivar = self.nmat.ivar
     self.cut  = scan.cut
     # Optional extra filter
     if filter:
         freq = fft.rfftfreq(scan.nsamp, 1/scan.srate)
         fknee, alpha = filter
         with utils.nowarn():
             self.filter = (1 + (freq/fknee)**-alpha)**-1
     else: self.filter = None
示例#12
0
def build_rangedata(tod, rcut, d, ivar):
    nmax = np.max(rcut.ranges[:, 1] - rcut.ranges[:, 0])
    nrange = rcut.nrange

    rdata = bunch.Bunch()
    rdata.detmap = np.zeros(nrange, int)
    rdata.tod = np.zeros([nrange, nmax], dtype)
    rdata.pos = np.zeros([nrange, nmax, 2])
    rdata.ivar = np.zeros([nrange, nmax], dtype)
    # Build our detector mapping
    for di in range(rcut.ndet):
        rdata.detmap[rcut.detmap[di]:rcut.detmap[di + 1]] = di
    rdata.n = rcut.ranges[:, 1] - rcut.ranges[:, 0]
    # Extract our tod samples and coordinates
    for i, r in enumerate(rcut.ranges):
        di = rdata.detmap[i]
        rn = r[1] - r[0]
        rdata.tod[i, :rn] = tod[di, r[0]:r[1]]
        bore = d.boresight[:, r[0]:r[1]]
        mjd = utils.ctime2mjd(bore[0])
        pos_hor = bore[1:] + d.point_offset[di, :, None]
        pos_rel = coordinates.transform(tod_sys,
                                        sys,
                                        pos_hor,
                                        time=mjd,
                                        site=d.site)
        rdata.pos[i, :rn] = pos_rel.T
        # Expand noise ivar too, including the effect of our normal data cut
        rdata.ivar[
            i, :rn] = ivar[di] * (1 - d.cut[di:di + 1, r[0]:r[1]].to_mask()[0])

    # Precompute our fourier space units
    rdata.freqs = fft.rfftfreq(nmax, 1 / d.srate)
    # And precompute out butterworth filter
    rdata.butter = filters.mce_filter(rdata.freqs, d.mce_fsamp, d.mce_params)
    # Store the fiducial time constants for reference
    rdata.tau = d.tau
    # These are also nice to have
    rdata.dsens = ivar**-0.5 / d.srate**0.5
    rdata.asens = np.sum(ivar)**-0.5 / d.srate**0.5
    rdata.srate = d.srate
    rdata.dets = d.dets
    rdata.beam = d.beam
    rdata.id = d.entry.id
    return rdata
示例#13
0
 def __init__(self,
              fwhm,
              vel,
              dec_ref,
              fknee,
              alpha,
              nsigma=1000,
              nsub=50,
              order=3):
     # Vel is [dra,ddec]/s.
     sigma = fwhm / (8 * np.log(2))**0.5
     res = sigma / nsub
     vel = np.array(vel)
     vel[0] *= np.cos(dec_ref)
     speed = np.sum(vel**2)**0.5
     # Build coordinate system along velocity
     npoint = 2 * nsigma * nsub
     x = (np.arange(npoint) - npoint / 2) * res
     # Build the beam along the velocity
     vbeam = np.exp(-0.5 * (x**2 / sigma**2))
     # Apply fourier filter. Our angular step size is res radians. This
     # corresponds to a time step of res/speed in seconds.
     fbeam = fft.rfft(vbeam)
     freq = fft.rfftfreq(npoint, res / speed)
     fbeam[1:] /= 1 + (freq[1:] / fknee)**-alpha
     vbeam = fft.ifft(fbeam, vbeam, normalize=True)
     # Beam should be zero at large distances
     vbeam -= vbeam[0]
     # Prefilter for fast lookups
     vbeam = utils.interpol_prefilter(vbeam, npre=0, order=order)
     # The total beam will be this beam times a normal one in the
     # perpendicular direction.
     self.dec_ref = dec_ref
     self.e_para = vel / np.sum(vel**2)**0.5
     self.e_orto = np.array([-self.e_para[1], self.e_para[0]])
     self.sigma = sigma
     self.res = res
     self.vbeam = vbeam
     self.order = order
     # Not really necessary to store these
     self.fwhm = fwhm
     self.vel = vel  # physical
     self.fknee = fknee
     self.alpha = alpha
示例#14
0
def build_rangedata(tod, rcut, d, ivar):
	nmax   = np.max(rcut.ranges[:,1]-rcut.ranges[:,0])
	nrange = rcut.nrange

	rdata  = bunch.Bunch()
	rdata.detmap = np.zeros(nrange,int)
	rdata.tod = np.zeros([nrange,nmax],dtype)
	rdata.pos = np.zeros([nrange,nmax,2])
	rdata.ivar= np.zeros([nrange,nmax],dtype)
	# Build our detector mapping
	for di in range(rcut.ndet):
		rdata.detmap[rcut.detmap[di]:rcut.detmap[di+1]] = di
	rdata.n = rcut.ranges[:,1]-rcut.ranges[:,0]
	# Extract our tod samples and coordinates
	for i, r in enumerate(rcut.ranges):
		di  = rdata.detmap[i]
		rn  = r[1]-r[0]
		rdata.tod[i,:rn] = tod[di,r[0]:r[1]]
		bore = d.boresight[:,r[0]:r[1]]
		mjd  = utils.ctime2mjd(bore[0])
		pos_hor = bore[1:] + d.point_offset[di,:,None]
		pos_rel = coordinates.transform(tod_sys, sys, pos_hor, time=mjd, site=d.site)
		rdata.pos[i,:rn] = pos_rel.T
		# Expand noise ivar too, including the effect of our normal data cut
		rdata.ivar[i,:rn] = ivar[di] * (1-d.cut[di:di+1,r[0]:r[1]].to_mask()[0])
	
	# Precompute our fourier space units
	rdata.freqs  = fft.rfftfreq(nmax, 1/d.srate)
	# And precompute out butterworth filter
	rdata.butter = filters.mce_filter(rdata.freqs, d.mce_fsamp, d.mce_params)
	# Store the fiducial time constants for reference
	rdata.tau    = d.tau
	# These are also nice to have
	rdata.dsens = ivar**-0.5 / d.srate**0.5
	rdata.asens = np.sum(ivar)**-0.5 / d.srate**0.5
	rdata.srate = d.srate
	rdata.dets  = d.dets
	rdata.beam  = d.beam
	rdata.id    = d.entry.id
	return rdata
示例#15
0
	def __init__(self, fwhm, vel, dec_ref, fknee, alpha, nsigma=1000, nsub=50, order=3):
		# Vel is [dra,ddec]/s.
		sigma  = fwhm/(8*np.log(2))**0.5
		res    = sigma/nsub
		vel    = np.array(vel)
		vel[0]*= np.cos(dec_ref)
		speed  = np.sum(vel**2)**0.5
		# Build coordinate system along velocity
		npoint = 2*nsigma*nsub
		x      = (np.arange(npoint)-npoint/2)*res
		# Build the beam along the velocity
		vbeam  = np.exp(-0.5*(x**2/sigma**2))
		# Apply fourier filter. Our angular step size is res radians. This
		# corresponds to a time step of res/speed in seconds.
		fbeam  = fft.rfft(vbeam)
		freq   = fft.rfftfreq(npoint, res/speed)
		fbeam[1:] /= 1 + (freq[1:]/fknee)**-alpha
		vbeam  = fft.ifft(fbeam, vbeam, normalize=True)
		# Beam should be zero at large distances
		vbeam -= vbeam[0]
		# Prefilter for fast lookups
		vbeam  = utils.interpol_prefilter(vbeam, npre=0, order=order)
		# The total beam will be this beam times a normal one in the
		# perpendicular direction.
		self.dec_ref = dec_ref
		self.e_para  = vel/np.sum(vel**2)**0.5
		self.e_orto  = np.array([-self.e_para[1],self.e_para[0]])
		self.sigma   = sigma
		self.res     = res
		self.vbeam   = vbeam
		self.order   = order
		# Not really necessary to store these
		self.fwhm  = fwhm
		self.vel   = vel # physical
		self.fknee = fknee
		self.alpha = alpha
示例#16
0
	entry = filedb.data[id]
	try:
		with bench.mark("read"):
			d = actdata.read(entry)
		with bench.mark("calib"):
			d = actdata.calibrate(d, exclude=["autocut"])
		if d.ndet < 2 or d.nsamp < 1: raise errors.DataMissing("no data in tod")
	except errors.DataMissing as e:
		print "%s skipped: %s" % (id, e.message)
		continue
	tod = d.tod.astype(dtype)
	del d.tod
	# Apply high-pass filter. Will assume white tod after this
	with bench.mark("filter"):
		freqs = fft.rfftfreq(d.nsamp)*d.srate
		ft    = fft.rfft(tod)
		ps    = np.abs(ft)**2
		rpows = [measure_power(ps,rfreq,drfreq,d.srate) for rfreq,drfreq in zip(rfreqs, drfreqs)]
		rpows = np.array(rpows)
		# Determine the fknee to use. First get a typical spectrum.
		# This does not work well with s16, which currently doesn't
		# have time constants.
		ps     = np.median(ps,0)
		bps    = bin_spectrum(ps, bsize_fknee)
		fknee  = measure_fknee(bps, d.srate/2/ps.size*bsize_fknee)
		#np.savetxt("ps.txt", ps)
		#1/0
		fknee *= args.fknee_mul
		ft[:,0]   = 0
		ft[:,1:] /= 1 + (freqs[1:]/fknee)**-args.alpha
示例#17
0
		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.
	# Proceed to make simple binned map
	with bench.show("actscan"):
		scan = actscan.ACTScan(entry, d=d)
	with bench.show("pmat"):
		pmap = pmat.PmatMap(scan, area, sys=sys)
		pcut = pmat.PmatCut(scan)
示例#18
0
 entry = filedb.data[id]
 try:
     with bench.mark("read"):
         d = actdata.read(entry)
     with bench.mark("calib"):
         d = actdata.calibrate(d, exclude=["autocut"])
     if d.ndet < 2 or d.nsamp < 1:
         raise errors.DataMissing("no data in tod")
 except errors.DataMissing as e:
     print "%s skipped: %s" % (id, str(e))
     continue
 tod = d.tod.astype(dtype)
 del d.tod
 # Apply high-pass filter. Will assume white tod after this
 with bench.mark("filter"):
     freqs = fft.rfftfreq(d.nsamp) * d.srate
     ft = fft.rfft(tod)
     ps = np.abs(ft)**2
     rpows = [
         measure_power(ps, rfreq, drfreq, d.srate)
         for rfreq, drfreq in zip(rfreqs, drfreqs)
     ]
     rpows = np.array(rpows)
     # Determine the fknee to use. First get a typical spectrum.
     # This does not work well with s16, which currently doesn't
     # have time constants.
     ps = np.median(ps, 0)
     bps = bin_spectrum(ps, bsize_fknee)
     fknee = measure_fknee(bps, d.srate / 2 / ps.size * bsize_fknee)
     #np.savetxt("ps.txt", ps)
     #1/0
示例#19
0
		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
	# a white noise model.
	with bench.show("pmat"):
		P = PmatTot(scan, srcpos, sys=sys)
		N = NmatWhite(ivar)