def build_model_data(self, ctx): """Compute all data defined by this core and add it to the context.""" # Update parameters logger.debug(f"Updating parameters: {ctx.getParams()}") astro_params, cosmo_params = self._update_params(ctx.getParams()) logger.debug(f"AstroParams: {astro_params}") logger.debug(f"CosmoParams: {cosmo_params}") # Call C-code coeval = p21.run_coeval( redshift=self.redshift, astro_params=astro_params, cosmo_params=cosmo_params, flag_options=self.flag_options, user_params=self.user_params, regenerate=False, random_seed=self.initial_conditions_seed, write=self.io_options["cache_mcmc"], direc=self.io_options["cache_dir"], **self.global_params, ) logger.debug(f"Adding {self.ctx_variables} to context data") for key in self.ctx_variables: try: ctx.add(key, [getattr(c, key) for c in coeval]) except AttributeError: raise ValueError( f"ctx_variable {key} not an attribute of Coeval")
def produce_coeval_power_spectra(redshift, **kwargs): options = get_all_options(redshift, **kwargs) coeval = run_coeval(**options) p, k = get_power( coeval.brightness_temp, boxlength=coeval.user_params.BOX_LEN, ) return k, p, coeval
def produce_coeval_power_spectra(redshift, **kwargs): options = get_all_options(redshift, **kwargs) coeval = run_coeval(write=write_ics_only_hook, **options) p = {} for field in COEVAL_FIELDS: if hasattr(coeval, field): p[field], k = get_power(getattr(coeval, field), boxlength=coeval.user_params.BOX_LEN) return k, p, coeval
def setup(self): """ Perform setup of the core. Notes ----- This method is called automatically by its parent :class:`~LikelihoodComputationChain`, and should not be invoked directly. """ super().setup() # If the chain has different parameter truths, we want to use those for our defaults. self.astro_params, self.cosmo_params = self._update_params( self.chain.createChainContext().getParams()) # Here we save to disk the full default realization. # The init and perturb boxes here can usually be re-used, and the box serves # as a nice thing to compare to after MCMC. # If modifying cosmo, we don't want to do this, because we'll create them # on the fly on every iteration. if (all(p not in self.cosmo_params.self.keys() for p in self.parameter_names) and not self.change_seed_every_iter): logger.info("Initializing default boxes for the entire chain.") coeval = p21.run_coeval( redshift=self.redshift, user_params=self.user_params, cosmo_params=self.cosmo_params, astro_params=self.astro_params, flag_options=self.flag_options, write=True, regenerate=self.regenerate, direc=self.io_options["cache_dir"], random_seed=self.initial_conditions_seed, **self.global_params, ) # update the seed self.initial_conditions_seed = coeval[0].random_seed logger.info("Initialization done.")
# late, middle and early stage of reionization bins = np.array([[0.18, 0.22], [0.48, 0.52], [0.78, 0.82]]) compare_tobs_mean = np.zeros((bins.shape[0], tobs.size)) compare_tobs_std = np.zeros((bins.shape[0], tobs.size)) ic = p21c.initial_conditions(user_params=params, cosmo_params=c_params, random_seed=2021) compare_tobs = np.zeros((redshift.size, tobs.size)) for i in tqdm(range(len(redshift))): z = redshift[i] cube = p21c.run_coeval(redshift=z, init_box=ic, astro_params=a_params, zprime_step_factor=1.05) dT = cube.brightness_temp xH = cube.xH_box uv = uvs['%.3f' % z] Nant = uvs['Nant'] print('z = %.3f x_n = %.3f zeta = %.3f R_mfp = %.3f T_vir = %.3f' % (z, np.mean(cube.xH_box), zeta, Rmfp, Tvir)) for j, t in enumerate(tobs): noise_cube = t2c.noise_cube_coeval(params['HII_DIM'], z, depth_mhz=None,
def coeval(ic): return run_coeval( redshift=25.0, init_box=ic, write=True, flag_options={"USE_TS_FLUCT": True} )
def coeval(ic): return run_coeval(redshift=10.0, init_box=ic)
snapshot = snapshot2 NITER = 50 init = initial_conditions(user_params={ "HII_DIM": 50, "BOX_LEN": 125.0 }, regenerate=True) perturb = ( perturb_field(redshift=7, init_boxes=init), perturb_field(redshift=8, init_boxes=init), perturb_field(redshift=9, init_boxes=init), ) astro_params = {"HII_EFF_FACTOR": np.random.normal(30, 0.1)} for i in range(NITER): trace_print() coeval = run_coeval( redshift=[7, 8, 9], astro_params=astro_params, init_box=init, perturb=perturb, regenerate=True, random_seed=init.random_seed, write=False, )