def param2res(pa): epa = EstimatedParameters(*pa) # here we want to store only monthly values # although the computation takes place on a daily basis V_init = construct_V0(cpa, epa) # compute the days when we need the results # to be able to compare to the monthly output day_indices = month_2_day_index(range(cpa.number_of_months)) print("day_indices=", day_indices) apa = Parameters.from_EstimatedParametersAndUnEstimatedParameters( epa, cpa) mpa = ModelParameters(**{ k: v for k, v in apa._asdict().items() if k in ModelParameters._fields }) full_res = run_forward_simulation(V_init=V_init, day_indices=day_indices, mpa=mpa) # project the litter and soil pools tot_len = cpa.number_of_months c_litter = np.sum(full_res[:, 3:6], axis=1).reshape(tot_len, 1) c_soil = np.sum(full_res[:, 6:9], axis=1).reshape(tot_len, 1) out_simu = np.concatenate( [ full_res[:, 0:3], # the first 3 pools are used as they are c_litter, c_soil, full_res[:, 9:10] ], axis=1) return out_simu
def param2res(pa): epa = EstimatedParameters(*pa) # here we want to store only monthly values # although the computation takes place on a daily basis #x_init = np.array([cleaf_0,croot_0,cwood_0,epa[12],epa[13],clitter_0-epa[12]-epa[13],epa[14],csoil_0- epa[14] - epa[15], epa[15]]).reshape([9,1]) # Initial carbon pool size x_init = construct_X0(cpa, epa) # compute the days when we need the results # to be able to compare to the monthly output day_indices = month_2_day_index(range(cpa.number_of_months)) apa = Parameters.from_EstimatedParametersAndUnEstimatedParameters( epa, cpa) mpa = ModelParameters(**{ k: v for k, v in apa._asdict().items() if k in ModelParameters._fields }) full_res = run_forward_simulation( x_init=x_init, day_indices=day_indices, **mpa._asdict() #npp=npp, #clay=clay, #silt=silt, #lig_wood=lig_wood, #lig_leaf=epa.lig_leaf, #beta_leaf=epa.beta_leaf, #beta_root=epa.beta_root, #f_leaf2metlit=epa.f_leaf2metlit, #f_root2metlit=epa.f_root2metlit, #f_wood2CWD=f_wood2CWD, #f_metlit2mic=f_metlit2mic, #k_leaf=epa.k_leaf, #k_root=epa.k_root, #k_wood=epa.k_wood, #k_metlit=epa.k_metlit, #k_mic=epa.k_mic, #k_slowsom=epa.k_slowsom, #k_passsom=epa.k_passsom ) # project the litter and soil pools tot_len = cpa.number_of_months c_litter = np.sum(full_res[:, 3:6], axis=1).reshape(tot_len, 1) c_soil = np.sum(full_res[:, 6:9], axis=1).reshape(tot_len, 1) out_simu = np.concatenate( [ full_res[:, 0:3], # the first 3 pools are used as they are c_litter, c_soil, full_res[:, 9:10] ], axis=1) return out_simu
def test_param2res_sym(self): const_params = self.cpa param2res_sym = make_param2res_sym(const_params) res_sym = param2res_sym(self.epa0) day_indices = month_2_day_index(range(self.pa.number_of_months)), fig = plt.figure() plot_solutions(fig, times=day_indices, var_names=Observables._fields, tup=(res_sym, )) fig.savefig('solutions.pdf')
sol = np.stack(sols) return sol return param2res # + # now test it import matplotlib.pyplot as plt from general_helpers import plot_solutions const_params = cpa param2res_sym = make_param2res_sym(const_params) xs = param2res_sym(epa_0) day_indices = month_2_day_index(range(cpa.number_of_months)), fig = plt.figure() plot_solutions( fig, #times=day_indices, times=range(cpa.number_of_months), var_names=Observables._fields, tup=(xs, )) fig.savefig('solutions.pdf') # - # ### mcmc to optimize parameters # coming soon
def test_month_2_day_index(self): self.assertEqual(month_2_day_index([0]), [0]) self.assertEqual(month_2_day_index([1]), [31]) self.assertEqual(month_2_day_index([2]), [59]) self.assertEqual(month_2_day_index([3]), [90]) self.assertEqual(month_2_day_index([1, 3]), [31, 90])