def init_caete_dyn(self, input_fpath, stime_i, co2, pls_table, tsoil, ssoil): """ PREPARE A GRIDCELL TO RUN TODO adapt to change climatic data/ maybe another method input_fpath:(str or pathlib.Path) path to Files with climate and soil data co2: (list) a alist (association list) with yearly cCO2 ATM data(yyyy\t[CO2]\n) pls_table: np.ndarray with functional traits of a set of PLant life strategies """ assert self.filled == False, "already done" self.input_fpath = Path(os.path.join(input_fpath, self.input_fname)) assert self.input_fpath.exists() with bz2.BZ2File(self.input_fpath, mode='r') as fh: self.data = pkl.load(fh) os.makedirs(self.out_dir, exist_ok=True) self.flush_data = 0 self.pr = self.data['pr'] self.ps = self.data['ps'] self.rsds = self.data['rsds'] self.tas = self.data['tas'] self.rhs = self.data['hurs'] # SOIL AND NUTRIENTS self.input_nut = [] self.nutlist = ['tn', 'tp', 'ap', 'ip', 'op'] for nut in self.nutlist: self.input_nut.append(self.data[nut]) self.soil_dict = dict(zip(self.nutlist, self.input_nut)) self.data = None # TIME self.stime = copy.deepcopy(stime_i) self.calendar = self.stime['calendar'] self.time_index = self.stime['time_index'] self.time_unit = self.stime['units'] self.ssize = self.time_index.size self.sind = int(self.time_index[0]) self.eind = int(self.time_index[-1]) self.start_date = cftime.num2date(self.time_index[0], self.time_unit, calendar=self.calendar) self.end_date = cftime.num2date(self.time_index[-1], self.time_unit, calendar=self.calendar) # OTHER INPUTS self.pls_table = pls_table.copy() self.neighbours = neighbours_index(self.pos, mask) self.soil_temp = st.soil_temp_sub(self.tas[:1095] - 273.15) # Prepare co2 inputs (we have annually means) self.co2_data = copy.deepcopy(co2) self.tsoil = [] self.emaxm = [] # STATE self.wp_water_upper = np.float64(0.1) # vol/vol self.wp_water_lower = np.float64(0.1) # vol/vol self.wp_water_upper_mm = self.wp_water_upper * 300.0 self.wp_water_lower_mm = self.wp_water_lower * 700.0 self.wp_sat_water_upper_ratio = tsoil[0][self.y, self.x].copy() self.wp_field_capacity_upper = tsoil[1][self.y, self.x].copy() self.wp_wilting_point_upper = tsoil[2][self.y, self.x].copy() self.wp_sat_water_lower_ratio = ssoil[0][self.y, self.x].copy() self.wp_field_capacity_lower = ssoil[1][self.y, self.x].copy() self.wp_wilting_point_lower = ssoil[2][self.y, self.x].copy() self.wp_sat_water_upper_mm = self.wp_sat_water_upper_ratio * 300.0 self.wp_sat_water_lower_mm = self.wp_sat_water_lower_ratio * 700.0 self.wmax_mm = np.float64(self.wp_sat_water_upper_mm + self.wp_sat_water_lower_mm) # start biomass self.vp_cleaf, self.vp_croot, self.vp_cwood = m.spinup2( 1.0, self.pls_table) a, b, c, d = m.pft_area_frac(self.vp_cleaf, self.vp_croot, self.vp_cwood, self.pls_table[6, :]) self.vp_lsid = np.where(a > 0.0)[0] del a, b, c, d self.vp_dcl = np.zeros(shape=(npls, ), order='F') self.vp_dca = np.zeros(shape=(npls, ), order='F') self.vp_dcf = np.zeros(shape=(npls, ), order='F') self.vp_ocp = np.zeros(shape=(npls, ), order='F') self.vp_sto = np.zeros(shape=(3, npls), order='F') # # # SOIL START self.sp_csoil = np.zeros(shape=(4, ), order='F') + 1.0 self.sp_snc = np.zeros(shape=(8, ), order='F') self.sp_available_p = self.soil_dict['ap'] self.sp_available_n = 0.2 * self.soil_dict['tn'] self.sp_in_n = 0.5 * self.soil_dict['tn'] self.sp_so_n = 0.3 * self.soil_dict['tn'] self.sp_so_p = self.soil_dict['tp'] - sum(self.input_nut[2:]) self.sp_in_p = self.soil_dict['ip'] self.sp_uptk_costs = np.zeros(npls, order='F') self.sp_organic_n = 0.01 self.sp_sorganic_n = 0.01 self.sp_organic_p = 0.01 self.sp_sorganic_p = 0.01 self.outputs = dict() self.filled = True return None
def init_caete_dyn(self, input_fpath, stime_i, co2, pls_table): """ input_fpath: Files with climate and soil data co2: (list) a alist (association list) with yearly cCO2 ATM data pls_table: np.ndarray with functional traits of a set of PLant life strategies name: str a name for the gridcell group""" assert self.filled == False, "already done" self.input_fpath = Path(os.path.join(input_fpath, self.input_fname)) assert self.input_fpath.exists() with bz2.BZ2File(self.input_fpath, mode='r') as fh: self.data = pkl.load(fh) os.makedirs(self.out_dir, exist_ok=True) self.flush_data = 0 self.pr = self.data['pr'] self.ps = self.data['ps'] self.rsds = self.data['rsds'] self.tas = self.data['tas'] self.rhs = self.data['hurs'] # SOIL AND NUTRIENTS self.input_nut = [] self.nutlist = ['tn', 'tp', 'ap', 'ip', 'op'] for nut in self.nutlist: self.input_nut.append(self.data[nut]) self.soil_dict = dict(zip(self.nutlist, self.input_nut)) self.data = None # TIME self.stime = copy.deepcopy(stime_i) self.calendar = self.stime['calendar'] self.time_index = self.stime['time_index'] self.time_unit = self.stime['units'] self.ssize = self.time_index.size self.sind = int(self.time_index[0]) self.eind = int(self.time_index[-1]) self.start_date = cftime.num2date(self.time_index[0], self.time_unit, calendar=self.calendar) self.end_date = cftime.num2date(self.time_index[-1], self.time_unit, calendar=self.calendar) # OTHER INPUTS self.pls_table = pls_table.copy() self.neighbours = neighbours_index(self.pos, mask) self.soil_temp = st.soil_temp_sub(self.tas[:1095] - 273.15) # Prepare co2 inputs (we have annually means) self.co2_data = copy.deepcopy(co2) # STATE self.wfim = None self.gfim = None self.sfim = None self.wp_water = 0.01 self.wp_ice = 0.0 self.wp_snow = 0.0 self.tsoil = [] self.emaxm = [] # start biomass self.vp_cleaf, self.vp_croot, self.vp_cwood = m.spinup2( 1.0, self.pls_table) a, b, c, d = m.pft_area_frac(self.vp_cleaf, self.vp_croot, self.vp_cwood, self.pls_table[6, :]) self.vp_lsid = np.where(a > 0.0)[0] del a, b, c, d self.vp_csap = np.zeros(shape=(npls, ), order='F') self.vp_cheart = np.zeros(shape=(npls, ), order='F') self.vp_dcl = np.zeros(shape=(npls, ), order='F') self.vp_dca = np.zeros(shape=(npls, ), order='F') self.vp_dcf = np.zeros(shape=(npls, ), order='F') self.vp_ocp = np.zeros(shape=(npls, ), order='F') self.vp_sto = np.zeros(shape=(3, npls), order='F') # # # SOIL START self.sp_csoil = np.zeros(shape=(4, ), order='F') + 1.0 self.sp_snc = np.zeros(shape=(8, ), order='F') self.sp_available_p = self.soil_dict['ap'] self.sp_available_n = 0.2 * self.soil_dict['tn'] self.sp_in_n = 0.5 * self.soil_dict['tn'] self.sp_so_n = 0.3 * self.soil_dict['tn'] self.sp_so_p = self.soil_dict['tp'] - sum(self.input_nut[2:]) self.sp_in_p = self.soil_dict['ip'] self.sp_uptk_costs = np.zeros(npls, order='F') self.sp_organic_n = 0.01 self.sp_sorganic_n = 0.01 self.sp_organic_p = 0.01 self.sp_sorganic_p = 0.01 self.outputs = dict() self.filled = True return None