Пример #1
0
def main():

    # sweep the cmd line
    options, args = cmdline_parser()

    from file_parser import initialise_model_data
    # pylint: disable=C0103
    # pylint: disable=C0324
    # pylint: disable=C0103

    fname = "gday"
    fdir = "/Users/mdekauwe/src/python/GDAY_model/params"
    (adj_control, adj_params,
        adj_state, adj_files,
        adj_fluxes, met_data) = initialise_model_data(fname, default_dir=fdir)

    # figure out photosynthesis
    P = PlantProdModel(adj_control, adj_params, adj_state, adj_fluxes, met_data)

    adj_state.lai = (adj_params.slainit * const.M2_AS_HA /
                            const.KG_AS_TONNES / adj_params.cfracts *
                            adj_state.shoot)

    # Specific LAI (m2 onesided/kg DW)
    adj_state.sla = adj_params.slainit



    adj_control.assim_model = 3

    num_days = len(met_data['doy'])
    for i in xrange(num_days):

        if float_lt(adj_state.lai, adj_params.lai_cover):
            gcover = adj_state.lai / adj_params.lai_cover
        else:
            gcover = 1.0

        adj_state.fapar = ((1.0 - exp(-adj_params.kext * adj_state.lai /
                    gcover)) * gcover)

        adj_state.shootnc = adj_state.shootn / adj_state.shoot

        P.run_sim(i)


        print adj_fluxes.gpp / const.HA_AS_M2 * const.TONNES_AS_G

        #print adj_state.lai


        # this is done in derive so do here
        # Specific LAI (m2 onesided/kg DW)
        adj_state.sla = (adj_state.lai / const.M2_AS_HA *
                            const.KG_AS_TONNES *
                            adj_params.cfracts / adj_state.shoot)


    return
Пример #2
0
    # timing...
    import sys
    import time

    start_time = time.time()

    from file_parser import initialise_model_data
    import datetime
    from utilities import float_eq, float_lt, float_gt, calculate_daylength, uniq

    met_header = 4

    # fname = "/Users/mdekauwe/research/NCEAS_face/GDAY_ornl_simulation/params/NCEAS_or_youngforest.cfg"
    fname = "/Users/mdekauwe/research/FACE/GDAY_simulations/KSCO/experiment/params/NCEAS_KSCO_model_indust.cfg"
    (control, params, state, files, fluxes, met_data, print_opts) = initialise_model_data(fname, met_header, DUMP=False)

    control.ps_pathway = "C4"
    if control.ps_pathway == "C3":
        M = MateC3(control, params, state, fluxes, met_data)
    else:
        M = MateC4(control, params, state, fluxes, met_data)

    # flai = "/Users/mdekauwe/research/NCEAS_face/GDAY_ornl_simulation/experiments/silvias_LAI.txt"
    # lai_data = np.loadtxt(flai)

    project_day = 0

    # figure out the number of years for simulation and the number of
    # days in each year
    years = uniq(met_data["year"])
