Esempio n. 1
0
    def test_NumericCompartmentalMatrixFunc(self):
        for n in self.symbol_names:
            var(n)
        k_1o = Function("k_1o")
        sym_B = hr.compartmental_matrix_2(self.out_fluxes_by_symbol,
                                          self.internal_fluxes_by_symbol,
                                          self.state_variables)
        par_dict = {
            k_01: 1 / 100,  # 1/year
            k_10: 1 / 100,  # 1/year
            k_0o: 1 / 2,  # 1/year
        }

        def k_1o_func(t):
            omega = 2 * pi  # 1/year
            phi = pi / 8
            V_0 = 20  # kilogram/year
            V_range = 5  # kilogram/year
            u_res = V_0 + V_range * sin(omega * t + phi)
            return u_res

        func_dict = {'k_1o': k_1o_func}
        para_num = NumericParameterization(par_dict, func_dict)

        start_values_num = np.array([1, 2])  # kg
        times_num = NumericSimulationTimes(np.linspace(0, 20, 16))
        B_func = numericCompartmentalMatrixFunc(sym_B, self.state_variables,
                                                self.time_symbol, para_num)
        npsrm = numeric_parameterized_smooth_reservoir_model_1(
            srm=self.srm, para_num=para_num)

        smr = numeric_model_run_1(npsrm, start_values_num, times_num)
        xs = numeric_solution_array_1(smr)
        ress = numericCompartmentalMatrixSolutionTuple(xs, times_num, B_func)
Esempio n. 2
0
        T: 25,
        GPP: 3370,  #"gC*day^{-1}"
        eta_f: 0.14,
        eta_r: 0.26,
        eta_w: 0.14,
        gamma_f: 0.00258,
        gamma_w: 0.0000586,
        gamma_r: 0.00239
    },
    func_dict=frozendict({})
    # state_var_units=gram/kilometer**2,
    # time_unit=day
)
nsv1 = NumericStartValueDict({C_f: 250, C_w: 4145, C_r: 192})

ntimes = NumericSimulationTimes(np.arange(0, 150, 2.5))

