Skip to content

Commit

Permalink
Merge pull request #3480 from WikiWatershed/tt/add-public-mapshed-end…
Browse files Browse the repository at this point in the history
…point

Connects #3472
  • Loading branch information
rajadain authored Feb 18, 2022
2 parents 588a0fd + ee5990d commit 79cd1bd
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
59 changes: 59 additions & 0 deletions src/mmw/apps/geoprocessing_api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,62 @@
},
required=['location'],
)

nlcd_override_allowed_values = '", "'.join([
'nlcd-2019-30m-epsg5070-512-byte',
'nlcd-2016-30m-epsg5070-512-byte',
'nlcd-2011-30m-epsg5070-512-byte',
'nlcd-2006-30m-epsg5070-512-byte',
'nlcd-2001-30m-epsg5070-512-byte',
'nlcd-2011-30m-epsg5070-512-int8',
])
LAYER_OVERRIDES = Schema(
title='Layer Overrides',
type=TYPE_OBJECT,
description='MMW combines different datasets in model runs. These have '
'default values, but can be overridden by specifying them '
'here. Only specify a value for the layers you want to '
'override.',
properties={
'__LAND__': Schema(
type=TYPE_STRING,
example='nlcd-2019-30m-epsg5070-512-byte',
description='The NLCD layer to use. Valid options are: '
f'"{nlcd_override_allowed_values}". All "-byte" '
'layers are from the NLCD19 product. The "-int8" '
'layer is from the NLCD11 product. The default value '
'is NLCD19 2019 "nlcd-2019-30m-epsg5070-512-byte".',
),
'__STREAMS__': Schema(
type=TYPE_STRING,
example='nhdhr',
description='The streams layer to use. Valid options are: '
'"nhdhr" for NHD High Resolution Streams, "nhd" for '
'NHD Medium Resolution Streams, and "drb" for '
'Delaware High Resolution. The area of interest must '
'be completely within the Delaware River Basin for '
'"drb". "nhdhr" and "nhd" can be used within the '
'Continental United States. In some cases, "nhdhr" '
'may timeout. In such cases, "nhd" can be used as a '
'fallback. "nhdhr" is the default.'
)
},
)

MODELING_REQUEST = Schema(
title='Modeling Request',
type=TYPE_OBJECT,
properties={
'area_of_interest': MULTIPOLYGON,
'wkaoi': Schema(
title='Well-Known Area of Interest',
type=TYPE_STRING,
example='huc12__55174',
description='The table and ID for a well-known area of interest, '
'such as a HUC. '
'Format "table__id", eg. "huc12__55174" will analyze '
'the HUC-12 City of Philadelphia-Schuylkill River.',
),
'layer_overrides': LAYER_OVERRIDES,
},
)
2 changes: 2 additions & 0 deletions src/mmw/apps/geoprocessing_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
re_path(r'jobs/' + uuid_regex, get_job, name='get_job'),
re_path(r'modeling/worksheet/$', views.start_modeling_worksheet,
name='start_modeling_worksheet'),
re_path(r'modeling/gwlf-e/prepare/$', views.start_modeling_gwlfe_prepare,
name='start_modeling_gwlfe_prepare'),
re_path(r'watershed/$', views.start_rwd, name='start_rwd'),
]
43 changes: 42 additions & 1 deletion src/mmw/apps/geoprocessing_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
from apps.core.decorators import log_request
from apps.modeling import geoprocessing
from apps.modeling.mapshed.calcs import streams
from apps.modeling.mapshed.tasks import nlcd_streams
from apps.modeling.mapshed.tasks import (collect_data,
convert_data,
multi_mapshed,
nlcd_streams)
from apps.modeling.serializers import AoiSerializer
from apps.modeling.views import _parse_input as _parse_modeling_input

from apps.geoprocessing_api import schemas, tasks
from apps.geoprocessing_api.permissions import AuthTokenSerializerAuthentication # noqa
Expand Down Expand Up @@ -1365,6 +1369,43 @@ def start_modeling_worksheet(request, format=None):
], area_of_interest, user)


@swagger_auto_schema(method='post',
request_body=schemas.MODELING_REQUEST,
responses={200: schemas.JOB_STARTED_RESPONSE})
@decorators.api_view(['POST'])
@decorators.authentication_classes((SessionAuthentication,
TokenAuthentication, ))
@decorators.permission_classes((IsAuthenticated, ))
@decorators.throttle_classes([BurstRateThrottle, SustainedRateThrottle])
@log_request
def start_modeling_gwlfe_prepare(request, format=None):
"""
Starts a job to prepare an input payload for GWLF-E for a given area.
Given an area of interest or a WKAoI id, gathers data from land, soil type,
groundwater nitrogen, available water capacity, K-factor, slope, soil
nitrogen, soil phosphorus, base-flow index, and stream datasets.
By default, NLCD 2019 and NHD High Resolution Streams are used to prepare
the input payload. This can be changed using the `layer_overrides` option.
Only one of `area_of_interest` or `wkaoi` should be provided. If both are
given, the `area_of_interest` will be used.
The `result` should be used with the gwlf-e/run endpoint.
"""
user = request.user if request.user.is_authenticated else None
area_of_interest, wkaoi = _parse_modeling_input(request.data)

layer_overrides = request.data.get('layer_overrides', {})

return start_celery_job([
multi_mapshed(area_of_interest, wkaoi, layer_overrides),
convert_data.s(wkaoi),
collect_data.s(area_of_interest, layer_overrides=layer_overrides),
], area_of_interest, user)


def _initiate_rwd_job_chain(location, snapping, simplify, data_source,
job_id, testing=False):
errback = save_job_error.s(job_id)
Expand Down

0 comments on commit 79cd1bd

Please sign in to comment.