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")