Skip to content

Commit

Permalink
Merge branch 'main' into translations-update
Browse files Browse the repository at this point in the history
  • Loading branch information
emlys committed Oct 2, 2024
2 parents 276c74c + af8ce8b commit 7632025
Show file tree
Hide file tree
Showing 51 changed files with 1,031 additions and 641 deletions.
142 changes: 76 additions & 66 deletions .github/workflows/build-and-test.yml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ build:
tools:
python: "mambaforge-4.10"
jobs:
post_create_environment:
- pip install --upgrade-strategy=only-if-needed -r requirements.txt
- pip install --upgrade-strategy=only-if-needed -r requirements-dev.txt
- pip install --upgrade-strategy=only-if-needed -r requirements-docs.txt
post_install:
- make install
6 changes: 1 addition & 5 deletions .readthedocs_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,5 @@ channels:
- nodefaults
dependencies:
- python=3.11
- gdal>=3.4.2,<3.6.0
- gdal>=3.4.2
- pip
- pip:
- -r requirements.txt
- -r requirements-dev.txt
- -r requirements-docs.txt
63 changes: 55 additions & 8 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,26 @@

.. :changelog:
Unreleased Changes
------------------
* Workbench
* Several small updates to the model input form UI to improve usability
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)
* Fixed a bug that was allowing readonly workspace directories on Windows
(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)

3.14.2 (2024-05-29)
-------------------
* General
* Validation now covers file paths contained in CSVs. CSV validation
will fail if the files listed in a CSV fail to validate.
https://github.com/natcap/invest/issues/327
* We have updated validation in several ways that will improve the
developer experience of working with InVEST models, and we hope will also
improve the user experience:
Expand All @@ -59,15 +75,52 @@ Unreleased Changes
versions of InVEST would skip these parameters' type-specific
validation. Now, these parameters will be validated with their
type-specific validation checks.

