Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/1635-pollination-inf-values-in-outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
phargogh authored Oct 23, 2024
2 parents 8165704 + 9973dad commit 9bcf403
Show file tree
Hide file tree
Showing 30 changed files with 639 additions and 228 deletions.
38 changes: 28 additions & 10 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@
Unreleased Changes
------------------
* General
* InVEST has been updated to build against numpy 2.
https://github.com/natcap/invest/issues/1641
* Updating validation to handle a change in exceptions raised by GDAL in
``pygeoprocessing.get_raster_info`` and
``pygeoprocessing.get_vector_info``.
https://github.com/natcap/invest/issues/1645
* Coastal Vulnerability
* Fixed a regression where an AOI with multiple features could raise a
TypeError after intersecting with the landmass polygon.
https://github.com/natcap/invest/issues/1657
* Forest Carbon Edge Effects
* Updating vector reprojection to allow partial reprojection. Related to
https://github.com/natcap/invest/issues/1645
* Habitat Quality
* Access raster is now generated from the reprojected access vector
(https://github.com/natcap/invest/issues/1615).
* Rarity values are now output in CSV format (as well as in raster format)
(https://github.com/natcap/invest/issues/721).
* Pollination
* Fixed an issue with nodata handling that was causing some outputs to be
filled either with the float32 value for positive infinity, or else with
Expand All @@ -45,27 +64,26 @@ Unreleased Changes
updated the stated dtype of most pollination model outputs to be float32
instead of the float64 dtype that was being assumed previously. This
will result in smaller output filesizes with minimal loss of precision.
* Urban Flood Risk
* Fields present on the input AOI vector are now retained in the output.
(https://github.com/natcap/invest/issues/1600)
* 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)
and visual consistency (https://github.com/natcap/invest/issues/912).
* Fixed a bug that caused the application to crash when attempting to
open a workspace without a valid logfile
(https://github.com/natcap/invest/issues/1598)
(https://github.com/natcap/invest/issues/1598).
* Fixed a bug that was allowing readonly workspace directories on Windows
(https://github.com/natcap/invest/issues/1599)
(https://github.com/natcap/invest/issues/1599).
* Fixed a bug that, in certain scenarios, caused a datastack to be saved
with relative paths when the Relative Paths checkbox was left unchecked
(https://github.com/natcap/invest/issues/1609)
* Habitat Quality
* Access raster is now generated from the reprojected access vector.
(https://github.com/natcap/invest/issues/1615)
* Urban Flood Risk
* Fields present on the input AOI vector are now retained in the output.
(https://github.com/natcap/invest/issues/1600)
(https://github.com/natcap/invest/issues/1609).
* Improved error handling when a datastack cannot be saved with relative
paths across drives (https://github.com/natcap/invest/issues/1608).

3.14.2 (2024-05-29)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GIT_TEST_DATA_REPO_REV := 324abde73e1d770ad75921466ecafd1ec6297752

GIT_UG_REPO := https://github.com/natcap/invest.users-guide
GIT_UG_REPO_PATH := doc/users-guide
GIT_UG_REPO_REV := 0404bc5d4d43085cdc58f50f8fc29944b10cefb1
GIT_UG_REPO_REV := f203ec069f9f03560c9a85b268e67ebb6b994953

ENV = "./env"
ifeq ($(OS),Windows_NT)
Expand Down
3 changes: 0 additions & 3 deletions constraints_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
# occur with regular use of invest. https://github.com/OSGeo/gdal/issues/8497
GDAL!=3.6.*,!=3.7.*

# https://github.com/natcap/pygeoprocessing/issues/387
GDAL<3.8.5

# Pyinstaller 6.10 breaks our windows builds. Until we can figure out the
# root cause, let's cap the versions to those that work.
# https://github.com/natcap/invest/issues/1622
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ invest = "natcap.invest.cli:main"
# available at runtime.
requires = [
'setuptools>=61', 'wheel', 'setuptools_scm>=8.0', 'cython>=3.0.0', 'babel',
'oldest-supported-numpy'
'oldest-supported-numpy; python_version<="3.8"',
'numpy>=2; python_version>="3.9"', # numpy 2 only available for 3.9+
]
build-backend = "setuptools.build_meta"

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
GDAL>=3.4.2
Pyro4==4.77 # pip-only
pandas>=1.2.1
numpy>=1.11.0,!=1.16.0,<2.0
numpy>=1.11.0,!=1.16.0
Rtree>=0.8.2,!=0.9.1
shapely>=2.0.0
scipy>=1.9.0,!=1.12.*
pygeoprocessing>=2.4.2 # pip-only
pygeoprocessing>=2.4.6 # pip-only
taskgraph>=0.11.0
psutil>=5.6.6
chardet>=3.0.4
Expand Down
12 changes: 6 additions & 6 deletions scripts/invest-autovalidate.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!python

import os
import tempfile
import logging
import argparse
import unittest
import glob
import importlib
import shutil
import logging
import os
import pprint
import shutil
import tempfile
import unittest

from natcap.invest import datastack

Expand Down Expand Up @@ -81,7 +81,7 @@ def main(sampledatadir):

model_warnings = [] # define here in case of uncaught exception.
try:
LOGGER.info('validating %s ', datastack_path)
LOGGER.info('validating %s ', os.path.abspath(datastack_path))
model_warnings = getattr(
model_module, 'validate')(paramset.args)
except AttributeError as err:
Expand Down
22 changes: 8 additions & 14 deletions src/natcap/invest/coastal_vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from osgeo import gdal
from osgeo import ogr
from osgeo import osr
from shapely.geometry import LineString, MultiLineString
from shapely.geometry.base import BaseMultipartGeometry
from shapely.strtree import STRtree

Expand Down Expand Up @@ -1104,7 +1105,6 @@ def prepare_landmass_line_index_and_interpolate_shore_points(
# Get shapely geometries from landmass
landmass_polygon_shapely_list = _ogr_to_geometry_list(landmass_vector_path)
landmass_shapely = shapely.ops.unary_union(landmass_polygon_shapely_list)

landmass_polygon_shapely_list = None

# store polygon geom for point-in-poly check later in ray-casting
Expand Down Expand Up @@ -1170,19 +1170,13 @@ def prepare_landmass_line_index_and_interpolate_shore_points(
if aoi_shapely_prepped.intersects(landmass_line):
intersected_shapely_geom = aoi_shapely.intersection(
landmass_line)
if intersected_shapely_geom.geom_type == 'LineString':
lines_in_aoi_list.append(intersected_shapely_geom)
elif intersected_shapely_geom.geom_type == 'MultiLineString':
shapely_geom_explode = [
shapely.geometry.LineString(x)
for x in intersected_shapely_geom]

lines_in_aoi_list.extend(shapely_geom_explode)
else:
# intersection could generate a point geom
# or if somehow the intersection is empty,
# type will be GeometryCollection.
continue
# intersection could generate a point geom,
# or if somehow the intersection is empty,
# type will be GeometryCollection.
if isinstance(intersected_shapely_geom,
(LineString, MultiLineString)):
lines_in_aoi_list.extend(
_list_geometry(intersected_shapely_geom))

# if none of the lines were disjoint before this linemerge,
# unioned_line will now be a LineString.
Expand Down
15 changes: 13 additions & 2 deletions src/natcap/invest/datastack.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,9 @@ def build_parameter_set(args, model_name, paramset_path, relative=False):
Returns:
``None``
Raises:
ValueError if creating a relative path fails.
"""
def _recurse(args_param):
if isinstance(args_param, dict):
Expand All @@ -552,8 +555,16 @@ def _recurse(args_param):
if (normalized_path == '.' or
os.path.dirname(paramset_path) == normalized_path):
return '.'
temp_rel_path = os.path.relpath(
normalized_path, os.path.dirname(paramset_path))
try:
temp_rel_path = os.path.relpath(
normalized_path, os.path.dirname(paramset_path))
except ValueError:
# On Windows, ValueError is raised when ``path`` and
# ``start`` are on different drives
raise ValueError(
"""Error: Cannot save datastack with relative
paths across drives. Choose a different save
location, or use absolute paths.""")
# Always save unix paths.
linux_style_path = temp_rel_path.replace('\\', '/')
else:
Expand Down
13 changes: 8 additions & 5 deletions src/natcap/invest/forest_carbon_edge_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,14 @@ def _aggregate_carbon_map(
for poly_feat in target_aggregate_layer:
poly_fid = poly_feat.GetFID()
poly_feat.SetField(
'c_sum', serviceshed_stats[poly_fid]['sum'])
'c_sum', float(serviceshed_stats[poly_fid]['sum']))
# calculates mean pixel value per ha in for each feature in AOI
poly_geom = poly_feat.GetGeometryRef()
poly_area_ha = poly_geom.GetArea() / 1e4 # converts m^2 to hectare
poly_geom = None
poly_feat.SetField(
'c_ha_mean', serviceshed_stats[poly_fid]['sum']/poly_area_ha)
'c_ha_mean',
float(serviceshed_stats[poly_fid]['sum'] / poly_area_ha))

target_aggregate_layer.SetFeature(poly_feat)
target_aggregate_layer.CommitTransaction()
Expand Down Expand Up @@ -765,9 +766,11 @@ def _build_spatial_index(
local_model_dir, 'local_carbon_shape.shp')
lulc_projection_wkt = pygeoprocessing.get_raster_info(
base_raster_path)['projection_wkt']
pygeoprocessing.reproject_vector(
tropical_forest_edge_carbon_model_vector_path, lulc_projection_wkt,
carbon_model_reproject_path)

with utils._set_gdal_configuration('OGR_ENABLE_PARTIAL_REPROJECTION', 'TRUE'):
pygeoprocessing.reproject_vector(
tropical_forest_edge_carbon_model_vector_path, lulc_projection_wkt,
carbon_model_reproject_path)

model_vector = gdal.OpenEx(carbon_model_reproject_path)
model_layer = model_vector.GetLayer()
Expand Down
Loading

0 comments on commit 9bcf403

Please sign in to comment.