Raise error on invalid LULC years and test this
This commit is contained in:
parent
92acaa279b
commit
67c38b4d59
|
@ -120,7 +120,7 @@ MODEL_SPEC = {
|
|||
"name": gettext("baseline LULC year")
|
||||
},
|
||||
"lulc_alt_year": {
|
||||
"expression": "float(value).is_integer()",
|
||||
"expression": "float(value).is_integer() and value > MODEL_SPEC['lulc_bas_year']",
|
||||
"type": "number",
|
||||
"units": u.year_AD,
|
||||
"required": "do_valuation",
|
||||
|
@ -300,6 +300,13 @@ def execute(args):
|
|||
(_INTERMEDIATE_BASE_FILES, intermediate_output_dir),
|
||||
(_TMP_BASE_FILES, output_dir)], file_suffix)
|
||||
|
||||
if args['do_valuation'] and args['lulc_bas_year'] >= args['lulc_alt_year']:
|
||||
raise ValueError(
|
||||
f"Invalid input: The Alternate LULC Year ({args['lulc_alt_year']}) "
|
||||
"must be greater than the Baseline LULC Year ({args['lulc_bas_year']}). "
|
||||
"Ensure that the Baseline LULC Year is earlier than the Alternate LULC Year."
|
||||
)
|
||||
|
||||
carbon_pool_df = validation.get_validated_dataframe(
|
||||
args['carbon_pools_path'], **MODEL_SPEC['args']['carbon_pools_path'])
|
||||
|
||||
|
|
|
@ -433,3 +433,18 @@ class CarbonValidationTests(unittest.TestCase):
|
|||
'lulc_bas_year',
|
||||
'lulc_alt_year'])
|
||||
self.assertEqual(invalid_keys, expected_missing_keys)
|
||||
|
||||
def test_invalid_lulc_years(self):
|
||||
"""Test that providing an Alternate LULC year < Baseline LULC error
|
||||
raises a ValueError"""
|
||||
from natcap.invest import carbon
|
||||
|
||||
args = {
|
||||
'workspace_dir': self.workspace_dir,
|
||||
'do_valuation': True,
|
||||
'lulc_bas_year': 2025,
|
||||
'lulc_alt_year': 2023,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
carbon.execute(args)
|
||||
|
|
Loading…
Reference in New Issue