def __init__(self, cmb_sim, noise_sim_lib, beam_FWHM_amin, mask_map=None, cache_sims=False, lib_dir=None): self.cmb_sims = cmb_sim self.noise_sims = noise_sim_lib self.HD_shape = self.cmb_sims.shape self.LD_shape = self.noise_sims.shape self.lsides = self.cmb_sims.lsides self.beam_FWHM_amin = beam_FWHM_amin self.mask = mask_map self.allow_cache = cache_sims self.lib_dir = lib_dir assert len(self.HD_shape) == len(self.LD_shape) == 2 assert np.all(self.cmb_sims.lsides == self.noise_sims.lsides) assert IsPowerOfTwo(self.HD_shape[0]) and IsPowerOfTwo(self.HD_shape[1]) assert IsPowerOfTwo(self.LD_shape[0]) and IsPowerOfTwo(self.LD_shape[1]) assert self.HD_shape >= self.LD_shape if self.has_mask(): assert self.mask.shape == self.LD_shape assert np.all(self.mask >= 0.) assert np.all(self.mask <= 1.) # Does the user want to cache the sims ? : if cache_sims and pbs.rank == 0: assert (lib_dir is not None), "Specify lib_dir if you want to cache sims" if not os.path.exists(lib_dir): try: os.mkdir(lib_dir) except: print '** failed to create directory **' if not os.path.exists(lib_dir + '/sim_hash.pk'): pickle.dump(self.hashdict(), open(lib_dir + '/sim_hash.pk', 'w')) sim_libs.hash_check(pickle.load(open(lib_dir + '/sim_hash.pk', 'r')), self.hashdict(), ignore=['lib_dir'])
def __init__(self, sim_lib_pp, sim_lib_OO,lib_dir = None,cache_sims = False): assert hasattr(sim_lib_pp, 'shape') assert hasattr(sim_lib_pp, 'lsides') self.shape = sim_lib_pp.shape self.lsides = sim_lib_pp.lsides self.psim_lib = sim_lib_pp self.Osim_lib = sim_lib_OO if self.has_curl(): assert hasattr(sim_lib_OO, 'shape') and sim_lib_OO.shape == sim_lib_pp.shape assert hasattr(sim_lib_OO, 'lsides') and sim_lib_OO.lsides == sim_lib_pp.lsides self._cache_sim = cache_sims self.lib_dir = lib_dir if cache_sims and pbs.rank == 0: assert (lib_dir is not None), "Specify lib_dir if you want to cache sims" if not os.path.exists(lib_dir): try: os.mkdir(lib_dir) except: print '** failed to create directory **' if not os.path.exists(lib_dir + '/sim_hash.pk'): pickle.dump(self.hashdict(), open(lib_dir + '/sim_hash.pk', 'w')) sim_libs.hash_check(pickle.load(open(lib_dir + '/sim_hash.pk', 'r')), self.hashdict(), ignore=['lib_dir'])
def __init__(self, lib_dir, lmax, cls_unl, dlmax=1024, nside_lens=2048, lib_pha=None): #FIXME : add aberration and modulation if not os.path.exists(lib_dir) and pbs.rank == 0: os.makedirs(lib_dir) pbs.barrier() self.lmax = lmax self.dlmax = dlmax fields = get_fields(cls_unl) assert 'o' not in fields, 'Check lenscurv.py if everything is implemented. Should be easy.' if lib_pha is None and pbs.rank == 0: lib_pha = phas.lib_phas(lib_dir + '/phas', len(fields), lmax + dlmax) else: # Check that the lib_alms are compatible : assert lib_pha.lmax == lmax + dlmax pbs.barrier() self.nside_lens = nside_lens self.unlcmbs = sims_cmb_unl(cls_unl, lib_pha) self.lib_dir = lib_dir self.fields = get_fields(cls_unl) if pbs.rank == 0 and not os.path.exists(lib_dir + '/sim_hash.pk'): pk.dump(self.hashdict(), open(lib_dir + '/sim_hash.pk', 'w')) pbs.barrier() sims_generic.hash_check(self.hashdict(), pk.load(open(lib_dir + '/sim_hash.pk', 'r')))
def __init__(self,sims_cmb_len,cl_ttransf,cl_ptransf,nside = 2048,lib_dir = None): self.sims_cmb_len = sims_cmb_len self.cl_ttransf = cl_ttransf self.cl_ptransf = cl_ptransf self.nside = nside if lib_dir is not None: if pbs.rank == 0 and not os.path.exists(lib_dir + '/sim_hash.pk'): pk.dump(self.hashdict(), open(lib_dir + '/sim_hash.pk', 'w')) pbs.barrier() sims_generic.hash_check(self.hashdict(), pk.load(open(lib_dir + '/sim_hash.pk', 'r')))
def __init__(self, unlcmb_lib, displ_lib,lib_dir = None,cache_sims = False): self.unlcmb_sims = unlcmb_lib self.displ_sims = displ_lib self.shape = self.unlcmb_sims.shape self.lsides = self.unlcmb_sims.lsides self._cache_sims = cache_sims self.lib_dir = lib_dir if cache_sims and pbs.rank == 0: assert (lib_dir is not None), "Specify lib_dir if you want to cache sims" if not os.path.exists(lib_dir): try: os.mkdir(lib_dir) except: print '** failed to create directory **' if not os.path.exists(lib_dir + '/sim_hash.pk'): pickle.dump(self.hashdict(), open(lib_dir + '/sim_hash.pk', 'w')) sim_libs.hash_check(pickle.load(open(lib_dir + '/sim_hash.pk', 'r')), self.hashdict(), ignore=['lib_dir'])
def __init__(self, cmb_sim_lib, noise_sim_lib, beam_FWHM_amin, mask_map=None, cache_sims=False, lib_dir=None): self.cmb_sims = cmb_sim_lib self.noise_sims = noise_sim_lib self.HD_shape = self.cmb_sims.shape self.LD_shape = self.noise_sims.shape self.lsides = self.cmb_sims.lsides self.beam_FWHM_amin = beam_FWHM_amin self.mask = mask_map self.allow_cache = cache_sims self.lib_dir = lib_dir assert len(self.HD_shape) == len(self.LD_shape) == 2 assert np.all(self.cmb_sims.lsides == self.noise_sims.lsides) assert IsPowerOfTwo(self.HD_shape[0]) and IsPowerOfTwo(self.HD_shape[1]) assert IsPowerOfTwo(self.LD_shape[0]) and IsPowerOfTwo(self.LD_shape[1]) assert self.HD_shape >= self.LD_shape if self.has_mask(): assert self.mask.shape == self.LD_shape assert np.all(self.mask >= 0.) and np.all(self.mask <= 1) # Does the user want to cache the sims ? : if cache_sims and pbs.rank ==0 : assert (lib_dir is not None), "Specify lib_dir if you want to cache sims" if not os.path.exists(lib_dir): try: os.mkdir(lib_dir) except: print '** failed to create directory **' if not os.path.exists(lib_dir + '/sim_hash.pk'): pickle.dump(self.hashdict(), open(lib_dir + '/sim_hash.pk', 'w')) sim_libs.hash_check(pickle.load(open(lib_dir + '/sim_hash.pk', 'r')), self.hashdict(), ignore=['lib_dir']) if not os.path.exists(self.lib_dir + '/ellmap.npy') and pbs.rank == 0 : print 'ffs_sim_lib::caching HD_ellmap' kmin = 2. * np.pi / np.array(self.lsides) ky2 = Freq(np.arange(self.HD_shape[0]), self.HD_shape[0]) ** 2 * kmin[0] ** 2 kx2 = Freq(np.arange(self.HD_shape[1]/2 + 1), self.HD_shape[1]) ** 2 * kmin[1] ** 2 ones = np.ones(np.max(self.HD_shape)) freq_map = np.sqrt(np.outer(ky2, ones[0:self.HD_shape[1]/2 + 1]) + np.outer(ones[0:self.HD_shape[0]], kx2)) freq_map = np.uint16(np.round(freq_map - 0.5)) # map of integer ell. in int16 format. np.save(self.lib_dir + '/HD_ellmap', freq_map)