diff --git a/data/sim_suites/Australia20/mpg_emu_cosmo.npy b/data/sim_suites/Australia20/mpg_emu_cosmo.npy index 57439a76..d8c43fcb 100644 Binary files a/data/sim_suites/Australia20/mpg_emu_cosmo.npy and b/data/sim_suites/Australia20/mpg_emu_cosmo.npy differ diff --git a/data/validation_figures/Gadget/mpg_0.png b/data/validation_figures/Gadget/mpg_0.png index 1390d8d4..2a66ad95 100644 Binary files a/data/validation_figures/Gadget/mpg_0.png and b/data/validation_figures/Gadget/mpg_0.png differ diff --git a/data/validation_figures/Gadget/mpg_1.png b/data/validation_figures/Gadget/mpg_1.png index d80e8344..cd7255d5 100644 Binary files a/data/validation_figures/Gadget/mpg_1.png and b/data/validation_figures/Gadget/mpg_1.png differ diff --git a/data/validation_figures/Gadget/mpg_10.png b/data/validation_figures/Gadget/mpg_10.png index 265f0c5b..8688b7fe 100644 Binary files a/data/validation_figures/Gadget/mpg_10.png and b/data/validation_figures/Gadget/mpg_10.png differ diff --git a/data/validation_figures/Gadget/mpg_11.png b/data/validation_figures/Gadget/mpg_11.png index 35fa18c5..74f8de88 100644 Binary files a/data/validation_figures/Gadget/mpg_11.png and b/data/validation_figures/Gadget/mpg_11.png differ diff --git a/data/validation_figures/Gadget/mpg_12.png b/data/validation_figures/Gadget/mpg_12.png index bd203baa..e028e433 100644 Binary files a/data/validation_figures/Gadget/mpg_12.png and b/data/validation_figures/Gadget/mpg_12.png differ diff --git a/data/validation_figures/Gadget/mpg_13.png b/data/validation_figures/Gadget/mpg_13.png index 1a32313a..801dc104 100644 Binary files a/data/validation_figures/Gadget/mpg_13.png and b/data/validation_figures/Gadget/mpg_13.png differ diff --git a/data/validation_figures/Gadget/mpg_14.png b/data/validation_figures/Gadget/mpg_14.png index e6e363c8..60842985 100644 Binary files a/data/validation_figures/Gadget/mpg_14.png and b/data/validation_figures/Gadget/mpg_14.png differ diff --git a/data/validation_figures/Gadget/mpg_15.png b/data/validation_figures/Gadget/mpg_15.png index cb5d5dd3..0fb43a8d 100644 Binary files a/data/validation_figures/Gadget/mpg_15.png and b/data/validation_figures/Gadget/mpg_15.png differ diff --git a/data/validation_figures/Gadget/mpg_16.png b/data/validation_figures/Gadget/mpg_16.png index bfecad3e..373579e0 100644 Binary files a/data/validation_figures/Gadget/mpg_16.png and b/data/validation_figures/Gadget/mpg_16.png differ diff --git a/data/validation_figures/Gadget/mpg_17.png b/data/validation_figures/Gadget/mpg_17.png index cbea9f10..44c0432f 100644 Binary files a/data/validation_figures/Gadget/mpg_17.png and b/data/validation_figures/Gadget/mpg_17.png differ diff --git a/data/validation_figures/Gadget/mpg_18.png b/data/validation_figures/Gadget/mpg_18.png index 97c13f8c..11b8479d 100644 Binary files a/data/validation_figures/Gadget/mpg_18.png and b/data/validation_figures/Gadget/mpg_18.png differ diff --git a/data/validation_figures/Gadget/mpg_19.png b/data/validation_figures/Gadget/mpg_19.png index f455177b..ab974490 100644 Binary files a/data/validation_figures/Gadget/mpg_19.png and b/data/validation_figures/Gadget/mpg_19.png differ diff --git a/data/validation_figures/Gadget/mpg_2.png b/data/validation_figures/Gadget/mpg_2.png index d25a1d26..8d38a42e 100644 Binary files a/data/validation_figures/Gadget/mpg_2.png and b/data/validation_figures/Gadget/mpg_2.png differ diff --git a/data/validation_figures/Gadget/mpg_20.png b/data/validation_figures/Gadget/mpg_20.png index 4b9002c2..043f402c 100644 Binary files a/data/validation_figures/Gadget/mpg_20.png and b/data/validation_figures/Gadget/mpg_20.png differ diff --git a/data/validation_figures/Gadget/mpg_21.png b/data/validation_figures/Gadget/mpg_21.png index 4299dc0e..13da9c5f 100644 Binary files a/data/validation_figures/Gadget/mpg_21.png and b/data/validation_figures/Gadget/mpg_21.png differ diff --git a/data/validation_figures/Gadget/mpg_22.png b/data/validation_figures/Gadget/mpg_22.png index 7b55e707..29fb748e 100644 Binary files a/data/validation_figures/Gadget/mpg_22.png and b/data/validation_figures/Gadget/mpg_22.png differ diff --git a/data/validation_figures/Gadget/mpg_23.png b/data/validation_figures/Gadget/mpg_23.png index 991bfdd7..c76e7ddc 100644 Binary files a/data/validation_figures/Gadget/mpg_23.png and b/data/validation_figures/Gadget/mpg_23.png differ diff --git a/data/validation_figures/Gadget/mpg_24.png b/data/validation_figures/Gadget/mpg_24.png index b9ef3589..3da82901 100644 Binary files a/data/validation_figures/Gadget/mpg_24.png and b/data/validation_figures/Gadget/mpg_24.png differ diff --git a/data/validation_figures/Gadget/mpg_25.png b/data/validation_figures/Gadget/mpg_25.png index 885e6982..10a97e61 100644 Binary files a/data/validation_figures/Gadget/mpg_25.png and b/data/validation_figures/Gadget/mpg_25.png differ diff --git a/data/validation_figures/Gadget/mpg_26.png b/data/validation_figures/Gadget/mpg_26.png index a3732b53..0025e06a 100644 Binary files a/data/validation_figures/Gadget/mpg_26.png and b/data/validation_figures/Gadget/mpg_26.png differ diff --git a/data/validation_figures/Gadget/mpg_27.png b/data/validation_figures/Gadget/mpg_27.png index cb2168f8..afecd224 100644 Binary files a/data/validation_figures/Gadget/mpg_27.png and b/data/validation_figures/Gadget/mpg_27.png differ diff --git a/data/validation_figures/Gadget/mpg_28.png b/data/validation_figures/Gadget/mpg_28.png index 7dcedf91..8d4fbec7 100644 Binary files a/data/validation_figures/Gadget/mpg_28.png and b/data/validation_figures/Gadget/mpg_28.png differ diff --git a/data/validation_figures/Gadget/mpg_29.png b/data/validation_figures/Gadget/mpg_29.png index 6724272e..f9675862 100644 Binary files a/data/validation_figures/Gadget/mpg_29.png and b/data/validation_figures/Gadget/mpg_29.png differ diff --git a/data/validation_figures/Gadget/mpg_3.png b/data/validation_figures/Gadget/mpg_3.png index 176fafc5..ae9e58c8 100644 Binary files a/data/validation_figures/Gadget/mpg_3.png and b/data/validation_figures/Gadget/mpg_3.png differ diff --git a/data/validation_figures/Gadget/mpg_4.png b/data/validation_figures/Gadget/mpg_4.png index e9ed302d..42e2b9a8 100644 Binary files a/data/validation_figures/Gadget/mpg_4.png and b/data/validation_figures/Gadget/mpg_4.png differ diff --git a/data/validation_figures/Gadget/mpg_5.png b/data/validation_figures/Gadget/mpg_5.png index c88154ff..7b1d91e8 100644 Binary files a/data/validation_figures/Gadget/mpg_5.png and b/data/validation_figures/Gadget/mpg_5.png differ diff --git a/data/validation_figures/Gadget/mpg_6.png b/data/validation_figures/Gadget/mpg_6.png index 985f7134..cf5715ef 100644 Binary files a/data/validation_figures/Gadget/mpg_6.png and b/data/validation_figures/Gadget/mpg_6.png differ diff --git a/data/validation_figures/Gadget/mpg_7.png b/data/validation_figures/Gadget/mpg_7.png index e132ad99..b7d94b38 100644 Binary files a/data/validation_figures/Gadget/mpg_7.png and b/data/validation_figures/Gadget/mpg_7.png differ diff --git a/data/validation_figures/Gadget/mpg_8.png b/data/validation_figures/Gadget/mpg_8.png index 36b758a0..c04928bf 100644 Binary files a/data/validation_figures/Gadget/mpg_8.png and b/data/validation_figures/Gadget/mpg_8.png differ diff --git a/data/validation_figures/Gadget/mpg_9.png b/data/validation_figures/Gadget/mpg_9.png index 4fe3551c..985fd609 100644 Binary files a/data/validation_figures/Gadget/mpg_9.png and b/data/validation_figures/Gadget/mpg_9.png differ diff --git a/data/validation_figures/Gadget/mpg_central.png b/data/validation_figures/Gadget/mpg_central.png index ab547244..0d6dbde4 100644 Binary files a/data/validation_figures/Gadget/mpg_central.png and b/data/validation_figures/Gadget/mpg_central.png differ diff --git a/data/validation_figures/Nyx/nyx_0.png b/data/validation_figures/Nyx/nyx_0.png index 22e77044..1a9ea1d9 100644 Binary files a/data/validation_figures/Nyx/nyx_0.png and b/data/validation_figures/Nyx/nyx_0.png differ diff --git a/data/validation_figures/Nyx/nyx_1.png b/data/validation_figures/Nyx/nyx_1.png index 5a00bdcf..72d10e1f 100644 Binary files a/data/validation_figures/Nyx/nyx_1.png and b/data/validation_figures/Nyx/nyx_1.png differ diff --git a/data/validation_figures/Nyx/nyx_10.png b/data/validation_figures/Nyx/nyx_10.png index eba5972b..48c40dc0 100644 Binary files a/data/validation_figures/Nyx/nyx_10.png and b/data/validation_figures/Nyx/nyx_10.png differ diff --git a/data/validation_figures/Nyx/nyx_11.png b/data/validation_figures/Nyx/nyx_11.png index caf453ac..8ac7e71c 100644 Binary files a/data/validation_figures/Nyx/nyx_11.png and b/data/validation_figures/Nyx/nyx_11.png differ diff --git a/data/validation_figures/Nyx/nyx_12.png b/data/validation_figures/Nyx/nyx_12.png index fd8cec4f..19e880a1 100644 Binary files a/data/validation_figures/Nyx/nyx_12.png and b/data/validation_figures/Nyx/nyx_12.png differ diff --git a/data/validation_figures/Nyx/nyx_13.png b/data/validation_figures/Nyx/nyx_13.png index 0fb104ee..2f35632e 100644 Binary files a/data/validation_figures/Nyx/nyx_13.png and b/data/validation_figures/Nyx/nyx_13.png differ diff --git a/data/validation_figures/Nyx/nyx_2.png b/data/validation_figures/Nyx/nyx_2.png index 2190a931..2c8a70d0 100644 Binary files a/data/validation_figures/Nyx/nyx_2.png and b/data/validation_figures/Nyx/nyx_2.png differ diff --git a/data/validation_figures/Nyx/nyx_3.png b/data/validation_figures/Nyx/nyx_3.png index a49f5ac9..d5cfcfbc 100644 Binary files a/data/validation_figures/Nyx/nyx_3.png and b/data/validation_figures/Nyx/nyx_3.png differ diff --git a/data/validation_figures/Nyx/nyx_4.png b/data/validation_figures/Nyx/nyx_4.png index dec56b58..439a48f3 100644 Binary files a/data/validation_figures/Nyx/nyx_4.png and b/data/validation_figures/Nyx/nyx_4.png differ diff --git a/data/validation_figures/Nyx/nyx_5.png b/data/validation_figures/Nyx/nyx_5.png index 5f31579d..5855eae8 100644 Binary files a/data/validation_figures/Nyx/nyx_5.png and b/data/validation_figures/Nyx/nyx_5.png differ diff --git a/data/validation_figures/Nyx/nyx_6.png b/data/validation_figures/Nyx/nyx_6.png index 5209329a..20fafd25 100644 Binary files a/data/validation_figures/Nyx/nyx_6.png and b/data/validation_figures/Nyx/nyx_6.png differ diff --git a/data/validation_figures/Nyx/nyx_7.png b/data/validation_figures/Nyx/nyx_7.png index 9078ec04..64b60f6f 100644 Binary files a/data/validation_figures/Nyx/nyx_7.png and b/data/validation_figures/Nyx/nyx_7.png differ diff --git a/data/validation_figures/Nyx/nyx_8.png b/data/validation_figures/Nyx/nyx_8.png index 76acdc45..c279dd80 100644 Binary files a/data/validation_figures/Nyx/nyx_8.png and b/data/validation_figures/Nyx/nyx_8.png differ diff --git a/data/validation_figures/Nyx/nyx_9.png b/data/validation_figures/Nyx/nyx_9.png index a1fe3d9e..f0e6065d 100644 Binary files a/data/validation_figures/Nyx/nyx_9.png and b/data/validation_figures/Nyx/nyx_9.png differ diff --git a/data/validation_figures/Nyx/nyx_central.png b/data/validation_figures/Nyx/nyx_central.png index 1e8ff9c4..9042e857 100644 Binary files a/data/validation_figures/Nyx/nyx_central.png and b/data/validation_figures/Nyx/nyx_central.png differ diff --git a/lace/archive/base_archive.py b/lace/archive/base_archive.py index 0b4e9afc..e5fc9201 100644 --- a/lace/archive/base_archive.py +++ b/lace/archive/base_archive.py @@ -74,6 +74,7 @@ def _average_over_samples(self, average="both", drop_axis=None): "ind_axis", "ind_rescaling", "cosmo_params", + "star_params", ] keys_spe = ["p1d_Mpc"] @@ -163,6 +164,7 @@ def _average_over_samples(self, average="both", drop_axis=None): dict_av["ind_rescaling"] = ind_rescaling dict_av["ind_snap"] = ind_snap dict_av["cosmo_params"] = self.data[ind_merge[0]]["cosmo_params"] + dict_av["star_params"] = self.data[ind_merge[0]]["star_params"] # list of available keys to merger key_list = self.data[ind_merge[0]].keys() @@ -377,13 +379,17 @@ def get_training_data( if mask: if all( x in list_keys - or (x in ["A_lya","n_lya","omega_m","H_0","A_UVB"] and "cosmo_params" in list_keys) + or ( + x in ["A_lya", "n_lya", "omega_m", "H_0", "A_UVB"] + and "cosmo_params" in list_keys + ) for x in emu_params ): if any( np.isnan(arch_av[ii][x]) for x in emu_params - if x not in ["A_lya","n_lya","omega_m","H_0","A_UVB"] + if x + not in ["A_lya", "n_lya", "omega_m", "H_0", "A_UVB"] ) | any( np.any(np.isnan(arch_av[ii][x])) for x in key_power ): @@ -502,9 +508,16 @@ def get_testing_data( if mask: if emu_params is None: testing_data.append(arch_av[ii]) - #elif all(x in list_keys for x in emu_params): - elif all(x in list_keys or (isinstance(list_keys, dict) and x in list_keys.get('cosmo', [])) for x in emu_params.keys()): - print('activated') + # elif all(x in list_keys for x in emu_params): + elif all( + x in list_keys + or ( + isinstance(list_keys, dict) + and x in list_keys.get("cosmo", []) + ) + for x in emu_params.keys() + ): + print("activated") if any(np.isnan(arch_av[ii][x]) for x in emu_params) | any( np.any(np.isnan(arch_av[ii][x])) for x in key_power ): diff --git a/lace/archive/gadget_archive.py b/lace/archive/gadget_archive.py index 17d972c6..f8fb188f 100644 --- a/lace/archive/gadget_archive.py +++ b/lace/archive/gadget_archive.py @@ -30,6 +30,8 @@ def __init__( kp_Mpc=None, force_recompute_linP_params=False, verbose=False, + z_star=3, + kp_kms=0.009, ): """ Initialize the archive object. @@ -67,6 +69,8 @@ def __init__( if isinstance(kp_Mpc, (int, float, type(None))) == False: raise TypeError("kp_Mpc must be a number or None") self.kp_Mpc = kp_Mpc + self.z_star = z_star + self.kp_kms = kp_kms if isinstance(verbose, bool) == False: raise TypeError("verbose must be boolean") @@ -327,6 +331,7 @@ def _get_emu_cosmo(self, sim_label, force_recompute_linP_params=False): else: cosmo_params = file_cosmo[ii]["cosmo_params"] linP_params = file_cosmo[ii]["linP_params"] + star_params = file_cosmo[ii]["star_params"] break if compute_linP_params == True: @@ -350,6 +355,11 @@ def _get_emu_cosmo(self, sim_label, force_recompute_linP_params=False): # compute linear power parameters at each z (in Mpc units) linP_zs = fit_linP.get_linP_Mpc_zs(sim_cosmo, zs, self.kp_Mpc) + + # compute linear power parameters (in kms units) + star_params = fit_linP.parameterize_cosmology_kms( + sim_cosmo, None, self.z_star, self.kp_kms + ) # compute conversion from Mpc to km/s using cosmology dkms_dMpc_zs = camb_cosmo.dkms_dMpc(sim_cosmo, z=np.array(zs)) @@ -366,7 +376,7 @@ def _get_emu_cosmo(self, sim_label, force_recompute_linP_params=False): else: linP_params[lab][ii] = linP_zs[ii][lab] - return cosmo_params, linP_params + return cosmo_params, linP_params, star_params def _get_file_names(self, sim_label, ind_phase, ind_z, ind_axis): """ @@ -539,7 +549,7 @@ def _load_data(self, force_recompute_linP_params): ## read info from all sims, all snapshots, all rescalings # iterate over simulations for sim_label in self.list_sim: - cosmo_params, linP_params = self._get_emu_cosmo( + cosmo_params, linP_params, star_params = self._get_emu_cosmo( sim_label, force_recompute_linP_params ) @@ -548,6 +558,7 @@ def _load_data(self, force_recompute_linP_params): # set linear power parameters describing snapshot snap_data = {} snap_data["cosmo_params"] = cosmo_params + snap_data["star_params"] = star_params for lab in linP_params.keys(): if lab == "kp_Mpc": snap_data[lab] = linP_params[lab] diff --git a/lace/archive/nyx_archive.py b/lace/archive/nyx_archive.py index dcdd9082..ddab1b27 100644 --- a/lace/archive/nyx_archive.py +++ b/lace/archive/nyx_archive.py @@ -20,6 +20,8 @@ def __init__( force_recompute_linP_params=False, verbose=False, nfiles=18, + z_star=3, + kp_kms=0.009, ): ## check input if isinstance(nyx_version, str) == False: @@ -41,6 +43,8 @@ def __init__( if isinstance(kp_Mpc, (int, float, type(None))) == False: raise TypeError("kp_Mpc must be a number or None") self.kp_Mpc = kp_Mpc + self.z_star = z_star + self.kp_kms = kp_kms if isinstance(verbose, bool) == False: raise TypeError("verbose must be boolean") @@ -49,7 +53,7 @@ def __init__( ## sets list simulations available for this suite # list of especial simulations - self.list_sim_test = ["nyx_central", "nyx_seed", "nyx_wdm"] + self.list_sim_test = ["nyx_central", "nyx_seed", "nyx_3_ic", "nyx_wdm"] # list of hypercube simulations self.list_sim_cube = [] # simulation 14 was identified as problematic by the Nyx team @@ -103,7 +107,8 @@ def _set_info_sim(self, nfiles): # file and lace bookkeeping self.sim_conv = { "fiducial": "nyx_central", - "bar_ic_grid_3": "nyx_seed", + "bar_ic_grid_3": "nyx_3_ic", + "CGAN_4096_base": "nyx_seed", "wdm_3.5kev_grid_1": "nyx_wdm", } for ii in range(nfiles): @@ -218,11 +223,12 @@ def _get_emu_cosmo( else: cosmo_params = file_cosmo[ii]["cosmo_params"] linP_params = file_cosmo[ii]["linP_params"] + star_params = file_cosmo[ii]["star_params"] break if sim_in_file == False: file_error = ( "The file " - + file_cosmo + + self.file_cosmo + " does not contain " + isim + ". To speed up calculations, " @@ -244,6 +250,10 @@ def _get_emu_cosmo( cosmo_params["A_s"] = 2.10e-9 cosmo_params["n_s"] = 0.966 cosmo_params["h"] = cosmo_params["H_0"] / 100 + elif isim == "nyx_seed": + cosmo_params["A_s"] = 2.15865e-9 + cosmo_params["n_s"] = 0.96 + cosmo_params["h"] = cosmo_params["H_0"] / 100 # setup CAMB object sim_cosmo = camb_cosmo.get_Nyx_cosmology(cosmo_params) @@ -251,6 +261,9 @@ def _get_emu_cosmo( linP_zs = fit_linP.get_linP_Mpc_zs( sim_cosmo, self.list_sim_redshifts, self.kp_Mpc ) + star_params = fit_linP.parameterize_cosmology_kms( + sim_cosmo, None, self.z_star, self.kp_kms + ) zs = np.array(self.list_sim_redshifts) # compute conversion from Mpc to km/s using cosmology dkms_dMpc_zs = camb_cosmo.dkms_dMpc(sim_cosmo, z=zs) @@ -268,7 +281,7 @@ def _get_emu_cosmo( else: linP_params[lab][ii] = linP_zs[ii][lab] - return cosmo_params, linP_params + return cosmo_params, linP_params, star_params def _load_data(self, nyx_file=None, force_recompute_linP_params=False): # set nyx_file if not provided @@ -312,13 +325,16 @@ def _load_data(self, nyx_file=None, force_recompute_linP_params=False): # this simulation seems to have issues if isim == "cosmo_grid_14": continue + # contained in CGAN_4096_base + elif isim == "CGAN_4096_val": + continue if self.verbose: print("read Nyx sim", isim) # read cosmo information and linear power parameters # (will only need CAMB if pivot point kp_Mpc is changed) - cosmo_params, linP_params = self._get_emu_cosmo( + cosmo_params, linP_params, star_params = self._get_emu_cosmo( ff, isim, force_recompute_linP_params ) @@ -328,9 +344,13 @@ def _load_data(self, nyx_file=None, force_recompute_linP_params=False): zval = float(split_string(iz)[1]) # find redshift index to read linear power parameters - ind_z = np.where( - np.isclose(self.list_sim_redshifts, zval, 1e-10) - )[0][0] + try: + ind_z = np.where( + np.isclose(self.list_sim_redshifts, zval, 1e-10) + )[0][0] + except IndexError: + print("Could not find redshift", zval, "in ", isim) + continue scalings_avail = list(ff[isim][iz].keys()) # loop over scalings @@ -345,6 +365,7 @@ def _load_data(self, nyx_file=None, force_recompute_linP_params=False): # dictionary containing measurements and relevant info _arch = {} _arch["cosmo_params"] = cosmo_params + _arch["star_params"] = star_params for lab in linP_params.keys(): if lab == "kp_Mpc": _arch[lab] = linP_params[lab] @@ -387,17 +408,18 @@ def _load_data(self, nyx_file=None, force_recompute_linP_params=False): _arch["k_Mpc"] = p1d["k"] _arch["p1d_Mpc"] = p1d["Pk1d"] if "3d power kmu" in _data: - p3d = np.array( - _data["3d power kmu"]["fine binning"] - ) - _arch["k3d_Mpc"] = p3d["k"].reshape( - self.kbins, self.mubins - ) - _arch["mu3d"] = p3d["mu"].reshape( - self.kbins, self.mubins - ) - _arch["p3d_Mpc"] = p3d["Pkmu"].reshape( - self.kbins, self.mubins - ) + if "fine binning" in _data["3d power kmu"]: + p3d = np.array( + _data["3d power kmu"]["fine binning"] + ) + _arch["k3d_Mpc"] = p3d["k"].reshape( + self.kbins, self.mubins + ) + _arch["mu3d"] = p3d["mu"].reshape( + self.kbins, self.mubins + ) + _arch["p3d_Mpc"] = p3d["Pkmu"].reshape( + self.kbins, self.mubins + ) self.data.append(_arch) ff.close() diff --git a/lace/emulator/gp_emulator.py b/lace/emulator/gp_emulator.py index 16ff0c79..fcf6c1ef 100644 --- a/lace/emulator/gp_emulator.py +++ b/lace/emulator/gp_emulator.py @@ -23,7 +23,7 @@ class GPEmulator(base_emulator.BaseEmulator): :type archive: class, optional :param training_set: Specific training set. Options are 'Perdersen21' and 'Cabayol23'. :type training_set: str, optional - :param emulator_label: Specific emulator label. Options are 'Pedersen21', 'Pedersen23', 'Cabayol23'. + :param emulator_label: Specific emulator label. Options are 'Pedersen21', 'Pedersen23'. :type emulator_label: str, optional :param emu_type: Type of emulator. Defaults to 'polyfit'. :type emu_type: str, optional @@ -105,6 +105,7 @@ def __init__( self.list_sim_cube = archive.list_sim_cube self.kp_Mpc = archive.kp_Mpc self.emulator_label = emulator_label + print(emulator_label) emulator_label_all = [ "Pedersen21", diff --git a/lace/utils/plotting_functions.py b/lace/utils/plotting_functions.py index e94741fd..622deaee 100644 --- a/lace/utils/plotting_functions.py +++ b/lace/utils/plotting_functions.py @@ -1,12 +1,13 @@ import os import numpy as np -from matplotlib import pyplot as plt +import matplotlib.pyplot as plt from lace.utils import poly_p1d import matplotlib.cm as cm def plot_p1d_vs_emulator(testing_data, emulator, save_path=None): """ - Plots the true P1D and the emulated P1D for each redshift in the testing data. + Plots the true P1D and the emulated P1D for each redshift in the testing data, + along with a relative error panel below the main plot. Parameters: - testing_data: List of dictionaries containing the data for different redshifts. @@ -16,23 +17,23 @@ def plot_p1d_vs_emulator(testing_data, emulator, save_path=None): - None (displays the plot). """ # Initialize arrays to store true and emulated P1D values - Nk = len(testing_data[0]['p1d_Mpc'][(testing_data[0]['k_Mpc']>0)&(testing_data[0]['k_Mpc']<4)]) - z = [d['z'] for d in testing_data if d['z']<4.8 ] + Nk = len(testing_data[0]['p1d_Mpc'][(testing_data[0]['k_Mpc'] > 0) & (testing_data[0]['k_Mpc'] < 4)]) + z = [d['z'] for d in testing_data if d['z'] < 4.8] Nz = len(z) - p1ds_true = np.zeros(shape=(Nz, Nk)) - p1ds = np.zeros(shape=(Nz, Nk)) + p1ds_true = np.zeros((Nz, Nk)) + p1ds = np.zeros((Nz, Nk)) - # Create a colormap with 11 unique colors - cmap = cm.get_cmap('viridis', Nz) + # Use the 'inferno' colormap for a more intense color scheme + cmap = cm.get_cmap('tab20', Nz) + + # Set up figure with two subplots: main plot and relative error plot + fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, gridspec_kw={'height_ratios': [3, 1]}, figsize=(8, 8)) - plt.figure() - - # Loop through the entries in the testing data for m in range(Nz): if 'kF_Mpc' not in testing_data[m]: continue - + # Extract relevant data p1d_true = testing_data[m]['p1d_Mpc'] kMpc = testing_data[m]['k_Mpc'] @@ -45,33 +46,41 @@ def plot_p1d_vs_emulator(testing_data, emulator, save_path=None): fit_p1d = poly_p1d.PolyP1D(kMpc_test, p1d_true, kmin_Mpc=1e-3, kmax_Mpc=4, deg=5) p1d_true = fit_p1d.P_Mpc(kMpc_test) - # Emulate P1D using the provided emulator + # Emulate P1D using the emulator p1d = emulator.emulate_p1d_Mpc(testing_data[m], kMpc_test) # Store the results p1ds_true[m] = p1d_true p1ds[m] = p1d - - # Get the redshift and assign a unique color from the colormap + + # Get the redshift and assign color redshift = testing_data[m]['z'] color = cmap(m) + + # Plot on the main P1D plot + ax1.scatter(kMpc_test, kMpc_test * p1d, label=f'$z={redshift:.1f}$', color=color, marker='^') + ax1.plot(kMpc_test, kMpc_test * p1d_true, color=color) + + # Calculate and plot relative error on the second panel + relative_error = (p1d_true - p1d) / p1d_true + ax2.plot(kMpc_test, relative_error, label=f'$z={redshift:.1f}$', color=color) - # Plot the true and emulated P1D - plt.scatter(kMpc_test, kMpc_test * p1d, label=f'$z={redshift:.1f}$', color=color, marker='^') - plt.plot(kMpc_test, kMpc_test * p1d_true, color=color) - - # Set axis labels - plt.xlabel(r'$k$ [1/Mpc]') - plt.ylabel(r'$k$ * P1D') + # Set labels and titles + ax1.set_ylabel(r'$k \times P1D$', fontsize=14) + ax2.set_xlabel(r'$k$ [1/Mpc]', fontsize=14) + ax2.set_ylabel('Relative Error', fontsize=12) - # Add the legend outside the plot for better readability - plt.legend(loc='center left', bbox_to_anchor=(1, 0.5)) + # Add grid and legend to the plots + ax1.grid(True, which='both', linestyle='--', alpha=0.7) + ax2.grid(True, which='both', linestyle='--', alpha=0.7) + ax1.legend(loc='center left', bbox_to_anchor=(1, 0.5)) - # Save the plot - if save_path != None: + # Set fonts to serif for the entire plot + plt.rc('font', family='serif') + + # Save and show the plot + if save_path is not None: plt.savefig(save_path, bbox_inches='tight') - # Show the plot plt.show() plt.close() - return \ No newline at end of file diff --git a/scripts/make_plots_emulator.py b/scripts/make_plots_emulator.py index 30c8550d..51610753 100644 --- a/scripts/make_plots_emulator.py +++ b/scripts/make_plots_emulator.py @@ -21,7 +21,6 @@ def plot_emulated_p1d(archive_name='Nyx'): Parameters: archive (str): Archive to use for data ('Nyx' or 'Gadget') """ - # Print the type of archive selected for debugging print(f"Selected archive: {archive_name}") diff --git a/scripts/save_mpg_emu_cosmo.py b/scripts/save_mpg_emu_cosmo.py index ede8ae3c..2df8821a 100644 --- a/scripts/save_mpg_emu_cosmo.py +++ b/scripts/save_mpg_emu_cosmo.py @@ -25,6 +25,7 @@ def main(): )[0, 0] if archive.data[ind]["ind_snap"] == list_snap[0]: sim_dict["cosmo_params"] = archive.data[ind]["cosmo_params"] + sim_dict["star_params"] = archive.data[ind]["star_params"] sim_dict["linP_params"] = {} sim_dict["linP_params"]["kp_Mpc"] = archive.data[ind]["kp_Mpc"] for lab in labels: diff --git a/scripts/save_nyx_emu_cosmo.py b/scripts/save_nyx_emu_cosmo.py index 1b1994a2..46bb8d71 100644 --- a/scripts/save_nyx_emu_cosmo.py +++ b/scripts/save_nyx_emu_cosmo.py @@ -13,6 +13,7 @@ def main(): # file containing Nyx data nyx_version = "Oct2023" + nyx_version = "Jul2024" nyx_fname = os.environ["NYX_PATH"] + "/models_Nyx_" + nyx_version + ".hdf5" # file that will be written containing cosmo data for Nyx file cosmo_fname = ( @@ -31,6 +32,13 @@ def main(): all_dict = [] # iterate over simulations for sim_label in sim_avail: + # this simulation seems to have issues + if sim_label == "cosmo_grid_14": + continue + # contained in CGAN_4096_base + elif sim_label == "CGAN_4096_val": + continue + isim = nyx_archive.sim_conv[sim_label] sim_dict = {} sim_dict["sim_label"] = isim @@ -50,6 +58,7 @@ def main(): if first: sim_dict["cosmo_params"] = nyx_archive.data[ind]["cosmo_params"] + sim_dict["star_params"] = nyx_archive.data[ind]["star_params"] sim_dict["linP_params"] = {} sim_dict["linP_params"]["kp_Mpc"] = nyx_archive.data[ind][ "kp_Mpc"