Пример #3
0
    def __init__(self, fname=None, DUMP=False, spin_up=False, met_header=4):

        """ Set up model

        * Read meterological forcing file
        * Read user config file and adjust the model parameters, control or
          initial state attributes that are used within the code.
        * Setup all class instances...perhaps this isn't the tidyest place for
          this?
        * Initialise things, zero stores etc.

        Parameters:
        ----------
        fname : string
            filename of model parameters, including path
        chk_cmd_line : logical
            parse the cmd line?
        DUMP : logical
            dump a the default parameters to a file
        met_header : in
            row number of met file header with variable name
        Returns:
        -------
        Nothing
            Controlling class of the model, runs things.

        """
        self.day_output = [] # store daily output
        # initialise model structures and read met data
        (self.control, self.params,
         self.state, self.files,
         self.fluxes, self.met_data,
         self.print_opts) = initialise_model_data(fname, met_header, DUMP=DUMP)

        # params are defined in per year, needs to be per day
        # Important this is done here as rate constants elsewhere in the code
        # are assumed to be in units of days not years!
        self.correct_rate_constants(output=False)

        # class instance
        self.cs = CarbonSoilFlows(self.control, self.params, self.state,
                                  self.fluxes, self.met_data)

        self.ns = NitrogenSoilFlows(self.control, self.params, self.state,
                                    self.fluxes, self.met_data)

        self.lf = Litter(self.control, self.params, self.state, self.fluxes)

        self.pg = PlantGrowth(self.control, self.params, self.state,
                              self.fluxes, self.met_data)

        self.cb = CheckBalance(self.control, self.params, self.state,
                               self.fluxes, self.met_data)

        self.db = Disturbance(self.control, self.params, self.state,
                              self.fluxes, self.met_data)

        if self.control.deciduous_model:
            if self.state.max_lai is None:
                self.state.max_lai = 0.01 # initialise to something really low
                self.state.max_shoot = 0.01 # initialise to something really low
            
            # Are we reading in last years average growing season?
            if (float_eq(self.state.avg_alleaf, 0.0) and 
                float_eq(self.state.avg_alstem, 0.0) and 
                float_eq(self.state.avg_albranch, 0.0) and 
                float_eq(self.state.avg_alleaf, 0.0) and 
                float_eq(self.state.avg_alroot, 0.0) and 
                float_eq(self.state.avg_alcroot, 0.0)): 
                self.pg.calc_carbon_allocation_fracs(0.0) #comment this!!
            else:
                
                self.fluxes.alleaf = self.state.avg_alleaf
                self.fluxes.alstem = self.state.avg_alstem 
                self.fluxes.albranch = self.state.avg_albranch 
                self.fluxes.alroot = self.state.avg_alroot 
                self.fluxes.alcroot = self.state.avg_alcroot
            
            
            self.pg.allocate_stored_c_and_n(init=True)
            #self.pg.enforce_sensible_nstore()
            self.P = Phenology(self.fluxes, self.state, self.control,
                               self.params.previous_ncd,
                              store_transfer_len=self.params.store_transfer_len)

        self.pr = PrintOutput(self.params, self.state, self.fluxes,
                              self.control, self.files, self.print_opts)

        # build list of variables to prin
        (self.print_state, self.print_fluxes) = self.pr.get_vars_to_print()

        # print model defaul
        if DUMP == True:
            self.pr.save_default_parameters()
            sys.exit(0)

        self.dead = False # johnny 5 is alive

        # calculate initial stuff, e.g. C:N ratios and zero annual flux sum
        self.day_end_calculations(INIT=True)
        self.state.pawater_root = self.params.wcapac_root
        self.state.pawater_topsoil = self.params.wcapac_topsoil
        self.spin_up = spin_up
        self.state.lai = max(0.01, (self.params.sla * const.M2_AS_HA /
                                    const.KG_AS_TONNES / self.params.cfracts *
                                    self.state.shoot))

        # figure out the number of years for simulation and the number of
        # days in each year
        self.years = uniq(self.met_data["year"])
        self.days_in_year = [self.met_data["year"].count(yr)
                             for yr in self.years]

        if self.control.water_stress == False:
            sys.stderr.write("**** You have turned off the drought stress")
            sys.stderr.write(", I assume you're debugging??!\n")