mvs = MVarSet({
    BibInfo(  # Bibliographical Information
        name="",
        longName="",
        version="",
        entryAuthor="Verónika Ceballos-Núñez",
        entryAuthorOrcid="0000-0002-0046-1160",
        entryCreationDate="24/3/2016",
        doi="",
        #        further_references=BibInfo(doi=""),
        #        modApproach: process based,
        #        partitioningScheme: fixed,
        #        claimedDynamicPart: "no",
        #        spaceScale: global,
Esempio n. 3
0
},
                              func_dict=frozendict({}))
nsv6 = NumericStartValueDict({Y: 0.3, O: 3.99})

#        - "Sewage sludge":
np7 = NumericParameterization(par_dict={
    k_1: 0.8,
    k_2: 0.00605,
    i: 0.296,
    h: 0.34,
    r: 0.97
},
                              func_dict=frozendict({}))
nsv7 = NumericStartValueDict({Y: 0.3, O: 4.14})
# ntimes can be used for all parameter sets
ntimes = NumericSimulationTimes(np.arange(0, 100, 0.1))

mvs = CMTVS(
    {
        BibInfo(  # Bibliographical Information
            name="ICBM",
            longName="Introductory Carbon Balance Model",
            version="",
            entryAuthor="Holger Metzler",
            entryAuthorOrcid="0000-0002-8239-1601",
            entryCreationDate="09/03/2016",
            doi="10.1890/1051-0761(1997)007[1226:ITICBM]2.0.CO;2",
            sym_dict=sym_dict),
        B,  # the overall compartmental matrix
        u,  # the overall input
        t,  # time for the complete system
Esempio n. 4
0
    # state_var_units=kilogram/meter**2,
    # time_unit=day
)
nsv1 = NumericStartValueDict({
    C_f: 58,
    C_lab: 60,
    C_w: 770,
    C_r: 102
})

## We create the parameterized model explicitly , although the framework would find the ingredients
nsrm = NumericParameterizedSmoothReservoirModel(srm,np1)



ntimes = NumericSimulationTimes(np.arange(0, 1096, 1))

## We create the model run explicitly again, although the framework would find the ingredients
nsmr= numeric_model_run_1(
    nsrm, 
    numeric_start_value_array_1(nsv1,x),
    ntimes
)



qp1 = quantity_parameterization_1(
    np1,
    state_var_units=(
        kilogram/meter**2,
        kilogram/meter**2,
Esempio n. 5
0
 [    0   ,    0   ,    0   ,       l_s      ,-(s_p+s_dr)]
])

## The following are default values suggested by this entry's creator only to be able to run the model:
np1 = NumericParameterization(
    par_dict={u: 1400, eta_f: 0.48, eta_r: 0.44, eta_w: 0.49, gamma_r: 3.03, gamma_f: 23.32, gamma_w: 0.04},
    func_dict=frozendict({})
)

nsv1 = NumericStartValueDict({
    C_f: 200, 
    C_w: 5000, 
    C_r: 300
})

ntimes = NumericSimulationTimes(np.arange(0, 20000, 0.01))

#    doi: 10.1016/0304-3800(88)90112-3
np2 = NumericParameterization(
    par_dict={
    eta_f: Rational(25,100), eta_r: Rational(40,100), eta_w: Rational(35,100), gamma_r: Rational(40,100), gamma_f: Rational(33,100), gamma_w: Rational(0,100)},
    func_dict=frozendict({})
)

#    doi: 10.1093/treephys/9.1-2.161 # Hunt1991TreePhysiol
np3 = NumericParameterization(
    par_dict={
    eta_f: Rational(20,100), eta_r: Rational(55,100), eta_w: Rational(25,100), gamma_r: Rational(75,100)},
    func_dict=frozendict({})
)
Esempio n. 6
0
    def test_numeric_input_tuple(self):
        # setup the paths to the testdata
        cable_out_path = Path(
            '/home/data/cable-data/example_runs/parallel_1901_2004_with_spinup/output/new4'
        )
        # cable_data_set = cH.cable_ds(cable_out_path)
        time_slice = slice(0, None)
        landpoint_slice = slice(1590, 1637)  # cheated
        # landpoint_slice = slice(None,None)
        # time_slice=slice(None,None,None)

        zarr_cache_path = cP.slice_dir_path(
            cable_out_path,
            sub_dir_trunk="zarr_mm11",
            time_slice=time_slice,
            landpoint_slice=landpoint_slice,
        )
        if "cable_data_set" not in dir():
            cable_data_set = cH.cable_ds(cable_out_path)
        args = {
            "cable_data_set": cable_data_set,
            "zarr_cache_path": zarr_cache_path,
            "landpoint_slice": landpoint_slice,
            "time_slice": time_slice,
            #'batch_size': 128,
            "batch_size": 12,
            #'rm': True
        }

        x_org_iveg = cH.cacheWrapper(cC.x_org_iveg, **args)
        time = cH.cacheWrapper(cC.time, **args)

        patches, landpoints = cC.all_pools_vary_cond_nz(**args)
        pcs = patches.compute()
        lpcs = landpoints.compute()
        pcs, lpcs
        p = Path('plots')
        p.mkdir(exist_ok=True)
        ind = 0  # first pair that has a nonconstant solution for
        lp = lpcs[ind]
        patch = lpcs[ind]

        # get the symbolic represantation from the database
        mvs = self.mvs

        # define some stuff to extend it with

        def default(t):
            return 1

        leaf = Symbol('leaf')
        fine_root = Symbol('fine_root')
        Npp = Function("Npp")
        bvec_leaf = Function("bvec_leaf")
        bvec_fine_root = Function("bvec_fine_root")
        xk_leaf_cold = Function("xk_leaf_cold")
        xk_leaf_dry = Function("xk_leaf_dry")
        kleaf = Function("kleaf")
        kfroot = Function("kfroot")
        # bvec_wood = Function("bvec_wood")

        np1 = NumericParameterization(
            par_dict={},
            func_dict=frozendict({
                Npp: default,
                bvec_fine_root: default,
                bvec_leaf: default,
                xk_leaf_cold: default,
                kleaf: default,
                kfroot: default,
                xk_leaf_dry: default,
            }),
        )
        nsv1 = NumericStartValueDict({leaf: 0.3, fine_root: 3.96})
        ntimes1 = NumericSimulationTimes(np.linspace(0, 1, 11))

        # extend the symbolice version with the new stuff
        pvs = mvs.provided_mvar_values
        #from IPython import embed; embed()
        pvs1 = pvs.union(frozenset({np1, nsv1, ntimes1}))
        mvs1 = MVarSet(pvs1)

        x = mvs1.get_StateVariableTuple()
        Input = mvs1.get_InputTuple()
        #B = mvs1.get_CompartmentalMatrix()
        sym_times = mvs1.get_NumericSimulationTimes()
        sol_smooth = mvs1.get_NumericSolutionArray()

        comp_slice = slice(0, 100)
        n = sol_smooth.shape[1]
        fig = plt.figure()
        for pool in range(n):
            ax = fig.add_subplot(n + 1, 1, 2 + pool)
            title = "\$" + latex(x[pool]) + "\$"
            #ax.plot(
            #    sym_times[comp_slice],
            #    sol_smooth[comp_slice, pool],
            #    color='r'
            #)
            ax.plot(time[comp_slice],
                    x_org_iveg[comp_slice, pool, patch, lp],
                    color='b')
            fontsize = 10
            ax.set_title(title, fontsize=fontsize)

        fig.savefig('solution.pdf')