def get_coverage(fsky, nside, center_radec=[-30, -30]): center = qubic.equ2gal(center_radec[0], center_radec[1]) uvcenter = np.array(hp.ang2vec(center[0], center[1], lonlat=True)) uvpix = np.array(hp.pix2vec(nside, np.arange(12 * nside**2))) ang = np.arccos(np.dot(uvcenter, uvpix)) indices = np.argsort(ang) okpix = ang < -1 okpix[indices[0:int(fsky * 12 * nside**2)]] = True mask = np.zeros(12 * nside**2) mask[okpix] = 1 return mask
def rms_method(name, residuals_way, zones=1): """ Get the std of the residuals from one simulation. STD are computed over realisations and pixels for I, Q, U separately. Parameters ---------- name : str Simulation file. residuals_way : str Way to compute residuals. 3 keywords : noiseless, conv or mean_recon zones : int Number of zones to divide the patch. Returns ------- rms_I, rms_Q, rms_U : dictionarys containing RMS for IQU setpar : a dict with some parameters of the simu. """ # Get the repository where the simulation is rep_simu = Qubic_DataDir(datafile=name + '.dict') + '/' # print('rep_simu : ', rep_simu) # Dictionary saved during the simulation d = qubic.qubicdict.qubicDict() d.read_from_file(rep_simu + name + '.dict') setpar = {'tol': d['tol'], 'nep': d['detector_nep'], 'npoint': d['npointings']} nf_recon = d['nf_recon'] rms_I, rms_Q, rms_U = dict(), dict(), dict() for irec in nf_recon: residuals = get_residuals(name, rep_simu, residuals_way, irec) files, maps_recon_patch, maps_conv_patch, maps_diff_patch = \ rmc.get_patch_many_files(rep_simu + name, '*nfrecon{}*False*'.format(irec), verbose=False) npix_patch = maps_diff_patch.shape[2] setpar.update({'pixpatch': npix_patch}) # print(setpar) nreals = np.shape(residuals)[0] # This if is for the number of zones (1 or more) if zones == 1: rms_i, rms_q, rms_u = np.empty((irec,)), np.empty((irec,)), np.empty((irec,)) for i in range(irec): # STD over pixels and realisations rms_i[i] = np.std(residuals[:, i, :, 0]) rms_q[i] = np.std(residuals[:, i, :, 1]) rms_u[i] = np.std(residuals[:, i, :, 2]) else: angle = False if zones == 2: angle = True center = qubic.equ2gal(d['RA_center'], d['DEC_center']) seenmap = rmc.get_seenmap(files[0]) nside = d['nside'] residuals_zones = np.empty((nreals, zones, irec, npix_patch, 3)) for real in range(nreals): pix_zones, residuals_zones[real] = rmc.make_zones(residuals[real], zones, nside, center, seenmap, angle=angle, dtheta=d['dtheta'], verbose=False, doplot=False) rms_i, rms_q, rms_u = np.empty((zones, irec,)), np.empty((zones, irec,)), np.empty((zones, irec,)) for izone in range(zones): for i in range(irec): rms_i[izone, i] = np.std(residuals_zones[:, izone, i, :, 0]) rms_q[izone, i] = np.std(residuals_zones[:, izone, i, :, 1]) rms_u[izone, i] = np.std(residuals_zones[:, izone, i, :, 2]) rms_I.update({str(irec): rms_i}) rms_Q.update({str(irec): rms_q}) rms_U.update({str(irec): rms_u}) return rms_I, rms_Q, rms_U, setpar
coverage = P.pT1() mask = coverage > 10 P = P.restrict(mask, inplace=True) unpack = UnpackOperator(mask) # map without covariance matrix solution1 = pcg(P.T * P, P.T(y + noise), M=DiagonalOperator(1/coverage[mask]), disp=True) x1 = unpack(solution1['x']) # map with covariance matrix solution2 = pcg(P.T * invntt * P, (P.T * invntt)(y + noise), M=DiagonalOperator(1/coverage[mask]), disp=True) x2 = unpack(solution2['x']) def display(x, title): x = x.copy() x[~mask] = np.nan hp.gnomview(x, rot=center, reso=5, xsize=600, min=-200, max=200, title=title) center = equ2gal(racenter, deccenter) display(C(x0), 'Original convolved map') #hp.projplot(np.radians(pointings[..., 0]), np.radians(pointings[..., 1])) display(x1, 'Reconstructed map no invntt') display(x2, 'Reconstructed map with invntt') display(coverage, 'Coverage') mp.show()
m0 = np.zeros(12 * d['nside'] ** 2) x0 = np.zeros((d['nf_sub'], len(m0), 3)) id = hp.pixelfunc.ang2pix(d['nside'], fix_azimuth['el'], fix_azimuth['az'], lonlat=True) source = m0 * 0 source[id] = 1 arcToRad = np.pi / (180 * 60.) source = hp.sphtfunc.smoothing(source, fwhm=30 * arcToRad) x0[:, :, component] = source hp.mollview(x0[0, :, component]) plt.show() if p.fix_az: center = (fix_azimuth['az'], fix_azimuth['el']) else: center = qubic.equ2gal(d['RA_center'], d['DEC_center']) # Make TOD Nbfreq_in, nus_edge_in, nus_in, deltas_in, Delta_in, Nbbands_in = qubic.compute_freq(d['filter_nu'] / 1e9, d['nf_sub'], d['filter_relative_bandwidth']) a = qubic.QubicMultibandAcquisition(q, p, s, d, nus_edge_in) TOD = a.get_observation(x0, noiseless=True, convolution=False) plt.plot(TOD[0, :]) plt.xlabel('pointing index') plt.ylabel('TOD') plt.show() # Map making
import Tools as tl import ReadMC as rmc import SpectroImLib as si import qubic from qubic import gal2equ, equ2gal from qubic import Xpol from qubic import apodize_mask thespec = ['TT', 'EE', 'BB', 'TE', 'EB', 'TB'] stokes = ['I', 'Q', 'U'] #Coordinates of the zone observed in the sky center = equ2gal(0., -57.) name = 'pitch_test_I=0_0' #============= Get the simulation files ================== #Simulation repository # rep_simu = '/home/louisemousset/QUBIC/Qubic_work/SpectroImagerie/SimuJCResults/noiseless211118' # rep_simu = '/home/louisemousset/QUBIC/Qubic_work/SpectroImagerie/SimuLouise/noiseless_I=0' # rep_simu = '/home/louisemousset/QUBIC/Qubic_work/SpectroImagerie/SimuLouise/test_ptg' rep_simu = '/home/louisemousset/QUBIC/Qubic_work/SpectroImagerie/SimuLouise/pitch_test/' # rep_simu = '/home/louisemousset/QUBIC/Qubic_work/SpectroImagerie/SimuLouise/vary_tol' #Number of subbands used during the simulation # nsubvals = np.array([1,2,3,4]) nfiles = 7
def GenerateMaps(d, nus_in, reso = 1.5, size=200, p=None, writemap = False, readmap = False ): """ Compute input maps to use in: calibration (for both methods Fit and Sigma) & QUBIC pipeline. Number of maps == len(nus_in) Input: d: QUBIC dictionary nus_in: frequencies where compute the point source map Return: input_maps: partition of the sky where the point source is. m0: point source (already integrated over pixels) [RING ordered] """ if p: if p.fix_az: center = (d['fix_azimuth']['az'],d['fix_azimuth']['el']) elif not p.fix_az: center = qubic.equ2gal(d['RA_center'], d['DEC_center']) else: center = qubic.equ2gal(d['RA_center'], d['DEC_center']) nsideLow, nsideHigh, _, _, sigma2fwhm = Parameters(d) #center_gal = qubic.equ2gal(d['RA_center'], d['DEC_center']) pixel = hp.pixelfunc.ang2pix(nsideHigh, np.deg2rad(90-center[1]), np.deg2rad(center[0]), nest = True) vec_pix = hp.pix2vec(nsideHigh, pixel, nest = True) vec_pixeles = hp.pix2vec(nsideHigh, np.arange(12*nsideHigh**2), nest = True ) ang_pixeles = np.arccos(np.dot(vec_pix,vec_pixeles)) if d['config'] == 'FI': CteConfig = 61.347409 elif d['config'] == 'TD': CteConfig = 153.36 #mask print(nus_in) if not readmap: mask = np.rad2deg(ang_pixeles) < d['dtheta'] # Generate Gaussian maps - model of point source with FWHM (or Sigma) given by nus_in c0 = np.zeros((len(nus_in),12*nsideHigh**2,3)) noise = np.zeros((len(nus_in), 12*nsideHigh**2,1)) T = d['temperature'] amplitude = 1e22 for i, n_i in enumerate(nus_in): print('Map {}'.format(i)) fwhm_in = CteConfig/n_i # nus to fwhm for j,each in enumerate(ang_pixeles): if mask[j] == True: c0[i,j,0] = amplitude*f(each, fwhm_in, sigma2fwhm) c0[:,:,1] = c0[:,:,0] c0[:,:,2] = c0[:,:,0] m0 = np.empty((len(nus_in),12*nsideLow**2,3)) m0[:,:,0] = hp.ud_grade(c0[:,:,0], nsideLow, order_in = 'NESTED', order_out = 'RING') input_maps = np.empty((len(nus_in),size,size)) for i, mapa in enumerate(m0): input_maps[i] = hp.gnomview(mapa[:,0], rot = center, reso = reso, xsize = size, return_projected_map=True) mp.close('all') if writemap: FitsArray(m0).save('point-source-map-TD-150GHz.fits') return input_maps, m0 elif readmap: m0 = FitsArray('point-source-map-TD-150GHz.fits') input_maps = np.empty((len(nus_in),size,size)) for i, mapa in enumerate(m0): input_maps[i] = hp.gnomview(mapa[:,0], rot = center, reso = reso, xsize = size, return_projected_map=True) mp.close('all') return input_maps, m0
# f_a and f_b are the workspaces of the corresponding fiels (see below) def compute_master(f_a, f_b, wsp): cl_coupled = nmt.compute_coupled_cell(f_a, f_b) cl_decoupled = wsp.decouple_cell(cl_coupled) return cl_decoupled # compute apodization mask lmin = 20 lmax = 3 * nside - 1 delta_ell = 20 racenter = 0.0 deccenter = -57.0 maxang = 20. center = equ2gal(racenter, deccenter) veccenter = hp.ang2vec(pi / 2 - np.radians(center[1]), np.radians(center[0])) vecpix = hp.pix2vec(nside, np.arange(12 * nside ** 2)) cosang = np.dot(veccenter, vecpix) maskok = np.degrees(np.arccos(cosang)) < maxang msk_apo = nmt.mask_apodization(maskok, 1, apotype='C1') # Select a binning scheme b = nmt.NmtBin(nside, nlb=20, is_Dell=True) leff = b.get_effective_ells() # gaussian beam beam = hp.gauss_beam(np.radians(0.39), lmax) # initial maps and workspaces mp_t, mp_q, mp_u = hp.synfast(spectra, nside=nside,
stokes = ['I', 'Q', 'U'] # ================= Get the simulation files ================ # Simulation date and name date_name = '20190813_QU10' # Get the repository where the simulation is rep_simu = Qubic_DataDir(datafile=date_name + '.dict') + '/' # Dictionary saved during the simulation d = qubic.qubicdict.qubicDict() d.read_from_file(rep_simu + date_name + '.dict') # Coordinates of the zone observed in the sky center = equ2gal(d['RA_center'], d['DEC_center']) # Number of subbands used during the simulation nf_recon = d['nf_recon'][0] nf_sub = d['nf_sub'] print('nf_sub = {}, nf_recon = {}'.format(nf_sub, nf_recon)) # Get fits files names in a list fits_noise = np.sort(glob.glob(rep_simu + date_name + '*nfrecon{}_noiselessFalse*.fits'.format(nf_recon))) fits_noiseless = glob.glob(rep_simu + date_name + '*noiselessTrue*.fits') # Number of noise realisations nreals = len(fits_noise) print('nreals = ', nreals) # ================= Corrections =======================
d150Q['effective_duration'] = 3 #150 galactic center patch (thereafter GC patch) d150G = d150Q.copy() d150G['effective_duration'] = 1 # # 220 Qubic patch d220Q = d150Q.copy() d220Q['filter_nu'] = 220e9 # 220 GC patch d220G = d220Q.copy() d150G['effective_duration'] = 1 # Qubic patch - galactic coordinates centerQ = qubic.equ2gal(d150Q['RA_center'], d150Q['DEC_center']) # Galactic center patch - galactic coordinates centerG = np.array([0,0]) d150G['RA_center'], d150G['DEC_center'] = qubic.gal2equ(centerG[0], centerG[1]) d220G['RA_center'], d220G['DEC_center'] = d150G['RA_center'], d150G['DEC_center'] centers = [centerQ, centerQ, centerG, centerG] dictionaries = [d150Q, d220Q, d150G, d220G] regions = ['Qubic_field', 'GalCen_field'] bands = ['150', '220'] nf_recon = d150Q['nf_recon'] print(" =========== DONE ======== ")
import scipy import pysm3.units as u from pysm3 import utils from pysm3 import bandpass_unit_conversion from qubic import camb_interface as qc import sys import qubic import pickle from qubic import mcmc from qubic import NamasterLib as nam from forecast_tools import cl2dl, _get_Cl_cmb import os.path as op CMB_CL_FILE = op.join( '/pbs/home/m/mregnier/sps1/QUBIC+/forecast/Cls_Planck2018_%s.fits') center = qubic.equ2gal(-30, -30) # If there is not this command, the kernel shut down every time.. os.environ['KMP_DUPLICATE_LIB_OK'] = 'True' def get_coverage(fsky, nside, center_radec=[-30, -30]): center = qubic.equ2gal(center_radec[0], center_radec[1]) uvcenter = np.array(hp.ang2vec(center[0], center[1], lonlat=True)) uvpix = np.array(hp.pix2vec(nside, np.arange(12 * nside**2))) ang = np.arccos(np.dot(uvcenter, uvpix)) indices = np.argsort(ang) okpix = ang < -1 okpix[indices[0:int(fsky * 12 * nside**2)]] = True mask = np.zeros(12 * nside**2) mask[okpix] = 1 return mask