1
+ # Import necessary modules
2
+ from lace .archive .gadget_archive import GadgetArchive
3
+ from lace .emulator .emulator_manager import set_emulator
4
+ from lace .utils import poly_p1d
5
+ import numpy as np
6
+
7
+ def create_emulator ():
8
+ # Define the parameters for the emulator
9
+ emu_params = ['Delta2_p' , 'n_p' , 'mF' , 'sigT_Mpc' , 'gamma' , 'kF_Mpc' ]
10
+
11
+ # Initialize a GadgetArchive instance for postprocessing data
12
+ archive = GadgetArchive (postproc = "Cabayol23" )
13
+
14
+ # Retrieve testing data from the archive
15
+ testing_data = archive .get_testing_data (sim_label = 'mpg_central' )
16
+
17
+ # Extract kMpc and p1d_true data from testing data
18
+ kMpc = testing_data [0 ]['k_Mpc' ]
19
+ p1d_true = testing_data [4 ]['p1d_Mpc' ]
20
+ p1d_true = p1d_true [(kMpc > 0 ) & (kMpc < 4 )]
21
+ kMpc = kMpc [(kMpc > 0 ) & (kMpc < 4 )]
22
+
23
+ # Fit a polynomial to the true p1d data
24
+ fit_p1d = poly_p1d .PolyP1D (kMpc , p1d_true , kmin_Mpc = 1e-3 , kmax_Mpc = 4 , deg = 5 )
25
+ p1d_true = fit_p1d .P_Mpc (kMpc )
26
+
27
+ # Set up the emulator
28
+ emulator_C23 = set_emulator (emulator_label = "Cabayol23+" )
29
+
30
+ # Emulate p1d_Mpc data using the emulator
31
+ p1d = emulator_C23 .emulate_p1d_Mpc (testing_data [4 ], kMpc )
32
+
33
+ # Calculate the percentage error between the emulated and true p1d data
34
+ percent_error = np .mean ((p1d / p1d_true - 1 ) * 100 )
35
+
36
+ # Assert that the percentage error is less than 1%
37
+ assert percent_error < 1
38
+ # Call the function to execute the test
39
+ create_emulator ()
0 commit comments