* Add support for latest GDAL versions; remove test-specific constraint on
GDAL versions from invest requirements.
https://github.com/natcap/invest/issues/916
* Updated to Cython 3 (https://github.com/natcap/invest/issues/556)
* Annual Water Yield
* Added the results_suffix to a few intermediate files where it was
missing. https://github.com/natcap/invest/issues/1517
* Coastal Blue Carbon
* Updated model validation to prevent the case where a user provides only
one snapshot year and no analysis year
(`#1534 <https://github.com/natcap/invest/issues/1534>`_).
Also enforces that the analysis year, if provided, is greater than the
latest snapshot year. An analysis year equal to the latest snapshot year
is no longer allowed.
* Coastal Vulnerability
* Fixed a bug in handling ``nan`` as the nodata value of the bathymetry
raster. ``nan`` pixels will now be propertly ignored before calculating
mean depths along fetch rays.
https://github.com/natcap/invest/issues/1528
* HRA
* Fixed a bug where habitat and stressor vectors were not being rasterized
with the `ALL_TOUCHED=TRUE` setting.
* Scenic Quality
* Fixed an issue with viewshed calculations where some slight numerical
error was introduced on M1 Macs, but not on x86-based computers. This
numerical error was leading to slightly different visibility results.
https://github.com/natcap/invest/issues/1562
* SDR
* Fixed an issue encountered in the sediment deposition function where
rasters with more than 2^32 pixels would raise a cryptic error relating
to negative dimensions. https://github.com/natcap/invest/issues/1431
* Optimized the creation of the summary vector by minimizing the number of
times the target vector needs to be rasterized.
* Seasonal Water Yield
* Fixed an issue with the precip directory units. Units for these input
rasters are now correctly stated as mm/month.
https://github.com/natcap/invest/issues/1571
* Fixed an issue where the monthly quickflow values were being summed over
a block area and not summed pixelwise. This caused the quickflow
output ``QF.tif`` to have malformed values.
https://github.com/natcap/invest/issues/1541
* Wind Energy
* Fixed a bug where some number inputs were not being properly cast to
``float`` or ``int`` types. If the inputs happened to be passed as
a ``str`` this caused unintended side effects such as a concatenation
error. (https://github.com/natcap/invest/issues/1498)
* Urban Nature Access
* Fixed a ``NameError`` that occurred when running the model using
search radii defined per population group with an exponential search
Expand All @@ -91,12 +144,6 @@ Unreleased Changes
* Fixed an issue where an LULC raster without a nodata value would
always raise in exception during reclassification.
https://github.com/natcap/invest/issues/1539
* SDR
* Fixed an issue encountered in the sediment deposition function where
rasters with more than 2^32 pixels would raise a cryptic error relating
to negative dimensions. https://github.com/natcap/invest/issues/1431
* Optimized the creation of the summary vector by minimizing the number of
times the target vector needs to be rasterized.

3.14.1 (2023-12-18)
-------------------
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
DATA_DIR := data
GIT_SAMPLE_DATA_REPO := https://bitbucket.org/natcap/invest-sample-data.git
GIT_SAMPLE_DATA_REPO_PATH := $(DATA_DIR)/invest-sample-data
GIT_SAMPLE_DATA_REPO_REV := 2e7cd618c661ec3f3b2a3bddfd2ce7d4704abc05
GIT_SAMPLE_DATA_REPO_REV := ab8c74a62a93fd0019de2bca064abc0a5a07afab

GIT_TEST_DATA_REPO := https://bitbucket.org/natcap/invest-test-data.git
GIT_TEST_DATA_REPO_PATH := $(DATA_DIR)/invest-test-data
GIT_TEST_DATA_REPO_REV := da013683e80ea094fbb2309197e2488c02794da8
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 := fa6b181d49136089dce56d4ff8f3dcaf12eb4ced
GIT_UG_REPO_REV := 0404bc5d4d43085cdc58f50f8fc29944b10cefb1

ENV = "./env"
ifeq ($(OS),Windows_NT)
Expand Down Expand Up @@ -251,6 +251,7 @@ $(INVEST_BINARIES_DIR): | $(DIST_DIR) $(BUILD_DIR)
-$(RMDIR) $(INVEST_BINARIES_DIR)
$(PYTHON) -m PyInstaller --workpath $(BUILD_DIR)/pyi-build --clean --distpath $(DIST_DIR) exe/invest.spec
$(CONDA) list > $(INVEST_BINARIES_DIR)/package_versions.txt
$(PYTHON) -m pip list >> $(INVEST_BINARIES_DIR)/package_versions.txt
$(INVEST_BINARIES_DIR)/invest list

# Documentation.
Expand Down
15 changes: 15 additions & 0 deletions constraints_tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file contains package constraints needed to run the invest test suite.
# It follows the pip constraints file format:
# https://pip.pypa.io/en/stable/user_guide/#constraints-files

# A gdal bug caused our test suite to fail, but this issue is unlikely to
# 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
#pyinstaller<6.10
6 changes: 5 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ RUN cd / && \

# Create the container for distribution that has runtime dependencies.
FROM mambaorg/micromamba:1.5.0-bookworm-slim
# Python version should match the version used in stage 1.
# If we update the stage 1 debian version, also update this python version
ARG PYTHON_VERSION="3.11"
COPY --from=build /invest/dist/*.whl /tmp/

# The environment.yml file will be built during github actions.
COPY --chown=$MAMBA_USER:$MAMBA_USER environment.yml /tmp/environment.yml
RUN micromamba install -y -n base -c conda-forge -f /tmp/environment.yml && \
RUN micromamba install -y -n base -c conda-forge python==${PYTHON_VERSION} && \
micromamba install -y -n base -c conda-forge -f /tmp/environment.yml && \
micromamba clean --all --yes && \
/opt/conda/bin/python -m pip install /tmp/*.whl && \
/opt/conda/bin/python -m pip cache purge && \
Expand Down
5 changes: 1 addition & 4 deletions exe/hooks/rthook.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import sys
import os
import multiprocessing
import platform

multiprocessing.freeze_support()
import sys

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

Expand Down
3 changes: 3 additions & 0 deletions exe/invest.spec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ kwargs = {
'pkg_resources.py2_warn',
'cmath',
'charset_normalizer',
'scipy.special._cdflib',
'scipy.special._special_ufuncs',
'scipy._lib.array_api_compat.numpy.fft',
],
'datas': [proj_datas],
'cipher': block_cipher,
Expand Down
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "natcap.invest"
description = "InVEST Ecosystem Service models"
readme = "README_PYTHON.rst"
requires-python = ">=3.8,<3.12"
requires-python = ">=3.8"
license = {file = "LICENSE.txt"}
maintainers = [
{name = "Natural Capital Project Software Team"}
Expand All @@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Cython",
"License :: OSI Approved :: BSD License",
"Topic :: Scientific/Engineering :: GIS"
Expand All @@ -44,7 +45,7 @@ invest = "natcap.invest.cli:main"
# that we can provide a much easier build experience so long as GDAL is
# available at runtime.
requires = [
'setuptools>=61', 'wheel', 'setuptools_scm>=8.0', 'cython', 'babel',
'setuptools>=61', 'wheel', 'setuptools_scm>=8.0', 'cython>=3.0.0', 'babel',
'oldest-supported-numpy'
]
build-backend = "setuptools.build_meta"
Expand Down Expand Up @@ -78,4 +79,11 @@ where = ["src"]

[tool.pytest.ini_options]
# raise warnings to errors, except for deprecation warnings
filterwarnings = ["error", "default::DeprecationWarning"]
filterwarnings = [
"error",
"default::DeprecationWarning",
"default::FutureWarning",
# don't error on a specific runtime warning coming from a shapely
# issue on M1: https://github.com/natcap/invest/issues/1562
"default:invalid value encountered in intersection:RuntimeWarning",
]
9 changes: 6 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
# Any lines with "# pip-only" at the end will be processed by
# scripts/convert-requirements-to-conda-yml.py as though it can only be found
# on pip.
# Sometimes conda-forge does not install the latest available version,
# pip-only can be a workaround for that.

Cython<3.0.0
virtualenv>=12.0.1
pytest
pytest-subtests
wheel>=0.27.0
pypiwin32; sys_platform == 'win32' # pip-only
setuptools>=8.0,<60.7.0 # https://github.com/pyinstaller/pyinstaller/issues/6564
PyInstaller>=4.10

# 60.7.0 exception because of https://github.com/pyinstaller/pyinstaller/issues/6564
setuptools>=8.0,!=60.7.0
PyInstaller>=4.10 # pip-only
setuptools_scm>=6.4.0
requests
coverage
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
# scripts/convert-requirements-to-conda-yml.py as though it can only be found
# on pip.

GDAL>=3.4.2,<3.6.0
GDAL>=3.4.2
Pyro4==4.77 # pip-only
pandas>=1.2.1
numpy>=1.11.0,!=1.16.0
numpy>=1.11.0,!=1.16.0,<2.0
Rtree>=0.8.2,!=0.9.1
shapely>=2.0.0
scipy>=1.9.0,!=1.12.*
Expand Down
37 changes: 23 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import platform
import subprocess

import Cython.Build
import numpy
from Cython.Build import cythonize
from setuptools import setup
from setuptools.command.build_py import build_py as _build_py
from setuptools.extension import Extension
Expand Down Expand Up @@ -46,25 +46,34 @@ def run(self):

setup(
install_requires=_REQUIREMENTS,
ext_modules=[
ext_modules=cythonize([
Extension(
name=f'natcap.invest.{package}.{module}',
sources=[f'src/natcap/invest/{package}/{module}.pyx'],
include_dirs=[numpy.get_include()],
extra_compile_args=compiler_and_linker_args,
extra_compile_args=compiler_args + compiler_and_linker_args,
extra_link_args=compiler_and_linker_args,
language='c++'
) for package, module in [
('delineateit', 'delineateit_core'),
('recreation', 'out_of_core_quadtree'),
('scenic_quality', 'viewshed'),
('ndr', 'ndr_core'),
('sdr', 'sdr_core'),
('seasonal_water_yield', 'seasonal_water_yield_core')
language='c++',
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
) for package, module, compiler_args in [
('delineateit', 'delineateit_core', []),
('recreation', 'out_of_core_quadtree', []),
# clang-14 defaults to -ffp-contract=on, which causes the
# arithmetic of A*B+C to be implemented using a contraction, which
# causes an unexpected change in the precision in some viewshed
# tests on ARM64 (mac M1). See these issues for more details:
# * https://github.com/llvm/llvm-project/issues/91824
# * https://github.com/natcap/invest/issues/1562
# * https://github.com/natcap/invest/pull/1564/files
# Using this flag on gcc and on all versions of clang should work
# as expected, with consistent results.
('scenic_quality', 'viewshed', ['-ffp-contract=off']),
('ndr', 'ndr_core', []),
('sdr', 'sdr_core', []),
('seasonal_water_yield', 'seasonal_water_yield_core', [])
]
],
], compiler_directives={'language_level': '3'}),
include_dirs=[numpy.get_include()],
cmdclass={
'build_ext': Cython.Build.build_ext,
'build_py': build_py
}
)
6 changes: 6 additions & 0 deletions src/natcap/invest/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import multiprocessing
import sys

# We want to guarantee that this is called BEFORE any other processes start,
# which could happen at import time.
if __name__ == '__main__':
multiprocessing.freeze_support()

from . import cli

if __name__ == '__main__':
Expand Down
22 changes: 8 additions & 14 deletions src/natcap/invest/coastal_blue_carbon/coastal_blue_carbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@
LOGGER = logging.getLogger(__name__)

INVALID_ANALYSIS_YEAR_MSG = gettext(
"Analysis year {analysis_year} must be >= the latest snapshot year "
"Analysis year ({analysis_year}) must be greater than the latest snapshot year "
"({latest_year})")
INVALID_SNAPSHOT_RASTER_MSG = gettext(
"Raster for snapshot {snapshot_year} could not be validated.")
MISSING_ANALYSIS_YEAR_MSG = gettext(
"Analysis year is required if only one snapshot year is provided.")
INVALID_TRANSITION_VALUES_MSG = gettext(
"The transition table expects values of {model_transitions} but found "
"values of {transition_values}.")
Expand Down Expand Up @@ -2166,7 +2166,6 @@ def validate(args, limit_to=None):
"""
validation_warnings = validation.validate(
args, MODEL_SPEC['args'])

sufficient_keys = validation.get_sufficient_keys(args)
invalid_keys = validation.get_invalid_keys(validation_warnings)

Expand All @@ -2177,19 +2176,14 @@ def validate(args, limit_to=None):
**MODEL_SPEC['args']['landcover_snapshot_csv']
)['raster_path'].to_dict()

for snapshot_year, snapshot_raster_path in snapshots.items():
raster_error_message = validation.check_raster(
snapshot_raster_path)
if raster_error_message:
validation_warnings.append((
['landcover_snapshot_csv'],
INVALID_SNAPSHOT_RASTER_MSG.format(
snapshot_year=snapshot_year
) + ' ' + raster_error_message))
snapshot_years = set(snapshots.keys())
if len(snapshot_years) == 1 and "analysis_year" not in sufficient_keys:
validation_warnings.append(
(['analysis_year'], MISSING_ANALYSIS_YEAR_MSG))

if ("analysis_year" not in invalid_keys
and "analysis_year" in sufficient_keys):
if max(set(snapshots.keys())) > int(args['analysis_year']):
if max(snapshot_years) >= int(args['analysis_year']):
validation_warnings.append((
['analysis_year'],
INVALID_ANALYSIS_YEAR_MSG.format(
Expand Down
Loading

0 comments on commit 7632025

Please sign in to comment.