phydrus / phydrus

:sweat_drops: Python implementation of the HYDRUS-1D unsaturated zone model
https://phydrus.readthedocs.io/
GNU Lesser General Public License v3.0
82 stars 33 forks source link

.OUT Files Not Found #12

Closed Boberthy-py closed 3 years ago

Boberthy-py commented 3 years ago

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

raoulcollenteur commented 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..

Boberthy-py commented 3 years ago

Thank for the quick response!!

This is the code: I just copied it from example 3, just trying to get my bearings on phydrus

1

import os import pandas as pd import phydrus as ps import numpy as np

2

Folder for Hydrus files to be stored

ws = "example_3"

Path to folder containing hydrus.exe

exe = os.path.join(os.getcwd(), "C:\Program Files (x86)\PC-Progress\Hydrus-1D 4.xx\hydrus.exe")

Description

desc = "Root water uptake in a soil profile"

Create model

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)

3

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)

4

nodes = 120 # Disctretize soil column into n elements depth = -300 # Depth of the soil column ihead = -100 # Determine initial Pressure Head

Create Profile

profile = ps.create_profile(bot=depth, dx=abs(depth / (nodes-1)), h=ihead)

Discretize profile based on node density

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)

5

Add observation nodes at depth

ml.add_obs_nodes([0, -300])

6

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)

7

ml.add_root_uptake(model=0, crootmax=1, poptm=[-25], omegac=1)

8

ml.write_input() ml.simulate()

9

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

uuuu-s commented 3 years ago

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"

Description

desc = "Infiltration of Water into a Single-Layered Soil Profile"

Create model

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

Create Profile

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

Add observation nodes at depth

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 ml.plots.profile_information("Water Content") File "C:\Users\qqhr3\PycharmProjects\software\venv\lib\site-packages\phydrus\plot.py", line 112, in profile_information dfs = self.ml.read_nod_inf(times=times) File "C:\Users\qqhr3\PycharmProjects\software\venv\lib\site-packages\phydrus\model.py", line 1234, in read_nod_inf data = read_nod_inf(path=path, times=times) File "C:\Users\qqhr3\PycharmProjects\software\venv\lib\site-packages\phydrus\decorators.py", line 10, in _check_file_path "File {} has not been found.".format(path)) FileNotFoundError: File example_1\NOD_INF.OUT has not been found. """

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,

mvremec commented 3 years ago

Hi Yuushi. We will check on this! Are you working on Windows/Linux/Mac?

uuuu-s commented 3 years ago

Thank you for your quick reply! I'm working on Windows.

uuuu-s commented 3 years ago

Hello. I've solved that problem! I could get output files at example1 folder! Thank you very much!