Skip to content

Commit

Permalink
Merge branch 'hotfix/1.33.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadain committed Apr 27, 2022
2 parents 44c2ae9 + 2671182 commit 3539001
Show file tree
Hide file tree
Showing 6 changed files with 75 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.2.0"
geop_version: "5.3.0"
geop_cache_enabled: 1
geop_timeout: 200

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 3.2.13 on 2022-04-20 23:35

from django.db import migrations


def clear_nlcd2019_tr55_results(apps, schema_editor):
"""
Clear the results For all scenarios belonging to TR-55 projects made after
the release of 1.33.0, which switched NLCD19 2019 to be the default on
2022-01-17:
https://github.com/WikiWatershed/model-my-watershed/releases/tag/1.33.0
These will be recalculated with NLCD11 2011 the next time it is opened.
"""
Scenario = apps.get_model('modeling', 'Scenario')

Scenario.objects.filter(
project__model_package='tr-55',
project__created_at__gte='2022-01-17'
).update(
results='[]',
modification_hash='',
aoi_census='{}',
modification_censuses='{}',
)


class Migration(migrations.Migration):

dependencies = [
('modeling', '0039_override_sedaadjust_for_old_scenarios'),
]

operations = [
migrations.RunPython(clear_nlcd2019_tr55_results)
]
14 changes: 9 additions & 5 deletions src/mmw/apps/modeling/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,14 @@ def add_huc12(srat_huc12, aggregate):


@shared_task(throws=Exception)
def nlcd_soil(result):
if 'error' in result:
raise Exception(f'[nlcd_soil] {result["error"]}')
def nlcd_soil_tr55(results):
if 'error' in results:
raise Exception(f'[nlcd_soil_tr55] {results["error"]}')

return [nlcd_soil(result) for result in results]


def nlcd_soil(result):
dist = {}
total_count = 0

Expand All @@ -222,10 +226,10 @@ def nlcd_soil(result):
count + (dist[label]['cell_count'] if label in dist else 0)
)}

return [{
return {
'cell_count': total_count,
'distribution': dist,
}]
}


@shared_task
Expand Down
20 changes: 10 additions & 10 deletions src/mmw/apps/modeling/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@shared_task
def get_test_histogram():
return {
return [{
'List(21,1)': 22,
'List(21,2)': 1,
'List(21,4)': 5,
Expand All @@ -31,12 +31,12 @@ def get_test_histogram():
'List(24,1)': 537,
'List(24,2)': 268,
'List(24,4)': 279,
}
}]


class ExerciseGeoprocessing(TestCase):
def test_census(self):
histogram = {
histogram = [{
'List(11, 1)': 434,
'List(82, 4)': 202,
'List(23, 4)': 1957,
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_census(self):
'List(31, 2)': 25,
'List(31, 1)': 37,
'List(43, 2)': 800
}
}]

expected = [{
'cell_count': 136100,
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_census(self):
'd:woody_wetlands': {'cell_count': 1093}
}
}]
actual = tasks.nlcd_soil(histogram)
actual = tasks.nlcd_soil_tr55(histogram)
self.assertEqual(actual, expected)


Expand Down Expand Up @@ -307,7 +307,7 @@ def test_tr55_chain_doesnt_generate_censuses_if_they_exist(self):

skipped_tasks = [
'run',
'nlcd_soil'
'nlcd_soil_tr55'
]

needed_tasks = [
Expand Down Expand Up @@ -344,7 +344,7 @@ def test_tr55_chain_doesnt_generate_aoi_census_if_it_exists_and_mods(self):
# we still need to generate modification censuses
needed_tasks = [
'run',
'nlcd_soil',
'nlcd_soil_tr55',
'run_tr55'
]

Expand Down Expand Up @@ -390,7 +390,7 @@ def test_tr55_chain_doesnt_generate_aoi_census_if_it_exists_and_no_mods(self):

skipped_tasks = [
'run',
'nlcd_soil',
'nlcd_soil_tr55',
]

needed_tasks = [
Expand Down Expand Up @@ -450,7 +450,7 @@ def test_tr55_chain_generates_modification_censuses_if_they_are_old(self):

needed_tasks = [
'run',
'nlcd_soil',
'nlcd_soil_tr55',
'run_tr55'
]

Expand All @@ -477,7 +477,7 @@ def test_tr55_chain_generates_both_censuses_if_they_are_missing(self):

needed_tasks = [
'run',
'nlcd_soil',
'nlcd_soil_tr55',
'run_tr55'
]

Expand Down
9 changes: 6 additions & 3 deletions src/mmw/apps/modeling/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,9 @@ def _construct_tr55_job_chain(model_input, job_id):
aoi_census = model_input.get('aoi_census')
modification_censuses = model_input.get('modification_censuses')
layer_overrides = model_input.get('layer_overrides', {})
# Default to NLCD 2011 unless explicitly specified otherwise
layer_overrides['__LAND__'] = layer_overrides.get(
'__LAND__', 'nlcd-2011-30m-epsg5070-512-int8')
# Non-overlapping polygons derived from the modifications
pieces = model_input.get('modification_pieces', [])
# The hash of the current modifications
Expand All @@ -625,15 +628,15 @@ def _construct_tr55_job_chain(model_input, job_id):

job_chain.append(tasks.run_tr55.s(censuses, aoi, model_input))
else:
job_chain.append(tasks.nlcd_soil.s())
job_chain.append(tasks.nlcd_soil_tr55.s())

if aoi_census and pieces:
polygons = [m['shape']['geometry'] for m in pieces]
geop_input = {'polygon': [json.dumps(p) for p in polygons]}

job_chain.insert(
0,
geoprocessing.run.s('nlcd_soil',
geoprocessing.run.s('nlcd_soil_tr55',
geop_input,
layer_overrides=layer_overrides))
job_chain.append(tasks.run_tr55.s(aoi, model_input,
Expand All @@ -646,7 +649,7 @@ def _construct_tr55_job_chain(model_input, job_id):

job_chain.insert(
0,
geoprocessing.run.s('nlcd_soil',
geoprocessing.run.s('nlcd_soil_tr55',
geop_input,
wkaoi,
layer_overrides=layer_overrides))
Expand Down
13 changes: 13 additions & 0 deletions src/mmw/mmw/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,19 @@ def get_env_setting(setting):
'zoom': 0
}
},
'nlcd_soil_tr55': {
'input': {
'polygon': [],
'polygonCRS': 'LatLng',
'rasters': [
'__LAND__',
'__SOIL__'
],
'rasterCRS': 'ConusAlbers',
'operationType': 'RasterGroupedCountMany',
'zoom': 0
}
},
'nlcd_streams': {
'input': {
'polygon': [],
Expand Down

0 comments on commit 3539001

Please sign in to comment.