Beispiel #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)
    def test_solve_num(self):
        C_0, C_1, t, k_01, k_10, k_0o = (
            Symbol(s) for s in ("C_0", "C_1", "t", "k_01", "k_10", "k_0o")
        )

        k_1o = Function("k_1o")

        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

        para = NumericParameterization(
                par_dict=par_dict,
                func_dict={k_1o: k_1o_func}
        )
        npsrm = NumericParameterizedSmoothReservoirModel(
            srm=self.srm, parameterization=para
        )
        # The parameterdict and the functions, possibly even the matrix/flux
        # expressions have implicit unit assumption, which the user is required
        # to maintain consistently.  To make modelruns comparable it is
        # important to remember the units for which this consistency can be
        # guaranteed.

        # A model run can then adapt the units of times and masses since it
        times_num = np.linspace(0, 20, 16)
        start_values_num = NumericStartValueArray([1, 2])
        # start_values_dict = frozendict({C_0: 1,C_1: 2}) 
        # would be a bit more intuitive but both formulations 
        # rely on the information stored in the model

        nmr = numeric_model_run_1(npsrm, start_values_num, times_num)
        print(nmr.solve())
Beispiel #3
0
#Model based on Fig. 1 in page 127 (3 in the PDF) of doi= "10.1016/0304-3800(88)90112-3", no ODEs in publication
t = TimeSymbol("t") #"the model has a daily and a yearly component. Allocation occurs yearly"
x = StateVariableTuple((C_f, C_r, C_w,C_frl,C_s))
b = ImmutableMatrix((eta_f, eta_w, eta_r))
Input = InputTuple(tuple(u * b)+(0,0))
A = CompartmentalMatrix(
[[-gamma_f,    0   ,    0   ,   (l_p*eta_f)  ,(s_p*eta_f)],
 [    0   ,-gamma_r,    0   ,   (l_p*eta_r)  ,(s_p*eta_r)],
 [    0   ,    0   ,-gamma_w,   (l_p*eta_w)  ,(s_p*eta_w)],
 [ gamma_f, gamma_r, gamma_w, -(l_p+l_s+l_dr),      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({})
Beispiel #4
0
np1 = NumericParameterization(
    par_dict={
        a_f: 0.16
        #    ,buf:
        #    ,bvr:
        #    ,bmf:
        #    ,bmr:
        #    ,bam:
        #    ,ban:
        #    ,bau:
        #    ,bav:
        ,
        baw: 0.413,
        bas: 0.42,
        bsa: 0.35
        #    ,bsu:
        #    ,bsv:
        ,
        bsw: 0.175,
        bps: 0.032,
        bpa: 0.004,
        bap: 0.45,
        s_f: 0.12  #"year^{-1}"
        ,
        s_r: 1.0  #"year^{-1}"
        ,
        s_w: 0.0069  #"year^{-1}"
    },
    func_dict=frozendict({})
    # state_var_units=kgC*m^{-2}
    # time_unit=year
)
Beispiel #5
0
                         [0, 0, 0, 0, f_75, f_76, -c_7, 0],
                         [0, 0, 0, 0, 0, f_86, f_87, -c_8]])
np1 = NumericParameterization(par_dict={
    GPP: 3.370,
    b_1: 0.14,
    b_2: 0.26,
    b_3: 0.14,
    f_41: 0.9,
    f_51: 0.1,
    f_52: 1,
    f_43: 0.2,
    f_53: 0.8,
    f_64: 0.45,
    f_65: 0.275,
    f_75: 0.275,
    f_76: 0.296,
    f_86: 0.004,
    f_67: 0.42,
    f_87: 0.01,
    f_68: 0.45,
    c_1: 0.00258,
    c_2: 0.0000586,
    c_3: 0.002390,
    c_4: 0.0109,
    c_5: 0.00095,
    c_6: 0.0105,
    c_7: 0.0000995,
    c_8: 0.0000115
},
                              func_dict=frozendict({}))
# "Initial values as in Wang and Luo"
nsv1 = NumericStartValueDict({
Beispiel #6
0
         LIT_A / C_A, LIT_S / C_S, LIT_L / C_L, LIT_R / C_R, 0, 0,
         -DEC_LIT / C_LIT, 0, 0
     ], [0, 0, 0, 0, LIT_WL / C_WL, LIT_WR / C_WR, 0, -DEC_CWD / C_CWD, 0],
     [
         0, 0, 0, 0, 0, 0, ((1 - c_lit_atm) * DEC_LIT) / C_LIT,
         ((1 - c_cwd_atm) * DEC_CWD) / C_CWD, -DEC_SOIL / C_SOIL
     ]])
