def test_scan_ghosts(self): ''' Perform a (low resolution) scan with two detectors, compare to detector + ghost. ''' mlen = 10 * 60 rot_period = 120 mmax = 2 ra0=-10 dec0=-57.5 fwhm = 200 nside = 128 az_throw = 10 scs = ScanStrategy(duration=mlen, sample_rate=10, location='spole') # Create two Gaussian (main) beams. beam_opts = dict(az=0, el=0, polang=0, fwhm=fwhm, lmax=self.lmax, symmetric=True) ghost_opts = dict(az=-4, el=10, polang=34, fwhm=fwhm, lmax=self.lmax, symmetric=True, amplitude=0.1) scs.add_to_focal_plane(Beam(**beam_opts)) scs.add_to_focal_plane(Beam(**ghost_opts)) # Allocate and assign parameters for mapmaking. scs.allocate_maps(nside=nside) # Set HWP rotation. scs.set_hwp_mod(mode='continuous', freq=3.) # Generate timestreams, bin them and store as attributes. scs.scan_instrument_mpi(self.alm, verbose=0, ra0=ra0, dec0=dec0, az_throw=az_throw, scan_speed=2., binning=False, nside_spin=nside, max_spin=mmax, save_tod=True) tod = scs.data(scs.chunks[0], beam=scs.beams[0][0], data_type='tod') tod += scs.data(scs.chunks[0], beam=scs.beams[1][0], data_type='tod') tod = tod.copy() # Repeat with single beam + ghost. scs.remove_from_focal_plane(scs.beams[1][0]) scs.beams[0][0].create_ghost(**ghost_opts) scs.reset_hwp_mod() scs.scan_instrument_mpi(self.alm, verbose=0, ra0=ra0, dec0=dec0, az_throw=az_throw, scan_speed=2., binning=False, nside_spin=nside, max_spin=mmax, save_tod=True) tod_w_ghost = scs.data(scs.chunks[0], beam=scs.beams[0][0], data_type='tod') # Sum TOD of two beams must match TOD of single beam + ghost. np.testing.assert_array_almost_equal(tod, tod_w_ghost, decimal=10)
def scan(lmax=500, nside=512, mmax=2): '''Time scanning single detector.''' os.environ["OMP_NUM_THREADS"] = "10" import numpy as np import healpy as hp from beamconv import ScanStrategy from beamconv import Beam ndays_range = np.logspace(np.log10(0.001), np.log10(50), 15) lmax = lmax nside = nside freq = 100. timings = np.ones((ndays_range.size), dtype=float) timings_cpu = np.ones((ndays_range.size), dtype=float) S = ScanStrategy(duration=24 * 3600, sample_rate=freq) beam_opts = dict(az=1, el=1, polang=10., fwhm=40, btype='Gaussian', lmax=lmax, symmetric=mmax == 0) beam = Beam(**beam_opts) S.add_to_focal_plane(beam) alm = np.zeros((3, hp.Alm.getsize(lmax=lmax)), dtype=np.complex128) print('init detpair...') S.init_detpair(alm, beam, beam_b=None, nside_spin=nside, max_spin=mmax, verbose=True) print('...done') spinmaps = copy.deepcopy(S.spinmaps) # Calculate q_bore for 0.1 day of scanning and reuse this. const_el_opts = dict(az_throw=50., scan_speed=10., dec0=-70.) S.partition_mission() print('cons_el_scan...') const_el_opts.update(dict(start=0, end=int(24 * 3600 * 100 * 0.1))) S.constant_el_scan(**const_el_opts) print('...done') q_bore_day = S.q_bore ctime_day = S.ctime for nidx, ndays in enumerate(ndays_range): duration = ndays * 24 * 3600 nsamp = duration * freq S = ScanStrategy(duration=duration, sample_rate=freq, external_pointing=True) S.add_to_focal_plane(beam) S.partition_mission() q_bore = np.repeat(q_bore_day, np.ceil(10 * ndays), axis=0) ctime = np.repeat(q_bore_day, np.ceil(10 * ndays)) def q_bore_func(start=None, end=None, q_bore=None): return q_bore[int(start):int(end), :] def ctime_func(start=None, end=None, ctime=None): return ctime[int(start):int(end)] S.spinmaps = spinmaps t0 = time.time() t0c = time.clock() S.scan_instrument_mpi(alm, binning=False, reuse_spinmaps=True, interp=False, q_bore_func=q_bore_func, ctime_func=ctime_func, q_bore_kwargs={'q_bore': q_bore}, ctime_kwargs={'ctime': ctime}, start=0, end=int(nsamp), cidx=0) t1 = time.time() t1c = time.clock() print t1 - t0 print t1c - t0c timings[nidx] = t1 - t0 timings_cpu[nidx] = t1c - t0c np.save( './scan_timing_lmax{}_nside{}_mmax{}.npy'.format(lmax, nside, mmax), timings) np.save( './scan_timing_cpu_lmax{}_nside{}_mmax{}.npy'.format( lmax, nside, mmax), timings_cpu) np.save('./scan_ndays_lmax{}_nside{}_mmax{}.npy'.format(lmax, nside, mmax), ndays_range)