Merge branch 'feature/routing-refactor' into feature/routing-refactor-compare
This commit is contained in:
commit
3c9b795d06
|
@ -53,7 +53,24 @@ jobs:
|
|||
perl -0777 -i -pe \
|
||||
"s/Unreleased Changes\n------------------/..\n Unreleased Changes\n ------------------\n\n${HEADER}\n${UNDERLINE}/g" \
|
||||
HISTORY.rst
|
||||
|
||||
- name: Install dependencies
|
||||
run: pip install rst2html5
|
||||
|
||||
- name: Generate changelog.html
|
||||
run: rst2html5 HISTORY.rst workbench/changelog.html
|
||||
|
||||
- name: Update package.json version
|
||||
uses: BellCubeDev/update-package-version-by-release-tag@v2
|
||||
with:
|
||||
version: ${{ inputs.version }}
|
||||
package-json-path: workbench/package.json
|
||||
|
||||
- name: Commit updated HISTORY.rst, changelog.html, and package.json
|
||||
run: |
|
||||
git add HISTORY.rst
|
||||
git add workbench/changelog.html
|
||||
git add workbench/package.json
|
||||
git commit -m "Committing the $VERSION release."
|
||||
|
||||
- name: Tag and push
|
||||
|
|
|
@ -99,7 +99,7 @@ jobs:
|
|||
twine upload \
|
||||
--username="__token__" \
|
||||
--password=${{ secrets.PYPI_NATCAP_INVEST_TOKEN }} \
|
||||
artifacts/natcap.invest*
|
||||
artifacts/natcap.invest* artifacts/natcap_invest*
|
||||
|
||||
- name: Roll back on failure
|
||||
if: failure()
|
||||
|
|
20
HISTORY.rst
20
HISTORY.rst
|
@ -48,6 +48,12 @@ Unreleased Changes
|
|||
reflect changes in how InVEST is installed on modern systems, and also to
|
||||
include images of the InVEST workbench instead of just broken links.
|
||||
https://github.com/natcap/invest/issues/1660
|
||||
* Updated translations for Spanish and Chinese
|
||||
* natcap.invest now works with (and requires) ``gdal.UseExceptions``. A
|
||||
``FutureWarning`` is raised on import if GDAL exceptions are not enabled.
|
||||
* Fixed an issue on Windows where GDAL fails to find its DLLs due to
|
||||
an interfering GDAL installation on the PATH, such as from anaconda.
|
||||
https://github.com/natcap/invest/issues/1643
|
||||
* Workbench
|
||||
* Several small updates to the model input form UI to improve usability
|
||||
and visual consistency (https://github.com/natcap/invest/issues/912).
|
||||
|
@ -61,6 +67,8 @@ Unreleased Changes
|
|||
(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).
|
||||
* The InVEST changelog now displays in the Workbench the first time a new
|
||||
version is launched (https://github.com/natcap/invest/issues/1368).
|
||||
* Coastal Vulnerability
|
||||
* Fixed a regression where an AOI with multiple features could raise a
|
||||
TypeError after intersecting with the landmass polygon.
|
||||
|
@ -73,6 +81,18 @@ Unreleased Changes
|
|||
(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
|
||||
a value very close to it. https://github.com/natcap/invest/issues/1635
|
||||
* While working on https://github.com/natcap/invest/issues/1635, we also
|
||||
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.
|
||||
* Seasonal Water Yield
|
||||
* Added support for zero padding in month numbers in ET and precipitation
|
||||
file names (i.e., users can now name their file Precip_01.tif).
|
||||
(https://github.com/natcap/invest/issues/1166)
|
||||
* Urban Flood Risk
|
||||
* Fields present on the input AOI vector are now retained in the output.
|
||||
(https://github.com/natcap/invest/issues/1600)
|
||||
|
|
9
Makefile
9
Makefile
|
@ -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 := f203ec069f9f03560c9a85b268e67ebb6b994953
|
||||
GIT_UG_REPO_REV := 5ee3616d4549baf3b1e44e0fcef485145389e29a
|
||||
|
||||
ENV = "./env"
|
||||
ifeq ($(OS),Windows_NT)
|
||||
|
@ -66,6 +66,7 @@ PYTHON_ARCH := $(shell $(PYTHON) -c "import sys; print('x86' if sys.maxsize <= 2
|
|||
|
||||
GSUTIL := gsutil
|
||||
SIGNTOOL := SignTool
|
||||
RST2HTML5 := rst2html5
|
||||
|
||||
# local directory names
|
||||
DIST_DIR := dist
|
||||
|
@ -73,6 +74,8 @@ DIST_DATA_DIR := $(DIST_DIR)/data
|
|||
BUILD_DIR := build
|
||||
WORKBENCH := workbench
|
||||
WORKBENCH_DIST_DIR := $(WORKBENCH)/dist
|
||||
CHANGELOG_SRC := HISTORY.rst
|
||||
CHANGELOG_DEST := $(WORKBENCH)/changelog.html
|
||||
|
||||
# The fork name and user here are derived from the git path on github.
|
||||
# The fork name will need to be set manually (e.g. make FORKNAME=natcap/invest)
|
||||
|
@ -141,6 +144,7 @@ help:
|
|||
@echo " binaries to build pyinstaller binaries"
|
||||
@echo " apidocs to build HTML API documentation"
|
||||
@echo " userguide to build HTML version of the users guide"
|
||||
@echo " changelog to build HTML version of the changelog"
|
||||
@echo " python_packages to build natcap.invest wheel and source distributions"
|
||||
@echo " codesign_mac to sign the mac disk image using the codesign utility"
|
||||
@echo " codesign_windows to sign the windows installer using the SignTool utility"
|
||||
|
@ -366,6 +370,9 @@ deploy:
|
|||
@echo "Application binaries (if they were created) can be downloaded from:"
|
||||
@echo " * $(DOWNLOAD_DIR_URL)"
|
||||
|
||||
changelog:
|
||||
$(RST2HTML5) $(CHANGELOG_SRC) $(CHANGELOG_DEST)
|
||||
|
||||
# Notes on Makefile development
|
||||
#
|
||||
# * Use the -drR to show the decision tree (and none of the implicit rules)
|
||||
|
|
86
README.rst
86
README.rst
|
@ -35,7 +35,6 @@ General Information
|
|||
Dependencies
|
||||
------------
|
||||
|
||||
Run ``make check`` to test if all required dependencies are installed on your system.
|
||||
OS-specific installation instructions are found either online at
|
||||
http://invest.readthedocs.io/en/latest/installing.html or locally at ``doc/api-docs/installing.rst``.
|
||||
|
||||
|
@ -57,30 +56,50 @@ Or on Windows, use the following instead from a CMD prompt::
|
|||
> make env
|
||||
> .\env\bin\activate
|
||||
|
||||
This makefile target is included for convenience ... you may of course choose to
|
||||
manage your own virtual environment. ``requirements.txt``,
|
||||
``requirements-dev.txt`` and ``requirements-docs.txt`` list the python
|
||||
dependencies needed.
|
||||
This makefile target is included for convenience. It uses ``conda`` and installs packages from ``conda-forge``.
|
||||
It also uses the `-p` flag with `conda create`, creating a `./env` folder containing the environment.
|
||||
|
||||
Using a different environment name
|
||||
""""""""""""""""""""""""""""""""""
|
||||
If you prefer a different name for your environment, you may pass the environment name as
|
||||
Using a different environment folder name
|
||||
"""""""""""""""""""""""""""""""""""""""""
|
||||
If you prefer a different path for your environment, you may pass the environment path as
|
||||
a parameter to make::
|
||||
|
||||
$ make ENV=myEnv env
|
||||
|
||||
You could then activate the environment created at ``myEnv``.
|
||||
You could then activate the environment created at ``./myEnv``.
|
||||
|
||||
|
||||
Using a different environment management tool
|
||||
"""""""""""""""""""""""""""""""""""""""""""""
|
||||
The InVEST Makefile uses ``virtualenv`` to set up an environment, but this is
|
||||
not the only `environment management tool out there
|
||||
<https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments>`_.
|
||||
You may elect to manage your virtual environment a different way, independent
|
||||
of ``make env``. The only requirement for the build process is that the required
|
||||
tools are available on your PATH and the required python packages can be imported.
|
||||
You may of course choose to manage your own virtual environment without using the Makefile.
|
||||
|
||||
We suggest using ``conda`` or ``mamba`` and ``conda-forge``.
|
||||
|
||||
``requirements.txt``, ``requirements-dev.txt`` and ``requirements-docs.txt`` list the python
|
||||
dependencies needed.
|
||||
|
||||
Installing ``natcap.invest`` from local source code
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
From an activated virtual environment, it's safest to uninstall any existing installation
|
||||
and then install `natcap.invest`::
|
||||
|
||||
$ pip uninstall natcap.invest
|
||||
$ make install
|
||||
|
||||
In practice, it can be convenient to use an "editable install" instead to avoid needing
|
||||
to uninstall & re-install after making changes to source code::
|
||||
|
||||
$ pip install -e .
|
||||
|
||||
Note that with an editable install any changes to non-Python (Cython, C++) files will
|
||||
require compilation using one of the above installation methods.
|
||||
|
||||
*The Workbench is not part of the* ``natcap.invest`` *Python package. See*
|
||||
``workbench/readme.md`` *for developer details.*
|
||||
|
||||
A successful ``natcap.invest`` installation will include the InVEST CLI::
|
||||
|
||||
$ invest list
|
||||
|
||||
Building InVEST Distributions
|
||||
-----------------------------
|
||||
|
@ -150,6 +169,13 @@ To build the user's guide::
|
|||
This will build HTML and PDF documentation, writing them to ``dist/userguide``
|
||||
and ``dist/InVEST_*_Documentation.pdf``, respectively.
|
||||
|
||||
The User's Guide is maintained in a separate git repository. InVEST will build
|
||||
the User's Guide with the commit defined in the ``Makefile``::
|
||||
|
||||
GIT_UG_REPO := https://github.com/natcap/invest.users-guide
|
||||
GIT_UG_REPO_PATH := doc/users-guide
|
||||
GIT_UG_REPO_REV := f203ec069f9f03560c9a85b268e67ebb6b994953
|
||||
|
||||
|
||||
API Documentation
|
||||
+++++++++++++++++
|
||||
|
@ -173,22 +199,12 @@ build zip archives of the sample data::
|
|||
|
||||
This will write the data zipfiles to ``dist/data``. ``git`` command is needed.
|
||||
|
||||
Single archive of sample data
|
||||
+++++++++++++++++++++++++++++
|
||||
|
||||
For trainings, it is especially convenient to distribute all sample data as a
|
||||
single zip archive. As an added bonus, this single zip archive can be provided
|
||||
to the InVEST installer for Windows as either the 'Advanced' input on the front
|
||||
page of the installer, or by a CLI flag, thus preventing the installer from
|
||||
downloading datasets from the internet. See
|
||||
``installer/windows/invest_installer.nsi`` for more details. To build a single
|
||||
archive of all InVEST sample data::
|
||||
|
||||
$ make sampledata_single
|
||||
|
||||
This will write the single sampledata archive to
|
||||
``dist/InVEST_*_sample_data.zip``.
|
||||
Sample data is tracked in a ``git-lfs`` repo and will be packaged based on the commit
|
||||
defined in the ``Makefile``::
|
||||
|
||||
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 := 0f8b41557753dad3670ba8220f41650b51435a93
|
||||
|
||||
Tests
|
||||
-----
|
||||
|
@ -202,6 +218,16 @@ To run tests on the suite of Ecosystem Service models in InVEST::
|
|||
|
||||
$ make test
|
||||
|
||||
Tests depend on test data that is tracked in a ``git-lfs`` repo defined in the ``Makefile``::
|
||||
|
||||
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 := 324abde73e1d770ad75921466ecafd1ec6297752
|
||||
|
||||
Test data (and Sample Data) can be retrieved using::
|
||||
|
||||
$ make fetch
|
||||
|
||||
|
||||
Changing how GNU make runs tests
|
||||
++++++++++++++++++++++++++++++++
|
||||
|
|
|
@ -5,14 +5,17 @@ import sys
|
|||
os.environ['PROJ_LIB'] = os.path.join(sys._MEIPASS, 'proj')
|
||||
|
||||
if platform.system() == 'Darwin':
|
||||
# This allows Qt 5.13+ to start on Big Sur.
|
||||
# See https://bugreports.qt.io/browse/QTBUG-87014
|
||||
# and https://github.com/natcap/invest/issues/384
|
||||
os.environ['QT_MAC_WANTS_LAYER'] = '1'
|
||||
|
||||
# Rtree will look in this directory first for libspatialindex_c.dylib.
|
||||
# In response to issues with github mac binary builds:
|
||||
# https://github.com/natcap/invest/issues/594
|
||||
# sys._MEIPASS is the path to where the pyinstaller entrypoint bundle
|
||||
# lives. See the pyinstaller docs for more details.
|
||||
os.environ['SPATIALINDEX_C_LIBRARY'] = sys._MEIPASS
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
# sys._MEIPASS contains gdal DLLs. It does not otherwise end
|
||||
# up on the PATH, which means that gdal can discover
|
||||
# incompatible DLLs from some other place on the PATH, such
|
||||
# as an anaconda gdal installation.
|
||||
if 'PATH' in os.environ:
|
||||
os.environ['PATH'] = f"{sys._MEIPASS};{os.environ['PATH']}"
|
||||
|
|
|
@ -26,3 +26,4 @@ requests
|
|||
coverage
|
||||
xlwt
|
||||
build # pip-only
|
||||
rst2html5
|
||||
|
|
|
@ -2,3 +2,4 @@ Sphinx>=1.3.1,!=1.7.1
|
|||
sphinx-rtd-theme
|
||||
sphinx-intl
|
||||
sphinx-reredirects
|
||||
pyyaml
|
||||
|
|
|
@ -4,8 +4,10 @@ import logging
|
|||
import os
|
||||
import sys
|
||||
from gettext import translation
|
||||
import warnings
|
||||
|
||||
import babel
|
||||
from osgeo import gdal
|
||||
|
||||
LOGGER = logging.getLogger('natcap.invest')
|
||||
LOGGER.addHandler(logging.NullHandler())
|
||||
|
@ -28,6 +30,14 @@ LOCALE_NAME_MAP = {
|
|||
locale: babel.Locale(locale).display_name for locale in LOCALES
|
||||
}
|
||||
|
||||
if not gdal.GetUseExceptions():
|
||||
warnings.warn(('''
|
||||
natcap.invest requires GDAL exceptions to be enabled. You must
|
||||
call gdal.UseExceptions() to avoid unexpected behavior from
|
||||
natcap.invest. A future version will enable exceptions on import.
|
||||
gdal.UseExceptions() affects global state, so this may affect the
|
||||
behavior of other packages.'''), FutureWarning)
|
||||
|
||||
|
||||
def set_locale(locale_code):
|
||||
"""Set the `gettext` attribute of natcap.invest.
|
||||
|
|
|
@ -12,6 +12,8 @@ import sys
|
|||
import textwrap
|
||||
import warnings
|
||||
|
||||
from pygeoprocessing.geoprocessing_core import GDALUseExceptions
|
||||
with GDALUseExceptions():
|
||||
import natcap.invest
|
||||
from natcap.invest import datastack
|
||||
from natcap.invest import model_metadata
|
||||
|
@ -20,7 +22,6 @@ from natcap.invest import spec_utils
|
|||
from natcap.invest import ui_server
|
||||
from natcap.invest import utils
|
||||
|
||||
|
||||
DEFAULT_EXIT_CODE = 1
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -218,6 +219,7 @@ def main(user_args=None):
|
|||
so models may be run in this way without having GUI packages
|
||||
installed.
|
||||
"""
|
||||
with GDALUseExceptions():
|
||||
parser = argparse.ArgumentParser(
|
||||
description=(
|
||||
'Integrated Valuation of Ecosystem Services and Tradeoffs. '
|
||||
|
|
|
@ -1737,15 +1737,16 @@ def extract_bathymetry_along_ray(
|
|||
iy = int((point.y - bathy_gt[3]) / bathy_gt[5])
|
||||
win_size = 1
|
||||
|
||||
try:
|
||||
value = bathy_band.ReadAsArray(
|
||||
xoff=ix, yoff=iy,
|
||||
win_xsize=win_size, win_ysize=win_size)
|
||||
if value is None:
|
||||
except RuntimeError as ex:
|
||||
location = {'xoff': ix, 'yoff': iy, 'win_xsize': win_size,
|
||||
'win_ysize': win_size}
|
||||
raise ValueError(
|
||||
f'got a {value} when trying to read bathymetry at {location}. '
|
||||
'Does the bathymetry input fully cover the fetch ray area?')
|
||||
f'Failed to read bathymetry at {location}. Does the bathymetry '
|
||||
'input fully cover the fetch ray area?') from ex
|
||||
if bathy_nodata is None or not numpy.isclose(
|
||||
value[0][0], bathy_nodata, equal_nan=True):
|
||||
bathy_values.append(value)
|
||||
|
@ -2468,8 +2469,13 @@ def search_for_vector_habitat(
|
|||
|
||||
geometry = feature.GetGeometryRef()
|
||||
if not geometry.IsValid():
|
||||
try:
|
||||
geometry = geometry.Buffer(0) # sometimes this fixes geometry
|
||||
if geometry is not None: # geometry is None if the buffer failed.
|
||||
except RuntimeError:
|
||||
LOGGER.warning(
|
||||
f"FID {feature.GetFID()} in {habitat_vector_path} has invalid "
|
||||
"geometry and will be excluded")
|
||||
continue
|
||||
clipped_geometry = geometry.Intersection(base_srs_clipping_geom)
|
||||
if not clipped_geometry.IsEmpty():
|
||||
if target_spatial_reference != base_spatial_reference:
|
||||
|
@ -2483,10 +2489,6 @@ def search_for_vector_habitat(
|
|||
shapely_geom = shapely.wkb.loads(
|
||||
bytes(clipped_geometry.ExportToWkb()))
|
||||
shapely_geometry_list.extend(_list_geometry(shapely_geom))
|
||||
else:
|
||||
LOGGER.warning(
|
||||
f"FID {feature.GetFID()} in {habitat_vector_path} has invalid "
|
||||
"geometry and will be excluded")
|
||||
|
||||
if not shapely_geometry_list:
|
||||
LOGGER.warning(f'No valid features exist in {habitat_vector_path}')
|
||||
|
|
|
@ -782,6 +782,7 @@ def _build_spatial_index(
|
|||
# put all the polygons in the kd_tree because it's fast and simple
|
||||
for poly_feature in model_layer:
|
||||
poly_geom = poly_feature.GetGeometryRef()
|
||||
if poly_geom.IsValid():
|
||||
poly_centroid = poly_geom.Centroid()
|
||||
# put in row/col order since rasters are row/col indexed
|
||||
kd_points.append([poly_centroid.GetY(), poly_centroid.GetX()])
|
||||
|
@ -790,6 +791,8 @@ def _build_spatial_index(
|
|||
poly_feature.GetField(feature_id) for feature_id in
|
||||
['theta1', 'theta2', 'theta3']])
|
||||
method_model_parameter.append(poly_feature.GetField('method'))
|
||||
else:
|
||||
LOGGER.warning(f'skipping invalid geometry {poly_geom}')
|
||||
|
||||
method_model_parameter = numpy.array(
|
||||
method_model_parameter, dtype=numpy.int32)
|
||||
|
|
|
@ -27,7 +27,8 @@ When we are ready to get a new batch of translations, here is the process. These
|
|||
pybabel extract \
|
||||
--no-wrap \
|
||||
--project InVEST \
|
||||
--msgid-bugs-address esoth@stanford.edu \
|
||||
--version $(python -m setuptools_scm) \
|
||||
--msgid-bugs-address natcap-software@lists.stanford.edu \
|
||||
--copyright-holder "Natural Capital Project" \
|
||||
--output src/natcap/invest/internationalization/messages.pot \
|
||||
src/
|
||||
|
@ -38,6 +39,7 @@ pybabel update \
|
|||
--input-file src/natcap/invest/internationalization/messages.pot \
|
||||
--output-file src/natcap/invest/internationalization/locales/$LL/LC_MESSAGES/messages.po
|
||||
```
|
||||
This looks through the source code for strings wrapped in the `gettext(...)` function and writes them to the message catalog template. Then it updates the message catalog for the specificed language. New strings that don't yet have a translation will have an empty `msgstr` value. Previously translated messages that are no longer needed will be commented out but remain in the file. This will save translator time if they're needed again in the future.
|
||||
|
||||
2. Check that the changes look correct, then commit:
|
||||
```
|
||||
|
@ -45,7 +47,6 @@ git diff
|
|||
git add src/natcap/invest/internationalization/messages.pot src/natcap/invest/internationalization/locales/$LL/LC_MESSAGES/messages.po
|
||||
git commit -m "extract message catalog template and update $LL catalog from it"
|
||||
```
|
||||
This looks through the source code for strings wrapped in the `gettext(...)` function and writes them to the message catalog template. Then it updates the message catalog for the specificed language. New strings that don't yet have a translation will have an empty `msgstr` value. Previously translated messages that are no longer needed will be commented out but remain in the file. This will save translator time if they're needed again in the future.
|
||||
|
||||
3. Send `src/natcap/invest/internationalization/locales/$LL/LC_MESSAGES/messages.po` to the translator and wait to get it back. The translator will fill in the `msgstr` values for any new or edited messages.
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -855,6 +855,7 @@ def execute(args):
|
|||
floral_resources_index_path_map[species],
|
||||
convolve_ps_path],
|
||||
target_path=pollinator_abundance_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_INDEX_NODATA),
|
||||
dependent_task_list=[
|
||||
foraged_flowers_index_task_map[(species, season)],
|
||||
|
@ -935,7 +936,9 @@ def execute(args):
|
|||
rasters=[
|
||||
half_saturation_raster_path,
|
||||
total_pollinator_abundance_index_path],
|
||||
target_path=farm_pollinator_season_path),
|
||||
target_path=farm_pollinator_season_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_INDEX_NODATA),
|
||||
dependent_task_list=[
|
||||
half_saturation_task, total_pollinator_abundance_task[season]],
|
||||
target_path_list=[farm_pollinator_season_path]))
|
||||
|
@ -976,7 +979,9 @@ def execute(args):
|
|||
kwargs=dict(
|
||||
op=pyt_op,
|
||||
rasters=[managed_pollinator_path, farm_pollinator_path],
|
||||
target_path=total_pollinator_yield_path),
|
||||
target_path=total_pollinator_yield_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_INDEX_NODATA),
|
||||
dependent_task_list=[farm_pollinator_task, managed_pollinator_task],
|
||||
target_path_list=[total_pollinator_yield_path])
|
||||
|
||||
|
@ -984,12 +989,14 @@ def execute(args):
|
|||
wild_pollinator_yield_path = os.path.join(
|
||||
output_dir, _WILD_POLLINATOR_YIELD_FILE_PATTERN % file_suffix)
|
||||
wild_pollinator_task = task_graph.add_task(
|
||||
task_name='calcualte_wild_pollinators',
|
||||
task_name='calculate_wild_pollinators',
|
||||
func=pygeoprocessing.raster_map,
|
||||
kwargs=dict(
|
||||
op=pyw_op,
|
||||
rasters=[managed_pollinator_path, total_pollinator_yield_path],
|
||||
target_path=wild_pollinator_yield_path),
|
||||
target_path=wild_pollinator_yield_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_INDEX_NODATA),
|
||||
dependent_task_list=[pyt_task, managed_pollinator_task],
|
||||
target_path_list=[wild_pollinator_yield_path])
|
||||
|
||||
|
@ -1392,7 +1399,8 @@ def _sum_arrays(*array_list):
|
|||
result = numpy.empty_like(array_list[0])
|
||||
result[:] = 0
|
||||
for array in array_list:
|
||||
local_valid_mask = ~pygeoprocessing.array_equals_nodata(array, _INDEX_NODATA)
|
||||
local_valid_mask = ~pygeoprocessing.array_equals_nodata(
|
||||
array, _INDEX_NODATA)
|
||||
result[local_valid_mask] += array[local_valid_mask]
|
||||
valid_mask |= local_valid_mask
|
||||
result[~valid_mask] = _INDEX_NODATA
|
||||
|
@ -1423,6 +1431,7 @@ def _calculate_habitat_nesting_index(
|
|||
pygeoprocessing.raster_map(
|
||||
op=max_op,
|
||||
rasters=substrate_path_list,
|
||||
target_dtype=numpy.float32,
|
||||
target_path=target_habitat_nesting_index_path)
|
||||
|
||||
|
||||
|
@ -1432,6 +1441,7 @@ def _multiply_by_scalar(raster_path, scalar, target_path):
|
|||
op=lambda array: array * scalar,
|
||||
rasters=[raster_path],
|
||||
target_path=target_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_INDEX_NODATA,
|
||||
)
|
||||
|
||||
|
@ -1455,6 +1465,7 @@ def _calculate_pollinator_supply_index(
|
|||
op=lambda f_r, h_n: species_abundance * f_r * h_n,
|
||||
rasters=[habitat_nesting_suitability_path, floral_resources_path],
|
||||
target_path=target_path,
|
||||
target_dtype=numpy.float32,
|
||||
target_nodata=_INDEX_NODATA
|
||||
)
|
||||
|
||||
|
|
|
@ -1603,26 +1603,18 @@ def _validate_same_projection(base_vector_path, table_path):
|
|||
|
||||
invalid_projections = False
|
||||
for path in data_paths:
|
||||
|
||||
def error_handler(err_level, err_no, err_msg):
|
||||
"""Empty error handler to avoid stderr output."""
|
||||
pass
|
||||
gdal.PushErrorHandler(error_handler)
|
||||
gis_type = pygeoprocessing.get_gis_type(path)
|
||||
if gis_type == pygeoprocessing.UNKNOWN_TYPE:
|
||||
return f"{path} did not load"
|
||||
elif gis_type == pygeoprocessing.RASTER_TYPE:
|
||||
raster = gdal.OpenEx(path, gdal.OF_RASTER)
|
||||
gdal.PopErrorHandler()
|
||||
if raster is not None:
|
||||
projection_as_str = raster.GetProjection()
|
||||
ref = osr.SpatialReference()
|
||||
ref.ImportFromWkt(projection_as_str)
|
||||
raster = None
|
||||
else:
|
||||
vector = gdal.OpenEx(path, gdal.OF_VECTOR)
|
||||
if vector is None:
|
||||
return f"{path} did not load"
|
||||
layer = vector.GetLayer()
|
||||
ref = osr.SpatialReference(layer.GetSpatialRef().ExportToWkt())
|
||||
layer = None
|
||||
vector = None
|
||||
if not base_ref.IsSame(ref):
|
||||
invalid_projections = True
|
||||
if invalid_projections:
|
||||
|
|
|
@ -659,33 +659,8 @@ def execute(args):
|
|||
output_align_list = [
|
||||
file_registry['lulc_aligned_path'], file_registry['dem_aligned_path']]
|
||||
if not args['user_defined_local_recharge']:
|
||||
precip_path_list = []
|
||||
et0_path_list = []
|
||||
|
||||
et0_dir_list = [
|
||||
os.path.join(args['et0_dir'], f) for f in os.listdir(
|
||||
args['et0_dir'])]
|
||||
precip_dir_list = [
|
||||
os.path.join(args['precip_dir'], f) for f in os.listdir(
|
||||
args['precip_dir'])]
|
||||
|
||||
for month_index in range(1, N_MONTHS + 1):
|
||||
month_file_match = re.compile(r'.*[^\d]%d\.[^.]+$' % month_index)
|
||||
|
||||
for data_type, dir_list, path_list in [
|
||||
('et0', et0_dir_list, et0_path_list),
|
||||
('Precip', precip_dir_list, precip_path_list)]:
|
||||
file_list = [
|
||||
month_file_path for month_file_path in dir_list
|
||||
if month_file_match.match(month_file_path)]
|
||||
if len(file_list) == 0:
|
||||
raise ValueError(
|
||||
"No %s found for month %d" % (data_type, month_index))
|
||||
if len(file_list) > 1:
|
||||
raise ValueError(
|
||||
"Ambiguous set of files found for month %d: %s" %
|
||||
(month_index, file_list))
|
||||
path_list.append(file_list[0])
|
||||
precip_path_list = _get_monthly_file_lists(N_MONTHS, args['precip_dir'])
|
||||
et0_path_list = _get_monthly_file_lists(N_MONTHS, args['et0_dir'])
|
||||
|
||||
input_align_list = (
|
||||
precip_path_list + [args['soil_group_path']] + et0_path_list +
|
||||
|
@ -1380,6 +1355,42 @@ def _aggregate_recharge(
|
|||
aggregate_vector = None
|
||||
|
||||
|
||||
def _get_monthly_file_lists(n_months, in_dir):
|
||||
"""Create list of monthly files for data type
|
||||
|
||||
Parameters:
|
||||
n_months (int): Number of months to iterate over (should be 12)
|
||||
in_dir (string): Path to directory of monthly files (for specific
|
||||
data type)
|
||||
|
||||
Raises:
|
||||
ValueError: If no file or multiple files are found for a month
|
||||
|
||||
Returns:
|
||||
list: contains monthly file paths for data type
|
||||
"""
|
||||
in_path_list = [os.path.join(in_dir, f) for f in os.listdir(in_dir)]
|
||||
out_path_list = []
|
||||
|
||||
for month_index in range(1, n_months + 1):
|
||||
month_file_pattern = re.compile(r'.*[^\d]0?%d\.[^.]+$' % month_index)
|
||||
file_list = [
|
||||
month_file_path for month_file_path in in_path_list
|
||||
if month_file_pattern.match(month_file_path)]
|
||||
if len(file_list) == 0:
|
||||
raise ValueError(
|
||||
"No files found in %s for month %d. Please ensure that \
|
||||
filenames end in the month number (e.g., precip_1.tif)."
|
||||
% (in_dir, month_index))
|
||||
if len(file_list) > 1:
|
||||
raise ValueError(
|
||||
"Ambiguous set of files found for month %d: %s" %
|
||||
(month_index, file_list))
|
||||
out_path_list.append(file_list[0])
|
||||
|
||||
return out_path_list
|
||||
|
||||
|
||||
@validation.invest_validator
|
||||
def validate(args, limit_to=None):
|
||||
"""Validate args to ensure they conform to `execute`'s contract.
|
||||
|
|
|
@ -2093,11 +2093,10 @@ def _write_supply_demand_vector(source_aoi_vector_path, feature_attrs,
|
|||
Returns:
|
||||
``None``
|
||||
"""
|
||||
source_vector = ogr.Open(source_aoi_vector_path)
|
||||
driver = ogr.GetDriverByName('GPKG')
|
||||
driver.CopyDataSource(source_vector, target_aoi_vector_path)
|
||||
source_vector = None
|
||||
driver = None
|
||||
gdal.VectorTranslate(
|
||||
target_aoi_vector_path, source_aoi_vector_path,
|
||||
format='GPKG',
|
||||
preserveFID=True)
|
||||
|
||||
target_vector = gdal.OpenEx(target_aoi_vector_path, gdal.GA_Update)
|
||||
target_layer = target_vector.GetLayer()
|
||||
|
|
|
@ -50,7 +50,9 @@ def _log_gdal_errors(*args, **kwargs):
|
|||
"""Log error messages to osgeo.
|
||||
|
||||
All error messages are logged with reasonable ``logging`` levels based
|
||||
on the GDAL error level.
|
||||
on the GDAL error level. While we are now using ``gdal.UseExceptions()``,
|
||||
we still need this to handle GDAL logging that does not get raised as
|
||||
an exception.
|
||||
|
||||
Note:
|
||||
This function is designed to accept any number of positional and
|
||||
|
|
|
@ -304,19 +304,16 @@ def check_raster(filepath, projected=False, projection_units=None, **kwargs):
|
|||
if file_warning:
|
||||
return file_warning
|
||||
|
||||
gdal.PushErrorHandler('CPLQuietErrorHandler')
|
||||
try:
|
||||
gdal_dataset = gdal.OpenEx(filepath, gdal.OF_RASTER)
|
||||
gdal.PopErrorHandler()
|
||||
|
||||
if gdal_dataset is None:
|
||||
except RuntimeError:
|
||||
return MESSAGES['NOT_GDAL_RASTER']
|
||||
|
||||
# Check that an overview .ovr file wasn't opened.
|
||||
if os.path.splitext(filepath)[1] == '.ovr':
|
||||
return MESSAGES['OVR_FILE']
|
||||
|
||||
srs = osr.SpatialReference()
|
||||
srs.ImportFromWkt(gdal_dataset.GetProjection())
|
||||
|
||||
srs = gdal_dataset.GetSpatialRef()
|
||||
projection_warning = _check_projection(srs, projected, projection_units)
|
||||
if projection_warning:
|
||||
gdal_dataset = None
|
||||
|
@ -378,9 +375,10 @@ def check_vector(filepath, geometries, fields=None, projected=False,
|
|||
if file_warning:
|
||||
return file_warning
|
||||
|
||||
gdal.PushErrorHandler('CPLQuietErrorHandler')
|
||||
try:
|
||||
gdal_dataset = gdal.OpenEx(filepath, gdal.OF_VECTOR)
|
||||
gdal.PopErrorHandler()
|
||||
except RuntimeError:
|
||||
return MESSAGES['NOT_GDAL_VECTOR']
|
||||
|
||||
geom_map = {
|
||||
'POINT': [ogr.wkbPoint, ogr.wkbPointM, ogr.wkbPointZM,
|
||||
|
@ -402,9 +400,6 @@ def check_vector(filepath, geometries, fields=None, projected=False,
|
|||
for geom in geometries:
|
||||
allowed_geom_types += geom_map[geom]
|
||||
|
||||
if gdal_dataset is None:
|
||||
return MESSAGES['NOT_GDAL_VECTOR']
|
||||
|
||||
# NOTE: this only checks the layer geometry type, not the types of the
|
||||
# actual geometries (layer.GetGeometryTypes()). This is probably equivalent
|
||||
# in most cases, and it's more efficient than checking every geometry, but
|
||||
|
|
|
@ -1148,23 +1148,18 @@ def _copy_vector_or_raster(base_file_path, target_file_path):
|
|||
ValueError if the base file can't be opened by GDAL.
|
||||
|
||||
"""
|
||||
# Open the file as raster first
|
||||
gis_type = pygeoprocessing.get_gis_type(base_file_path)
|
||||
if gis_type == pygeoprocessing.RASTER_TYPE:
|
||||
source_dataset = gdal.OpenEx(base_file_path, gdal.OF_RASTER)
|
||||
target_driver_name = _RASTER_DRIVER_NAME
|
||||
if source_dataset is None:
|
||||
# File didn't open as a raster; assume it's a vector
|
||||
elif gis_type == pygeoprocessing.VECTOR_TYPE:
|
||||
source_dataset = gdal.OpenEx(base_file_path, gdal.OF_VECTOR)
|
||||
target_driver_name = _VECTOR_DRIVER_NAME
|
||||
|
||||
# Raise an exception if the file can't be opened by GDAL
|
||||
if source_dataset is None:
|
||||
raise ValueError(
|
||||
'File %s is neither a GDAL-compatible raster nor vector.'
|
||||
% base_file_path)
|
||||
|
||||
else:
|
||||
raise ValueError(f'File {base_file_path} is neither a GDAL-compatible '
|
||||
'raster nor vector.')
|
||||
driver = gdal.GetDriverByName(target_driver_name)
|
||||
driver.CreateCopy(target_file_path, source_dataset)
|
||||
source_dataset = None
|
||||
|
||||
|
||||
def _interpolate_vector_field_onto_raster(
|
||||
|
|
|
@ -1758,10 +1758,9 @@ def _calculate_land_to_grid_distance(
|
|||
# Copy the point vector
|
||||
_, driver_name = _get_file_ext_and_driver_name(
|
||||
target_land_vector_path)
|
||||
base_land_vector = ogr.Open(base_land_vector_path, gdal.OF_VECTOR)
|
||||
driver = ogr.GetDriverByName(driver_name)
|
||||
driver.CopyDataSource(base_land_vector, target_land_vector_path)
|
||||
base_land_vector = None
|
||||
gdal.VectorTranslate(
|
||||
target_land_vector_path, base_land_vector_path,
|
||||
format=driver_name)
|
||||
|
||||
target_land_vector = gdal.OpenEx(
|
||||
target_land_vector_path, gdal.OF_VECTOR | gdal.GA_Update)
|
||||
|
@ -1846,7 +1845,7 @@ def _mask_by_distance(base_raster_path, min_dist, max_dist, out_nodata,
|
|||
|
||||
|
||||
def _create_distance_raster(base_raster_path, base_vector_path,
|
||||
target_dist_raster_path, work_dir):
|
||||
target_dist_raster_path, work_dir, where_clause=None):
|
||||
"""Create and rasterize vector onto a raster, and calculate dist transform.
|
||||
|
||||
Create a raster where the pixel values represent the euclidean distance to
|
||||
|
@ -1858,6 +1857,9 @@ def _create_distance_raster(base_raster_path, base_vector_path,
|
|||
base_vector_path (str): path to vector to be rasterized.
|
||||
target_dist_raster_path (str): path to raster with distance transform.
|
||||
work_dir (str): path to create a temp folder for saving files.
|
||||
where_clause (str): If not None, is an SQL query-like string to filter
|
||||
which features are rasterized. This kwarg is passed to
|
||||
``pygeoprocessing.rasterize``.
|
||||
|
||||
Returns:
|
||||
None
|
||||
|
@ -1885,7 +1887,8 @@ def _create_distance_raster(base_raster_path, base_vector_path,
|
|||
base_vector_path,
|
||||
rasterized_raster_path,
|
||||
burn_values=[1],
|
||||
option_list=["ALL_TOUCHED=TRUE"])
|
||||
option_list=["ALL_TOUCHED=TRUE"],
|
||||
where_clause=where_clause)
|
||||
|
||||
# Calculate euclidean distance transform
|
||||
pygeoprocessing.distance_transform_edt(
|
||||
|
@ -2590,67 +2593,25 @@ def _calculate_distances_land_grid(base_point_vector_path, base_raster_path,
|
|||
# A list to hold the land to grid distances in order for each point
|
||||
# features 'L2G' field
|
||||
l2g_dist = []
|
||||
# A list to hold the individual distance transform path's in order
|
||||
# A list to hold the individual distance transform paths in order
|
||||
land_point_dist_raster_path_list = []
|
||||
|
||||
# Get the original layer definition which holds needed attribute values
|
||||
base_layer_defn = base_point_layer.GetLayerDefn()
|
||||
file_ext, driver_name = _get_file_ext_and_driver_name(
|
||||
base_point_vector_path)
|
||||
output_driver = ogr.GetDriverByName(driver_name)
|
||||
single_feature_vector_path = os.path.join(
|
||||
temp_dir, 'single_feature' + file_ext)
|
||||
target_vector = output_driver.CreateDataSource(single_feature_vector_path)
|
||||
|
||||
# Create the new layer for target_vector using same name and
|
||||
# geometry type from base_vector as well as spatial reference
|
||||
target_layer = target_vector.CreateLayer(base_layer_defn.GetName(),
|
||||
base_point_layer.GetSpatialRef(),
|
||||
base_layer_defn.GetGeomType())
|
||||
|
||||
# Get the number of fields in original_layer
|
||||
base_field_count = base_layer_defn.GetFieldCount()
|
||||
|
||||
# For every field, create a duplicate field and add it to the new
|
||||
# shapefiles layer
|
||||
for fld_index in range(base_field_count):
|
||||
base_field = base_layer_defn.GetFieldDefn(fld_index)
|
||||
target_field = ogr.FieldDefn(base_field.GetName(),
|
||||
base_field.GetType())
|
||||
# NOT setting the WIDTH or PRECISION because that seems to be
|
||||
# unneeded and causes interesting OGR conflicts
|
||||
target_layer.CreateField(target_field)
|
||||
|
||||
fid_field = base_point_layer.GetFIDColumn()
|
||||
if not fid_field:
|
||||
fid_field = 'FID'
|
||||
# Create a new shapefile with only one feature to burn onto a raster
|
||||
# in order to get the distance transform based on that one feature
|
||||
for feature_index, point_feature in enumerate(base_point_layer):
|
||||
# Get the point features land to grid value and add it to the list
|
||||
field_index = point_feature.GetFieldIndex('L2G')
|
||||
l2g_dist.append(float(point_feature.GetField(field_index)))
|
||||
l2g_dist.append(float(point_feature.GetField('L2G')))
|
||||
|
||||
# Copy original_datasource's feature and set as new shapes feature
|
||||
output_feature = ogr.Feature(feature_def=target_layer.GetLayerDefn())
|
||||
|
||||
# Since the original feature is of interest add its fields and
|
||||
# Values to the new feature from the intersecting geometries
|
||||
# The False in SetFrom() signifies that the fields must match
|
||||
# exactly
|
||||
output_feature.SetFrom(point_feature, False)
|
||||
target_layer.CreateFeature(output_feature)
|
||||
target_vector.SyncToDisk()
|
||||
target_layer.DeleteFeature(point_feature.GetFID())
|
||||
|
||||
dist_raster_path = os.path.join(temp_dir,
|
||||
'dist_%s.tif' % feature_index)
|
||||
_create_distance_raster(base_raster_path, single_feature_vector_path,
|
||||
dist_raster_path, work_dir)
|
||||
dist_raster_path = os.path.join(temp_dir, f'dist_{feature_index}.tif')
|
||||
_create_distance_raster(
|
||||
base_raster_path, base_point_vector_path, dist_raster_path,
|
||||
work_dir, where_clause=f'{fid_field}={point_feature.GetFID()}')
|
||||
# Add each features distance transform result to list
|
||||
land_point_dist_raster_path_list.append(dist_raster_path)
|
||||
|
||||
target_layer = None
|
||||
target_vector = None
|
||||
base_point_layer = None
|
||||
base_point_vector = None
|
||||
l2g_dist_array = numpy.array(l2g_dist)
|
||||
|
||||
def _min_land_ocean_dist(*grid_distances):
|
||||
|
|
|
@ -6,13 +6,14 @@ import os
|
|||
|
||||
import pandas
|
||||
import numpy
|
||||
from osgeo import gdal
|
||||
import pygeoprocessing
|
||||
|
||||
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'annual_water_yield')
|
||||
SAMPLE_DATA = os.path.join(REGRESSION_DATA, 'input')
|
||||
|
||||
gdal.UseExceptions()
|
||||
|
||||
class AnnualWaterYieldTests(unittest.TestCase):
|
||||
"""Regression Tests for Annual Water Yield Model."""
|
||||
|
|
|
@ -12,6 +12,7 @@ import numpy.random
|
|||
import numpy.testing
|
||||
import pygeoprocessing
|
||||
|
||||
gdal.UseExceptions()
|
||||
|
||||
def make_simple_raster(base_raster_path, fill_val, nodata_val):
|
||||
"""Create a 10x10 raster on designated path with fill value.
|
||||
|
|
|
@ -10,12 +10,13 @@ import json
|
|||
import importlib
|
||||
import uuid
|
||||
|
||||
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
|
||||
from osgeo import gdal
|
||||
gdal.UseExceptions()
|
||||
|
||||
@contextlib.contextmanager
|
||||
def redirect_stdout():
|
||||
|
|
|
@ -17,6 +17,7 @@ from natcap.invest import validation
|
|||
from osgeo import gdal
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data',
|
||||
'coastal_blue_carbon')
|
||||
|
|
|
@ -20,6 +20,7 @@ from shapely.geometry import MultiPolygon
|
|||
from shapely.geometry import Point
|
||||
from shapely.geometry import Polygon
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data',
|
||||
'coastal_vulnerability')
|
||||
|
@ -931,14 +932,8 @@ class CoastalVulnerabilityTests(unittest.TestCase):
|
|||
REGRESSION_DATA, 'coastal_exposure.gpkg')
|
||||
|
||||
# This input gets modified in place, so first copy to working dir
|
||||
# I'm using GPKG driver to copy because that driver may have problems
|
||||
# updating a file created by a different GPKG driver version, and the
|
||||
# version used is dependent on GDAL version.
|
||||
# https://gdal.org/drivers/vector/gpkg.html
|
||||
base_shore_point_vector = ogr.Open(base_vector_path)
|
||||
gpkg_driver = ogr.GetDriverByName('GPKG')
|
||||
gpkg_driver.CopyDataSource(
|
||||
base_shore_point_vector, target_point_vector_path)
|
||||
base_shore_point_vector = gdal.OpenEx(base_vector_path, gdal.OF_VECTOR)
|
||||
gdal.VectorTranslate(target_point_vector_path, base_shore_point_vector)
|
||||
|
||||
coastal_vulnerability.calculate_final_risk(
|
||||
target_point_vector_path, target_point_csv_path)
|
||||
|
@ -968,17 +963,9 @@ class CoastalVulnerabilityTests(unittest.TestCase):
|
|||
# This gpkg has a feature with an empty field value for 'R_slr'
|
||||
# The function modifies the file in place, so copy to test workspace
|
||||
# first.
|
||||
|
||||
# I'm using GPKG driver to copy because that driver may have problems
|
||||
# updating a file created by a different GPKG driver version, and the
|
||||
# version used is dependent on GDAL version.
|
||||
# https://gdal.org/drivers/vector/gpkg.html
|
||||
base_vector_path = os.path.join(
|
||||
REGRESSION_DATA, 'test_missing_values.gpkg')
|
||||
base_shore_point_vector = ogr.Open(base_vector_path)
|
||||
gpkg_driver = ogr.GetDriverByName('GPKG')
|
||||
gpkg_driver.CopyDataSource(
|
||||
base_shore_point_vector, target_vector_path)
|
||||
gdal.VectorTranslate(target_vector_path, base_vector_path)
|
||||
|
||||
coastal_vulnerability.calculate_final_risk(
|
||||
target_vector_path, target_csv_path)
|
||||
|
|
|
@ -9,6 +9,7 @@ from osgeo import gdal
|
|||
import pandas
|
||||
import pygeoprocessing
|
||||
|
||||
gdal.UseExceptions()
|
||||
MODEL_DATA_PATH = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data',
|
||||
'crop_production_model', 'model_data')
|
||||
|
|
|
@ -18,6 +18,7 @@ import shapely.geometry
|
|||
from osgeo import gdal
|
||||
from osgeo import ogr
|
||||
|
||||
gdal.UseExceptions()
|
||||
_TEST_FILE_CWD = os.path.dirname(os.path.abspath(__file__))
|
||||
DATA_DIR = os.path.join(_TEST_FILE_CWD,
|
||||
'..', 'data', 'invest-test-data', 'data_stack')
|
||||
|
|
|
@ -19,6 +19,7 @@ from shapely.geometry import box
|
|||
from shapely.geometry import MultiPoint
|
||||
from shapely.geometry import Point
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data',
|
||||
'delineateit')
|
||||
|
|
|
@ -7,7 +7,7 @@ import os
|
|||
from osgeo import gdal
|
||||
import numpy
|
||||
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data',
|
||||
'forest_carbon_edge_effect')
|
||||
|
|
|
@ -12,6 +12,7 @@ from osgeo import ogr
|
|||
from osgeo import osr
|
||||
from shapely.geometry import Polygon
|
||||
|
||||
gdal.UseExceptions()
|
||||
|
||||
def make_raster_from_array(
|
||||
base_array, base_raster_path, nodata_val=-1, gdal_type=gdal.GDT_Int32):
|
||||
|
|
|
@ -18,6 +18,7 @@ from osgeo import gdal
|
|||
from osgeo import ogr
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
ORIGIN = (1180000.0, 690000.0)
|
||||
_SRS = osr.SpatialReference()
|
||||
_SRS.ImportFromEPSG(26910) # UTM zone 10N
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
import unittest
|
||||
import os
|
||||
|
||||
from osgeo import gdal
|
||||
gdal.UseExceptions()
|
||||
|
||||
class FileRegistryTests(unittest.TestCase):
|
||||
"""Tests for the InVEST file registry builder."""
|
||||
|
|
|
@ -4,7 +4,9 @@ import unittest
|
|||
|
||||
import pint
|
||||
from natcap.invest.model_metadata import MODEL_METADATA
|
||||
from osgeo import gdal
|
||||
|
||||
gdal.UseExceptions()
|
||||
valid_nested_types = {
|
||||
None: { # if no parent type (arg is top-level), then all types are valid
|
||||
'boolean',
|
||||
|
|
|
@ -12,6 +12,7 @@ from osgeo import gdal
|
|||
from osgeo import ogr
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'ndr')
|
||||
|
||||
|
|
|
@ -7,9 +7,11 @@ import unittest
|
|||
import numpy
|
||||
import pygeoprocessing
|
||||
import shapely.geometry
|
||||
from osgeo import gdal
|
||||
from osgeo import ogr
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'pollination')
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import warnings
|
|||
|
||||
from natcap.invest import utils
|
||||
|
||||
gdal.UseExceptions()
|
||||
Pyro4.config.SERIALIZER = 'marshal' # allow null bytes in strings
|
||||
|
||||
REGRESSION_DATA = os.path.join(
|
||||
|
|
|
@ -9,6 +9,7 @@ import numpy
|
|||
from osgeo import gdal
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
|
||||
class RouteDEMTests(unittest.TestCase):
|
||||
"""Tests for RouteDEM with Pygeoprocessing 1.x routing API."""
|
||||
|
|
|
@ -5,7 +5,9 @@ import shutil
|
|||
import os
|
||||
|
||||
import pandas
|
||||
from osgeo import gdal
|
||||
|
||||
gdal.UseExceptions()
|
||||
TEST_DATA_DIR = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data',
|
||||
'scenario_gen_proximity')
|
||||
|
|
|
@ -14,6 +14,7 @@ from shapely.geometry import LineString
|
|||
from shapely.geometry import Point
|
||||
from shapely.geometry import Polygon
|
||||
|
||||
gdal.UseExceptions()
|
||||
_SRS = osr.SpatialReference()
|
||||
_SRS.ImportFromEPSG(32731) # WGS84 / UTM zone 31s
|
||||
WKT = _SRS.ExportToWkt()
|
||||
|
|
|
@ -9,6 +9,7 @@ import pygeoprocessing
|
|||
from osgeo import gdal
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'sdr')
|
||||
SAMPLE_DATA = os.path.join(REGRESSION_DATA, 'input')
|
||||
|
|
|
@ -10,6 +10,7 @@ from osgeo import gdal
|
|||
from osgeo import ogr
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data',
|
||||
'seasonal_water_yield')
|
||||
|
@ -165,6 +166,30 @@ def make_precip_rasters(precip_dir_path):
|
|||
make_raster_from_array(precip_array, precip_raster_path)
|
||||
|
||||
|
||||
def make_zeropadded_rasters(dir_path, prefix):
|
||||
"""Make twelve 1x1 raster files with filenames ending in zero-padded
|
||||
month number.
|
||||
|
||||
Args:
|
||||
dir_path (str): path to the directory for saving the rasters.
|
||||
file_prefix (str): prefix of new files to create.
|
||||
|
||||
Returns:
|
||||
list: monthly raster filenames
|
||||
"""
|
||||
size = 1
|
||||
monthly_raster_list = []
|
||||
|
||||
for month in range(1, 13):
|
||||
raster_path = os.path.join(
|
||||
dir_path, prefix + str(month).zfill(2) + '.tif')
|
||||
temp_array = numpy.full((size, size), 1, dtype=numpy.int8)
|
||||
make_raster_from_array(temp_array, raster_path)
|
||||
monthly_raster_list.append(raster_path)
|
||||
|
||||
return monthly_raster_list
|
||||
|
||||
|
||||
def make_recharge_raster(recharge_ras_path):
|
||||
"""Make a 100x100 raster of user defined recharge.
|
||||
|
||||
|
@ -317,6 +342,61 @@ class SeasonalWaterYieldUnusualDataTests(unittest.TestCase):
|
|||
"""Delete workspace after test is done."""
|
||||
shutil.rmtree(self.workspace_dir, ignore_errors=True)
|
||||
|
||||
def test_zeropadded_monthly_filenames(self):
|
||||
"""test filenames with zero-padded months in
|
||||
_get_monthly_file_lists function
|
||||
"""
|
||||
from natcap.invest.seasonal_water_yield.seasonal_water_yield import _get_monthly_file_lists
|
||||
|
||||
n_months = 12
|
||||
|
||||
# Make directory and file names with zero-padded months
|
||||
test_precip_dir_path = os.path.join(self.workspace_dir,
|
||||
'test_0pad_precip_dir')
|
||||
os.makedirs(test_precip_dir_path)
|
||||
precip_file_list = make_zeropadded_rasters(test_precip_dir_path, 'Prcp')
|
||||
|
||||
test_eto_dir_path = os.path.join(self.workspace_dir,
|
||||
'test_0pad_eto_dir')
|
||||
os.makedirs(test_eto_dir_path)
|
||||
eto_file_list = make_zeropadded_rasters(test_eto_dir_path, 'et0_')
|
||||
|
||||
# Create list of monthly files for data_type
|
||||
eto_path_list = _get_monthly_file_lists(
|
||||
n_months, test_eto_dir_path)
|
||||
|
||||
precip_path_list = _get_monthly_file_lists(
|
||||
n_months, test_precip_dir_path)
|
||||
|
||||
# Verify that the returned lists match the input
|
||||
self.assertEqual(precip_path_list, precip_file_list)
|
||||
self.assertEqual(eto_path_list, eto_file_list)
|
||||
|
||||
def test_nonpadded_monthly_filenames(self):
|
||||
"""test filenames without zero-padded months in
|
||||
_get_monthly_file_lists function
|
||||
"""
|
||||
from natcap.invest.seasonal_water_yield.seasonal_water_yield import _get_monthly_file_lists
|
||||
|
||||
n_months = 12
|
||||
|
||||
# Make directory and file names with (non-zero-padded) months
|
||||
precip_dir_path = os.path.join(self.workspace_dir, 'precip_dir')
|
||||
os.makedirs(precip_dir_path)
|
||||
make_precip_rasters(precip_dir_path)
|
||||
|
||||
precip_path_list = _get_monthly_file_lists(
|
||||
n_months, precip_dir_path)
|
||||
|
||||
# Create lists of monthly filenames to which to compare function output
|
||||
# Note this is hardcoded to match the filenames created in make_precip_rasters
|
||||
match_precip = [os.path.join(precip_dir_path,
|
||||
"precip_mm_" + str(m) + ".tif")
|
||||
for m in range(1, n_months + 1)]
|
||||
|
||||
# Verify that the returned lists match the input
|
||||
self.assertEqual(precip_path_list, match_precip)
|
||||
|
||||
def test_ambiguous_precip_data(self):
|
||||
"""SWY test case where there are more than 12 precipitation files."""
|
||||
from natcap.invest.seasonal_water_yield import seasonal_water_yield
|
||||
|
|
|
@ -2,7 +2,9 @@ import unittest
|
|||
|
||||
from natcap.invest import spec_utils
|
||||
from natcap.invest.unit_registry import u
|
||||
from osgeo import gdal
|
||||
|
||||
gdal.UseExceptions()
|
||||
|
||||
class TestSpecUtils(unittest.TestCase):
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import pygeoprocessing
|
|||
from pygeoprocessing.geoprocessing_core import (
|
||||
DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS as opts_tuple)
|
||||
|
||||
|
||||
gdal.UseExceptions()
|
||||
TEST_DATA = os.path.join(os.path.dirname(
|
||||
__file__), '..', 'data', 'invest-test-data', 'stormwater')
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@ from unittest.mock import patch
|
|||
from babel.messages import Catalog, mofile
|
||||
import natcap.invest
|
||||
from natcap.invest import validation
|
||||
from osgeo import gdal
|
||||
|
||||
gdal.UseExceptions()
|
||||
TEST_LANG = 'll'
|
||||
|
||||
# assign to local variable so that it won't be changed by translation
|
||||
|
|
|
@ -8,6 +8,7 @@ import numpy
|
|||
import pandas
|
||||
from osgeo import gdal
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'ucm')
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ from osgeo import gdal
|
|||
from osgeo import ogr
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
|
||||
class UFRMTests(unittest.TestCase):
|
||||
"""Tests for the Urban Flood Risk Mitigation Model."""
|
||||
|
|
|
@ -6,7 +6,9 @@ import unittest
|
|||
from unittest.mock import Mock, patch
|
||||
|
||||
from natcap.invest import ui_server
|
||||
from osgeo import gdal
|
||||
|
||||
gdal.UseExceptions()
|
||||
TEST_DATA_PATH = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data')
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ from osgeo import gdal
|
|||
from osgeo import ogr
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
_DEFAULT_ORIGIN = (444720, 3751320)
|
||||
_DEFAULT_PIXEL_SIZE = (30, -30)
|
||||
_DEFAULT_EPSG = 3116
|
||||
|
@ -904,8 +905,14 @@ class UNATests(unittest.TestCase):
|
|||
from natcap.invest import urban_nature_access
|
||||
args = _build_model_args(self.workspace_dir)
|
||||
|
||||
admin_vector = gdal.OpenEx(args['admin_boundaries_vector_path'])
|
||||
admin_layer = admin_vector.GetLayer()
|
||||
fid = admin_layer.GetNextFeature().GetFID()
|
||||
admin_layer = None
|
||||
admin_vector = None
|
||||
|
||||
feature_attrs = {
|
||||
0: {
|
||||
fid: {
|
||||
'my-field-1': float(1.2345),
|
||||
'my-field-2': numpy.float32(2.34567),
|
||||
'my-field-3': numpy.float64(3.45678),
|
||||
|
@ -924,10 +931,10 @@ class UNATests(unittest.TestCase):
|
|||
vector = gdal.OpenEx(target_vector_path)
|
||||
self.assertEqual(vector.GetLayerCount(), 1)
|
||||
layer = vector.GetLayer()
|
||||
self.assertEqual(len(layer.schema), len(feature_attrs[0]))
|
||||
self.assertEqual(len(layer.schema), len(feature_attrs[fid]))
|
||||
self.assertEqual(layer.GetFeatureCount(), 1)
|
||||
feature = layer.GetFeature(0)
|
||||
for field_name, expected_field_value in feature_attrs[0].items():
|
||||
feature = layer.GetFeature(fid)
|
||||
for field_name, expected_field_value in feature_attrs[fid].items():
|
||||
self.assertEqual(
|
||||
feature.GetField(field_name), expected_field_value)
|
||||
finally:
|
||||
|
|
|
@ -13,6 +13,7 @@ import shapely.geometry
|
|||
import numpy
|
||||
import numpy.testing
|
||||
|
||||
gdal.UseExceptions()
|
||||
|
||||
class UsageLoggingTests(unittest.TestCase):
|
||||
"""Tests for the InVEST usage logging framework."""
|
||||
|
|
|
@ -25,6 +25,7 @@ from osgeo import osr
|
|||
from shapely.geometry import Point
|
||||
from shapely.geometry import Polygon
|
||||
|
||||
gdal.UseExceptions()
|
||||
|
||||
class SuffixUtilsTests(unittest.TestCase):
|
||||
"""Tests for natcap.invest.utils.make_suffix_string."""
|
||||
|
@ -412,17 +413,22 @@ class GDALWarningsLoggingTests(unittest.TestCase):
|
|||
|
||||
logfile = os.path.join(self.workspace, 'logfile.txt')
|
||||
|
||||
# this warning should go to stdout.
|
||||
gdal.Open('this_file_should_not_exist.tif')
|
||||
invalid_polygon = ogr.CreateGeometryFromWkt(
|
||||
'POLYGON ((-20 -20, -16 -20, -20 -16, -16 -16, -20 -20))')
|
||||
|
||||
# This produces a GDAL warning that does not raise an
|
||||
# exception with UseExceptions(). Without capture_gdal_logging,
|
||||
# it will be printed directly to stderr
|
||||
invalid_polygon.IsValid()
|
||||
|
||||
with utils.log_to_file(logfile) as handler:
|
||||
with utils.capture_gdal_logging():
|
||||
# warning should be captured.
|
||||
gdal.Open('file_file_should_also_not_exist.tif')
|
||||
invalid_polygon.IsValid()
|
||||
handler.flush()
|
||||
|
||||
# warning should go to stdout
|
||||
gdal.Open('this_file_should_not_exist.tif')
|
||||
# warning should go to stderr
|
||||
invalid_polygon.IsValid()
|
||||
|
||||
with open(logfile) as opened_logfile:
|
||||
messages = [msg for msg in opened_logfile.read().split('\n')
|
||||
|
@ -499,7 +505,11 @@ class PrepareWorkspaceTests(unittest.TestCase):
|
|||
with utils.prepare_workspace(workspace,
|
||||
'some_model'):
|
||||
warnings.warn('deprecated', UserWarning)
|
||||
gdal.Open('file should not exist')
|
||||
invalid_polygon = ogr.CreateGeometryFromWkt(
|
||||
'POLYGON ((-20 -20, -16 -20, -20 -16, -16 -16, -20 -20))')
|
||||
# This produces a GDAL warning that does not raise an
|
||||
# exception with UseExceptions()
|
||||
invalid_polygon.IsValid()
|
||||
|
||||
self.assertTrue(os.path.exists(workspace))
|
||||
logfile_glob = glob.glob(os.path.join(workspace, '*.txt'))
|
||||
|
@ -509,11 +519,9 @@ class PrepareWorkspaceTests(unittest.TestCase):
|
|||
with open(logfile_glob[0]) as logfile:
|
||||
logfile_text = logfile.read()
|
||||
# all the following strings should be in the logfile.
|
||||
expected_string = (
|
||||
'file should not exist: No such file or directory')
|
||||
self.assertTrue(
|
||||
expected_string in logfile_text) # gdal error captured
|
||||
self.assertEqual(len(re.findall('WARNING', logfile_text)), 1)
|
||||
self.assertTrue( # gdal logging captured
|
||||
'Self-intersection at or near point -18 -18' in logfile_text)
|
||||
self.assertEqual(len(re.findall('WARNING', logfile_text)), 2)
|
||||
self.assertTrue('Elapsed time:' in logfile_text)
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ from osgeo import gdal
|
|||
from osgeo import ogr
|
||||
from osgeo import osr
|
||||
|
||||
gdal.UseExceptions()
|
||||
|
||||
class SpatialOverlapTest(unittest.TestCase):
|
||||
"""Test Spatial Overlap."""
|
||||
|
|
|
@ -18,6 +18,7 @@ from shapely.geometry import Point
|
|||
from natcap.invest import utils
|
||||
import pygeoprocessing
|
||||
|
||||
gdal.UseExceptions()
|
||||
REGRESSION_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'wave_energy')
|
||||
SAMPLE_DATA = os.path.join(REGRESSION_DATA, 'input')
|
||||
|
|
|
@ -17,6 +17,7 @@ from osgeo import osr
|
|||
|
||||
import pygeoprocessing
|
||||
|
||||
gdal.UseExceptions()
|
||||
SAMPLE_DATA = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'wind_energy',
|
||||
'input')
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "invest-workbench",
|
||||
"version": "0.1.0",
|
||||
"version": "3.14.2",
|
||||
"description": "Models that map and value the goods and services from nature that sustain and fulfill human life",
|
||||
"main": "build/main/main.js",
|
||||
"homepage": "./",
|
||||
|
|
|
@ -121,18 +121,24 @@ These instructions assume you have defined the two-letter locale code in an envi
|
|||
git add src/main/i18n/$LL.json src/renderer/i18n/$LL.json
|
||||
git commit -m "add new messages into $LL translation files"
|
||||
```
|
||||
3. (if the translator uses PO format) Convert JSON to PO
|
||||
3. Convert JSON to PO using [i18next-gettext-converter](https://github.com/i18next/i18next-gettext-converter):
|
||||
```
|
||||
i18next-conv -l $LL -s src/main/i18n/$LL.json -t src/main/i18n/$LL.po
|
||||
i18next-conv -l $LL -s src/renderer/i18n/$LL.json -t src/renderer/i18n/$LL.po
|
||||
|
||||
4. Send `src/main/i18n/$LL.[json,po]` and `src/renderer/i18n/$LL.[json,po]` to the translator and wait to receive a copy with translations added.
|
||||
```
|
||||
|
||||
5. (if the translator uses PO format) Convert PO to JSON
|
||||
If the translator works with PO files, we can convert them to JSON using this tool: https://github.com/i18next/i18next-gettext-converter
|
||||
4. Send `src/main/i18n/$LL.po` and `src/renderer/i18n/$LL.po` to the translator and wait to receive a copy with translations added.
|
||||
|
||||
6. Replace `src/main/i18n/$LL.[json,po]` and `src/renderer/i18n/$LL.json` with the updated versions received from the translator
|
||||
5. Receive the updated PO files from the translator, then convert PO to JSON using [i18next-gettext-converter](https://github.com/i18next/i18next-gettext-converter). Replace `src/main/i18n/$LL.json` and `src/renderer/i18n/$LL.json` with the updated versions:
|
||||
```
|
||||
i18next-conv -l $LL -s new_main_translations.po -t src/main/i18n/$LL.json
|
||||
i18next-conv -l $LL -s new_renderer_translations.po -t src/renderer/i18n/$LL.json
|
||||
|
||||
7. Commit the changes:
|
||||
```
|
||||
|
||||
6. Commit the changes:
|
||||
```
|
||||
git add src/main/i18n/$LL.json src/renderer/i18n/$LL.json
|
||||
git commit -m "add new translations for $LL"
|
||||
```
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"File": "",
|
||||
"Edit": "",
|
||||
"Speech": "",
|
||||
"View": "",
|
||||
"Window": "",
|
||||
"About": "",
|
||||
"About InVEST": "",
|
||||
"Report a problem": ""
|
||||
"File": "Archivo",
|
||||
"Edit": "Edición",
|
||||
"Speech": "Dicción",
|
||||
"View": "Vista",
|
||||
"Window": "Ventana",
|
||||
"About": "Acerca de",
|
||||
"About InVEST": "Acerca de InVEST",
|
||||
"Report a problem": "Informe de un problema"
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
export const ipcMainChannels = {
|
||||
BASE_URL: 'base-url',
|
||||
CHANGE_LANGUAGE: 'change-language',
|
||||
CHECK_FILE_PERMISSIONS: 'check-file-permissions',
|
||||
CHECK_STORAGE_TOKEN: 'check-storage-token',
|
||||
|
@ -12,6 +13,7 @@ export const ipcMainChannels = {
|
|||
INVEST_RUN: 'invest-run',
|
||||
INVEST_VERSION: 'invest-version',
|
||||
IS_FIRST_RUN: 'is-first-run',
|
||||
IS_NEW_VERSION: 'is-new-version',
|
||||
LOGGER: 'logger',
|
||||
OPEN_EXTERNAL_URL: 'open-external-url',
|
||||
OPEN_PATH: 'open-path',
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import path from 'path';
|
||||
|
||||
import i18n from './i18n/i18n';
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import {
|
||||
app,
|
||||
|
@ -9,35 +9,37 @@ import {
|
|||
ipcMain
|
||||
} from 'electron';
|
||||
|
||||
import BASE_URL from './baseUrl';
|
||||
import {
|
||||
createPythonFlaskProcess,
|
||||
getFlaskIsReady,
|
||||
shutdownPythonProcess
|
||||
shutdownPythonProcess,
|
||||
} from './createPythonFlaskProcess';
|
||||
import findInvestBinaries from './findInvestBinaries';
|
||||
import setupDownloadHandlers from './setupDownloadHandlers';
|
||||
import setupDialogs from './setupDialogs';
|
||||
import setupContextMenu from './setupContextMenu';
|
||||
import { ipcMainChannels } from './ipcMainChannels';
|
||||
import ELECTRON_DEV_MODE from './isDevMode';
|
||||
import { getLogger } from './logger';
|
||||
import menuTemplate from './menubar';
|
||||
import pkg from '../../package.json';
|
||||
import { settingsStore, setupSettingsHandlers } from './settingsStore';
|
||||
import { setupBaseUrl } from './setupBaseUrl';
|
||||
import setupCheckFilePermissions from './setupCheckFilePermissions';
|
||||
import { setupCheckFirstRun } from './setupCheckFirstRun';
|
||||
import { setupCheckStorageToken } from './setupCheckStorageToken';
|
||||
import {
|
||||
setupInvestRunHandlers,
|
||||
setupInvestLogReaderHandler
|
||||
} from './setupInvestHandlers';
|
||||
import setupContextMenu from './setupContextMenu';
|
||||
import setupDialogs from './setupDialogs';
|
||||
import setupDownloadHandlers from './setupDownloadHandlers';
|
||||
import setupGetElectronPaths from './setupGetElectronPaths';
|
||||
import setupGetNCPUs from './setupGetNCPUs';
|
||||
import {
|
||||
setupInvestLogReaderHandler,
|
||||
setupInvestRunHandlers,
|
||||
} from './setupInvestHandlers';
|
||||
import { setupIsNewVersion } from './setupIsNewVersion';
|
||||
import setupOpenExternalUrl from './setupOpenExternalUrl';
|
||||
import setupOpenLocalHtml from './setupOpenLocalHtml';
|
||||
import { settingsStore, setupSettingsHandlers } from './settingsStore';
|
||||
import setupGetElectronPaths from './setupGetElectronPaths';
|
||||
import setupRendererLogger from './setupRendererLogger';
|
||||
import { ipcMainChannels } from './ipcMainChannels';
|
||||
import menuTemplate from './menubar';
|
||||
import ELECTRON_DEV_MODE from './isDevMode';
|
||||
import BASE_URL from './baseUrl';
|
||||
import { getLogger } from './logger';
|
||||
import i18n from './i18n/i18n';
|
||||
import pkg from '../../package.json';
|
||||
|
||||
|
||||
const logger = getLogger(__filename.split('/').slice(-1)[0]);
|
||||
|
||||
|
@ -87,6 +89,7 @@ export const createWindow = async () => {
|
|||
setupDialogs();
|
||||
setupCheckFilePermissions();
|
||||
setupCheckFirstRun();
|
||||
setupIsNewVersion();
|
||||
setupCheckStorageToken();
|
||||
setupSettingsHandlers();
|
||||
setupGetElectronPaths();
|
||||
|
@ -94,6 +97,7 @@ export const createWindow = async () => {
|
|||
setupInvestLogReaderHandler();
|
||||
setupOpenExternalUrl();
|
||||
setupRendererLogger();
|
||||
setupBaseUrl();
|
||||
await getFlaskIsReady();
|
||||
|
||||
const devModeArg = ELECTRON_DEV_MODE ? '--devmode' : '';
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
import {
|
||||
ipcMain,
|
||||
} from 'electron';
|
||||
|
||||
import { ipcMainChannels } from './ipcMainChannels';
|
||||
|
||||
import baseUrl from './baseUrl';
|
||||
|
||||
export function setupBaseUrl() {
|
||||
ipcMain.handle(
|
||||
ipcMainChannels.BASE_URL, () => baseUrl
|
||||
);
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import {
|
||||
app,
|
||||
ipcMain,
|
||||
} from 'electron';
|
||||
|
||||
import { ipcMainChannels } from './ipcMainChannels';
|
||||
import { getLogger } from './logger';
|
||||
import pkg from '../../package.json';
|
||||
|
||||
const logger = getLogger(__filename.split('/').slice(-1)[0]);
|
||||
|
||||
export const APP_VERSION_TOKEN = 'app-version-token.txt';
|
||||
|
||||
/** Determine whether this is the first run of the current running version.
|
||||
*
|
||||
* @returns {boolean} true if this version has not run before, otherwise false
|
||||
*/
|
||||
export async function isNewVersion() {
|
||||
// Getting version from package.json is simplest because there is no need to
|
||||
// spawn an invest process simply to get the version of the installed binary.
|
||||
const currentVersion = pkg.version;
|
||||
const userDataPath = app.getPath('userData');
|
||||
const tokenPath = path.join(userDataPath, APP_VERSION_TOKEN);
|
||||
try {
|
||||
if (fs.existsSync(tokenPath)) {
|
||||
const tokenString = fs.readFileSync(tokenPath, {encoding: 'utf8'});
|
||||
if (tokenString) {
|
||||
const installedVersionList = tokenString.split(',');
|
||||
if (installedVersionList.includes(currentVersion)) {
|
||||
return false;
|
||||
}
|
||||
// If current version not found, add it
|
||||
fs.writeFileSync(tokenPath, `${tokenString},${currentVersion}`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// If file does not exist, create it
|
||||
fs.writeFileSync(tokenPath, currentVersion);
|
||||
} catch (error) {
|
||||
logger.warn(`Unable to write app-version token: ${error}`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function setupIsNewVersion() {
|
||||
ipcMain.handle(
|
||||
ipcMainChannels.IS_NEW_VERSION, () => isNewVersion()
|
||||
);
|
||||
}
|
|
@ -24,6 +24,7 @@ import DownloadProgressBar from './components/DownloadProgressBar';
|
|||
import { getInvestModelNames } from './server_requests';
|
||||
import InvestJob from './InvestJob';
|
||||
import { dragOverHandlerNone } from './utils';
|
||||
import Changelog from './components/Changelog';
|
||||
|
||||
const { ipcRenderer } = window.Workbench.electron;
|
||||
|
||||
|
@ -42,6 +43,8 @@ export default class App extends React.Component {
|
|||
recentJobs: [],
|
||||
showDownloadModal: false,
|
||||
downloadedNofN: null,
|
||||
showChangelog: false,
|
||||
changelogDismissed: false,
|
||||
};
|
||||
this.switchTabs = this.switchTabs.bind(this);
|
||||
this.openInvestModel = this.openInvestModel.bind(this);
|
||||
|
@ -65,6 +68,9 @@ export default class App extends React.Component {
|
|||
.includes(job.modelRunName)
|
||||
)),
|
||||
showDownloadModal: this.props.isFirstRun,
|
||||
// Show changelog if this is a new version,
|
||||
// but if it's the first run ever, wait until after download modal closes.
|
||||
showChangelog: this.props.isNewVersion && !this.props.isFirstRun,
|
||||
});
|
||||
await i18n.changeLanguage(window.Workbench.LANGUAGE);
|
||||
ipcRenderer.on('download-status', (downloadedNofN) => {
|
||||
|
@ -92,6 +98,20 @@ export default class App extends React.Component {
|
|||
this.setState({
|
||||
showDownloadModal: shouldShow,
|
||||
});
|
||||
// After close, show changelog if new version and app has just launched
|
||||
// (i.e., show changelog only once, after the first time the download modal closes).
|
||||
if (!shouldShow && this.props.isNewVersion && !this.state.changelogDismissed) {
|
||||
this.setState({
|
||||
showChangelog: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
closeChangelogModal() {
|
||||
this.setState({
|
||||
showChangelog: false,
|
||||
changelogDismissed: true,
|
||||
});
|
||||
}
|
||||
|
||||
/** Push data for a new InvestTab component to an array.
|
||||
|
@ -183,6 +203,7 @@ export default class App extends React.Component {
|
|||
openTabIDs,
|
||||
activeTab,
|
||||
showDownloadModal,
|
||||
showChangelog,
|
||||
downloadedNofN,
|
||||
} = this.state;
|
||||
|
||||
|
@ -277,6 +298,13 @@ export default class App extends React.Component {
|
|||
show={showDownloadModal}
|
||||
closeModal={() => this.showDownloadModal(false)}
|
||||
/>
|
||||
{
|
||||
showChangelog &&
|
||||
<Changelog
|
||||
show={showChangelog}
|
||||
close={() => this.closeChangelogModal()}
|
||||
/>
|
||||
}
|
||||
<TabContainer activeKey={activeTab}>
|
||||
<Navbar
|
||||
onDragOver={dragOverHandlerNone}
|
||||
|
@ -357,6 +385,7 @@ export default class App extends React.Component {
|
|||
|
||||
App.propTypes = {
|
||||
isFirstRun: PropTypes.bool,
|
||||
isNewVersion: PropTypes.bool,
|
||||
nCPU: PropTypes.number,
|
||||
};
|
||||
|
||||
|
@ -364,5 +393,6 @@ App.propTypes = {
|
|||
// can be undefined for unrelated tests.
|
||||
App.defaultProps = {
|
||||
isFirstRun: false,
|
||||
isNewVersion: false,
|
||||
nCPU: 1,
|
||||
};
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Button from 'react-bootstrap/Button';
|
||||
import Modal from 'react-bootstrap/Modal';
|
||||
import { MdClose } from 'react-icons/md';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import pkg from '../../../../package.json';
|
||||
import { ipcMainChannels } from '../../../main/ipcMainChannels';
|
||||
|
||||
const { ipcRenderer } = window.Workbench.electron;
|
||||
const { logger } = window.Workbench;
|
||||
|
||||
export default function Changelog(props) {
|
||||
const { t } = useTranslation();
|
||||
const [htmlContent, setHtmlContent] = useState('');
|
||||
|
||||
// Load HTML from external file (which is generated by Python build process).
|
||||
useEffect(() => {
|
||||
async function loadHtml() {
|
||||
const baseUrl = await ipcRenderer.invoke(ipcMainChannels.BASE_URL);
|
||||
const response = await fetch(`${baseUrl}/changelog.html`);
|
||||
if (!response.ok) {
|
||||
logger.debug(`Error fetching changelog HTML: ${response.status} ${response.statusText}`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const htmlString = await response.text();
|
||||
// Find the section whose heading explicitly matches the current version.
|
||||
const versionStr = pkg.version;
|
||||
const escapedVersionStr = versionStr.split('.').join('\\.');
|
||||
const sectionRegex = new RegExp(
|
||||
`<section.*?>[\\s]*?<h1>${escapedVersionStr}\\b[\\s\\S]*?</h1>[\\s\\S]*?</section>`
|
||||
);
|
||||
const sectionMatches = htmlString.match(sectionRegex);
|
||||
if (sectionMatches && sectionMatches.length) {
|
||||
let latestVersionSection = sectionMatches[0];
|
||||
const linkRegex = /<a\shref/g;
|
||||
// Ensure all links open in a new window and are styled with a relevant icon.
|
||||
latestVersionSection = latestVersionSection.replaceAll(
|
||||
linkRegex,
|
||||
'<a target="_blank" class="link-external" href'
|
||||
);
|
||||
setHtmlContent({
|
||||
__html: latestVersionSection
|
||||
});
|
||||
}
|
||||
} catch(error) {
|
||||
logger.debug(error);
|
||||
}
|
||||
}
|
||||
loadHtml();
|
||||
}, []);
|
||||
|
||||
// Once HTML content has loaded, set up links to open in browser
|
||||
// (instead of in an Electron window).
|
||||
useEffect(() => {
|
||||
const openLinkInBrowser = (event) => {
|
||||
event.preventDefault();
|
||||
ipcRenderer.send(
|
||||
ipcMainChannels.OPEN_EXTERNAL_URL, event.currentTarget.href
|
||||
);
|
||||
};
|
||||
document.querySelectorAll('.link-external').forEach(link => {
|
||||
link.addEventListener('click', openLinkInBrowser);
|
||||
});
|
||||
}, [htmlContent]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
show={props.show && htmlContent !== ''}
|
||||
onHide={props.close}
|
||||
size="lg"
|
||||
aria-labelledby="changelog-modal-title"
|
||||
>
|
||||
<Modal.Header>
|
||||
<Modal.Title id="changelog-modal-title">
|
||||
{t('New in this version')}
|
||||
</Modal.Title>
|
||||
<Button
|
||||
variant="secondary-outline"
|
||||
onClick={props.close}
|
||||
className="float-right"
|
||||
aria-label="Close modal"
|
||||
>
|
||||
<MdClose />
|
||||
</Button>
|
||||
</Modal.Header>
|
||||
{/* Setting inner HTML in this way is OK because
|
||||
the HTML content is controlled by our build process
|
||||
and not, for example, sourced from user input. */}
|
||||
<Modal.Body
|
||||
dangerouslySetInnerHTML={htmlContent}
|
||||
>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
Changelog.propTypes = {
|
||||
show: PropTypes.bool.isRequired,
|
||||
close: PropTypes.func.isRequired,
|
||||
};
|
|
@ -174,6 +174,38 @@ class DataDownloadModal extends React.Component {
|
|||
// Don't render until registry is loaded, since it loads async
|
||||
if (!dataRegistry) { return <div />; }
|
||||
|
||||
const displayNames = {
|
||||
'Annual Water Yield': t('Annual Water Yield'),
|
||||
'Carbon Storage and Sequestration': t('Carbon Storage and Sequestration'),
|
||||
'Coastal Blue Carbon': t('Coastal Blue Carbon'),
|
||||
'Coastal Vulnerability': t('Coastal Vulnerability'),
|
||||
'Crop Pollination': t('Crop Pollination'),
|
||||
'Crop Production': t('Crop Production'),
|
||||
'DelineateIt': t('DelineateIt'),
|
||||
'Forest Carbon Edge Effect': t('Forest Carbon Edge Effect'),
|
||||
'Habitat Quality': t('Habitat Quality'),
|
||||
'Habitat Risk Assessment': t('Habitat Risk Assessment'),
|
||||
'Nutrient Delivery Ratio': t('Nutrient Delivery Ratio'),
|
||||
'RouteDEM': t('RouteDEM'),
|
||||
'Scenario Generator: Proximity Based': t('Scenario Generator: Proximity Based'),
|
||||
'Scenic Quality': t('Scenic Quality'),
|
||||
'Seasonal Water Yield': t('Seasonal Water Yield'),
|
||||
'Sediment Delivery Ratio': t('Sediment Delivery Ratio'),
|
||||
'Urban Stormwater Retention': t('Urban Stormwater Retention'),
|
||||
'Urban Cooling': t('Urban Cooling'),
|
||||
'Urban Flood Risk Mitigation': t('Urban Flood Risk Mitigation'),
|
||||
'Urban Nature Access': t('Urban Nature Access'),
|
||||
'Visitation: Recreation and Tourism': t('Visitation: Recreation and Tourism'),
|
||||
'Wave Energy Production': t('Wave Energy Production'),
|
||||
'Wind Energy Production': t('Wind Energy Production'),
|
||||
'Global DEM & Landmass Polygon': t('Global DEM & Landmass Polygon'),
|
||||
};
|
||||
const displayNotes = {
|
||||
'(recommended to run model)': t('(recommended to run model)'),
|
||||
'(required to run model)': t('(required to run model)'),
|
||||
'(required for Wind & Wave Energy)': t('(required for Wind & Wave Energy)'),
|
||||
};
|
||||
|
||||
const downloadEnabled = Boolean(selectedLinksArray.length);
|
||||
const DatasetCheckboxRows = [];
|
||||
Object.keys(modelCheckBoxState)
|
||||
|
@ -196,11 +228,11 @@ class DataDownloadModal extends React.Component {
|
|||
)}
|
||||
/>
|
||||
<Form.Check.Label>
|
||||
{modelName}
|
||||
{displayNames[modelName]}
|
||||
</Form.Check.Label>
|
||||
</Form.Check>
|
||||
</td>
|
||||
<td><em>{note}</em></td>
|
||||
<td><em>{displayNotes[note]}</em></td>
|
||||
<td>{filesizeStr}</td>
|
||||
</tr>
|
||||
);
|
||||
|
@ -211,6 +243,7 @@ class DataDownloadModal extends React.Component {
|
|||
show={this.props.show}
|
||||
onHide={this.closeDialog}
|
||||
size="lg"
|
||||
aria-labelledby="download-modal-title"
|
||||
>
|
||||
<Form>
|
||||
<Modal.Header>
|
||||
|
@ -230,7 +263,9 @@ class DataDownloadModal extends React.Component {
|
|||
<p className="mb-0"><em>{this.state.alertPath}</em></p>
|
||||
</Alert>
|
||||
)
|
||||
: <Modal.Title>{t("Download InVEST sample data")}</Modal.Title>
|
||||
: <Modal.Title id="download-modal-title">
|
||||
{t("Download InVEST sample data")}
|
||||
</Modal.Title>
|
||||
}
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
|
|
|
@ -32,11 +32,8 @@ class OpenButton extends React.Component {
|
|||
datastack = await fetchDatastackFromFile({ filepath: data.filePaths[0] });
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
alert(
|
||||
t(
|
||||
'No InVEST model data can be parsed from the file:\n {{filepath}}',
|
||||
{ filepath: data.filePaths[0] }
|
||||
)
|
||||
alert( // eslint-disable-line no-alert
|
||||
`${t('No InVEST model data can be parsed from the file:')}\n${data.filePaths[0]}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -317,10 +317,7 @@ class SetupTab extends React.Component {
|
|||
} catch (error) {
|
||||
logger.error(error);
|
||||
alert( // eslint-disable-line no-alert
|
||||
t(
|
||||
'No InVEST model data can be parsed from the file:\n {{filepath}}',
|
||||
{ filepath: filepath }
|
||||
)
|
||||
`${t('No InVEST model data can be parsed from the file:')}\n${filepath}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,44 @@
|
|||
{
|
||||
"Annual Water Yield": "Producción anual de agua",
|
||||
"Carbon Storage and Sequestration": "Almacenamiento y secuestración de carbono",
|
||||
"Coastal Blue Carbon": "Carbono azul costero",
|
||||
"Coastal Vulnerability": "Vulnerabilidad de las costas",
|
||||
"Crop Pollination": "Polinización de cultivos",
|
||||
"Crop Production": "Producción de cultivos",
|
||||
"DelineateIt": "DelineatIt",
|
||||
"Forest Carbon Edge Effect": "Efecto de borde del carbono forestal",
|
||||
"Habitat Quality": "Calidad del hábitat",
|
||||
"Habitat Risk Assessment": "Evaluación de riesgo de hábitats",
|
||||
"Nutrient Delivery Ratio": "Tasa de entrega de nutrientes",
|
||||
"RouteDEM": "RouteDEM",
|
||||
"Scenario Generator: Proximity Based": "Generador de Escenarios: Basado en Proximidad",
|
||||
"Scenic Quality": "Calidad escénica",
|
||||
"Seasonal Water Yield": "Producción de agua estacional",
|
||||
"Sediment Delivery Ratio": "Tasa de entrega de sedimentos",
|
||||
"Urban Stormwater Retention": "Retención urbana de agua de tormenta",
|
||||
"Urban Cooling": "Enfriamiento urbano",
|
||||
"Urban Flood Risk Mitigation": "Mitigación de riesgos de inundaciones urbanas",
|
||||
"Urban Nature Access": "Acceso urbano a la naturaleza",
|
||||
"Visitation: Recreation and Tourism": "Visitación: recreación y turismo",
|
||||
"Wave Energy Production": "Producción de energía de olas",
|
||||
"Wind Energy Production": "Producción de energía eólica",
|
||||
"Global DEM & Landmass Polygon": "MED Global y Polígono de Masa Terrestre",
|
||||
"(recommended to run model)": "(se recomienda para que corra el modelo)",
|
||||
"(required to run model)": "(se requiere para que corra el modelo)",
|
||||
"(required for Wind & Wave Energy)": "(se requiere para Energía Eólica y de Olas)",
|
||||
"Please choose a different folder. This application does not have permission to write to folder:": "Por favor, seleccione una carpeta diferente. Esta aplicación no tiene permiso para escribir en la carpeta:",
|
||||
"Download InVEST sample data": "Descargar datos de muestra de InVEST",
|
||||
"Cancel": "Cancelar",
|
||||
"Download": "Descargar",
|
||||
"Download Failed": "Falló la descarga",
|
||||
"Download Complete": "Descarga completa",
|
||||
"Downloading {{number}} of {{nTotal}}": "",
|
||||
"Downloading {{number}} of {{nTotal}}": "Descargando {{number}} of {{nTotal}}",
|
||||
"Something went wrong": "Algo salió mal",
|
||||
"Please help us fix this by reporting the problem.You may follow these steps:": "",
|
||||
"Find the Workbench log files using the button below.": "",
|
||||
"There may be multiple files with a \".log\" extension.": "",
|
||||
"Please help us fix this by reporting the problem.You may follow these steps:": "Por favor, ayúdenos a reparar esto informando sobre el problema. Puede seguir estos pasos:",
|
||||
"Find the Workbench log files using the button below.": "Halle los archivos de registro Workbench usando el botón de abajo.",
|
||||
"There may be multiple files with a \".log\" extension.": "Puede haber varios archivos con una extensión \".log\".",
|
||||
"Find My Logs": "Encontrar mis registros",
|
||||
"Create a post on our forum ": "Crear un mensaje en nuestro foro",
|
||||
"Create a post on our forum ": "Genere un mensaje en nuestro foro ",
|
||||
"and upload all the log files, along with a brief description of what happened before you saw this message.": "y suba todos los archivos de registro, junto con una breve descripción de lo que ocurrió antes de ver este mensaje.",
|
||||
"Model Complete": "Modelo completo",
|
||||
"Recent runs:": "Corridas recientes:",
|
||||
|
@ -21,62 +49,88 @@
|
|||
"Cancel Run": "Cancelar la ejecución",
|
||||
"Error: see log for details": "Error: ver el registro para más detalles",
|
||||
"Run Canceled": "Ejecución cancelada",
|
||||
"No InVEST model data can be parsed from the file:": "No hay datos de modelos InVEST que puedan ser analizados desde el archivo:",
|
||||
"Browse to a datastack (.json) or InVEST logfile (.txt)": "Buscar una pila de datos (.json) o un archivo de registro InVEST (.txt)",
|
||||
"Open": "Abrir",
|
||||
"User's Guide": "Guía de uso",
|
||||
"Frequently Asked Questions": "Preguntas frecuentes",
|
||||
"Save as...": "Guardar como...",
|
||||
"Datastack options": "Opciones de Datastack",
|
||||
"Save your parameters in a JSON file. This includes thepaths to your input data, but not the data itself. Open this file in InVEST to restore your parameters.": "",
|
||||
"Save your parameters in a JSON file. This includes the paths to your input data, but not the data itself. Open this file in InVEST to restore your parameters.": "Guarde sus parámetros en un archivo JSON. Esto incluye las rutas a los datos de entrada, pero no los datos en sí. Abra este archivo en InVEST para restaurar sus parámetros.",
|
||||
"Save your parameters and input data in a compressed archive. This archive contains the same JSON file produced by the \"Parameters only\" option, plus the data. You can open this file in InVEST to restore your parameters. This option is useful to copy all the necessary data to a different location.": "Guarde sus parámetros y datos de entrada en un archivo comprimido. Este archivo contiene el mismo archivo JSON producido por la opción \"Sólo parámetros\", además de los datos. Puede abrir este archivo en InVEST para restaurar sus parámetros. Esta opción es útil para copiar todos los datos necesarios en una ubicación diferente.",
|
||||
"Save your parameters in a python script. This includes the paths to your input data, but not the data itself. Running the python script will programmatically run the model with your parameters. Use this as a starting point for batch scripts.": "Guarde sus parámetros en un script de Python. Esto incluye las rutas a los datos de entrada, pero no los datos en sí. Al ejecutar el script de Python, el modelo se ejecutará mediante programación con sus parámetros. Utilícelo como punto de partida para scripts por lotes.",
|
||||
"Save": "",
|
||||
"Save": "Guardar",
|
||||
"Synchronous": "Sincrónico",
|
||||
"Threaded task management": "Manejo encadenado de tareas",
|
||||
"CPUs": "CPUs",
|
||||
"DEBUG": "DEPURAR",
|
||||
"INFO": "INFORMACIÓN",
|
||||
"WARNING": "ADVERTENCIA",
|
||||
"ERROR": "ERROR",
|
||||
"InVEST Settings": "Configuración de InVEST",
|
||||
"Language": "Idioma",
|
||||
"Changing this setting will refresh the app and close all tabs": "",
|
||||
"Logging threshold": "Umbral de registro",
|
||||
"Taskgraph logging threshold": "Umbral de registro del gráfico de tareas",
|
||||
"Taskgraph n_workers parameter": "Parámetro n_workers del gráfico de tareas",
|
||||
"more info": "",
|
||||
"synchronous task execution is most reliable": "la ejecución de tareas sincrónicas es la más fiable",
|
||||
"more info": "más información",
|
||||
"synchronous task execution is most reliable": "la ejecución sincrónica de tareas es la más fiable",
|
||||
"threaded task management: tasks execute only in the main process, using multiple threads.": "gestión de tareas por hilos: las tareas se ejecutan solo en el proceso principal, utilizando varios hilos.",
|
||||
"n CPUs: depending on the InVEST model, tasks may execute in parallel using up to this many processes.": "n CPUs: dependiendo del modelo de InVEST, las tareas pueden ejecutarse en paralelo utilizando hasta este número de procesos.",
|
||||
"Reset to Defaults": "Valores predeterminados",
|
||||
"Download Sample Data": "Descargar datos de muestra",
|
||||
"Clear Recent Jobs": "Borrar trabajos recientes",
|
||||
"no invest workspaces will be deleted": "no se eliminará ningún espacio de trabajo de InVEST",
|
||||
"Bounding box does not intersect at least one other:": "La caja delimitadora no se interseca al menos con otra:",
|
||||
"optional": "",
|
||||
"Warning": "Advertencia",
|
||||
"Changing this setting will close your tabs and relaunch the app.": "Cambiar esta opciín cerrará las pestañas y relanzará la aplicación.",
|
||||
"Change to ": "Cambiar a ",
|
||||
"Not all of the spatial layers overlap each other. Bounding box:": "No todas las capas espaciales se traslapan entre ellas. Caja delmitadora:",
|
||||
"optional": "opcional",
|
||||
"boolean": "booleano",
|
||||
"integer": "entero",
|
||||
"csv": "csv",
|
||||
"directory": "directorio",
|
||||
"file": "archivo",
|
||||
"number": "número",
|
||||
"percent": "porcentaje",
|
||||
"raster": "ráster",
|
||||
"ratio": "tasa",
|
||||
"vector": "vector",
|
||||
"text": "texto",
|
||||
"percent: a number from 0 - 100": "porcentaje: un número de 0 a 100",
|
||||
"ratio: a decimal from 0 - 1": "tasa: un decimal de 0 - 1",
|
||||
"User's guide entry": "Entrada de la guía del usuario",
|
||||
"Only drop one file at a time.": "Solo se puede soltar un archivo a la vez.",
|
||||
"Choose location to extract archive": "Seleccione la ubicación donde extraer el archivo",
|
||||
"Datastack/Logfile for {{modelName}} does not match this model.": "Datastack/Logfile para {{modelName}} no calza con este modelo.",
|
||||
"Running": "En curso",
|
||||
"Run": "Ejecutar",
|
||||
"Browse to a datastack (.json, .tgz) or InVEST logfile (.txt)": "Buscar una pila de datos (.json, .tgz) o un archivo de registro InVEST (.txt)",
|
||||
"Load parameters from file": "Cargar los parámetros desde un archivo",
|
||||
"No args to see here": "No hay argumentos que ver aquí",
|
||||
"version:": "",
|
||||
"Copyright 2022, The Natural Capital Project": "",
|
||||
"Documentation: ": "",
|
||||
"Homepage: ": "",
|
||||
"Project page: ": "",
|
||||
"License: ": "",
|
||||
"Open-Source Licenses:": "",
|
||||
"MIT and others": "",
|
||||
"Please help us by reporting problems.": "",
|
||||
"If the problem is related to a specific InVEST model, ": "",
|
||||
"please see the guidelines here for reporting problems: ": "",
|
||||
"Guidelines for posting software support questions": "",
|
||||
"If the problem is related to this User Interface, ": "",
|
||||
"rather than with a specific InVEST model,": "",
|
||||
"Consider taking a screenshot of the problem.": "",
|
||||
"Find the log files using the button below. There may be multiple files with a \".log\" extension; please include them all.": "",
|
||||
"Create a post on our forum and upload these items, along with a brief description of the problem.": "",
|
||||
"version:": "versión:",
|
||||
"Copyright 2023, The Natural Capital Project": "Copyright 2023, The Natural Capital Project",
|
||||
"Documentation": "Documentación",
|
||||
"Homepage": "Página web",
|
||||
"Project page": "Página del proyecto",
|
||||
"License": "Licencia",
|
||||
"InVEST Trademark and Logo Use Policy": "Política de uso de la marca y el logotipo de InVEST",
|
||||
"Open-Source Licenses:": "Licencias de código abierto:",
|
||||
"MIT and others": "MIT y otros",
|
||||
"Please help us by reporting problems.": "Por favor, ayúdenos informando sobre problemas.",
|
||||
"If the problem is related to a specific InVEST model, ": "Si el problema se relaciona con un modelo InVEST específico, ",
|
||||
"please see the guidelines here for reporting problems: ": "por favor, refiérase a la guía para informar sobre problemas aquí: ",
|
||||
"Guidelines for posting software support questions": "Guía para publicar preguntas de apoyo sobre software",
|
||||
"If the problem is related to this User Interface, ": "Si el problema se relaciona con esta interfaz de uso, ",
|
||||
"rather than with a specific InVEST model,": "más que con un modelo InVEST específico,",
|
||||
"Consider taking a screenshot of the problem.": "Considere hacer una captura de pantalla del problema.",
|
||||
"Find the log files using the button below. There may be multiple files with a \".log\" extension; please include them all.": "Halle los archivos de registro usando el botón más abajo. Podría haber varios archivos con una extensión \".log\"; por favor, incluya todos ellos.",
|
||||
"Create a post on our forum and upload these items, along with a brief description of the problem.": "Cree un posteo en nuestro foro y cargue estos ítemes junto a una breve descripción del problema.",
|
||||
"Save your parameters in a JSON file. This includes thepaths to your input data, but not the data itself. Open this file in InVEST to restore your parameters.": "Guarde sus parámetros en un archivo JSON. Esto incluye las rutas a sus datos de entrada, pero no los datos en sí. Abra este archivo en InVEST para reestablecer sus parámetros.",
|
||||
"Reset to Defaults": "Valores predeterminados",
|
||||
"Bounding box does not intersect at least one other:": "La caja delimitadora no se interseca al menos con otra:",
|
||||
"InVEST": "InVEST",
|
||||
"Find the Workbench log files ": "Buscar los archivos de registro de Workbench ",
|
||||
"Please help us fix this by reporting the problem. You may follow these steps:": "Por favor, ayúdenos a solucionar esto informando del problema. Puede seguir estos pasos:",
|
||||
"using the button below. There may be multiple files with a \".log\" extension.": "con el botón de abajo. Puede haber varios archivos con extensión \".log\".",
|
||||
"Save your parameters in a JSON file. This includes the paths to your input data, but not the data itself. Open this file in InVEST to restore your parameters.": "Guarde sus parámetros en un archivo JSON. Esto incluye las rutas a los datos de entrada, pero no los datos en sí. Abra este archivo en InVEST para restaurar sus parámetros."
|
||||
"Taskgraph n_workers parameter": "Parámetro n_workers del gráfico de tareas",
|
||||
"freestyle_string": "freestyle",
|
||||
"option_string": "option"
|
||||
}
|
|
@ -1,4 +1,32 @@
|
|||
{
|
||||
"Annual Water Yield": "年出水量",
|
||||
"Carbon Storage and Sequestration": "碳储存和碳封存",
|
||||
"Coastal Blue Carbon": "海岸蓝碳",
|
||||
"Coastal Vulnerability": "沿海地区的脆弱性",
|
||||
"Crop Pollination": "作物授粉",
|
||||
"Crop Production": "农作物生产",
|
||||
"DelineateIt": "划线",
|
||||
"Forest Carbon Edge Effect": "森林碳边效应",
|
||||
"Habitat Quality": "生境质量",
|
||||
"Habitat Risk Assessment": "生境风险评估",
|
||||
"Nutrient Delivery Ratio": "营养输送比",
|
||||
"RouteDEM": "路线高程",
|
||||
"Scenario Generator: Proximity Based": "情景生成器:基于邻近性",
|
||||
"Scenic Quality": "风景质量",
|
||||
"Seasonal Water Yield": "季节产水量",
|
||||
"Sediment Delivery Ratio": "沉积物输送比",
|
||||
"Urban Stormwater Retention": "城市雨水滞留",
|
||||
"Urban Cooling": "城市降温",
|
||||
"Urban Flood Risk Mitigation": "城市洪水风险缓解",
|
||||
"Urban Nature Access": "城市自然通道",
|
||||
"Visitation: Recreation and Tourism": "参观:娱乐和旅游",
|
||||
"Wave Energy Production": "波浪能生产",
|
||||
"Wind Energy Production": "风能生产",
|
||||
"Global DEM & Landmass Polygon": "全球 高程 和地块多边形",
|
||||
"(recommended to run model)": "(建议运行模型)",
|
||||
"(required to run model)": "(运行模型所需)",
|
||||
"(required for Wind & Wave Energy)": "(风能和波浪能所需)",
|
||||
"Please choose a different folder. This application does not have permission to write to folder:": "请选择其他文件夹。此应用程序没有写入文件夹的权限:",
|
||||
"Download InVEST sample data": "下载InVEST样例数据",
|
||||
"Cancel": "取消",
|
||||
"Download": "下载",
|
||||
|
@ -21,6 +49,7 @@
|
|||
"Cancel Run": "取消运行",
|
||||
"Error: see log for details": "错误:详见日志",
|
||||
"Run Canceled": "取消运行",
|
||||
"No InVEST model data can be parsed from the file:": "无法从文件中解析 InVEST 模型数据:",
|
||||
"Browse to a datastack (.json) or InVEST logfile (.txt)": "浏览到一个数据包(.json)或InVEST日志文件(.txt)。",
|
||||
"Open": "打开",
|
||||
"User's Guide": "用户指南",
|
||||
|
@ -40,24 +69,36 @@
|
|||
"ERROR": "错误",
|
||||
"InVEST Settings": "InVEST设置",
|
||||
"Language": "语言",
|
||||
"Changing this setting will refresh the app and close all tabs": "更改此设置将刷新应用程序并关闭所有选项卡",
|
||||
"Logging threshold": "日志阈值",
|
||||
"Taskgraph logging threshold": "任务图记录阈值",
|
||||
"more info": "更多信息",
|
||||
"synchronous task execution is most reliable": "同步任务的执行是最可靠的",
|
||||
"threaded task management: tasks execute only in the main process, using multiple threads.": "线程任务管理:任务只在主进程中使用多线程执行。",
|
||||
"n CPUs: depending on the InVEST model, tasks may execute in parallel using up to this many processes.": "n CPU:根据 InVEST 模型,任务最多可以在这么多个进程下执行任务。",
|
||||
"Reset to Defaults": "重置为默认值",
|
||||
"Download Sample Data": "下载样例数据",
|
||||
"Clear Recent Jobs": "清除最近的工作",
|
||||
"no invest workspaces will be deleted": "没有invest的工作空间将被删除",
|
||||
"Bounding box does not intersect at least one other:": "边界框至少不与另一个相交:",
|
||||
"Warning": "警告",
|
||||
"Changing this setting will close your tabs and relaunch the app.": "更改此设置将关闭标签页并重新启动应用程序。",
|
||||
"Change to ": "更改到",
|
||||
"Not all of the spatial layers overlap each other. Bounding box:": "并非所有空间层都相互重叠。边界框:",
|
||||
"optional": "可选项",
|
||||
"boolean": "布尔值",
|
||||
"integer": "整数",
|
||||
"csv": "csv",
|
||||
"directory": "模型数据目录",
|
||||
"file": "文件后缀",
|
||||
"number": "数量",
|
||||
"percent": "百分比",
|
||||
"raster": "栅格",
|
||||
"ratio": "比例",
|
||||
"vector": "向量",
|
||||
"text": "文本",
|
||||
"percent: a number from 0 - 100": "百分比:一个从0-100的数字",
|
||||
"ratio: a decimal from 0 - 1": "比率:一个从0-1的小数",
|
||||
"User's guide entry": "用户指南条目",
|
||||
"Only drop one file at a time.": "一次只能丢一个文件。",
|
||||
"Choose location to extract archive": "选择提取存档的位置",
|
||||
"Datastack/Logfile for {{modelName}} does not match this model.": "{{modelName}} 个数据堆栈/日志文件与此模型不匹配。",
|
||||
"Running": "运行中",
|
||||
"Run": "运行",
|
||||
|
@ -65,11 +106,12 @@
|
|||
"Load parameters from file": "从文件中加载参数",
|
||||
"No args to see here": "在args dict中缺少关键信息",
|
||||
"version:": "版本:",
|
||||
"Copyright 2022, The Natural Capital Project": "版权所有 2022, The Natural Capital Project",
|
||||
"Documentation: ": "文档:",
|
||||
"Homepage: ": "主页:",
|
||||
"Project page: ": "项目页面:",
|
||||
"License: ": "许可证:",
|
||||
"Copyright 2023, The Natural Capital Project": "版权所有 2023 年,自然资本项目",
|
||||
"Documentation": "文档",
|
||||
"Homepage": "首页",
|
||||
"Project page": "项目页面",
|
||||
"License": "许可证",
|
||||
"InVEST Trademark and Logo Use Policy": "InVEST 商标和徽标使用政策",
|
||||
"Open-Source Licenses:": "开源许可证:",
|
||||
"MIT and others": "MIT许可证及其他许可证",
|
||||
"Please help us by reporting problems.": "请通过报告问题来帮助我们。",
|
||||
|
@ -81,6 +123,14 @@
|
|||
"Consider taking a screenshot of the problem.": "请截屏保存以便随后发布帖子寻求帮助。",
|
||||
"Find the log files using the button below. There may be multiple files with a \".log\" extension; please include them all.": "使用下面的按钮查找日志文件。 可能有多个扩展名为“.log”的文件; 请把它们全部包括在内。",
|
||||
"Create a post on our forum and upload these items, along with a brief description of the problem.": "在我们的论坛上创建一个帖子并上传这些项目以及问题的简要说明。",
|
||||
"Changing this setting will refresh the app and close all tabs": "更改此设置将刷新应用程序并关闭所有选项卡",
|
||||
"Reset to Defaults": "重置为默认值",
|
||||
"Bounding box does not intersect at least one other:": "边界框至少不与另一个相交:",
|
||||
"Copyright 2022, The Natural Capital Project": "版权所有 2022, The Natural Capital Project",
|
||||
"Documentation: ": "文档:",
|
||||
"Homepage: ": "主页:",
|
||||
"Project page: ": "项目页面:",
|
||||
"License: ": "许可证:",
|
||||
"Export all input data to a compressed archive": "将所有输入数据导出到压缩档案中",
|
||||
"InVEST": "InVEST",
|
||||
"Save datastack": "保存数据包",
|
||||
|
@ -90,14 +140,8 @@
|
|||
"Save to Python script": "保存到Python脚本",
|
||||
"true/false": "真/假",
|
||||
"CSV": "CSV",
|
||||
"directory": "模型数据目录",
|
||||
"file": "文件后缀",
|
||||
"integer": "整数",
|
||||
"number": "数量",
|
||||
"option": "选项",
|
||||
"percent": "百分比",
|
||||
"raster": "栅格",
|
||||
"ratio": "比例",
|
||||
"vector": "向量",
|
||||
"Taskgraph n_workers parameter": "任务图n_workers参数"
|
||||
"Taskgraph n_workers parameter": "任务图n_workers参数",
|
||||
"freestyle_string": "自由式",
|
||||
"option_string": "选项"
|
||||
}
|
|
@ -9,6 +9,7 @@ import { ipcMainChannels } from '../main/ipcMainChannels';
|
|||
const { ipcRenderer } = window.Workbench.electron;
|
||||
|
||||
const isFirstRun = await ipcRenderer.invoke(ipcMainChannels.IS_FIRST_RUN);
|
||||
const isNewVersion = await ipcRenderer.invoke(ipcMainChannels.IS_NEW_VERSION);
|
||||
const nCPU = await ipcRenderer.invoke(ipcMainChannels.GET_N_CPUS);
|
||||
|
||||
const root = createRoot(document.getElementById('App'));
|
||||
|
@ -16,6 +17,7 @@ root.render(
|
|||
<ErrorBoundary>
|
||||
<App
|
||||
isFirstRun={isFirstRun}
|
||||
isNewVersion={isNewVersion}
|
||||
nCPU={nCPU}
|
||||
/>
|
||||
</ErrorBoundary>
|
||||
|
|
|
@ -617,3 +617,18 @@ input[type=text]::placeholder {
|
|||
.error-boundary .btn {
|
||||
margin: 1rem;
|
||||
}
|
||||
|
||||
/* Changelog modal */
|
||||
.link-external {
|
||||
&:after {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
/* Icon is react-icons/md/MdOpenInNew, as a URL-encoded SVG */
|
||||
background-image: url("data:image/svg+xml,%3Csvg stroke='currentColor' fill='currentColor' stroke-width='0' viewBox='0 0 24 24' class='mr-1' height='1em' width='1em' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='none' d='M0 0h24v24H0z'%3E%3C/path%3E%3Cpath d='M19 19H5V5h7V3H5a2 2 0 00-2 2v14a2 2 0 002 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z'%3E%3C/path%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: left 0.125rem top 0.125rem;
|
||||
background-size: 1rem 1rem;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import puppeteer from 'puppeteer-core';
|
|||
|
||||
import pkg from '../../package.json';
|
||||
import { APP_HAS_RUN_TOKEN } from '../../src/main/setupCheckFirstRun';
|
||||
import { APP_VERSION_TOKEN } from '../../src/main/setupIsNewVersion';
|
||||
|
||||
jest.setTimeout(240000);
|
||||
const PORT = 9009;
|
||||
|
@ -26,9 +27,10 @@ let BINARY_PATH;
|
|||
// append to this prefix and the image will be uploaded to github artifacts
|
||||
// E.g. page.screenshot({ path: `${SCREENSHOT_PREFIX}screenshot.png` })
|
||||
let SCREENSHOT_PREFIX;
|
||||
// We'll clear this token before launching the app so we can have a
|
||||
// We'll clear these tokens before launching the app so we can have a
|
||||
// predictable startup page.
|
||||
let APP_HAS_RUN_TOKEN_PATH;
|
||||
let APP_VERSION_TOKEN_PATH;
|
||||
|
||||
// On GHA macos, invest validation can time-out reading from os.tmpdir
|
||||
// So on GHA, use the homedir instead.
|
||||
|
@ -45,6 +47,9 @@ if (process.platform === 'darwin') {
|
|||
APP_HAS_RUN_TOKEN_PATH = path.join(
|
||||
os.homedir(), 'Library/Application Support', pkg.name, APP_HAS_RUN_TOKEN
|
||||
);
|
||||
APP_VERSION_TOKEN_PATH = path.join(
|
||||
os.homedir(), 'Library/Application Support', pkg.name, APP_VERSION_TOKEN
|
||||
);
|
||||
} else if (process.platform === 'win32') {
|
||||
[BINARY_PATH] = glob.sync('./dist/win-unpacked/InVEST*.exe');
|
||||
SCREENSHOT_PREFIX = path.join(
|
||||
|
@ -53,6 +58,9 @@ if (process.platform === 'darwin') {
|
|||
APP_HAS_RUN_TOKEN_PATH = path.join(
|
||||
os.homedir(), 'AppData/Roaming', pkg.name, APP_HAS_RUN_TOKEN
|
||||
);
|
||||
APP_VERSION_TOKEN_PATH = path.join(
|
||||
os.homedir(), 'AppData/Roaming', pkg.name, APP_VERSION_TOKEN
|
||||
);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(BINARY_PATH)) {
|
||||
|
@ -97,6 +105,7 @@ afterAll(() => {
|
|||
// https://github.com/facebook/jest/issues/8688
|
||||
beforeEach(() => {
|
||||
try { fs.unlinkSync(APP_HAS_RUN_TOKEN_PATH); } catch {}
|
||||
try { fs.unlinkSync(APP_VERSION_TOKEN_PATH); } catch {}
|
||||
// start the invest app and forward stderr to console
|
||||
ELECTRON_PROCESS = spawn(
|
||||
`"${BINARY_PATH}"`,
|
||||
|
@ -164,11 +173,22 @@ test('Run a real invest model', async () => {
|
|||
});
|
||||
await page.screenshot({ path: `${SCREENSHOT_PREFIX}1-page-load.png` });
|
||||
|
||||
const downloadModal = await page.waitForSelector('.modal-dialog');
|
||||
const downloadModal = await page.waitForSelector(
|
||||
'aria/[name="Download InVEST sample data"][role="dialog"]'
|
||||
);
|
||||
const downloadModalCancel = await downloadModal.waitForSelector(
|
||||
'aria/[name="Cancel"][role="button"]');
|
||||
await page.waitForTimeout(WAIT_TO_CLICK); // waiting for click handler to be ready
|
||||
await downloadModalCancel.click();
|
||||
|
||||
const changelogModal = await page.waitForSelector(
|
||||
'aria/[name="New in this version"][role="dialog"]'
|
||||
);
|
||||
const changelogModalClose = await changelogModal.waitForSelector(
|
||||
'aria/[name="Close modal"][role="button"]');
|
||||
await page.waitForTimeout(WAIT_TO_CLICK); // waiting for click handler to be ready
|
||||
await changelogModalClose.click();
|
||||
|
||||
// We need to get the modelButton from w/in this list-group because there
|
||||
// are buttons with the same name in the Recent Jobs container.
|
||||
const investModels = await page.waitForSelector('.invest-list-group');
|
||||
|
@ -233,12 +253,23 @@ test('Check local userguide links', async () => {
|
|||
page.on('error', (err) => {
|
||||
console.log(err);
|
||||
});
|
||||
const downloadModal = await page.waitForSelector('.modal-dialog');
|
||||
|
||||
const downloadModal = await page.waitForSelector(
|
||||
'aria/[name="Download InVEST sample data"][role="dialog"]'
|
||||
);
|
||||
const downloadModalCancel = await downloadModal.waitForSelector(
|
||||
'aria/[name="Cancel"][role="button"]');
|
||||
await page.waitForTimeout(WAIT_TO_CLICK); // waiting for click handler to be ready
|
||||
await downloadModalCancel.click();
|
||||
|
||||
const changelogModal = await page.waitForSelector(
|
||||
'aria/[name="New in this version"][role="dialog"]'
|
||||
);
|
||||
const changelogModalClose = await changelogModal.waitForSelector(
|
||||
'aria/[name="Close modal"][role="button"]');
|
||||
await page.waitForTimeout(WAIT_TO_CLICK); // waiting for click handler to be ready
|
||||
await changelogModalClose.click();
|
||||
|
||||
const investList = await page.waitForSelector('.invest-list-group');
|
||||
const modelButtons = await investList.$$('aria/[role="button"]');
|
||||
|
||||
|
|
|
@ -180,12 +180,14 @@ describe('createWindow', () => {
|
|||
test('should register various ipcMain listeners', async () => {
|
||||
await createWindow();
|
||||
const expectedHandleChannels = [
|
||||
ipcMainChannels.BASE_URL,
|
||||
ipcMainChannels.CHANGE_LANGUAGE,
|
||||
ipcMainChannels.CHECK_STORAGE_TOKEN,
|
||||
ipcMainChannels.CHECK_FILE_PERMISSIONS,
|
||||
ipcMainChannels.GET_SETTING,
|
||||
ipcMainChannels.GET_N_CPUS,
|
||||
ipcMainChannels.INVEST_VERSION,
|
||||
ipcMainChannels.IS_NEW_VERSION,
|
||||
ipcMainChannels.IS_FIRST_RUN,
|
||||
ipcMainChannels.OPEN_PATH,
|
||||
ipcMainChannels.SHOW_OPEN_DIALOG,
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
import React from 'react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { render } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
import App from '../../src/renderer/app';
|
||||
import pkg from '../../package.json';
|
||||
|
||||
describe('Changelog', () => {
|
||||
const currentVersion = pkg.version;
|
||||
const nonexistentVersion = 'nonexistent-version';
|
||||
beforeEach(() => {
|
||||
jest.spyOn(window, 'fetch')
|
||||
.mockResolvedValue({
|
||||
ok: true,
|
||||
text: () => `
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<section>
|
||||
<h1>${currentVersion}</h1>
|
||||
</section>
|
||||
<section>
|
||||
<h1>${nonexistentVersion}</h1>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
});
|
||||
});
|
||||
|
||||
test('Changelog modal opens immediately on launch of a new version', async () => {
|
||||
const { findByRole } = render(<App isNewVersion />);
|
||||
const changelogModal = await findByRole('dialog', { name: 'New in this version' });
|
||||
expect(changelogModal).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('On first run (of any version), Changelog modal opens after Download modal is closed', async () => {
|
||||
const { findByRole, getByText } = render(<App isFirstRun isNewVersion />);
|
||||
|
||||
let changelogModalFound = true;
|
||||
try {
|
||||
await findByRole('dialog', { name: 'New in this version' });
|
||||
} catch {
|
||||
changelogModalFound = false;
|
||||
}
|
||||
expect(changelogModalFound).toBe(false);
|
||||
|
||||
const downloadModal = await findByRole('dialog', { name: 'Download InVEST sample data' });
|
||||
expect(downloadModal).toBeInTheDocument();
|
||||
|
||||
await userEvent.click(getByText('Cancel'));
|
||||
expect(downloadModal).not.toBeInTheDocument();
|
||||
const changelogModal = await findByRole('dialog', { name: 'New in this version' });
|
||||
expect(changelogModal).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Changelog modal does not open when current version has been run before', async () => {
|
||||
const { findByRole } = render(<App isNewVersion={false} />);
|
||||
let changelogModalFound = true;
|
||||
try {
|
||||
await findByRole('dialog', { name: 'New in this version' });
|
||||
} catch {
|
||||
changelogModalFound = false;
|
||||
}
|
||||
expect(changelogModalFound).toBe(false);
|
||||
});
|
||||
|
||||
test('Changelog modal contains only content relevant to the current version', async () => {
|
||||
const { findByRole, queryByRole } = render(<App isNewVersion />);
|
||||
const currentVersionSectionHeading = await findByRole('heading', { name: currentVersion });
|
||||
expect(currentVersionSectionHeading).toBeInTheDocument();
|
||||
|
||||
const nonexistentVersionSectionHeading = queryByRole('heading', { name: nonexistentVersion });
|
||||
expect(nonexistentVersionSectionHeading).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
|
@ -24,6 +24,7 @@ export default defineConfig({
|
|||
path.resolve(PROJECT_ROOT, 'splash.html'),
|
||||
path.resolve(PROJECT_ROOT, 'report_a_problem.html'),
|
||||
path.resolve(PROJECT_ROOT, 'about.html'),
|
||||
path.resolve(PROJECT_ROOT, 'changelog.html'),
|
||||
],
|
||||
},
|
||||
emptyOutDir: true,
|
||||
|
|
Loading…
Reference in New Issue