# -*- coding: utf-8 -*- # @Author: Alan Lau # @Date: 2017-09-06 17:47:51 # @Last Modified by: Alan Lau # @Last Modified time: 2017-09-06 17:47:51 from canopy import Canopy import numpy as np from PIL import Image # dataset = np.random.rand(10, 3) dataset = Image.open('1.jpg') image = np.array(dataset, dtype=np.float64) / 255 # print(image) print(image.shape) # print(dataset) gc = Canopy(image) gc.setThreshold(0.6, 0.4) canopies = gc.clustering() print(len(canopies))
def worker(potentials, pft_height, pft_la_sa, pft_sapwood_density, pft_name, p, total_exp, cpu_count, node): g0 = 0.0 theta_J = 0.85 Rd25 = 0.92 Q10 = 1.92 Vcmax25 = p.Vcmax Jmax25 = p.Jmax Eav = 58550.0 deltaSv = 629.26 Eaj = 29680. deltaSj = 631.88 FAO = False psi_stem0 = -0.5 psi_f = p.psiv kp_sat = p.kpsat g1 = p.g1 s50 = p.s50 sf = p.sf F = Canopy(g1=g1, g0=g0, theta_J=theta_J, Rd25=Rd25, Q10=Q10, Vcmax25=Vcmax25, Jmax25=Jmax25, Eav=Eav, deltaSv=deltaSv, Eaj=Eaj, deltaSj=deltaSj) D = Desica(psi_stem0=psi_stem0, psi_f=psi_f, F=F, g1=g1, stop_dead=True, FAO=FAO, kp_sat=kp_sat, s50=s50, sf=sf, height=pft_height, la_sa=pft_la_sa, sapwood_density=pft_sapwood_density) names = ['Tmax', 'Dmax', 'Dmean', 'gmin', 'lai', 'p50', 'Cl', 'Cs', \ 'b', 'psi_e', 'depth', 'psi_stem', 'plc', 'day_of_death'] df = pd.DataFrame(columns=names) #count = 0 #last_progress = 9.0 for gmin, lai, p50, Cl, Cs, soil_depth, b, psi_e in potentials: #""" (D.gmin, D.lai, D.p50, D.Cl, D.Cs, D.soil_depth, D.b, D.psi_e) = gmin, lai, p50, Cl, Cs, soil_depth, b, psi_e out, day_of_death = D.run_simulation(met) psi_stem = out.psi_stem.iloc[-1] plc = out.plc.iloc[-1] result = [Tmax, Dmax, Dmean, gmin, lai, p50, Cl, Cs, \ b, psi_e, soil_depth, psi_stem, plc, day_of_death] print(day_of_death) print(p) print(" ") s = pd.Series(result, index=df.columns) df = df.append(s, ignore_index=True) #""" #progress = (count / total_exp) * 100.0 #if progress > last_progress: # print(pft_name, "--", round(progress,3), count, ":", total_exp) # last_progress += 9. #count += 1 odir = "outputs" if not os.path.exists(odir): os.makedirs(odir) ofn = "%s_trait_sensitivity_%d_%d.csv" % (pft_name, node, cpu_count) ofname = os.path.join(odir, ofn) df.to_csv(ofname, index=False)
# -*- coding: utf-8 -*- # @Author: Alan Lau # @Date: 2017-09-06 17:47:51 # @Last Modified by: Alan Lau # @Last Modified time: 2017-09-06 17:47:51 from canopy import Canopy import numpy as np dataset = np.random.rand(500, 2) gc = Canopy(dataset) gc.setThreshold(0.6, 0.4) canopies = gc.clustering() print(len(canopies))
deltaSj = 631.88 FAO = False psi_stem0 = -0.5 psi_f = p.psiv kp_sat = p.kpsat g1 = p.g1 s50 = p.s50 sf = p.sf AL = lai_mu psi_e = -1.32 * c.KPA_2_MPA # Sandy clay loam, MPa b = 6.77 #psi_e = -3.17 * c.KPA_2_MPA # Silty clay clay loam, MPa #b = 10.39 # Silty clay, SW retention curve param F = Canopy(g1=g1, g0=g0, theta_J=theta_J, Rd25=Rd25, Q10=Q10, Vcmax25=Vcmax25, Jmax25=Jmax25, Eav=Eav, deltaSv=deltaSv, Eaj=Eaj, deltaSj=deltaSj) D = Desica(psi_stem0=psi_stem0, psi_f=psi_f, F=F, g1=g1, stop_dead=True, FAO=FAO, kp_sat=kp_sat, s50=s50, sf=sf, AL=AL, force_refilling=False) out, day_of_death = D.run_simulation(met) #odir = "/Users/mdekauwe/Desktop/refilling_plots" #odir = "/Users/mdekauwe/Desktop/new_plots" odir = "/Users/mdekauwe/Desktop/old_plots" if not os.path.exists(odir): os.makedirs(odir) plot_time_to_mortality(odir, out, time_step, to_screen=False, pft=pft)
def main(pft_name, p, ranges): time_step = 30 lat = -35.76 lon = 148.0 g0 = 0.0 theta_J = 0.85 Rd25 = 0.92 Q10 = 1.92 Vcmax25 = p.Vcmax Jmax25 = p.Jmax Eav = 58550.0 deltaSv = 629.26 Eaj = 29680. deltaSj = 631.88 FAO = False psi_stem0 = -0.5 psi_f = p.psiv kp_sat = p.kpsat g1 = p.g1 s50 = p.s50 sf = p.sf AL = 2.0 F = Canopy(g1=g1, g0=g0, theta_J=theta_J, Rd25=Rd25, Q10=Q10, Vcmax25=Vcmax25, Jmax25=Jmax25, Eav=Eav, deltaSv=deltaSv, Eaj=Eaj, deltaSj=deltaSj) D = Desica(psi_stem0=psi_stem0, psi_f=psi_f, F=F, g1=g1, stop_dead=True, FAO=FAO, kp_sat=kp_sat, s50=s50, sf=sf, AL=AL) names = ['Tmax', 'Dmax', 'Dmean', 'gmin', 'lai', 'p50', 'Cl', 'Cs', \ 'depth', 'psi_stem', 'cwd', 'plc', 'day_of_death'] df = pd.DataFrame(columns=names) Tmax = 35. RH = 10. met = generate_met_data(Tmin=15, Tmax=Tmax, RH=RH, ndays=720, lat=lat, lon=lon, time_step=time_step) Dmax = np.max(met.vpd) Dmean = np.mean(met.vpd) for gmin, AL, p50, Cl, Cs, soil_depth, in \ itertools.product(*ranges): #""" (D.gmin, D.AL, D.p50, D.Cl, D.Cs, D.soil_depth) = gmin, AL, p50, Cl, Cs, soil_depth out, day_of_death = D.run_simulation(met) psi_stem = out.psi_stem.iloc[-1] plc = out.plc.iloc[-1] cwd = out.cwd.iloc[-1] result = [Tmax, Dmax, Dmean, gmin, AL, p50, Cl, Cs, \ soil_depth, psi_stem, cwd, plc, day_of_death] s = pd.Series(result, index=df.columns) df = df.append(s, ignore_index=True) #""" return df
time_step = 30 met = generate_met_data(Tmin=10, RH=30, ndays=200, time_step=time_step) psi_stem0 = 0. # initial stem water potential, MPa AL = 6. # plant leaf area, m2 p50 = -4. # xylem pressure inducing 50% loss of hydraulic conductivity # due to embolism, MPa psi_f = -3. # reference potential for Tuzet model, MPa gmin = 10. # minimum stomatal conductance, mmol m-2 s-1 Cl = 10000. # leaf capacitance, mmol MPa-1 (total plant) Cs = 120000. # stem capacitance, mmol MPa-1 g1 = 4.0 # sensitivity of stomatal conductance to the assimilation # rate, kPa F = Canopy(g1=g1) D = Desica(psi_stem0=psi_stem0, AL=AL, p50=p50, psi_f=psi_f, gmin=gmin, Cl=Cl, Cs=Cs, F=F, g1=g1, nruns=3, stop_dead=True) out = D.run_simulation(met) make_plot(out, time_step) plot_swp_sw(out)