New error running sdr in virtual environment

What is the issue or question you have?

Similar to a previous question, I am trying to run InVEST in a conda virtual environment. This time, I am having trouble running the sediment delivery ratio model in the environment, when it runs fine using the GUI on the same parameters and inputs. I get the following errors:

Traceback (most recent call last):
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 568, in raster_calculator
    float(target_stddev))
TypeError: can't convert complex to float
09/06/2023 16:01:35  (taskgraph.Task) Task.add_task(706) ERROR Something went wrong when adding task align input rasters (0), terminating taskgraph.
Traceback (most recent call last):
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/taskgraph/Task.py", line 674, in add_task
    new_task._call()
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/taskgraph/Task.py", line 1093, in _call
    payload = self._func(*self._args, **self._kwargs)
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 986, in align_and_resize_raster_stack
    warp_raster(
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 2391, in warp_raster
    mask_raster(
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 3435, in mask_raster
    raster_calculator(
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 568, in raster_calculator
    float(target_stddev))
TypeError: can't convert complex to float
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/natcap/invest/sdr/sdr.py", line 569, in execute
    align_task = task_graph.add_task(
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/taskgraph/Task.py", line 674, in add_task
    new_task._call()
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/taskgraph/Task.py", line 1093, in _call
    payload = self._func(*self._args, **self._kwargs)
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 986, in align_and_resize_raster_stack
    warp_raster(
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 2391, in warp_raster
    mask_raster(
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 3435, in mask_raster
    raster_calculator(
  File "/Users/kevinli/anaconda3/envs/invest-3130/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 568, in raster_calculator
    float(target_stddev))
TypeError: can't convert complex to float

What do you expect to happen?

I expect the sdr model to run as it ran in the GUI.

What have you tried so far?

Following previous advice from @esoth, I have already reverted pandas from 2.1.0 to 2.0.3, so I don’t think this should be the issue. I am not able to figure out whether other package versions are causing the issue, based on the error message.

Attach the logfile here:

I am running InVEST from the terminal and I don’t know how to output a log file (any tips?), but here is the logging output:

09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(470) INFO starting stats_worker
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(476) INFO started stats_worker <Thread(Thread-41, started daemon 6234714112)>
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(555) INFO 100.0% complete
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(558) INFO Waiting for raster stats worker result.
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.align_and_resize_raster_stack(996) INFO 1 of 4 aligned: aligned_dem_PdS_sdr.tif
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(470) INFO starting stats_worker
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(476) INFO started stats_worker <Thread(Thread-42, started daemon 6234714112)>
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(555) INFO 100.0% complete
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(558) INFO Waiting for raster stats worker result.
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.align_and_resize_raster_stack(996) INFO 2 of 4 aligned: aligned_lulc_PdS_sdr.tif
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(470) INFO starting stats_worker
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(476) INFO started stats_worker <Thread(Thread-43, started daemon 6234714112)>
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(555) INFO 100.0% complete
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(558) INFO Waiting for raster stats worker result.
09/06/2023 16:01:35  (pygeoprocessing.geoprocessing) geoprocessing.raster_calculator(571) ERROR exception encountered in raster_calculator

This is another environment issue. You need to use Cython<3.0.0.

Thanks again for your help! I have installed cython 0.29.36, but this does not fix the issue. Is there a version that is known to work?

Are you using the latest version of pygeoprocessing, released yesterday? Stats worker may return a complex when pygeoprocessing is built with `Cython >= 3.0.0` · Issue #342 · natcap/pygeoprocessing · GitHub

Our Github Actions CI workflow saves a summary of the conda environment it runs in. You can download the conda env artifacts from each successful test run, for example: Merge pull request #1392 from emlys/task/1391 · natcap/invest@740d193 · GitHub

1 Like

Thank you for the tips. Installing pygeoprocessing 2.4.1 fixed the issue!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.