Is it possible to run Water Yield in Python?

Hey what’s up everyone? I have a question: is it possible to run annual water yield in python? Just to share codes with different people feeling more comfortable working in python environment.
Tnx in advance.

Hi @Behzad_AK,
All InVEST models have a python API, you can see the complete API reference here. Note that annual water yield is listed under its other name, hydropower water yield. There is some documentation on how to run models this way. Basically, you call the execute function with all the parameters that you would normally enter into the UI form. Let us know if you have any further questions!

Thanks Esoth for considering my question. I’ll focus on the documents you’ve send, hope it would work out for me cause I’m a beginner only knowing very basics in Python. I really like to start working with invest codes, though. Do have any idea how to start? Your documents look a bit complicated for me at this point.
Cheers
Behzad

It depends on what you want to accomplish by running InVEST with python instead of the UI. Do you want to run the model many times with different parameters?

Well yeah, my plan is to run it 30 times with same input data except 30 different Z values (1-30). Moreover, as a student it feels kinda good to look a the codes under the UI. I know the very basics of Python and my initial plan was to run it in Pycharm. Please let me know if Visual Studio is needed!

Hi Behzad_AK,

Yes, it is possible to run these models using Pycharm on windows or Ubuntu. However, I had a hard time dealing with the dependencies, i.e., trying to install pygeoprocessing. Anyway, It was totally worth it to facilitate batch processing analysis.

Best,
Sergio

Hi Sergio, hope you’re doing fine these days! Yeah the batch processing is very helpful. I wonder how the results would get generated using batch processing in Python? Are they gonna get produced in a directory file as if you’re using the UI?
Given the fact that you had already installed the dependencies (e.g. pygeoprocessing)
do you have any suggestion for me how to start more efficiently (I’m a Win 10 user)? Tnx anyway for considering my questions!

In every model you can go to the Development menu > Save to python script… which will create a simple script that you can use to run the model. You can put that within a for loop to iterate over it 30 times and change the Z value each time. See the examples here.

For installing the dependencies, I have better luck using conda.

1 Like

Good, I already discovered “Save to python script” option. I’m facing a difficult time to runing that code in Pycharm, though.
Anyway, can you tell me exactly where to put the loop function in the code script?
Also how to train the system to ramp up the Z value from 1 to 30? Tnx as always for your time :slight_smile:

Hi @Behzad_AK ,

Check out this site for some resources on getting started with Python:

Cheers,

Doug