Skip to content

Commit

Permalink
Merge pull request #3448 from WikiWatershed/tt/adjust-calculations
Browse files Browse the repository at this point in the history
Connects #3447
Connects #3434
Connects #3446
  • Loading branch information
rajadain committed Jan 7, 2022
2 parents a77fdb4 + 7ca1b8b commit f527257
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 19 deletions.
2 changes: 1 addition & 1 deletion deployment/ansible/group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ docker_compose_version: "1.26.*"
geop_host: "localhost"
geop_port: 8090

geop_version: "5.0.0"
geop_version: "5.1.0"
geop_cache_enabled: 1

nginx_cache_dir: "/var/cache/nginx"
Expand Down
13 changes: 5 additions & 8 deletions src/mmw/apps/modeling/calcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from django.conf import settings
from django.db import connection

from django.contrib.gis.geos import WKBReader

from apps.modeling.mapshed.calcs import (area_calculations,
nearest_weather_stations,
average_weather_data
Expand Down Expand Up @@ -431,7 +429,7 @@ def _get_boundary_search_query(search_term):
subquery = ' UNION ALL '.join(selects)

return f"""
SELECT id, code, name, rank, center
SELECT id, code, name, rank, ST_X(center) AS x, ST_Y(center) AS y
FROM ({subquery}) AS subquery
ORDER BY rank DESC, name
"""
Expand All @@ -448,14 +446,13 @@ def _do_boundary_search(search_term):
wildcard_term = f'%{search_term}%'
cursor.execute(query, {'term': wildcard_term})

wkb_r = WKBReader()

for row in cursor.fetchall():
id = row[0]
code = row[1]
name = row[2]
rank = row[3]
point = wkb_r.read(row[4])
x = row[4]
y = row[5]

layer = _get_boundary_layer_by_code(code)

Expand All @@ -465,8 +462,8 @@ def _do_boundary_search(search_term):
'text': name,
'label': layer['short_display'],
'rank': rank,
'y': point.y,
'x': point.x,
'x': x,
'y': y,
})

return result
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 3.2.10 on 2021-12-27 19:26
import json
from django.db import migrations


def override_sedaadjust_for_old_projects(apps, schema_editor):
"""
The default value of SedAAdjust is being changed from 1.5 to 1.25 for all
new projects, which will use the high resolution "nhdhr" stream data. For
older projects using the medium resolution "nhd" data, we override the
value to be 1.5, so they remain consistent with old data, unless they were
overridden by a user.
"""
db_alias = schema_editor.connection.alias
Project = apps.get_model('modeling', 'Project')

ps = Project.objects.filter(layer_overrides__contains={'__STREAMS__':'nhd'})

for p in ps:
for s in p.scenarios.all():
mods = json.loads(s.modifications)
m_other = next((m for m in mods if m['modKey'] == 'entry_other'), None)

if m_other:
if 'SedAAdjust' not in m_other['output']:
m_other['output']['SedAAdjust'] = 1.5
m_other['userInput']['SedAAdjust'] = 1.5

s.modifications = json.dumps(mods)
s.save()
else:
mods.append({
'modKey': 'entry_other',
'output': {'SedAAdjust': 1.5},
'userInput': {'SedAAdjust': 1.5}})

s.modifications = json.dumps(mods)
s.save()


class Migration(migrations.Migration):

dependencies = [
('modeling', '0038_alter_project_layer_overrides'),
]

operations = [
migrations.RunPython(override_sedaadjust_for_old_projects),
]
15 changes: 8 additions & 7 deletions src/mmw/apps/modeling/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,21 +455,22 @@ def _initiate_subbasin_gwlfe_job_chain(model_input, mapshed_job_uuid,
# If we don't chunk, a shape that has 60+ subbasins could take >60sec
# to generate a response (and thus timeout) because we'll be waiting to
# submit one task for each subbasin.
gwlfe_chunked_group = group(iter([
gwlfe_chunked_group = group([
tasks.run_subbasin_gwlfe_chunks.s(mapshed_job_uuid,
modifications,
stream_lengths,
inputmod_hash,
watershed_id_chunk)
.set(link_error=errback)
for watershed_id_chunk in watershed_id_chunks]))
for watershed_id_chunk in watershed_id_chunks])

post_process = \
tasks.subbasin_results_to_dict.s().set(link_error=errback) | \
tasks.run_srat.s(mapshed_job_uuid).set(link_error=errback) | \
save_job_result.s(job_id, mapshed_job_uuid)
job_chain = (
gwlfe_chunked_group |
tasks.subbasin_results_to_dict.s().set(link_error=errback) |
tasks.run_srat.s(mapshed_job_uuid).set(link_error=errback) |
save_job_result.s(job_id, mapshed_job_uuid))

return (gwlfe_chunked_group | post_process).apply_async()
return chain(job_chain).apply_async()


@decorators.api_view(['POST'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</p>
{% if showSubbasinModelingButton %}
<a data-action="view-subbasin-attenuated-results" id="view-subbasin-results-link">
View subbasin attentuated results
View subbasin attenuated results
</a>
{% endif %}
<div class="quality-table-region"></div>
2 changes: 1 addition & 1 deletion src/mmw/mmw/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_env_setting(setting):
# The longest running tasks contain geoprocessing requests
# Keep the task and request time limit above, but in the ballpark of
# https://github.com/WikiWatershed/mmw-geoprocessing/blob/develop/api/src/main/resources/application.conf#L9
CELERY_TASK_TIME_LIMIT = 90
CELERY_TASK_TIME_LIMIT = 120
TASK_REQUEST_TIMEOUT = CELERY_TASK_TIME_LIMIT - 10
# END CELERY CONFIGURATION

Expand Down
2 changes: 1 addition & 1 deletion src/mmw/mmw/settings/gwlfe_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
'CountyFlag': b.NO, # Flag: County Layer Detected (0 No; 1 Yes)
'SoilPFlag': b.YES, # Flag: Soil P Layer Detected (0 No; 1 Yes)
'GWNFlag': b.YES, # Flag: Groundwater N Layer Detected (0 No; 1 Yes)
'SedAAdjust': 1.5, # Default Percent ET
'SedAAdjust': 0.8, # Default Percent ET
'BankNFrac': 0.25, # % Bank N Fraction (0 - 1)
'BankPFrac': 0.25, # % Bank P Fraction (0 - 1)
'ManuredAreas': 2, # Manure Spreading Periods (Default = 2)
Expand Down
1 change: 1 addition & 0 deletions src/mmw/requirements/development.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-r base.txt

flake8==4.0.1
jedi==0.17.2
ipython==7.17.0
ipdb==0.13.9

0 comments on commit f527257

Please sign in to comment.