Пример #4
0
    # timing...
    import sys
    import time
    start_time = time.time()
    
    from file_parser import initialise_model_data
    import datetime
    from utilities import float_eq, float_lt, float_gt, calculate_daylength, uniq
    
    met_header=4
    
    #fname = "/Users/mdekauwe/research/NCEAS_face/GDAY_ornl_simulation/params/NCEAS_or_youngforest.cfg"
    fname = "/Users/mdekauwe/research/FACE/GDAY_simulations/KSCO/experiment/params/NCEAS_KSCO_model_indust.cfg"
    (control, params, state, files,
        fluxes, met_data,
            print_opts) = initialise_model_data(fname, met_header, DUMP=False)
    
    control.ps_pathway = "C4"
    if control.ps_pathway == "C3":
        M = MateC3(control, params, state, fluxes, met_data)
    else:
        M = MateC4(control, params, state, fluxes, met_data)
   
    #flai = "/Users/mdekauwe/research/NCEAS_face/GDAY_ornl_simulation/experiments/silvias_LAI.txt"
    #lai_data = np.loadtxt(flai)
   

    # Specific LAI (m2 onesided/kg DW)
    state.sla = params.slainit

    
Пример #5
0



if __name__ == "__main__":
    
    
    from file_parser import initialise_model_data
    from utilities import float_lt, day_length
    import datetime

    fname = "/Users/mdekauwe/src/python/pygday/params/duke_testing.cfg"

    (control, params, state, files,
        fluxes, met_data,
            print_opts) = initialise_model_data(fname, DUMP=False)

    B = Bewdy(control, params, state, fluxes, met_data)
    
    
    state.lai = (params.slainit * const.M2_AS_HA /
                            const.KG_AS_TONNES / params.cfracts *
                            state.shoot)

    # Specific LAI (m2 onesided/kg DW)
    state.sla = params.slainit


    year = str(control.startyear)
    month = str(control.startmonth)
    day = str(control.startday)
    def __init__(self, fname=None, chk_cmd_line=True, DUMP=False):

        """ Set up model

        Read meterological forcing file and user config file and adjust the
        model parameters, control or initial state attributes that are used
        within the code.

        Parameters:
        ----------
        fname : string
            filename of model parameters, including path
        chk_cmd_line : logical
            parse the cmd line?
        DUMP : logical
            dump a the default parameters to a file

        Returns:
        -------
        Nothing
            Controlling class of the model, runs things.

        """
        # sweep the cmd line
        if chk_cmd_line == True:
            options, args = cmdline_parser()
            DUMP=options.DUMP

        (self.control, self.params,
            self.state, self.files,
            self.fluxes, self.met_data,
            print_opts) = initialise_model_data(fname, DUMP=DUMP)

        # printing stuff
        self.pr = PrintOutput(self.params, self.state, self.fluxes,
                              self.control, self.files, print_opts)

        # print model defaults
        if DUMP == True:
            self.pr.save_default_parameters()
            sys.exit(0)

        if self.control.print_options > 1:
            raise ValueError("Unknown output print option: %s  (try 0 or 1)" %
                             self.control.print_options)

        # set initial lai -> m2/m2
        self.state.lai = (self.params.slainit * const.M2_AS_HA /
                          const.KG_AS_TONNES / self.params.cfracts *
                          self.state.shoot)

        # Specific leaf area (m2 onesided/kg DW)
        self.state.sla = self.params.slainit

        # start date of simulation
        self.date = self.simulation_start_date()

        self.time_constants = ['rateuptake', 'rateloss', 'retransmob',
                                'fdecay', 'fdecaydry', 'rdecay', 'rdecaydry',
                                'bdecay', 'wdecay', 'kdec1', 'kdec2', 'kdec3',
                                'kdec4', 'kdec5', 'kdec6', 'kdec7', 'nuptakez']
        self.correct_rate_constants(output=False)
