def test_polarizer(): sampling = QubicSampling(0, 0, 0) scene = QubicScene(150, kind='I') instruments = [ QubicInstrument(polarizer=False, detector_ngrids=2), QubicInstrument(polarizer=True, detector_ngrids=2), QubicInstrument(polarizer=False), QubicInstrument(polarizer=True), QubicInstrument(polarizer=False, detector_ngrids=2)[:992], QubicInstrument(polarizer=True, detector_ngrids=2)[:992] ] n = len(instruments[0]) expecteds = [ np.r_[np.ones(n // 2), np.zeros(n // 2)], np.full(n, 0.5), np.ones(n // 2), np.full(n // 2, 0.5), np.ones(n // 2), np.full(n // 2, 0.5) ] def func(instrument, expected): op = instrument.get_polarizer_operator(sampling, scene) sky = np.ones((len(instrument), 1)) assert_equal(op(sky).ravel(), expected) for instrument, expected in zip(instruments, expecteds): yield func, instrument, expected
def test(): kinds = 'I', 'IQU' instrument = QubicInstrument(synthbeam_dtype=float)[:400] np.random.seed(0) sampling = create_random_pointings([0, 90], 30, 5) skies = np.ones(12 * 256**2), np.ones((12 * 256**2, 3)) def func(sampling, kind, sky, ref1, ref2, ref3, ref4, ref5, ref6): nprocs_instrument = max(size // 2, 1) acq = QubicAcquisition(instrument, sampling, kind=kind, nprocs_instrument=nprocs_instrument) assert_equal(acq.comm.size, size) assert_equal(acq.instrument.detector.comm.size, nprocs_instrument) assert_equal(acq.sampling.comm.size, size / nprocs_instrument) H = acq.get_operator() invntt = acq.get_invntt_operator() tod = H(sky) #actual1 = acq.unpack(H(sky)) #assert_same(actual1, ref1, atol=20) actual2 = H.T(invntt(tod)) assert_same(actual2, ref2, atol=20) actual2 = (H.T * invntt * H)(sky) assert_same(actual2, ref2, atol=20) actual3, actual4 = tod2map_all(acq, tod, disp=False, maxiter=2) assert_same(actual3, ref3, atol=20) assert_same(actual4, ref4, atol=20) #actual5, actual6 = tod2map_each(acq, tod, disp=False) #assert_same(actual5, ref5, atol=1000) #assert_same(actual6, ref6) for kind, sky in zip(kinds, skies): acq = QubicAcquisition(instrument, sampling, kind=kind, comm=MPI.COMM_SELF) assert_equal(acq.comm.size, 1) H = acq.get_operator() invntt = acq.get_invntt_operator() tod = H(sky) ref1 = acq.unpack(tod) ref2 = H.T(invntt(tod)) ref3, ref4 = tod2map_all(acq, tod, disp=False, maxiter=2) ref5, ref6 = None, None #tod2map_each(acq, tod, disp=False) yield (func, sampling, kind, sky, ref1, ref2, ref3, ref4, ref5, ref6)
def test(): instrument = QubicInstrument()[:10] sampling = create_random_pointings([0, 90], 30, 5) nside = 64 scenes = QubicScene(nside, kind='I'), QubicScene(nside) def func(scene, max_nbytes, ref1, ref2, ref3, ref4, ref5, ref6): acq = QubicAcquisition(instrument, sampling, scene, max_nbytes=max_nbytes) sky = np.ones(scene.shape) H = acq.get_operator() actual1 = H(sky) assert_same(actual1, ref1, atol=10) actual2 = H.T(actual1) assert_same(actual2, ref2, atol=10) actual2 = (H.T * H)(sky) assert_same(actual2, ref2, atol=10) actual3, actual4 = tod2map_all(acq, ref1, disp=False) assert_same(actual3, ref3, atol=10000) assert_same(actual4, ref4) actual5, actual6 = tod2map_each(acq, ref1, disp=False) assert_same(actual5, ref5, atol=1000) assert_same(actual6, ref6) for scene in scenes: acq = QubicAcquisition(instrument, sampling, scene) sky = np.ones(scene.shape) nbytes_per_sampling = acq.get_operator_nbytes() // len(acq.sampling) H = acq.get_operator() ref1 = H(sky) ref2 = H.T(ref1) ref3, ref4 = tod2map_all(acq, ref1, disp=False) ref5, ref6 = tod2map_each(acq, ref1, disp=False) for max_sampling in 10, 29, 30: max_nbytes = None if max_sampling is None \ else max_sampling * nbytes_per_sampling yield (func, scene, max_nbytes, ref1, ref2, ref3, ref4, ref5, ref6)
from __future__ import division import numpy as np from pyoperators.utils import settingerr from pyoperators.utils.testing import assert_equal, assert_same, assert_is_type from pysimulators import BeamGaussian, BeamUniformHalfSpace, FitsArray from qubic import (create_random_pointings, QubicAcquisition, QubicInstrument, QubicSampling, QubicScene) q = QubicInstrument() s = create_random_pointings([0, 90], 5, 10.) def test_detector_indexing(): expected = FitsArray('test/data/detector_indexing.fits') assert_same(q.detector.index, expected) def test_beams(): assert_is_type(q.primary_beam, BeamGaussian) assert_is_type(q.secondary_beam, BeamGaussian) a = QubicAcquisition(150, s, primary_beam=BeamUniformHalfSpace(), secondary_beam=BeamUniformHalfSpace()) assert_is_type(a.instrument.primary_beam, BeamUniformHalfSpace) assert_is_type(a.instrument.secondary_beam, BeamUniformHalfSpace) def test_primary_beam(): def primary_beam(theta, phi): import numpy as np
os.system('\cp ' + path + '/TD_CalQubic_HornArray_v4.fits ' + path + '/CalQubic_HornArray_v5.fits') os.system('\cp ' + path + '/TD_CalQubic_DetArray_v3.fits ' + path + '/CalQubic_DetArray_v4.fits') else: print('First Instrument') os.system('rm -f ' + path + '/CalQubic_HornArray_v5.fits') os.system('rm -f ' + path + '/CalQubic_DetArray_v4.fits') ###### Monochromatic Instrument ##################################################################### nside = 256 scene = QubicScene(nside) from qubic import QubicInstrument instTD = QubicInstrument(filter_nu=150e9) ############ Visualizing the Horns and detectors ################################ clf() subplot(1, 2, 1) instTD.detector.plot() xx, yy, zz = instTD.detector.center.T index_det = instTD.detector.index for i in range(len(instTD.detector)): text(xx[i] - 0.0012, yy[i], '{}'.format(index_det[i]), fontsize=6, color='r') subplot(1, 2, 2) instTD.horn.plot()
SOURCE_POWER = 1 # [W] SOURCE_THETA = np.radians(3) # [rad] SOURCE_PHI = np.radians(45) # [rad] NPOINT_FOCAL_PLANE = 512**2 # number of detector plane sampling points NSIDE = 512 #primary_beam = MyBeam(alternative_beam, fwhm1, fwhm2, x0_1, x0_2, weight1, weight2, NSIDE) #secondary_beam = MyBeam(alternative_beam, fwhm1, fwhm2, x0_1, x0_2, weight1, weight2, NSIDE, backward=True) #qubic = MyQubicInstrument( # primary_beam=primary_beam, secondary_beam=secondary_beam, # detector_ngrids=1, filter_nu=NU) qubic = QubicInstrument(detector_ngrids=1, filter_nu=NU) qubic.horn.open[:] = False #qubic.horn.open[10] = True #qubic.horn.open[14] = True qubic.horn.open[78] = True qubic.horn.open[82] = True qubic.horn.plot(facecolor_closed='white', facecolor_open='red') FOCAL_PLANE_LIMITS = (np.nanmin(qubic.detector.vertex[..., 0]), np.nanmax(qubic.detector.vertex[..., 0])) # [m] # to check energy conservation (unrealistic detector plane): #FOCAL_PLANE_LIMITS = (-4, 4) # [m] #FOCAL_PLANE_LIMITS = (-0.2, 0.2) # [m] #################
ptg = [1., 0, 180] ptg2 = [1., 1, 180] pta = np.asarray(ptg) pta2 = np.asarray(ptg2) ptgs = ptg, [ptg], [ptg, ptg], [[ptg, ptg], [ptg2, ptg2, ptg2]], \ pta, [pta], [pta, pta], [[pta, pta], [pta2, pta2, pta2]], \ np.asarray([pta]), np.asarray([pta, pta]), [np.asarray([pta, pta])], \ [np.asarray([pta, pta]), np.asarray([pta2, pta2, pta2])] block_n = [[1], [1], [2], [2, 3], [1], [1], [2], [2, 3], [1], [2], [2], [2, 3], [2, 3]] caltree = QubicCalibration(detarray='CalQubic_DetArray_v1.fits') selection = np.zeros((32, 32), dtype=bool) selection[30:, 30:] = True qubic = QubicInstrument(calibration=caltree, filter_nu=160e9, synthbeam_fraction=0.99) qubic = qubic[qubic.pack(selection)] @skiptest def test_pointing(): def func(p, n): p = np.asarray(p) smp = QubicSampling(azimuth=p[..., 0], elevation=p[..., 1], pitch=p[..., 2]) acq = QubicAcquisition(qubic, smp) assert_equal(acq.block.n, n) assert_equal(len(acq.pointing), sum(n))
from __future__ import division import matplotlib.pyplot as mp import numpy as np from pyoperators import MaskOperator from pysimulators import create_fitsheader, SceneGrid from qubic import QubicInstrument NU = 150e9 # [Hz] SOURCE_THETA = np.radians(0) # [rad] SOURCE_PHI = np.radians(0) # [rad] NPOINT_FOCAL_PLANE = 512**2 # number of detector plane sampling points qubic = QubicInstrument(filter_nu=NU) # example for a baseline selection: #qubic.horn.open[:] = False #qubic.horn.open[0] = True #qubic.horn.open[14] = True FOCAL_PLANE_LIMITS = (np.nanmin(qubic.detector.vertex[..., 0]), np.nanmax(qubic.detector.vertex[..., 0])) # [m] # to check energy conservation (unrealistic detector plane): FOCAL_PLANE_LIMITS = (-0.2, 0.2) # [m] ################# # FOCAL PLANE #################
angspeed_psi = 0.1 # deg/sec maxpsi = 45. # deg nsweeps_el = 300 duration = 24 # hours ts = 0.1 # seconds # get the sampling model np.random.seed(0) sampling = create_sweeping_pointings( [racenter, deccenter], duration, ts, angspeed, delta_az, nsweeps_el, angspeed_psi, maxpsi) scene = QubicScene(nside) # get the instrument model with only one detector idetector = 0 instrument = QubicInstrument()[idetector] # get the acquisition model from the instrument, sampling and scene models acq = QubicAcquisition(instrument, sampling, scene) # get noiseless timeline x0 = qubic.io.read_map(qubic.data.PATH + 'syn256_pol.fits') y, x0_convolved = acq.get_observation(x0, convolution=True, noiseless=True) # inversion through Preconditioned Conjugate Gradient x, coverage = tod2map_all(acq, y, disp=True, tol=1e-3, coverage_threshold=0) mask = coverage > 0 # some display