Skip to content

Commit

Permalink
Merge branch 'main' into feature/1580-automate-codesigning-in-release
Browse files Browse the repository at this point in the history
  • Loading branch information
phargogh authored Feb 5, 2025
2 parents 9784a26 + 4820c9e commit 2fefbff
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-part-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- uses: actions/checkout@v4
if: env.RUN == 'true'
with:
fetch-depth: 0 # fetch entire history, for versioning
token: ${{ secrets.AUTORELEASE_BOT_PAT }}

- name: Install dependencies
Expand Down
9 changes: 9 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@
Unreleased Changes
------------------
* General
* Fixed an issue where a user's PROJ_DATA environment variable could
trigger a RuntimeError about a missing proj.db file.
https://github.com/natcap/invest/issues/1742
* Now testing and building against Python 3.13.
No longer testing and building with Python 3.8, which reached EOL.
https://github.com/natcap/invest/issues/1755
* InVEST's windows binaries are now distributed once again with a valid
signature, signed by Stanford University.
https://github.com/natcap/invest/issues/1580
* Annual Water Yield
* Fixed an issue where the model would crash if the valuation table was
provided, but the demand table was not. Validation will now warn about
this, and the ``MODEL_SPEC`` has been improved to reflect that this table
is now required when doing valuation.
https://github.com/natcap/invest/issues/1769
* Carbon
* Updated styling of the HTML report generated by the carbon model, for
visual consistency with the Workbench (`InVEST #1732
Expand Down
1 change: 1 addition & 0 deletions exe/hooks/rthook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys

os.environ['PROJ_LIB'] = os.path.join(sys._MEIPASS, 'proj')
os.environ['PROJ_DATA'] = os.path.join(sys._MEIPASS, 'proj')

if platform.system() == 'Darwin':
# Rtree will look in this directory first for libspatialindex_c.dylib.
Expand Down
7 changes: 3 additions & 4 deletions src/natcap/invest/annual_water_yield.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@
}
},
"index_col": "lucode",
"required": False,
"required": "valuation_table_path",
"about": gettext(
"A table of water demand for each LULC class. Each LULC code "
"in the LULC raster must have a corresponding row in this "
"table."),
"table. Required if 'valuation_table_path' is provided."),
"name": gettext("water demand table")
},
"valuation_table_path": {
Expand Down Expand Up @@ -501,14 +501,13 @@ def execute(args):
a path to an input CSV
table of LULC classes, showing consumptive water use for each
landuse / land-cover type (cubic meters per year) to calculate
water scarcity.
water scarcity. Required if ``valuation_table_path`` is provided.
args['valuation_table_path'] (string): (optional) if a non-empty
string, a path to an input CSV table of
hydropower stations with the following fields to calculate
valuation: 'ws_id', 'time_span', 'discount', 'efficiency',
'fraction', 'cost', 'height', 'kw_price'
Required if ``calculate_valuation`` is True.
args['n_workers'] (int): (optional) The number of worker processes to
use for processing this model. If omitted, computation will take
Expand Down
37 changes: 25 additions & 12 deletions tests/test_annual_water_yield.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Module for Regression Testing the InVEST Annual Water Yield module."""
import unittest
import tempfile
import shutil
import os
import shutil
import tempfile
import unittest

import pandas
import numpy
from osgeo import gdal
import pandas
import pygeoprocessing

from osgeo import gdal

REGRESSION_DATA = os.path.join(
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'annual_water_yield')
Expand Down Expand Up @@ -74,7 +73,7 @@ def test_invalid_lulc_veg(self):
with self.assertRaises(ValueError) as cm:
annual_water_yield.execute(args)
self.assertTrue('veg value must be either 1 or 0' in str(cm.exception))

def test_missing_lulc_value(self):
"""Hydro: catching missing LULC value in Biophysical table."""
from natcap.invest import annual_water_yield
Expand All @@ -89,21 +88,21 @@ def test_missing_lulc_value(self):
bio_df = bio_df[bio_df['lucode'] != 2]
bio_df.to_csv(bad_biophysical_path)
bio_df = None

args['biophysical_table_path'] = bad_biophysical_path

with self.assertRaises(ValueError) as cm:
annual_water_yield.execute(args)
self.assertTrue(
"The missing values found in the LULC raster but not the table"
" are: [2]" in str(cm.exception))

def test_missing_lulc_demand_value(self):
"""Hydro: catching missing LULC value in Demand table."""
from natcap.invest import annual_water_yield

args = AnnualWaterYieldTests.generate_base_args(self.workspace_dir)

args['demand_table_path'] = os.path.join(
SAMPLE_DATA, 'water_demand_table.csv')
args['sub_watersheds_path'] = os.path.join(
Expand All @@ -117,7 +116,7 @@ def test_missing_lulc_demand_value(self):
demand_df = demand_df[demand_df['lucode'] != 2]
demand_df.to_csv(bad_demand_path)
demand_df = None

args['demand_table_path'] = bad_demand_path

with self.assertRaises(ValueError) as cm:
Expand Down Expand Up @@ -247,7 +246,8 @@ def test_valuation_subshed(self):

def test_validation(self):
"""Hydro: test failure cases on the validation function."""
from natcap.invest import annual_water_yield, validation
from natcap.invest import annual_water_yield
from natcap.invest import validation

args = AnnualWaterYieldTests.generate_base_args(self.workspace_dir)

Expand Down Expand Up @@ -367,3 +367,16 @@ def test_validation(self):
self.assertTrue(
'but are not found in the valuation table' in
actual_message, actual_message)

# if the demand table is missing but the valuation table is present,
# make sure we have a validation error.
args_missing_demand_table = args.copy()
args_missing_demand_table['demand_table_path'] = ''
args_missing_demand_table['valuation_table_path'] = (
os.path.join(SAMPLE_DATA, 'hydropower_valuation_table.csv'))
validation_warnings = annual_water_yield.validate(
args_missing_demand_table)
self.assertEqual(len(validation_warnings), 1)
self.assertEqual(
validation_warnings[0],
(['demand_table_path'], 'Input is required but has no value'))

0 comments on commit 2fefbff

Please sign in to comment.