Пример #7
0
    def __init__(self, fname=None, DUMP=False, spin_up=False):

        """ Set up model

        Read meterological forcing file and user config file and adjust the
        model parameters, control or initial state attributes that are used
        within the code.

        Parameters:
        ----------
        fname : string
            filename of model parameters, including path
        chk_cmd_line : logical
            parse the cmd line?
        DUMP : logical
            dump a the default parameters to a file

        Returns:
        -------
        Nothing
            Controlling class of the model, runs things.

        """
        self.day_output = [] # store daily outputs
        (self.control, self.params,
            self.state, self.files,
            self.fluxes, self.met_data,
            self.print_opts) = initialise_model_data(fname, DUMP=DUMP)
        
        if self.control.water_stress == False:
            sys.stderr.write("**** You have turned off the drought stress")
            sys.stderr.write(", I assume you're debugging??!\n")

        # printing stuff
        self.pr = PrintOutput(self.params, self.state, self.fluxes,
                              self.control, self.files, self.print_opts)
        
        # build list of variables to print
        (self.print_state, self.print_fluxes) = self.pr.get_vars_to_print()
        
        # print model defaults
        if DUMP == True:
            self.pr.save_default_parameters()
            sys.exit(0)
        
        self.correct_rate_constants(output=False)

        # class instances
        self.cs = CarbonSoilFlows(self.control, self.params, self.state,
                                  self.fluxes, self.met_data)
        self.ns = NitrogenSoilFlows(self.control, self.params, self.state,
                                    self.fluxes, self.met_data)
        self.lf = Litter(self.control, self.params, self.state, self.fluxes)
        self.pg = PlantGrowth(self.control, self.params, self.state,
                              self.fluxes, self.met_data)
        
        if self.control.deciduous_model:
            self.pg.calc_carbon_allocation_fracs(0.0)
            self.pg.allocate_stored_c_and_n(init=True)
            self.P = Phenology(self.fluxes, self.state, self.control,
                               self.params.previous_ncd,
                               store_transfer_len=self.params.store_transfer_len)

        # calculate initial C:N ratios and zero annual flux sums
        self.day_end_calculations(0, INIT=True)
        self.state.pawater_root = self.params.wcapac_root
        self.state.pawater_tsoil = self.params.wcapac_topsoil
        self.spin_up = spin_up
        self.state.sla = self.params.slainit # Specific leaf area (m2/kg DW)
        self.state.lai = (self.params.slainit * const.M2_AS_HA /
                          const.KG_AS_TONNES / self.params.cfracts *
                          self.state.shoot)
Пример #8
0
Файл: gday.py Проект: npp97/GDAY
    def __init__(self, fname=None, DUMP=False, spin_up=False, met_header=4):
        """ Set up model

        * Read meterological forcing file
        * Read user config file and adjust the model parameters, control or
          initial state attributes that are used within the code.
        * Setup all class instances...perhaps this isn't the tidyest place for 
          this?
        * Initialise things, zero stores etc.
        
        Parameters:
        ----------
        fname : string
            filename of model parameters, including path
        chk_cmd_line : logical
            parse the cmd line?
        DUMP : logical
            dump a the default parameters to a file
        met_header : int
            row number of met file header with variable names
        Returns:
        -------
        Nothing
            Controlling class of the model, runs things.

        """
        self.day_output = []  # store daily outputs

        # initialise model structures and read met data
        (self.control, self.params, self.state, self.files, self.fluxes,
         self.met_data, self.print_opts) = initialise_model_data(fname,
                                                                 met_header,
                                                                 DUMP=DUMP)

        # params are defined in per year, needs to be per day
        # Important this is done here as rate constants elsewhere in the code
        # are assumed to be in units of days not years!
        self.correct_rate_constants(output=False)

        # class instances
        self.cs = CarbonSoilFlows(self.control, self.params, self.state,
                                  self.fluxes, self.met_data)

        self.ns = NitrogenSoilFlows(self.control, self.params, self.state,
                                    self.fluxes, self.met_data)

        self.lf = Litter(self.control, self.params, self.state, self.fluxes)

        self.pg = PlantGrowth(self.control, self.params, self.state,
                              self.fluxes, self.met_data)

        self.cb = CheckBalance(self.control, self.params, self.state,
                               self.fluxes, self.met_data)

        if self.control.deciduous_model:
            self.pg.calc_carbon_allocation_fracs(0.0, 0, 0)  #comment this!!
            self.pg.allocate_stored_c_and_n(init=True)
            self.P = Phenology(
                self.fluxes,
                self.state,
                self.control,
                self.params.previous_ncd,
                store_transfer_len=self.params.store_transfer_len)

        self.pr = PrintOutput(self.params, self.state, self.fluxes,
                              self.control, self.files, self.print_opts)

        # build list of variables to print
        (self.print_state, self.print_fluxes) = self.pr.get_vars_to_print()

        # print model defaults
        if DUMP == True:
            self.pr.save_default_parameters()
            sys.exit(0)

        # calculate initial stuff, e.g. C:N ratios and zero annual flux sums
        self.day_end_calculations(0, INIT=True)
        self.state.pawater_root = self.params.wcapac_root
        self.state.pawater_topsoil = self.params.wcapac_topsoil
        self.spin_up = spin_up
        self.state.sla = self.params.slainit  # Specific leaf area (m2/kg DW)
        self.state.lai = (self.params.slainit * const.M2_AS_HA /
                          const.KG_AS_TONNES / self.params.cfracts *
                          self.state.shoot)

        # figure out the number of years for simulation and the number of
        # days in each year
        self.years = uniq(self.met_data["year"])
        self.days_in_year = [self.met_data["year"].count(yr) \
                             for yr in self.years]

        if self.control.water_stress == False:
            sys.stderr.write("**** You have turned off the drought stress")
            sys.stderr.write(", I assume you're debugging??!\n")
