Skip to content

Commit

Permalink
Merge branch 'main' into task/1641-update-for-numpy-2
Browse files Browse the repository at this point in the history
  • Loading branch information
phargogh authored Oct 8, 2024
2 parents 5e7df94 + 3a4a4c7 commit a96fb1b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Unreleased Changes
* General
* InVEST has been updated to build against numpy 2.
https://github.com/natcap/invest/issues/1641
* Urban Nature Access
* The model now works as expected when the user provides an LULC raster
that does not have a nodata value defined.
https://github.com/natcap/invest/issues/1293
* Workbench
* Several small updates to the model input form UI to improve usability
and visual consistency (https://github.com/natcap/invest/issues/912)
Expand Down
12 changes: 5 additions & 7 deletions doc/api-docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@
# -- Options for HTML output ----------------------------------------------

import sphinx_rtd_theme

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = "_static/invest-logo.png"
Expand Down Expand Up @@ -130,16 +128,16 @@
# dir menu entry, description, category)
texinfo_documents = [
('index', 'InVEST', 'InVEST Documentation',
'The Natural Capital Project', 'InVEST',
'The Natural Capital Project', 'InVEST',
'Integrated Valuation of Ecosystem Services and Tradeoffs',
'Scientific Software'),
]


# -- Prepare for sphinx build ---------------------------------------------

# Use sphinx apidoc tool to generate documentation for invest. Generated rst
# files go into the api/ directory. Note that some apidoc options may not work
# Use sphinx apidoc tool to generate documentation for invest. Generated rst
# files go into the api/ directory. Note that some apidoc options may not work
# the same because we aren't using their values in the custom templates
apidoc.main([
'--force', # overwrite any files from previous run
Expand All @@ -164,7 +162,7 @@
All InVEST models share a consistent python API:
- Every InVEST model has a corresponding module or subpackage in the
- Every InVEST model has a corresponding module or subpackage in the
``natcap.invest`` package
- The model modules contain a function called ``execute``
- The ``execute`` function takes a single argument (``args``), a dictionary
Expand Down
21 changes: 10 additions & 11 deletions src/natcap/invest/urban_nature_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -2542,23 +2542,22 @@ def _warp_lulc(source_lulc_path, target_lulc_path, target_pixel_size,
"""
source_raster_info = pygeoprocessing.get_raster_info(source_lulc_path)
target_nodata = source_raster_info['nodata'][0]
if target_nodata is None:
# Guarantee that our nodata cannot be represented by the datatype -
# select a nodata value that's out of range.
target_nodata = pygeoprocessing.choose_nodata(
source_raster_info['numpy_type']) + 1

pygeoprocessing.warp_raster(
source_lulc_path, target_pixel_size, target_lulc_path,
'near', target_bb=target_bounding_box,
target_projection_wkt=source_raster_info['projection_wkt'])

# if there is no defined nodata, set a default value
raster = gdal.OpenEx(target_lulc_path, gdal.GA_Update)
band = raster.GetRasterBand(1)
band.SetNoDataValue(target_nodata)
band = None
raster = None
if target_nodata is None:
# Guarantee that our nodata cannot be represented by the datatype -
# select a nodata value that's out of range.
target_nodata = pygeoprocessing.choose_nodata(
source_raster_info['numpy_type']) + 1
raster = gdal.OpenEx(target_lulc_path, gdal.GA_Update)
band = raster.GetRasterBand(1)
band.SetNoDataValue(target_nodata)
band = None
raster = None


def _mask_raster(source_raster_path, mask_raster_path, target_raster_path):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_urban_nature_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,21 @@ def test_core_model(self):
self.assertAlmostEqual(numpy.min(valid_pixels), 1171.7352294921875)
self.assertAlmostEqual(numpy.max(valid_pixels), 11898.0712890625)

def test_no_lulc_nodata(self):
"""UNA: verify behavior when the LULC has no nodata value."""
from natcap.invest import urban_nature_access

args = _build_model_args(self.workspace_dir)
args['search_radius_mode'] = urban_nature_access.RADIUS_OPT_UNIFORM
args['search_radius'] = 100

raster = gdal.OpenEx(args['lulc_raster_path'], gdal.OF_RASTER)
band = raster.GetRasterBand(1)
band.DeleteNoDataValue()
band = None
raster = None
urban_nature_access.execute(args)

def test_split_urban_nature(self):
from natcap.invest import urban_nature_access

Expand Down

0 comments on commit a96fb1b

Please sign in to comment.