change assorted references to annual water yield

This commit is contained in:
emlys 2021-10-13 14:21:57 -07:00
parent 0f7c8e0d65
commit 2e3cb71ec6
8 changed files with 59 additions and 62 deletions

View File

@ -37,7 +37,7 @@ DATASTACKS = {
'globio': ['globio/globio_demo.invs.json'], 'globio': ['globio/globio_demo.invs.json'],
'habitat_quality': ['HabitatQuality/habitat_quality_willamette.invs.json'], 'habitat_quality': ['HabitatQuality/habitat_quality_willamette.invs.json'],
'hra': ['HabitatRiskAssess/hra_wcvi.invs.json'], 'hra': ['HabitatRiskAssess/hra_wcvi.invs.json'],
'hydropower_water_yield': ['Annual_Water_Yield/annual_water_yield_gura.invs.json'], 'annual_water_yield': ['Annual_Water_Yield/annual_water_yield_gura.invs.json'],
'ndr': ['NDR/ndr_gura.invs.json'], 'ndr': ['NDR/ndr_gura.invs.json'],
'pollination': ['pollination/pollination_willamette.invs.json'], 'pollination': ['pollination/pollination_willamette.invs.json'],
'recreation': ['recreation/recreation_andros.invs.json'], 'recreation': ['recreation/recreation_andros.invs.json'],

View File

@ -52,7 +52,6 @@ setup(
'natcap.invest.delineateit', 'natcap.invest.delineateit',
'natcap.invest.finfish_aquaculture', 'natcap.invest.finfish_aquaculture',
'natcap.invest.fisheries', 'natcap.invest.fisheries',
'natcap.invest.hydropower',
'natcap.invest.ui', 'natcap.invest.ui',
'natcap.invest.ndr', 'natcap.invest.ndr',
'natcap.invest.sdr', 'natcap.invest.sdr',

View File

@ -29,6 +29,12 @@ class _MODELMETA:
MODEL_METADATA = { MODEL_METADATA = {
'annual_water_yield': _MODELMETA(
model_title='Annual Water Yield',
pyname='natcap.invest.annual_water_yield',
gui='annual_water_yield.AnnualWaterYield',
userguide='annual_water_yield.html',
aliases=('hwy',)),
'carbon': _MODELMETA( 'carbon': _MODELMETA(
model_title='Carbon Storage and Sequestration', model_title='Carbon Storage and Sequestration',
pyname='natcap.invest.carbon', pyname='natcap.invest.carbon',
@ -99,7 +105,7 @@ MODEL_METADATA = {
model_title='GLOBIO', model_title='GLOBIO',
pyname='natcap.invest.globio', pyname='natcap.invest.globio',
gui='globio.GLOBIO', gui='globio.GLOBIO',
userguide='../documentation/globio.html', userguide='globio.html',
aliases=()), aliases=()),
'habitat_quality': _MODELMETA( 'habitat_quality': _MODELMETA(
model_title='Habitat Quality', model_title='Habitat Quality',
@ -113,12 +119,6 @@ MODEL_METADATA = {
gui='hra.HabitatRiskAssessment', gui='hra.HabitatRiskAssessment',
userguide='habitat_risk_assessment.html', userguide='habitat_risk_assessment.html',
aliases=('hra',)), aliases=('hra',)),
'hydropower_water_yield': _MODELMETA(
model_title='Annual Water Yield',
pyname='natcap.invest.hydropower.hydropower_water_yield',
gui='hydropower.HydropowerWaterYield',
userguide='reservoirhydropowerproduction.html',
aliases=('hwy',)),
'ndr': _MODELMETA( 'ndr': _MODELMETA(
model_title='Nutrient Delivery Ratio', model_title='Nutrient Delivery Ratio',
pyname='natcap.invest.ndr.ndr', pyname='natcap.invest.ndr.ndr',
@ -167,18 +167,18 @@ MODEL_METADATA = {
gui='seasonal_water_yield.SeasonalWaterYield', gui='seasonal_water_yield.SeasonalWaterYield',
userguide='seasonal_water_yield.html', userguide='seasonal_water_yield.html',
aliases=('swy',)), aliases=('swy',)),
'wind_energy': _MODELMETA(
model_title='Wind Energy Production',
pyname='natcap.invest.wind_energy',
gui='wind_energy.WindEnergy',
userguide='wind_energy.html',
aliases=()),
'wave_energy': _MODELMETA( 'wave_energy': _MODELMETA(
model_title='Wave Energy Production', model_title='Wave Energy Production',
pyname='natcap.invest.wave_energy', pyname='natcap.invest.wave_energy',
gui='wave_energy.WaveEnergy', gui='wave_energy.WaveEnergy',
userguide='wave_energy.html', userguide='wave_energy.html',
aliases=()), aliases=()),
'wind_energy': _MODELMETA(
model_title='Wind Energy Production',
pyname='natcap.invest.wind_energy',
gui='wind_energy.WindEnergy',
userguide='wind_energy.html',
aliases=()),
'urban_flood_risk_mitigation': _MODELMETA( 'urban_flood_risk_mitigation': _MODELMETA(
model_title='Urban Flood Risk Mitigation', model_title='Urban Flood Risk Mitigation',
pyname='natcap.invest.urban_flood_risk_mitigation', pyname='natcap.invest.urban_flood_risk_mitigation',

View File

@ -1,4 +1,4 @@
"""InVEST Hydropower Water Yield model.""" """InVEST Annual Water Yield model."""
import logging import logging
import os import os
import math import math
@ -17,8 +17,8 @@ from .. import MODEL_METADATA
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
ARGS_SPEC = { ARGS_SPEC = {
"model_name": MODEL_METADATA["hydropower_water_yield"].model_title, "model_name": MODEL_METADATA["annual_water_yield"].model_title,
"userguide_html": MODEL_METADATA["hydropower_water_yield"].userguide, "userguide_html": MODEL_METADATA["annual_water_yield"].userguide,
"args_with_spatial_overlap": { "args_with_spatial_overlap": {
"spatial_keys": ["depth_to_root_rest_layer_path", "spatial_keys": ["depth_to_root_rest_layer_path",
"precipitation_path", "precipitation_path",
@ -189,7 +189,7 @@ ARGS_SPEC = {
def execute(args): def execute(args):
"""Annual Water Yield: Reservoir Hydropower Production. """Annual Water Yield: Reservoir Hydropower Production.
Executes the hydropower/water_yield model Executes the hydropower/annual water yield model
Args: Args:
args['workspace_dir'] (string): a path to the directory that will write args['workspace_dir'] (string): a path to the directory that will write

View File

@ -1,18 +1,17 @@
# coding=UTF-8 # coding=UTF-8
from natcap.invest.ui import model, inputs from natcap.invest.ui import model, inputs
from natcap.invest.hydropower import hydropower_water_yield from natcap.invest import annual_water_yield, MODEL_METADATA
from natcap.invest import MODEL_METADATA
class HydropowerWaterYield(model.InVESTModel): class AnnualWaterYield(model.InVESTModel):
def __init__(self): def __init__(self):
model.InVESTModel.__init__( model.InVESTModel.__init__(
self, self,
label=MODEL_METADATA['hydropower_water_yield'].model_title, label=MODEL_METADATA['annual_water_yield'].model_title,
target=hydropower_water_yield.execute, target=annual_water_yield.execute,
validator=hydropower_water_yield.validate, validator=annual_water_yield.validate,
localdoc=MODEL_METADATA['hydropower_water_yield'].userguide) localdoc=MODEL_METADATA['annual_water_yield'].userguide)
self.precipitation = inputs.File( self.precipitation = inputs.File(
args_key='precipitation_path', args_key='precipitation_path',

View File

@ -1,4 +1,4 @@
"""Module for Regression Testing the InVEST Hydropower module.""" """Module for Regression Testing the InVEST Annual Water Yield module."""
import unittest import unittest
import tempfile import tempfile
import shutil import shutil
@ -8,15 +8,14 @@ import pandas
import numpy import numpy
import pygeoprocessing import pygeoprocessing
SAMPLE_DATA = os.path.join(
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'hydropower',
'input')
REGRESSION_DATA = os.path.join( REGRESSION_DATA = os.path.join(
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'hydropower') os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'annual_water_yield')
SAMPLE_DATA = os.path.join(REGRESSION_DATA, 'input')
class HydropowerTests(unittest.TestCase): class AnnualWaterYieldTests(unittest.TestCase):
"""Regression Tests for Annual Water Yield Hydropower Model.""" """Regression Tests for Annual Water Yield Model."""
def setUp(self): def setUp(self):
"""Overriding setUp func. to create temporary workspace directory.""" """Overriding setUp func. to create temporary workspace directory."""
@ -50,9 +49,9 @@ class HydropowerTests(unittest.TestCase):
def test_invalid_lulc_veg(self): def test_invalid_lulc_veg(self):
"""Hydro: catching invalid LULC_veg values.""" """Hydro: catching invalid LULC_veg values."""
from natcap.invest.hydropower import hydropower_water_yield from natcap.invest.annual_water_yield import annual_water_yield
args = HydropowerTests.generate_base_args(self.workspace_dir) args = AnnualWaterYieldTests.generate_base_args(self.workspace_dir)
new_lulc_veg_path = os.path.join(self.workspace_dir, new_lulc_veg_path = os.path.join(self.workspace_dir,
'new_lulc_veg.csv') 'new_lulc_veg.csv')
@ -63,7 +62,7 @@ class HydropowerTests(unittest.TestCase):
args['biophysical_table_path'] = new_lulc_veg_path args['biophysical_table_path'] = new_lulc_veg_path
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
hydropower_water_yield.execute(args) annual_water_yield.execute(args)
self.assertTrue('veg value must be either 1 or 0' in str(cm.exception)) self.assertTrue('veg value must be either 1 or 0' in str(cm.exception))
table_df = pandas.read_csv(args['biophysical_table_path']) table_df = pandas.read_csv(args['biophysical_table_path'])
@ -72,14 +71,14 @@ class HydropowerTests(unittest.TestCase):
args['biophysical_table_path'] = new_lulc_veg_path args['biophysical_table_path'] = new_lulc_veg_path
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
hydropower_water_yield.execute(args) annual_water_yield.execute(args)
self.assertTrue('veg value must be either 1 or 0' in str(cm.exception)) self.assertTrue('veg value must be either 1 or 0' in str(cm.exception))
def test_missing_lulc_value(self): def test_missing_lulc_value(self):
"""Hydro: catching missing LULC value in Biophysical table.""" """Hydro: catching missing LULC value in Biophysical table."""
from natcap.invest.hydropower import hydropower_water_yield from natcap.invest.annual_water_yield import annual_water_yield
args = HydropowerTests.generate_base_args(self.workspace_dir) args = AnnualWaterYieldTests.generate_base_args(self.workspace_dir)
# remove a row from the biophysical table so that lulc value is missing # remove a row from the biophysical table so that lulc value is missing
bad_biophysical_path = os.path.join( bad_biophysical_path = os.path.join(
@ -93,16 +92,16 @@ class HydropowerTests(unittest.TestCase):
args['biophysical_table_path'] = bad_biophysical_path args['biophysical_table_path'] = bad_biophysical_path
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
hydropower_water_yield.execute(args) annual_water_yield.execute(args)
self.assertTrue( self.assertTrue(
"The missing values found in the LULC raster but not the table" "The missing values found in the LULC raster but not the table"
" are: [2]" in str(cm.exception)) " are: [2]" in str(cm.exception))
def test_missing_lulc_demand_value(self): def test_missing_lulc_demand_value(self):
"""Hydro: catching missing LULC value in Demand table.""" """Hydro: catching missing LULC value in Demand table."""
from natcap.invest.hydropower import hydropower_water_yield from natcap.invest.annual_water_yield import annual_water_yield
args = HydropowerTests.generate_base_args(self.workspace_dir) args = AnnualWaterYieldTests.generate_base_args(self.workspace_dir)
args['demand_table_path'] = os.path.join( args['demand_table_path'] = os.path.join(
SAMPLE_DATA, 'water_demand_table.csv') SAMPLE_DATA, 'water_demand_table.csv')
@ -121,21 +120,21 @@ class HydropowerTests(unittest.TestCase):
args['demand_table_path'] = bad_demand_path args['demand_table_path'] = bad_demand_path
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
hydropower_water_yield.execute(args) annual_water_yield.execute(args)
self.assertTrue( self.assertTrue(
"The missing values found in the LULC raster but not the table" "The missing values found in the LULC raster but not the table"
" are: [2]" in str(cm.exception)) " are: [2]" in str(cm.exception))
def test_water_yield_subshed(self): def test_water_yield_subshed(self):
"""Hydro: testing water yield component only w/ subwatershed.""" """Hydro: testing water yield component only w/ subwatershed."""
from natcap.invest.hydropower import hydropower_water_yield from natcap.invest.annual_water_yield import annual_water_yield
from natcap.invest import utils from natcap.invest import utils
args = HydropowerTests.generate_base_args(self.workspace_dir) args = AnnualWaterYieldTests.generate_base_args(self.workspace_dir)
args['sub_watersheds_path'] = os.path.join( args['sub_watersheds_path'] = os.path.join(
SAMPLE_DATA, 'subwatersheds.shp') SAMPLE_DATA, 'subwatersheds.shp')
args['results_suffix'] = 'test' args['results_suffix'] = 'test'
hydropower_water_yield.execute(args) annual_water_yield.execute(args)
raster_results = ['aet_test.tif', 'fractp_test.tif', 'wyield_test.tif'] raster_results = ['aet_test.tif', 'fractp_test.tif', 'wyield_test.tif']
for raster_path in raster_results: for raster_path in raster_results:
@ -169,16 +168,16 @@ class HydropowerTests(unittest.TestCase):
def test_scarcity_subshed(self): def test_scarcity_subshed(self):
"""Hydro: testing Scarcity component w/ subwatershed.""" """Hydro: testing Scarcity component w/ subwatershed."""
from natcap.invest.hydropower import hydropower_water_yield from natcap.invest.annual_water_yield import annual_water_yield
from natcap.invest import utils from natcap.invest import utils
args = HydropowerTests.generate_base_args(self.workspace_dir) args = AnnualWaterYieldTests.generate_base_args(self.workspace_dir)
args['demand_table_path'] = os.path.join( args['demand_table_path'] = os.path.join(
SAMPLE_DATA, 'water_demand_table.csv') SAMPLE_DATA, 'water_demand_table.csv')
args['sub_watersheds_path'] = os.path.join( args['sub_watersheds_path'] = os.path.join(
SAMPLE_DATA, 'subwatersheds.shp') SAMPLE_DATA, 'subwatersheds.shp')
hydropower_water_yield.execute(args) annual_water_yield.execute(args)
raster_results = ['aet.tif', 'fractp.tif', 'wyield.tif'] raster_results = ['aet.tif', 'fractp.tif', 'wyield.tif']
for raster_path in raster_results: for raster_path in raster_results:
@ -207,10 +206,10 @@ class HydropowerTests(unittest.TestCase):
def test_valuation_subshed(self): def test_valuation_subshed(self):
"""Hydro: testing Valuation component w/ subwatershed.""" """Hydro: testing Valuation component w/ subwatershed."""
from natcap.invest.hydropower import hydropower_water_yield from natcap.invest.annual_water_yield import annual_water_yield
from natcap.invest import utils from natcap.invest import utils
args = HydropowerTests.generate_base_args(self.workspace_dir) args = AnnualWaterYieldTests.generate_base_args(self.workspace_dir)
args['demand_table_path'] = os.path.join( args['demand_table_path'] = os.path.join(
SAMPLE_DATA, 'water_demand_table.csv') SAMPLE_DATA, 'water_demand_table.csv')
args['valuation_table_path'] = os.path.join( args['valuation_table_path'] = os.path.join(
@ -218,7 +217,7 @@ class HydropowerTests(unittest.TestCase):
args['sub_watersheds_path'] = os.path.join( args['sub_watersheds_path'] = os.path.join(
SAMPLE_DATA, 'subwatersheds.shp') SAMPLE_DATA, 'subwatersheds.shp')
hydropower_water_yield.execute(args) annual_water_yield.execute(args)
raster_results = ['aet.tif', 'fractp.tif', 'wyield.tif'] raster_results = ['aet.tif', 'fractp.tif', 'wyield.tif']
for raster_path in raster_results: for raster_path in raster_results:
@ -247,33 +246,33 @@ class HydropowerTests(unittest.TestCase):
def test_validation(self): def test_validation(self):
"""Hydro: test failure cases on the validation function.""" """Hydro: test failure cases on the validation function."""
from natcap.invest.hydropower import hydropower_water_yield from natcap.invest.annual_water_yield import annual_water_yield
args = HydropowerTests.generate_base_args(self.workspace_dir) args = AnnualWaterYieldTests.generate_base_args(self.workspace_dir)
# default args should be fine # default args should be fine
self.assertEqual(hydropower_water_yield.validate(args), []) self.assertEqual(annual_water_yield.validate(args), [])
args_bad_vector = args.copy() args_bad_vector = args.copy()
args_bad_vector['watersheds_path'] = args_bad_vector['eto_path'] args_bad_vector['watersheds_path'] = args_bad_vector['eto_path']
bad_vector_list = hydropower_water_yield.validate(args_bad_vector) bad_vector_list = annual_water_yield.validate(args_bad_vector)
self.assertTrue('not be opened as a GDAL vector' self.assertTrue('not be opened as a GDAL vector'
in bad_vector_list[0][1]) in bad_vector_list[0][1])
args_bad_raster = args.copy() args_bad_raster = args.copy()
args_bad_raster['eto_path'] = args_bad_raster['watersheds_path'] args_bad_raster['eto_path'] = args_bad_raster['watersheds_path']
bad_raster_list = hydropower_water_yield.validate(args_bad_raster) bad_raster_list = annual_water_yield.validate(args_bad_raster)
self.assertTrue('not be opened as a GDAL raster' self.assertTrue('not be opened as a GDAL raster'
in bad_raster_list[0][1]) in bad_raster_list[0][1])
args_bad_file = args.copy() args_bad_file = args.copy()
args_bad_file['eto_path'] = 'non_existant_file.tif' args_bad_file['eto_path'] = 'non_existant_file.tif'
bad_file_list = hydropower_water_yield.validate(args_bad_file) bad_file_list = annual_water_yield.validate(args_bad_file)
self.assertTrue('File not found' in bad_file_list[0][1]) self.assertTrue('File not found' in bad_file_list[0][1])
args_missing_key = args.copy() args_missing_key = args.copy()
del args_missing_key['eto_path'] del args_missing_key['eto_path']
validation_warnings = hydropower_water_yield.validate( validation_warnings = annual_water_yield.validate(
args_missing_key) args_missing_key)
self.assertEqual( self.assertEqual(
validation_warnings, validation_warnings,
@ -296,7 +295,7 @@ class HydropowerTests(unittest.TestCase):
args_bad_biophysical_table['biophysical_table_path'] = ( args_bad_biophysical_table['biophysical_table_path'] = (
bad_biophysical_path) bad_biophysical_path)
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
hydropower_water_yield.execute(args_bad_biophysical_table) annual_water_yield.execute(args_bad_biophysical_table)
actual_message = str(cm.exception) actual_message = str(cm.exception)
self.assertTrue( self.assertTrue(
"The missing values found in the LULC raster but not the table" "The missing values found in the LULC raster but not the table"
@ -335,7 +334,7 @@ class HydropowerTests(unittest.TestCase):
# ensure that a missing watershed id the valuation table will # ensure that a missing watershed id the valuation table will
# raise an exception that's helpful # raise an exception that's helpful
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
hydropower_water_yield.execute(args_bad_demand_table) annual_water_yield.execute(args_bad_demand_table)
actual_message = str(cm.exception) actual_message = str(cm.exception)
self.assertTrue( self.assertTrue(
"The missing values found in the LULC raster but not the table" "The missing values found in the LULC raster but not the table"
@ -362,7 +361,7 @@ class HydropowerTests(unittest.TestCase):
break break
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
hydropower_water_yield.execute(args_bad_valuation_table) annual_water_yield.execute(args_bad_valuation_table)
actual_message = str(cm.exception) actual_message = str(cm.exception)
self.assertTrue( self.assertTrue(
'but are not found in the valuation table' in 'but are not found in the valuation table' in