Skip to content

Commit

Permalink
Merge pull request #1532 from emlys/feature/initial-plugin-pr
Browse files Browse the repository at this point in the history
Move all model-specific info out of workbench
  • Loading branch information
emlys authored Mar 18, 2024
2 parents 9a70648 + 8e029e0 commit 10af95d
Show file tree
Hide file tree
Showing 47 changed files with 1,032 additions and 1,127 deletions.
6 changes: 3 additions & 3 deletions scripts/userguide-filevalidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def main(userguide_dir):
Raises:
OSError if any models reference files that do not exist.
"""
from natcap.invest.model_metadata import MODEL_METADATA
from natcap.invest import models

missing_files = []
userguide_dir_source = os.path.join(userguide_dir, 'source', 'en')

for data in MODEL_METADATA.values():
for module in models.pyname_to_module.values():
# html referenced won't exist unless we actually built the UG,
# so check for the rst with the same basename.
model_rst = f'{os.path.splitext(data.userguide)[0]}.rst'
model_rst = f'{os.path.splitext(module.MODEL_SPEC["userguide"])[0]}.rst'
if not os.path.exists(os.path.join(
userguide_dir_source, model_rst)):
missing_files.append(data.userguide)
Expand Down
19 changes: 15 additions & 4 deletions src/natcap/invest/annual_water_yield.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from . import spec_utils
from . import utils
from . import validation
from .model_metadata import MODEL_METADATA
from .unit_registry import u

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -106,9 +105,21 @@
}

MODEL_SPEC = {
"model_name": MODEL_METADATA["annual_water_yield"].model_title,
"pyname": MODEL_METADATA["annual_water_yield"].pyname,
"userguide": MODEL_METADATA["annual_water_yield"].userguide,
"model_id": "annual_water_yield",
"model_name": gettext("Annual Water Yield"),
"pyname": "natcap.invest.annual_water_yield",
"userguide": "annual_water_yield.html",
"aliases": ("hwy", "awy"),
"ui_spec": {
"order": [
['workspace_dir', 'results_suffix'],
['precipitation_path', 'eto_path', 'depth_to_root_rest_layer_path', 'pawc_path'],
['lulc_path', 'biophysical_table_path', 'seasonality_constant'],
['watersheds_path', 'sub_watersheds_path'],
['demand_table_path', 'valuation_table_path']
],
"hidden": ["n_workers"]
},
"args_with_spatial_overlap": {
"spatial_keys": ["lulc_path",
"depth_to_root_rest_layer_path",
Expand Down
29 changes: 25 additions & 4 deletions src/natcap/invest/carbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from . import utils
from . import spec_utils
from .unit_registry import u
from .model_metadata import MODEL_METADATA
from . import gettext

LOGGER = logging.getLogger(__name__)
Expand All @@ -42,9 +41,22 @@
}

MODEL_SPEC = {
"model_name": MODEL_METADATA["carbon"].model_title,
"pyname": MODEL_METADATA["carbon"].pyname,
"userguide": MODEL_METADATA["carbon"].userguide,
"model_id": "carbon",
"model_name": gettext("Carbon Storage and Sequestration"),
"pyname": "natcap.invest.carbon",
"userguide": "carbonstorage.html",
"aliases": (),
"ui_spec": {
"order": [
['workspace_dir', 'results_suffix'],
['lulc_cur_path', 'carbon_pools_path'],
['calc_sequestration', 'lulc_fut_path'],
['do_redd', 'lulc_redd_path'],
['do_valuation', 'lulc_cur_year', 'lulc_fut_year', 'price_per_metric_ton_of_c', 'discount_rate', 'rate_change'],
],
"hidden": ["n_workers"],
"forum_tag": 'carbon'
},
"args_with_spatial_overlap": {
"spatial_keys": ["lulc_cur_path", "lulc_fut_path", "lulc_redd_path"],
},
Expand Down Expand Up @@ -77,6 +89,7 @@
"projected": True,
"projection_units": u.meter,
"required": "calc_sequestration",
"allowed": "calc_sequestration",
"about": gettext(
"A map of LULC for the future scenario. "
"If run valuation model is "
Expand All @@ -90,6 +103,7 @@
"do_redd": {
"type": "boolean",
"required": False,
"allowed": "calc_sequestration",
"about": gettext(
"Run REDD scenario analysis. This requires three "
"LULC maps: one for the current scenario, one "
Expand All @@ -102,6 +116,7 @@
"projected": True,
"projection_units": u.meter,
"required": "do_redd",
"allowed": "do_redd",
"about": gettext(
"A map of LULC for the REDD policy scenario. "
"All values in this raster must have corresponding entries in "
Expand Down Expand Up @@ -141,6 +156,7 @@
"type": "number",
"units": u.year_AD,
"required": "do_valuation",
"allowed": "do_valuation",
"about": gettext(
"The calendar year of the current scenario depicted in the "
"current LULC map. Required if Run Valuation model is selected."),
Expand All @@ -151,6 +167,7 @@
"type": "number",
"units": u.year_AD,
"required": "do_valuation",
"allowed": "do_valuation",
"about": gettext(
"The calendar year of the future scenario depicted in the "
"future LULC map. Required if Run Valuation model is selected."),
Expand All @@ -159,6 +176,7 @@
"do_valuation": {
"type": "boolean",
"required": False,
"allowed": "calc_sequestration",
"about": gettext(
"Calculate net present value for the future scenario, and the "
"REDD scenario if provided, and report it in the final HTML "
Expand All @@ -169,6 +187,7 @@
"type": "number",
"units": u.currency/u.metric_ton,
"required": "do_valuation",
"allowed": "do_valuation",
"about": gettext(
"The present value of carbon. "
"Required if Run Valuation model is selected."),
Expand All @@ -177,6 +196,7 @@
"discount_rate": {
"type": "ratio",
"required": "do_valuation",
"allowed": "do_valuation",
"about": gettext(
"The annual market discount rate in the price of carbon, "
"which reflects society's preference for immediate benefits "
Expand All @@ -187,6 +207,7 @@
"rate_change": {
"type": "ratio",
"required": "do_valuation",
"allowed": "do_valuation",
"about": gettext(
"The relative annual increase of the price of carbon. "
"Required if Run Valuation model is selected."),
Expand Down
Loading

0 comments on commit 10af95d

Please sign in to comment.