def interpolation(g, f, nside): f1, f2 = near_freq(g, f) sb1 = read_map('sb_nside{}_nu{:.3e}.fits'.format(nside, f1)) sb2 = read_map('sb_nside{}_nu{:.3e}.fits'.format(nside, f2)) alpha = (f - f1)/(f2 - f1) y = (1 - alpha)*sb1 + alpha*sb2 return y
def read_(nside, nu, idet, theta_max, syb_f=None): path = '/home/fincardona/Qubic/Compare_poly/maps/mono' if syb_f is None: return read_map( '%s/interfero/sb_nside{}_nu{:.3e}_idet{}_tmax{}.fits'. format(nside, nu, idet, theta_max) % path) else: return read_map( '%s/direct_conv/dc_nside{}_nu{:.3e}_idet{}_tmax{}_sybf{}.fits'. format(nside, nu, idet, theta_max, syb_f) % path)
def read_(nside, nu, idet, theta_max, syb_f=None, NPOINTS=1): path = '/home/fincardona/Qubic/spatial_extension/maps/mono' if syb_f is None: return read_map( '%s/interfero/sb_nside{}_nu{:.3e}_idet{}_tmax{}_Npoints{}.fits'. format(nside, nu, idet, theta_max, NPOINTS) % path) else: return read_map( '%s/direct_conv/dc_nside{}_nu{:.3e}_idet{}_tmax{}_sybf{}_Npoints{}.fits'.format(nside, nu, idet, theta_max, syb_f, NPOINTS) % path)
def read_(nside, nu, idet, theta_max, syb_f=None): path = '/home/fincardona/Qubic/Compare_poly/maps/mono' if syb_f is None: return read_map( '%s/interfero/sb_nside{}_nu{:.3e}_idet{}_tmax{}.fits'.format( nside, nu, idet, theta_max) % path) else: return read_map( '%s/direct_conv/dc_nside{}_nu{:.3e}_idet{}_tmax{}_sybf{}.fits'. format(nside, nu, idet, theta_max, syb_f) % path)
def wpixel(instr, ell, nside=1024, idet=231, theta_max=30): nu = instr.filter.name NPOINTS = instr.detector.NPOINTS if NPOINTS == 1: return np.ones(len(ell)) path_ = '/home/fincardona/Qubic/Compare_poly/maps/poly/interfero' pathN = '/home/fincardona/Qubic/spatial_extension/maps/poly/interfero' beam_ = read_map('%s/sb_nside{}_mono_{}Ghz_idet{}_tmax{}.fits'. format(nside, int(nu/1e9), idet, theta_max) % path_) beamN = read_map('%s/sb_nside{}_mono_{}Ghz_idet{}_tmax{}_Npoints{}.fits'. format(nside, int(nu/1e9), idet, theta_max, NPOINTS) % pathN) return (hp.anafast(beamN, lmax=ell[-1], pol=False) / hp.anafast(beam_, lmax=ell[-1], pol=False))[ell[0]:]
def read_poly_N(nside, n, nu, idet, theta_max, syb_f=None, NPOINTS=1): path = '/home/federico/Desktop/MAPS/spat_ext/poly' if syb_f is None and n==1: return read_map( '%s/interfero/sb_nside{}_mono_{}Ghz_idet{}_tmax{}_Npoints{}.fits'.format(nside, int(nu/1e9), idet, theta_max, NPOINTS) % path) elif syb_f is None: return read_map( '%s/interfero/sb_nside{}_poly{}_{}Ghz_idet{}_tmax{}_Npoints{}.fits'.format(nside, int(n), int(nu/1e9), idet, theta_max, NPOINTS) % path) elif syb_f is not None and n==1: return read_map( '%s/direct_conv/dc_nside{}_mono_{}Ghz_idet{}_tmax{}_sybf{}_Npoints{}.fits'.format(nside, int(nu/1e9), idet, theta_max, syb_f, NPOINTS) % path) elif syb_f is not None: return read_map( '%s/direct_conv/dc_nside{}_poly{}_{}Ghz_idet{}_tmax{}_sybf{}_Npoints{}.fits'.format(nside, int(n), int(nu/1e9), idet, theta_max, syb_f, NPOINTS) % path) else: raise ValueError('Error')
def func(nwrite, nread): with tempfile.TemporaryFile('a+b') as tmpfile: write_map(tmpfile, np.arange(12 * 16), nest=nwrite) tmpfile.seek(0) actual = read_map(tmpfile, nest=nread) with tempfile.NamedTemporaryFile('a+b') as tmpfile: hp.write_map(tmpfile.name, np.arange(12 * 16), nest=nwrite) expected = hp.read_map(tmpfile.name, nest=nread) assert_equal(expected, actual)
def test_read_header(): with tempfile.TemporaryFile('a+b') as tmpfile: write_map(tmpfile, np.arange(12), coord='E') tmpfile.seek(0) actual = read_map(tmpfile) header = actual.header assert_equal(header['coordsys'], 'E') assert_equal(header['nmaps'], 1) assert not header['hasmask']
def func(nwrite, nread): with tempfile.TemporaryFile('a+b') as tmpfile: write_map(tmpfile, np.arange(12*16), nest=nwrite) tmpfile.seek(0) actual = read_map(tmpfile, nest=nread) with tempfile.NamedTemporaryFile('a+b') as tmpfile: hp.write_map(tmpfile.name, np.arange(12*16), nest=nwrite) expected = hp.read_map(tmpfile.name, nest=nread) assert_equal(expected, actual)
def linear_integral(g, nside, T): # Integral on a linear grid weights = linear_weights(g) sb = np.zeros(12*nside**2) bar = progress_bar(len(g)) for i, nu in enumerate(g): sb_ = read_map('sb_nside{}_nu{:.3e}.fits'.format(nside, nu)) sb += sb_*deriv(nu, nside, T)*weights[i] bar.update() write_map('sb_nside{}_poly{}_{}Ghz.fits'.format( nside, len(g), int(np.mean(grid)/1e9)), sb)
def read_poly(nside, n, nu, idet, theta_max, syb_f=None): path = '/home/federico/Desktop/MAPS/no_spat_ext/poly' if syb_f is None and n == 1: return read_map( '%s/interfero/sb_nside{}_mono_{}Ghz_idet{}_tmax{}.fits'.format( nside, int(nu / 1e9), idet, theta_max) % path) elif syb_f is None: return read_map( '%s/interfero/sb_nside{}_poly{}_{}Ghz_idet{}_tmax{}.fits'.format( nside, int(n), int(nu / 1e9), idet, theta_max) % path) elif syb_f is not None and n == 1: return read_map( '%s/direct_conv/dc_nside{}_mono_{}Ghz_idet{}_tmax{}_sybf{}.fits'. format(nside, int(nu / 1e9), idet, theta_max, syb_f) % path) elif syb_f is not None: return read_map( '%s/direct_conv/dc_nside{}_poly{}_{}Ghz_idet{}_tmax{}_sybf{}.fits'. format(nside, int(n), int(nu / 1e9), idet, theta_max, syb_f) % path) else: raise ValueError('Error')
def getmapsready(file, newns, pixok): maps = read_map(file) newmaps_I = hp.ud_grade(maps[:,0], nside_out=newns) newmaps_Q = hp.ud_grade(maps[:,1], nside_out=newns) newmaps_U = hp.ud_grade(maps[:,2], nside_out=newns) newmaps_I[~pixok] = np.nan newmaps_Q[~pixok] = np.nan newmaps_U[~pixok] = np.nan #newmaps_I[pixok] -= np.mean(newmaps_I[pixok]) #newmaps_Q[pixok] -= np.mean(newmaps_Q[pixok]) #newmaps_U[pixok] -= np.mean(newmaps_U[pixok]) newmaps = np.array([newmaps_I, newmaps_Q, newmaps_U]).T return newmaps
def func(dtype, field, map, msk): with tempfile.TemporaryFile('a+b') as tmpfile: write_map(tmpfile, map.astype(dtype), msk, dtype=None) tmpfile.seek(0) actual = read_map(tmpfile, field=field, dtype=None) assert actual.dtype == dtype if np.isscalar(field): assert_equal(actual, complete[..., field].astype(dtype)) elif len(field) == 1: assert_equal(actual, complete[..., field[0]].astype(dtype)) else: for i, f in enumerate(field): assert_equal(actual[..., i], complete[..., f].astype(dtype))
def func(h, partial): with tempfile.NamedTemporaryFile('a+b') as tmpfile: hp.write_map(tmpfile.name, (np.arange(12), np.arange(12) + 1), coord='E') actual = read_map(tmpfile.name, partial=partial) expected = hp.read_map(tmpfile.name, h=h, field=(0, 1)) if partial: assert_is_none(actual[1]) actual = actual[0] if h: assert actual.header == expected[-1] assert_equal(actual, np.column_stack(expected[:-1])) else: assert_equal(actual, np.column_stack(expected))
def func(map, msk, partial, compress): with tempfile.TemporaryFile('a+b') as tmpfile: write_map(tmpfile, map, msk, compress=compress) tmpfile.seek(0) actual = read_map(tmpfile, partial=partial) if partial: out, mask_ = actual if msk is None: assert_is_none(mask_) actual = out else: actual = np.full(mask_.shape, np.nan) actual[mask_] = out assert_equal(actual.dtype.byteorder, '=') assert_same(actual, complete)
from pysimulators import profile from qubic import ( create_random_pointings, equ2gal, QubicAcquisition, PlanckAcquisition, QubicPlanckAcquisition, QubicScene) from qubic.data import PATH from qubic.io import read_map import healpy as hp import matplotlib.pyplot as mp import numpy as np racenter = 0.0 # deg deccenter = -57.0 # deg maxiter = 1000 tol = 5e-6 sky = read_map(PATH + 'syn256_pol.fits') nside = 256 sampling = create_random_pointings([racenter, deccenter], 1000, 10) scene = QubicScene(nside) acq_qubic = QubicAcquisition(150, sampling, scene, effective_duration=1) convolved_sky = acq_qubic.instrument.get_convolution_peak_operator()(sky) acq_planck = PlanckAcquisition(150, acq_qubic.scene, true_sky=convolved_sky) acq_fusion = QubicPlanckAcquisition(acq_qubic, acq_planck) H = acq_fusion.get_operator() invntt = acq_fusion.get_invntt_operator() y = acq_fusion.get_observation() A = H.T * invntt * H b = H.T * invntt * y
import numpy as np import matplotlib.pyplot as mp import os from Quad import qml from Quad import pyquad import healpy as hp from pysimulators import FitsArray from qubic.io import read_map from qubic import equ2gal import glob from qubic.utils import progress_bar directory = '/Volumes/Data/Qubic/SimulCurie_2015-05-30/tce120_dead_time5.0_period0.05_fknee0.1_nside256/' allfiles = glob.glob(directory+'rec*.fits') covmap = read_map(directory+'cov_map_coverage_angspeed1.0_delta_az30.0.fits') bla = read_map(allfiles[0]) racenter = -0.0 #deg deccenter = -45 #deg center = equ2gal(racenter, deccenter) hp.gnomview(covmap, rot=center, reso=10, xsize=40*10) hp.gnomview(np.log(covmap), rot=center, reso=10, xsize=40*10) def display(input, msg='', iplot=1, range=[30, 5, 5]): out = [] for i, (kind, lim) in enumerate(zip('IQU', range)): map = input[..., i] out += [hp.gnomview(map, rot=center, reso=5, xsize=800, min=-lim, max=lim, title=msg + ' ' + kind,
N = [512, 1024, 2048] T_cmb = 2.7255 # Kelvin nu_cent = 150e9 cut_on = 130e9 # Ideal Filter 150 GHz - 25% bandwidht cut_off = 170e9 res = 401 #nu_cent = 220e9 #cut_on = 190e9 # Ideal Filter 220 GHz - 25% bandwidht #cut_off = 250e9 #res = 601 grid = np.linspace(cut_on, cut_off, res) sample = np.unique(np.round(np.logspace(0, np.log10(res)))) for nside in N: bar = progress_bar(len(sample)) for n in sample: if n == 1: sb = read_map('sb_nside{}_nu{:.3e}.fits'.format(nside, nu_cent)) sb *= deriv(nu_cent, nside, T_cmb)*(cut_off - cut_on) write_map('sb_nside{}_mono_{}Ghz.fits'.format(nside, int(nu_cent/1e9)), sb) elif n == res: linear_integral(grid, nside, T_cmb) else: non_linear_integral(grid, n, nside, T_cmb) bar.update()
import qubic import shutil outpath = '' def setup(): global outpath outpath = 'test-' + str(uuid1())[:8] os.mkdir(outpath) def teardown(): shutil.rmtree(outpath) input_map = read_map(qubic.data.PATH + 'syn256_pol.fits') np.random.seed(0) center = gal2equ(0, 90) sampling = create_random_pointings(center, 100, 10) 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]]
from qubic.io import read_map mapsin = read_map('input_map_convolved_pointing_sigma_0.0_seed_22701.fits') mapsout = read_map('reconstructed_map_pointing_sigma_0.0_seed_22701.fits') def display(input, msg, iplot=1, reso=5, Trange=[100, 5, 5], xsize=800): out = [] for i, (kind, lim) in enumerate(zip('IQU', Trange)): map = input[..., i] out += [hp.gnomview(map, rot=center, reso=reso, xsize=xsize, min=-lim, max=lim, title=msg + ' ' + kind, sub=(3, 3, iplot + i), return_projected_map=True)] return out center = equ2gal(racenter, deccenter+10) reso=8 xsize=400 mp.clf() display(mapsin, 'Original map', iplot=1, reso=reso, xsize=xsize) display(mapsout, 'Reconstructed map', iplot=4, reso=reso, xsize=xsize) display(mapsin-mapsout, 'Residual map', iplot=7, reso=reso, xsize=xsize) hp.mollview(mapsin[:,1]-mapsout[:,1],min=-5,max=5)
NPOINTS = 4 nside = 256 scene = MultiQubicScene(nside) T_cmb = scene.T_cmb #np.random.seed(0) racenter = 0.0 # deg deccenter = -57.0 # deg sampling = create_random_pointings([racenter, deccenter], 1000, 10) detector_nep = 4.7e-17 * np.sqrt( len(sampling) * sampling.period / (365 * 86400)) maxiter = 1000 x0 = read_map(PATH + 'syn256_pol.fits') q = MultiQubicInstrument(NPOINTS=NPOINTS, NFREQS=NFREQS, filter_name=filter_name, detector_nep=detector_nep) C_nf = q.get_convolution_peak_operator() conv_sky_ = C_nf(x0) fwhm_t = np.sqrt(q.synthbeam.peak150.fwhm**2 - C_nf.fwhm**2) C_transf = HealpixConvolutionGaussianOperator(fwhm=fwhm_t) acq = MultiQubicAcquisition(q, sampling, scene=scene) acq_planck = PlanckAcquisition(np.int(filter_name / 1e9), scene,
NPOINTS = 4 nside = 256 scene = MultiQubicScene(nside) T_cmb = scene.T_cmb #np.random.seed(0) racenter = 0.0 # deg deccenter = -57.0 # deg sampling = create_random_pointings([racenter, deccenter], 1000, 10) detector_nep = 4.7e-17 * np.sqrt( len(sampling) * sampling.period / (365 * 86400)) maxiter = 1000 x0 = read_map(PATH + 'syn256_pol.fits') q = MultiQubicInstrument( NPOINTS=NPOINTS, NFREQS=NFREQS, filter_name=filter_name, detector_nep=detector_nep) C_nf = q.get_convolution_peak_operator() conv_sky_ = C_nf(x0) fwhm_t = np.sqrt(q.synthbeam.peak150.fwhm**2 - C_nf.fwhm**2) C_transf = HealpixConvolutionGaussianOperator(fwhm=fwhm_t) acq = MultiQubicAcquisition(q, sampling, scene=scene) acq_planck = PlanckAcquisition(np.int(filter_name/1e9), scene, true_sky=conv_sky_) H = acq.get_operator()
from pyoperators import pcg from pysimulators import profile from qubic import (create_random_pointings, equ2gal, QubicAcquisition, PlanckAcquisition, QubicPlanckAcquisition, QubicScene) from qubic.data import PATH from qubic.io import read_map import healpy as hp import matplotlib.pyplot as mp import numpy as np racenter = 0.0 # deg deccenter = -57.0 # deg maxiter = 1000 tol = 5e-6 sky = read_map(PATH + 'syn256_pol.fits') nside = 256 sampling = create_random_pointings([racenter, deccenter], 1000, 10) scene = QubicScene(nside) acq_qubic = QubicAcquisition(150, sampling, scene, effective_duration=1) convolved_sky = acq_qubic.instrument.get_convolution_peak_operator()(sky) cov = acq_qubic.get_coverage() mask = cov < cov.max() * 0.2 acq_planck = PlanckAcquisition(150, acq_qubic.scene, true_sky=convolved_sky, mask=mask) acq_fusion = QubicPlanckAcquisition(acq_qubic, acq_planck) H = acq_fusion.get_operator()
import shutil outpath = '' def setup(): global outpath outpath = 'test-' + str(uuid1())[:8] os.mkdir(outpath) def teardown(): shutil.rmtree(outpath) input_map = read_map(qubic.data.PATH + 'syn256_pol.fits') np.random.seed(0) center = gal2equ(0, 90) sampling = create_random_pointings(center, 100, 10) 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')