t = TimeSymbol("t")  # "day"

np1 = NumericParameterization(
    par_dict={
        c_lit_atm: 0.77,
        c_cwd_atm: 0.2,
        tau_LIT: 2.05  # "yr"
        ,
        tau_CWD: 60  # "yr"
        ,
        tau_SOIL: 100  # "yr"
        ,
        Q_10h: 1.4
    },
    func_dict=frozendict({}))

mvs = CMTVS(
    {
        BibInfo(  # Bibliographical Information
            name="JeDi-DGVM",
            longName="The Jena Diversity-Dynamic Global Vegetation Model",
            version="1",
            entryAuthor="Verónika Ceballos-Núñez",
            entryAuthorOrcid="0000-0002-0046-1160",
Beispiel #7
0
Input = InputTuple(u * ImmutableMatrix(b))
A = CompartmentalMatrix(diag(-gamma_f, -gamma_w, -gamma_r))
t = TimeSymbol("t")

# "Original parameters of the publication. Parameter value of GPP corresponds to an annual average"
# T, Q_10, and W are variables that should be looked at in a data set. What I have here are invented values
np1 = NumericParameterization(
    par_dict={
        Q_10: 1,
        W: 4.2,
        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="",
Beispiel #8
0
     ], [0, 0, 0, 0, f_stlit2slowsom, f_fastsom2slowsom, -cr_slowsom, 0],
     [0, 0, 0, 0, 0, f_fastsom2passsom, f_slowsom2passsom, -cr_passsom]])
np1 = NumericParameterization(par_dict={
    GPP: 3.370,
    b_foliage: 0.14,
    b_roots: 0.26,
    b_wood: 0.14,
    f_foliage2metlit: 0.9,
    f_foliage2stlit: 0.1,
    f_wood2stlit: 1,
    f_roots2metlit: 0.2,
    f_roots2stlit: 0.8,
    f_metlit2fastsom: 0.45,
    f_stlit2fastsom: 0.275,
    f_stlit2slowsom: 0.275,
    f_fastsom2slowsom: 0.296,
    f_fastsom2passsom: 0.004,
    f_slowsom2fastsom: 0.42,
    f_slowsom2passsom: 0.01,
    f_passsom2fastsom: 0.45,
    cr_foliage: 0.00258,
    cr_wood: 0.0000586,
    cr_root: 0.002390,
    cr_metlit: 0.0109,
    cr_stlit: 0.00095,
    cr_fastsom: 0.0105,
    cr_slowsom: 0.0000995,
    cr_passsom: 0.0000115
},
                              func_dict=frozendict({}))
# "Initial values as in Wang and Luo"
nsv1 = NumericStartValueDict({
Beispiel #9
0
xi = f_T * f_W  #environmental effects multiplier (DEFAG)
A = ([-k_1, 0, 0, 0, 0, 0,
      0], [0, -K_2, 0, 0, 0, 0,
           0], [0, 0, -k_3, 0, 0, 0, 0], [0, 0, 0, -K_4, 0, 0, 0], [
               alpha_51 * k_1, 0.45 * K_2, alpha_53 * k_3, 0.45 * K_4, -k_5,
               0.42 * K_6, 0.45 * K_7
           ], [alpha_61 * k_1, 0, alpha_63 * k_3, 0, alpha_65 * k_5, -K_6,
               0], [0, 0, 0, 0, 0.004 * k_5, 0.03 * K_6, -K_7])
B = CompartmentalMatrix(xi * ImmutableMatrix(A))
#Original values without effects of temperature and soil moisture:
np1 = NumericParameterization(par_dict={
    K_1: 0.076,
    K_2: 0.28,
    K_3: 0.094,
    K_4: 0.35,
    K_5: 0.14,
    K_6: 0.0038,
    K_7: 0.00013,
    xi: 1
},
                              func_dict=frozendict({}))
nsv1 = NumericStartValueDict({
    C_1: 100,
    C_2: 200,
    C_3: 00,
    C_4: 0,
    C_5: 0,
    C_6: 0,
    C_7: 0
})  #faked values by Markus to make it run
#ntimes = NumericSimulationTimes(np.arange())
Beispiel #10
0
C_i = (B_L / (a_0L * (B_R + B_S + B_L)))
C_delta = A_CC * C - R_g
a_L = ((1 - C_i) / (3 + a_0R + a_0S - Q_i - G_i - C_i))
a_R = ((1 + a_0R - G_i) / (3 + a_0R + a_0S - Q_i - G_i - C_i))
a_S = ((1 + a_0S - Q_i) / (3 + a_0R + a_0S - Q_i - G_i - C_i))
t = TimeSymbol("t")  # unit: "month"
x = StateVariableTuple((B_L, B_R, B_S))
u = C_delta
b = (a_L, a_R, a_S)
Input = InputTuple(u * ImmutableMatrix(b))
B = CompartmentalMatrix(diag(-gamma_f, -gamma_r, -gamma_w))
np1 = NumericParameterization(
    par_dict={
        a_0L: 0.3,
        a_0R: 0.5,
        a_0S: 0.2,
        Q_i: 1
    },
    #Q_i: 1 when light is highly available (See sup. material 1, pg 17)
    func_dict=frozendict({}))

mvs = CMTVS(
    {
        BibInfo(  # Bibliographical Information
            name="aDGVM",
            longName="",
            version="",
            #       modApproach= "individuals based"
            entryAuthor="Verónika Ceballos-Núñez",
            entryAuthorOrcid="0000-0002-0046-1160",
            entryCreationDate="17/7/2015",
Beispiel #11
0
eta_w = 1 - eta_f - eta_r

x = StateVariableTuple((F, R, W))
u = G
b = (eta_f, eta_r, eta_w)
Input = InputTuple(u * ImmutableMatrix(b))
A = CompartmentalMatrix(diag(-gamma_f, -gamma_r, 0))
t = TimeSymbol("t")  # units: days, years for allocation

#Parameter set:  "Chosen based on the performance of Pinus radiata at Puruki, New Zeland":
## eta_ are not mentioned in the paper... probably the different values they gave to them were part of the hypothesis
np1 = NumericParameterization(
    par_dict={
        k: 0.5,
        Phi_0: 2500,  #"MJ*m*^{-2}*year^{-1}" 
        omega: 5,  #"m*^2*kg^{-1}"
        gamma_r: 2,  #"kg^{-1}"
        gamma_f: 0.5
    },  #"kg^{-1}"
    func_dict=frozendict({}))

mvs = MVarSet({
    BibInfo(  # Bibliographical Information
        name="",
        longName="",
        version="1",
        entryAuthor="Verónika Ceballos-Núñez",
        entryAuthorOrcid="0000-0002-0046-1160",
        entryCreationDate="29/7/2015",
        doi="10.1093/treephys/12.2.119",
        sym_dict=sym_dict),
Beispiel #12
0
mu_S = mu_max * S / (K_s * theta + S)  # "hr^{-1}"
Exu = ExuM * exp(-ExuT * t)  # "hr^{-1}"
x = StateVariableTuple((X, S))
u = InputTuple((0, BGF + Exu))
T = ImmutableMatrix([[-1, Y], [K_r, -1]])
N = ImmutableMatrix([[D_max * K_d / (K_d + S / theta), 0],
                     [0, X / Y * mu_max / (K_s * theta + S)]])
B = CompartmentalMatrix(T * N)
# Original values from linked model (no nitrogen cycle considered in this model here):
np1 = NumericParameterization(par_dict={
    D_max: 0.26,
    Y: 0.44,
    K_s: 3.0,
    theta: 0.23,
    ExuT: 0.8,
    BGF: 0.15,
    K_d: 14.5,
    K_r: 0.4,
    ExuM: 8.0,
    mu_max: 0.063
},
                              func_dict=frozendict({}))

# Standard version of BACWAVE, optimized to simulate bacterial biomass along wheat roots:
nsv1 = NumericStartValueDict({X: 0.5, S: 1.5})  # "Low"
nsv2 = NumericStartValueDict({X: 1.0, S: 2.5})  # "Medium"
nsv3 = NumericStartValueDict({X: 1.5, S: 4.0})  # "High"
ntimes = NumericSimulationTimes(np.arange(0, 2000, 0.1))

mvs = CMTVS(
    {
Beispiel #13
0
xi = f_T * f_W # environmental effects multiplier
A = ImmutableMatrix([[  -k_1,    0 ,          0,         0, 0],
                     [     0,  -k_2,          0,         0, 0],
                     [ a*k_1, a*k_2, -k_3+a*k_3,     a*k_4, 0],
                     [ b*k_1, b*k_2,      b*k_3,-k_4+b*k_4, 0],
                     [     0,     0,          0,         0, 0]])
B = CompartmentalMatrix(xi * A)
# Original values without effects of temperature and soil moisture
# doi = {10.1007/978-3-642-61094-3_17},
np1 = NumericParameterization(
    par_dict={
              k_1: 10
              ,k_2: 0.3
              ,k_3: 0.66
              ,k_4: 0.02
              ,pClay: 23.4
              ,DR: 1.44
              ,J: 1.7
              ,xi: 1
},
    func_dict=frozendict({})
)

mvs = CMTVS(
    {
        BibInfo(# Bibliographical Information
            name="RothC-26.3",
            longName="", 
            version="",
            entryAuthor="Holger Metzler",
            entryAuthorOrcid="0000-0002-8239-1601",
Beispiel #14
0
    var(name)
t = TimeSymbol("t")  # unit: "day"
x = StateVariableTuple((x_1, x_2, x_3, x_4, x_5))
u = InputTuple((I_1, 0, I_3, 0, 0))
B = CompartmentalMatrix([[-F_1, 0, 0, 0, 0], [F_21, -F_2, 0, 0, 0],
                         [0, 0, -F_3, 0, 0], [F_41, F_42, F_43, -F_4, 0],
                         [0, F_52, F_53, F_54, -F_5]])
np1 = NumericParameterization(par_dict={
    I_1: 77,
    I_3: 36,
    F_1: 2.081,
    F_2: 0.0686,
    F_3: 0.5217,
    F_4: 0.5926,
    F_5: 9.813e-3,
    F_21: 0.8378,
    F_41: 0.5676,
    F_42: 0.0322,
    F_52: 4.425e-3,
    F_43: 0.1739,
    F_53: 0.0870,
    F_54: 0.0370
},
                              func_dict=frozendict({}))

nsv1 = NumericStartValueDict({x_1: 37, x_2: 452, x_3: 69, x_4: 81, x_5: 1121})
ntimes = NumericSimulationTimes(np.arange(0, 200, 0.1))

mvs = CMTVS(
    {
        BibInfo(  # Bibliographical Information
Beispiel #15
0
np1 = NumericParameterization(
    par_dict={
        NPP: Rational(409, 365),  # *gram*/(meter**2*day)
        # Note:
        # The (negative ) parameter value for mint (see below) suggests that
        # maxt and mint are given in the celsius scale.
        # The sympy unit system does not destinguish between absolute
        # temperature and celsius scale.
        # Conceptually 5 deg Celsius describe a temperature DIFFERENCE of 5 Kelvin
        # to the triple point of water.
        # Differences are always mesured in Kelvin
        # So although mint and maxt are given in Kelvin they are not understood
        # as absolute temperatures but as differences to the triple point.
        mint: -4,  # Kelvin (deg Celsius)
        maxt: 5,  # Kelvin (de Celsius)
        multtf: 0,
        multtl: 1,
        # p_2		    :0.47,
        p_3: 0.31,
        p_4: 0.43,
        p_5: 0.0027,  # 1/day
        p_6: 0.00000206,  # 1/day
        p_7: 0.00248,  # 1/day
        #
        # Althouhg p10 is considered to have unit 1/Kelvin
        # inspection of the T_rate expression connects it
        # to Temperature DIFFERENCE from  the triple point
        p_10: 0.0693,  # /kelvin
        p_14: 0.45,
        p_15: 0.001,  # 1/day
        p_16: 0.251,
    },
    func_dict=frozendict({})
    # state_var_units=kilogram/meter**2,
    # time_unit=day
)
Beispiel #16
0
Input = InputTuple(u * ImmutableMatrix(b))
A = CompartmentalMatrix(diag(-tau_f, -tau_r, -tau_w))
t = TimeSymbol("t")

# model_run_data is incomplete :
# Even parameter_sets cannot fully parameterize the symbolic model: mm made up
# a purely fictional parameters to show how a purely numeric could be build.
# (The yaml file lacks consistent unit information).
np1 = NumericParameterization(
    par_dict={
        alpha_f: Rational(1, 3),
        alpha_r: Rational(1, 3),
        alpha_w: Rational(1, 3),
        tau_f: 1.5,
        tau_r: 3,
        tau_w: 50,
        SOL: 1,  # completely faked by mm
        epsilon: 1.1,
        FPAR: 1,  # completely faked by mm
    },
    func_dict=frozendict({}))
# Original dataset of the publication":
#            values: {alpha_f: 'Rational(1,3)',alpha_r: 'Rational(1,3)',alpha_w: 'Rational(1,3)'}
# # epsilon varies from 1.1 - 1.4 gC*MJ^{-1}PAR in crop ecosystems.
#            doi: 10.1029/93GB02725
#        - "Tundra":
#            values: {alpha_f: 0.25, alpha_r: 0.25, alpha_w: 0.5, tau_f: 1.5, tau_r: 3, tau_w: 50}
#            doi: 10.2307/1313568
#        - "High-latitude forest":
#            values: {alpha_f: 0.30, alpha_r: 0.25, alpha_w: 0.45, tau_f: 1, tau_r: 3, tau_w: 50}
Beispiel #17
0
         0, -((f_np * lambda_p * W_p) + (f_ns * lambda_s * W_s) +
              (f_nr * lambda_r * W_r)) * ((kappa * W_C) / W_g**2), 0, 0, 0
     ], [0, (kappa * N * lambda_p * W_p) / W_g, 0, 0, 0],
     [0, (kappa * N * lambda_s * W_s) / W_g, 0, 0, 0],
     [0, (kappa * N * lambda_r * W_r) / W_g, 0, 0, 0]])
t = TimeSymbol("t")  # unit: "day"

np1 = NumericParameterization(par_dict={
    sigma_r: 0.01,
    I_dens: 1000,
    f_C: 0.5,
    Beta: 0.05,
    f_cp: 0.60,
    f_cr: 0.45,
    f_cs: 0.45,
    f_np: 0.16,
    f_nr: 0.03,
    f_ns: 0.005,
    h_max: 0.0003,
    h_half: 200,
    kappa: 300,
    rho: '5*10**5',
    C_i: 240
},
                              func_dict=frozendict({}))
nsv1 = NumericStartValueDict({
    N: 0.01,
    C: 0.15,
    W_p: 100,
    W_s: 100,
    W_r: 100,
    W_C: 45,
Beispiel #18
0
np1 = NumericParameterization(
    par_dict={
        Q_10: 1,
        W: 4.2,
        T: 25,
        U: 3370  #"gC*day^{-1}" # Average estimated value
        ,
        b_1: 0.14,
        b_2: 0.14,
        b_3: 0.26,
        c_1: 0.00258,
        c_2: 0.0000586,
        c_3: 0.00239,
        c_4: 0.0109,
        c_5: 0.00095,
        c_6: 0.0105,
        c_7: 0.0000995,
        c_8: 0.0000115,
        f_41: 0.9,
        f_51: 0.1,
        f_52: 1,
        f_43: 0.2,
        f_53: 0.8,
        f_64: 0.45,
        f_65: 0.275,
        f_75: 0.275,
        f_76: 0.296,
        f_86: 0.004,
        f_67: 0.42,
        f_87: 0.01,
        f_68: 0.45
    },
    func_dict=frozendict({})
    # state_var_units=gram/kilometer**2,
    # time_unit=day
)
Beispiel #19
0
}

for name in sym_dict.keys():
    var(name)
xi = r  #environmental effects multiplier
T = ImmutableMatrix([[-1, 0], [h, -1]])  #transition operator
N = diag(k_1, k_2)  #decomposition operator
t = TimeSymbol("t")  # unit: "year"
x = StateVariableTuple((Y, O))
u = InputTuple((i, 0))
B = CompartmentalMatrix(xi * T * N)
#        - "Bare fallow":
np1 = NumericParameterization(par_dict={
    k_1: 0.8,
    k_2: 0.00605,
    i: 0,
    h: 0.13,
    r: 1.32
},
                              func_dict=frozendict({}))
nsv1 = NumericStartValueDict({Y: 0.3, O: 3.96})

#        - "+N +straw":
np2 = NumericParameterization(par_dict={
    k_1: 0.8,
    k_2: 0.00605,
    i: 0.285,
    h: 0.125,
    r: 1.00
},
                              func_dict=frozendict({}))
nsv2 = NumericStartValueDict({Y: 0.3, O: 4.11})
Beispiel #20
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')
Beispiel #21
0
         -(t_litterC_soilC + t_litterC_atm) / C_litter, 0, t_CWDC / C_cwd
     ],
     [0, 0, 0, 0, 0, 0, t_litterC_soilC / C_litter, -t_soilC_atm / C_soil, 0],
     [0, 0, 0, tau_wood, 0, 0, 0, 0, -t_CWDC / C_cwd]])
t = TimeSymbol("t")

np1 = NumericParameterization(
    par_dict={
        tau_leaf: 0.0027,
        tau_wood: 5e-05,
        tau_root: 0.002,
        tau_excessC: 0.05,
        tau_litter: 0.029,
        tau_cwd: 0.001,
        tau_soil: 1e-04,
        Q_h: 1.4,
        m_resp_frac: 0.5,
        DON_leach_prop: 0.0015,
        leach_rate: 0.00001  # day^{-1}
        ,
        nitr_rate: 0.0001  # day^{-1}
    },
    func_dict=frozendict({})
    # state_var_units= gC*m^{-2}
    # time_unit=day
)
in_fl_c = carbon_in_fluxes_by_symbol_1(c_in_t, xc)
internal_fl_c = carbon_internal_fluxes_by_symbol_1(A_c, xc)
out_fl_c = carbon_out_fluxes_by_symbol_1(A_c, xc)

in_fl_n = {N_labile: U_Nfix, N_NH4: Ndep_NH4, N_NO3: Ndep_NO3}
out_fl_n = {N_soil: L_DON, N_NH4: U_NH4, N_NO3: U_NO3 + L_NO3}
Beispiel #22
0
                         [0, 0, 0, 0, 0, 0, 0, d_5 * p_pa, d_6 * p_ps, -d_7]])
# Commented out the following lines because original publication only has 3 parameter values
np1 = NumericParameterization(
    par_dict={
        #    G: , #"Mg*ha^{-1}*yr^{-1}"
        eta_f: 0.3,
        eta_r: 0.3,
        gamma_f: 0.5  #"yr^{-1}"
        ,
        gamma_r: 1.5  #"yr^{-1}"
        ,
        gamma_w: 0.01  #"yr^{-1}"
        ,
        lambda_f: 1,
        lambda_r: 1,
        omega: 0.45,
        L_fl: 0.2,
        L_rl: 0.16,
        T: 0.5,
        p_am: 0.45,
        p_an: 0.45,
        p_pa: 0.004,
        p_as: 0.42,
        p_ps: 0.03,
        p_ap: 0.45
    },
    func_dict=frozendict({})
    # state_var_units=gram/kilometer**2,
    # time_unit=day
)
#nsv1 = NumericStartValueDict({
#    F: , #"Mg/ha"