Closed Boberthy-py closed 3 years ago
Are the other files written after calling ml.write_files() ? What system are you on? Maybe changing backslash to forward slash may help..
Thank for the quick response!!
This is the code: I just copied it from example 3, just trying to get my bearings on phydrus
import os import pandas as pd import phydrus as ps import numpy as np
ws = "example_3"
exe = os.path.join(os.getcwd(), "C:\Program Files (x86)\PC-Progress\Hydrus-1D 4.xx\hydrus.exe")
desc = "Root water uptake in a soil profile"
ml = ps.Model(exe_name=exe, ws_name=ws, name="model", description=desc, mass_units="mmol", time_unit="days", length_unit="cm") ml.basic_info["lFlux"] = True ml.basic_info["lShort"] = False
time = [1, 2, 3, 4, 5, 6, 7, 8, 10, 15, 30] ml.add_time_info(tmax=30, print_array=time, dt=0.001)
ml.add_waterflow(model=3, top_bc=3, bot_bc=0)
m = ml.get_empty_material_df(n=1) m.loc[[1, 1]] = [[0.068, 0.38, 0.008, 1.09, 4.8, 0.5]] ml.add_material(m)
nodes = 120 # Disctretize soil column into n elements depth = -300 # Depth of the soil column ihead = -100 # Determine initial Pressure Head
profile = ps.create_profile(bot=depth, dx=abs(depth / (nodes-1)), h=ihead)
tld=0.1 # Lower denstiy at top node bud=0.3 # Upper density bottom node def det_h(nodes,depth, tld=1, lud=1): midnode = int((nodes*(lud+1)/2+((1+tld)/2))/((1+lud)/2+(1+tld)/2))
def get_dx(tld, lud, nnodes, depth):
startdx=depth*2/(nnodes-1)/((1+lud/tld))
enddx = depth/(nnodes-1)*lud/((tld+lud)/2)
return np.linspace(startdx,enddx,nnodes-1)
dx1 = get_dx(tld, 1, midnode, depth/2)
dx2 = get_dx(1, lud, nodes-midnode+1, depth/2)
values1=[0]
value0=0
for x in dx1:
y = value0+x
value0=y
values1.append(y)
values2=[]
value0=depth/2
for x in dx2:
y = value0+x
value0=y
values2.append(y)
profile = np.concatenate((values1, values2), axis=None)
return profile
profile["x"] = det_h(nodes,depth, tld, bud) profile["h"] = np.round(abs(profile["x"])+depth,5) profile.loc[2:78,"Beta"] = 1 ml.add_profile(profile)
ml.add_obs_nodes([0, -300])
bc = {"tAtm": (3, 30), "Prec": (2, 0), "rSoil": (0.1, 0.1), "rRoot": (0.5, 1.5)} atm = pd.DataFrame(bc, index=(3, 30)) ml.add_atmospheric_bc(atm, hcrits=0, hcrita=50000)
ml.add_root_uptake(model=0, crootmax=1, poptm=[-25], omegac=1)
ml.write_input() ml.simulate()
import matplotlib.pyplot as plt dfs = ml.read_obs_node() figx, ax=plt.subplots() for key, df in dfs.items(): dft = df[:][0:8] dft.plot(y="h", use_index=True,ax=ax, label=key) ax.set_ylim(-500,5) ml.plots.profile_information(times=[1, 3, 6]) ml.plots.profile_information("Water Flux", times=[1, 3, 5, 30])
plt.show()
Dear Raoul Collenteur
I'm Yuushi. I'm very sorry to interrupt your discussions.
Thank you for creating such a great python library. But, I have same problem Boberthy-py had.
This is my source code. I use PyCharm. I almost all copied your example code from "https://github.com/phydrus/phydrus/blob/master/examples/hydrus_orig/Example_1%20-%20hydrus%20tutorial.ipynb"
""" import phydrus as ps
ws = "example_1" exe = "hydrus.exe"
desc = "Infiltration of Water into a Single-Layered Soil Profile"
ml = ps.Model(exe_name=exe, ws_name=ws, name="model", description=desc, mass_units="mmol", time_unit="days", length_unit="cm") ml.basic_info["lFlux"] = True ml.basic_info["lShort"] = False
ml.add_time_info(tmax=1, print_times=True, nsteps=12, dt=0.001)
ml.add_waterflow(top_bc=0, bot_bc=4)
m = ml.get_empty_material_df(n=1) m.loc[[1, 1]] = [[0.078, 0.43, 0.036, 1.56, 24.96, 0.5]] ml.add_material(m)
elements = 100 # Disctretize soil column into n elements depth = -100 # Depth of the soil column ihead = -100 # Determine initial Pressure Head
profile = ps.create_profile(bot=depth, dx=abs(depth / elements), h=ihead) profile.iloc[0, 1] = 1 # Define initial Pressure Head at the surface ml.add_profile(profile) # Add the profile
ml.add_obs_nodes([-20, -40, -60, -80, -100])
ml.write_input(verbose=False) rs = ml.simulate() print(rs)
ml.plots.profile_information("Water Content") """
and this is the result.
"""
Successfully wrote example_1\SELECTOR.IN
Successfully wrote example_1\PROFILE.DAT
CompletedProcess(args=['hydrus.exe', 'example_1', '-1'], returncode=3221225781)
Traceback (most recent call last):
File "C:/Users/qqhr3/PycharmProjects/software/phydrus_test2.py", line 39, in
I downloaded the pre-compiled hydrus executable from "https://github.com/phydrus/phydrus/blob/master/source/hydrus.exe" and I copied it to the working folder where my python file is located.
I thought ml.write_input() and ml.simulate() worked well because the result showed below sentences. """ Successfully wrote example_1\SELECTOR.IN Successfully wrote example_1\PROFILE.DAT CompletedProcess(args=['hydrus.exe', 'example_1', '-1'], returncode=3221225781) """ However, I got FileNotFoundError when executing ml.plots.profile_information("Water Content") There are no output files in example_1 files and current directory. I'm not good at computing science and programming and I'm very sorry for my poor writing. If you have any ideas and free time, could you comment this thread?
Best regards,
Hi Yuushi. We will check on this! Are you working on Windows/Linux/Mac?
Thank you for your quick reply! I'm working on Windows.
Hello. I've solved that problem! I could get output files at example1 folder! Thank you very much!
Hey Hi!
I'm trying to run Phydrus examples and I'm getting the error that the .OUT files aren't in the folder that it creates? (FileNotFoundError: File example_3\OBS_NODE.OUT has not been found.)
I'm not sure what I'm missing or what step I skipped?
Thanks for the help! -Boberthy