def run_sim(self): """ Run model simulation! """ project_day = 0 # figure out the number of years for simulation and the number of # days in each year years = uniq(self.met_data["year"]) days_in_year = [self.met_data["year"].count(yr) for yr in years] # =============== # # YEAR LOOP # # =============== # for i, yr in enumerate(years): self.day_output = [] # empty daily storage list for outputs daylen = calculate_daylength(days_in_year[i], self.params.latitude) if self.control.deciduous_model: self.P.calculate_phenology_flows(daylen, self.met_data, days_in_year[i], project_day) self.zero_stuff() # =============== # # DAY LOOP # # =============== # for doy in xrange(days_in_year[i]): # litterfall rate: C and N fluxes (fdecay, rdecay) = self.lf.calculate_litter(doy) # co2 assimilation, N uptake and loss self.pg.calc_day_growth(project_day, fdecay, rdecay, daylen[doy], doy, float(days_in_year[i]), i) # soil C & N model fluxes self.cs.calculate_csoil_flows(project_day) self.ns.calculate_nsoil_flows() # calculate C:N ratios and increment annual flux sums self.day_end_calculations(project_day, days_in_year[i]) #print self.state.shoot, self.state.lai #print self.fluxes.gpp * 100, self.state.lai # =============== # # END OF DAY # # =============== # self.save_daily_outputs(yr, doy+1) project_day += 1 # =============== # # END OF YEAR # # =============== # if self.control.deciduous_model: self.pg.allocate_stored_c_and_n(init=False) if self.control.print_options == "DAILY" and self.spin_up == False: self.print_output_file() # close output files if self.control.print_options == "END" and self.spin_up == False: self.print_output_file() self.pr.clean_up()
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"]) # years = years[:-1] # dump last year as missing "site" LAI days_in_year = [met_data["year"].count(yr) for yr in years] for i, yr in enumerate(years): daylen = calculate_daylength(days_in_year[i], params.latitude) for doy in xrange(days_in_year[i]): state.wtfac_root = 1.0 # state.lai = lai_data[project_day] state.lai = 2.0 if state.lai > 0.0: state.shootnc = 0.03 # state.shootn / state.shoot state.ncontent = state.shootnc * params.cfracts / params.sla * const.KG_AS_G else: state.ncontent = 0.0 if float_lt(state.lai, params.lai_cover): frac_gcover = state.lai / params.lai_cover else: frac_gcover = 1.0
def run_sim(self): """ Run model simulation! """ # local variables years = self.years days_in_year = self.days_in_year # =============== # # YEAR LOOP # # =============== # project_day = 0 for i, yr in enumerate(years): self.day_output = [] # empty daily storage list for outputs daylen = calculate_daylength(days_in_year[i], self.params.latitude) if self.control.deciduous_model: self.P.calculate_phenology_flows(daylen, self.met_data, days_in_year[i], project_day) self.zero_stuff() # =============== # # DAY LOOP # # =============== # for doy in xrange(days_in_year[i]): #for pft in xrange(4): # litterfall rate: C and N fluxes (fdecay, rdecay) = self.lf.calculate_litter(doy) # co2 assimilation, N uptake and loss self.pg.calc_day_growth(project_day, fdecay, rdecay, daylen[doy], doy, float(days_in_year[i]), i) # soil C & N model fluxes self.cs.calculate_csoil_flows(project_day) self.ns.calculate_nsoil_flows(project_day) # calculate C:N ratios and increment annual flux sums self.day_end_calculations(project_day, days_in_year[i]) #print self.state.lai, self.fluxes.gpp*100, self.state.pawater_root, self.state.shootnc # =============== # # END OF DAY # # =============== # if not self.spin_up: self.save_daily_outputs(yr, doy + 1) # check the daily water balance #self.cb.check_water_balance(project_day) project_day += 1 # =============== # # END OF YEAR # # =============== # if self.control.deciduous_model: print "**", self.state.cstore self.pg.allocate_stored_c_and_n(init=False) if self.control.print_options == "DAILY" and not self.spin_up: self.print_output_file() # close output files if self.control.print_options == "END" and not self.spin_up: self.print_output_file() # only close printing file if not in spin up mode as we have yet # written the daily output... if self.spin_up: return (yr, doy + 1) else: self.pr.clean_up()
def run_sim(self): """ Run model simulation! """ # local variable years = self.years days_in_year = self.days_in_year if self.control.disturbance: # Figure out if any years have a disturbance self.db.initialise(years) # ===================== # # Y E A R L O O P # # ===================== # project_day = 0 for i, yr in enumerate(years): self.day_output = [] # empty daily storage list for outpu daylen = calculate_daylength(days_in_year[i], self.params.latitude) if self.control.deciduous_model: self.P.calculate_phenology_flows(daylen, self.met_data, days_in_year[i], project_day) # Change window size to length of growing season self.pg.sma.window_size = self.P.growing_seas_len self.zero_stuff() # =================== # # D A Y L O O P # # =================== # for doy in xrange(days_in_year[i]): # standard litter calculation # litterfall rate: C and N fluxe (fdecay, rdecay) = self.lf.calculate_litter(doy) # Fire Disturbance? if (self.control.disturbance != 0 and self.params.disturbance_doy == doy): self.db.check_for_fire(yr, self.pg) # Hurricane? elif (self.control.hurricane == 1 and self.params.hurricane_yr == yr and self.params.hurricane_doy == doy): self.db.hurricane() # photosynthesis & growth fsoilT = self.cs.soil_temp_factor(project_day) self.pg.calc_day_growth(project_day, fdecay, rdecay, daylen[doy], doy, float(days_in_year[i]), i, fsoilT) # soil C & N calculation self.cs.calculate_csoil_flows(project_day, doy) self.ns.calculate_nsoil_flows(project_day, doy) if self.control.ncycle == False: # Turn off all N calculations self.reset_all_n_pools_and_fluxes() # calculate C:N ratios and increment annual flux sum self.day_end_calculations(days_in_year[i]) # checking if we died during the timestep # - added for desert simulation if (not self.control.deciduous_model and self.control.disturbance == 0): self.are_we_dead() #print self.state.plantc, self.state.soilc #print yr, doy, self.state.lai, self.fluxes.gpp*100 #print self.fluxes.gpp*100, self.state.prev_sma # ======================= # # E N D O F D A Y # # ======================= # if not self.spin_up: self.save_daily_outputs(yr, doy+1) # check the daily water balance #self.cb.check_water_balance(project_day) project_day += 1 # ========================= # # E N D O F Y E A R # # ========================= # # Allocate stored C&N for the following year if self.control.deciduous_model: # Using average alloc fracs across growing season instead #self.pg.calc_carbon_allocation_fracs(0.0) #comment this!! self.pg.calculate_average_alloc_fractions(self.P.growing_seas_len) self.pg.allocate_stored_c_and_n(init=False) # reset the stress buffer at the end of the growing season self.pg.sma.reset_stream() #print self.fluxes.alleaf, self.fluxes.alroot, \ # (self.fluxes.albranch+self.fluxes.alstem) #print # GDAY died in the previous year, re-establish gday for the next yr # - added for desert simulation if (self.dead and not self.control.deciduous_model and self.control.disturbance == 0): self.re_establish_gday() if self.control.print_options == "DAILY" and not self.spin_up: self.print_output_file() # close output file if self.control.print_options == "END" and not self.spin_up: self.print_output_file() # only close printing file if not in spin up mode as we have ye # written the daily output... if self.spin_up: return (yr, doy+1) else: # Need to pass the project day to calculate NROWS for .hdr file self.pr.clean_up(project_day)
# Specific LAI (m2 onesided/kg DW) state.sla = params.slainit project_day = 0 # figure out the number of years for simulation and the number of # days in each year years = uniq(met_data["year"]) #years = years[:-1] # dump last year as missing "site" LAI days_in_year = [met_data["year"].count(yr) for yr in years] for i, yr in enumerate(years): daylen = calculate_daylength(days_in_year[i], params.latitude) for doy in xrange(days_in_year[i]): state.wtfac_root = 1.0 #state.lai = lai_data[project_day] state.lai = 2.0 if state.lai > 0.0: state.shootnc = 0.03 #state.shootn / state.shoot state.ncontent = (state.shootnc * params.cfracts / state.sla * const.KG_AS_G) else: state.ncontent = 0.0 if float_lt(state.lai, params.lai_cover): frac_gcover = state.lai / params.lai_cover else:
def run_sim(self): """ Run model simulation! """ # class instances cf = CarbonFlows(self.control, self.params, self.state, self.fluxes, self.met_data) nf = NitrogenFlows(self.control, self.params, self.state, self.fluxes) lf = LitterProduction(self.control, self.params, self.state, self.fluxes) pg = PlantGrowth(self.control, self.params, self.state, self.fluxes, self.met_data) cpl = CarbonPools(self.control, self.params, self.state, self.fluxes) npl = NitrogenPools(self.control, self.params, self.state, self.fluxes, self.met_data) ################## self.control.deciduous_model = 1 self.control.numyears_sim = 12 self.state.nc_fy = 0.06 self.state.npp_store = 5.2154 ################## if self.control.deciduous_model: total = self.initialise_deciduous_model() # In the first year we don't have last years data, so I have # precalculated the average of all the november-jan chilling values last_yrs_accumulated_ncd = 17.0 P = Phenology(self.fluxes, self.state, last_yrs_accumulated_ncd) # calculate initial C:N ratios and zero annual flux sums self.derive(1, self.date, INIT=True) self.state.pawater_root = self.params.wcapac_root self.state.pawater_tsoil = self.state.pawater_tsoil project_day = 0 for yr in xrange(self.control.startyear, self.control.startyear+self.control.numyears_sim-1): yr_days = calc_days_in_year(self.date.year) daylen = calculate_daylength(self.date, yr_days, self.params.latitude) if self.control.deciduous_model: self.zero_annual_sums() P.calculate_phenology_flows(daylen, self.date, self.met_data, yr_days) for d in xrange(yr_days): # litterfall rate: C and N fluxes (fdecay, rdecay) = lf.calculate_litter_flows(d) # co2 assimilation, N uptake and loss pg.grow(project_day, self.date, fdecay, rdecay, daylen[d], doy=d) # soil model fluxes cf.calculate_cflows(project_day) nf.calculate_nflows() self.fluxes.nep = self.calculate_nep() # soil model - update pools (cact, cslo, cpas) = cpl.calculate_cpools() npl.calculate_npools(cact, cslo, cpas, project_day) # calculate C:N ratios and increment annual flux sums self.derive(project_day, self.date) print self.fluxes.gpp * 100, self.state.lai if self.control.print_options == 0: self.pr.save_daily_output(project_day + 1, self.date) self.increment_date(yr_days) project_day += 1 sys.exit() # =============== # # END OF THE YEAR # # =============== # if self.control.deciduous_model: self.allocate_stored_c_and_n(total) if self.control.print_options == 1: # need to save initial SLA to current one! self.params.slainit = (self.state.lai / const.M2_AS_HA * const.KG_AS_TONNES * self.params.cfracts / self.state.shoot) self.correct_rate_constants(output=True) self.pr.save_state() # house cleaning, close ouput files self.pr.tidy_up()
def run_sim(self): """ Run model simulation! """ # local variable years = self.years days_in_year = self.days_in_year if self.control.disturbance: # Figure out if any years have a disturbance self.db.initialise(years) # ===================== # # Y E A R L O O P # # ===================== # project_day = 0 for i, yr in enumerate(years): self.day_output = [] # empty daily storage list for outpu daylen = calculate_daylength(days_in_year[i], self.params.latitude) if self.control.deciduous_model: self.P.calculate_phenology_flows(daylen, self.met_data, days_in_year[i], project_day) # Change window size to length of growing season self.pg.sma.window_size = self.P.growing_seas_len self.zero_stuff() # =================== # # D A Y L O O P # # =================== # for doy in xrange(days_in_year[i]): # standard litter calculation # litterfall rate: C and N fluxe (fdecay, rdecay) = self.lf.calculate_litter(doy) # Fire Disturbance? if (self.control.disturbance != 0 and self.params.disturbance_doy == doy): self.db.check_for_fire(yr, self.pg) # Hurricane? elif (self.control.hurricane == 1 and self.params.hurricane_yr == yr and self.params.hurricane_doy == doy): self.db.hurricane() # photosynthesis & growth fsoilT = self.cs.soil_temp_factor(project_day) self.pg.calc_day_growth(project_day, fdecay, rdecay, daylen[doy], doy, float(days_in_year[i]), i, fsoilT) # soil C & N calculation self.cs.calculate_csoil_flows(project_day, doy) self.ns.calculate_nsoil_flows(project_day, doy) if self.control.ncycle == False: # Turn off all N calculations self.reset_all_n_pools_and_fluxes() # calculate C:N ratios and increment annual flux sum self.day_end_calculations(days_in_year[i]) # checking if we died during the timestep # - added for desert simulation if (not self.control.deciduous_model and self.control.disturbance == 0): self.are_we_dead() #print self.state.plantc, self.state.soilc #print yr, doy, self.state.lai, self.fluxes.gpp*100 #print self.fluxes.gpp*100, self.state.prev_sma # ======================= # # E N D O F D A Y # # ======================= # if not self.spin_up: self.save_daily_outputs(yr, doy + 1) # check the daily water balance #self.cb.check_water_balance(project_day) project_day += 1 # ========================= # # E N D O F Y E A R # # ========================= # # Allocate stored C&N for the following year if self.control.deciduous_model: # Using average alloc fracs across growing season instead #self.pg.calc_carbon_allocation_fracs(0.0) #comment this!! self.pg.calculate_average_alloc_fractions( self.P.growing_seas_len) self.pg.allocate_stored_c_and_n(init=False) # reset the stress buffer at the end of the growing season self.pg.sma.reset_stream() #print self.fluxes.alleaf, self.fluxes.alroot, \ # (self.fluxes.albranch+self.fluxes.alstem) #print # GDAY died in the previous year, re-establish gday for the next yr # - added for desert simulation if (self.dead and not self.control.deciduous_model and self.control.disturbance == 0): self.re_establish_gday() if self.control.print_options == "DAILY" and not self.spin_up: self.print_output_file() # close output file if self.control.print_options == "END" and not self.spin_up: self.print_output_file() # only close printing file if not in spin up mode as we have ye # written the daily output... if self.spin_up: return (yr, doy + 1) else: # Need to pass the project day to calculate NROWS for .hdr file self.pr.clean_up(project_day)
def run_sim(self): """ Run model simulation! """ # local variables years = self.years days_in_year = self.days_in_year # =============== # # YEAR LOOP # # =============== # project_day = 0 for i, yr in enumerate(years): self.day_output = [] # empty daily storage list for outputs daylen = calculate_daylength(days_in_year[i], self.params.latitude) if self.control.deciduous_model: self.P.calculate_phenology_flows(daylen, self.met_data, days_in_year[i], project_day) self.zero_stuff() # =============== # # DAY LOOP # # =============== # for doy in xrange(days_in_year[i]): # for pft in xrange(4): # litterfall rate: C and N fluxes (fdecay, rdecay) = self.lf.calculate_litter(doy) # co2 assimilation, N uptake and loss self.pg.calc_day_growth(project_day, fdecay, rdecay, daylen[doy], doy, float(days_in_year[i]), i) # soil C & N model fluxes self.cs.calculate_csoil_flows(project_day) self.ns.calculate_nsoil_flows(project_day) # calculate C:N ratios and increment annual flux sums self.day_end_calculations(project_day, days_in_year[i]) print self.state.lai, self.fluxes.gpp * 100, self.state.pawater_root, self.state.shootnc # =============== # # END OF DAY # # =============== # if not self.spin_up: self.save_daily_outputs(yr, doy + 1) # check the daily water balance # self.cb.check_water_balance(project_day) project_day += 1 # =============== # # END OF YEAR # # =============== # if self.control.deciduous_model: print "**", self.state.cstore self.pg.allocate_stored_c_and_n(init=False) if self.control.print_options == "DAILY" and not self.spin_up: self.print_output_file() # close output files if self.control.print_options == "END" and not self.spin_up: self.print_output_file() # only close printing file if not in spin up mode as we have yet # written the daily output... if self.spin_up: return (yr, doy + 1) else: self.pr.clean_up()