Пример #9
0
        arg1 = self.params.alpha_j / 4.0
        arg2 = ((ci - gamma_star) / (ci + 2. * gamma_star))

        return arg1 * arg2 * const.MOL_C_TO_GRAMS_C


if __name__ == "__main__":

    from file_parser import initialise_model_data
    from utilities import float_lt, day_length
    import datetime

    fname = "/Users/mdekauwe/src/python/pygday/params/duke_testing.cfg"

    (control, params, state, files, fluxes, met_data,
     print_opts) = initialise_model_data(fname, DUMP=False)

    B = Bewdy(control, params, state, fluxes, met_data)

    state.lai = (params.slainit * const.M2_AS_HA / const.KG_AS_TONNES /
                 params.cfracts * state.shoot)

    # Specific LAI (m2 onesided/kg DW)
    state.sla = params.slainit

    year = str(control.startyear)
    month = str(control.startmonth)
    day = str(control.startday)
    datex = datetime.datetime.strptime((year + month + day), "%Y%m%d")

    #laifname = "/Users/mdekauwe/research/NCEAS_face/GDAY_duke_simulation/experiments/lai"
Пример #10
0
    import numpy as np
    # timing...
    import sys
    import time
    start_time = time.time()

    from file_parser import initialise_model_data
    import datetime
    from utilities import float_eq, float_lt, float_gt, calculate_daylength, uniq

    met_header = 4

    #fname = "/Users/mdekauwe/research/NCEAS_face/GDAY_ornl_simulation/params/NCEAS_or_youngforest.cfg"
    fname = "/Users/mdekauwe/research/FACE/GDAY_simulations/KSCO/experiment/params/NCEAS_KSCO_model_indust.cfg"
    (control, params, state, files, fluxes, met_data,
     print_opts) = initialise_model_data(fname, met_header, DUMP=False)

    control.ps_pathway = "C4"
    if control.ps_pathway == "C3":
        M = MateC3(control, params, state, fluxes, met_data)
    else:
        M = MateC4(control, params, state, fluxes, met_data)

    #flai = "/Users/mdekauwe/research/NCEAS_face/GDAY_ornl_simulation/experiments/silvias_LAI.txt"
    #lai_data = np.loadtxt(flai)

    # Specific LAI (m2 onesided/kg DW)
    state.sla = params.slainit

    project_day = 0