From fc3a3b743d7d289761ae78ea2caaa3e14d362aa3 Mon Sep 17 00:00:00 2001 From: Terence Tuhinanshu Date: Wed, 8 Jun 2022 21:01:17 +0000 Subject: [PATCH 1/2] Switch to using new NLCD layers These are correctly aligned. For details see: https://github.com/WikiWatershed/mmw-geoprocessing/issues/102 --- src/mmw/apps/geoprocessing_api/schemas.py | 16 ++++++++-------- src/mmw/apps/geoprocessing_api/views.py | 2 +- src/mmw/apps/modeling/calcs.py | 2 +- src/mmw/js/src/modeling/utils.js | 10 +++++----- src/mmw/mmw/settings/base.py | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/mmw/apps/geoprocessing_api/schemas.py b/src/mmw/apps/geoprocessing_api/schemas.py index 006ef4a49..44fd327c5 100644 --- a/src/mmw/apps/geoprocessing_api/schemas.py +++ b/src/mmw/apps/geoprocessing_api/schemas.py @@ -192,11 +192,11 @@ ) 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-2019-30m-epsg5070-512-uint8raw', + 'nlcd-2016-30m-epsg5070-512-uint8raw', + 'nlcd-2011-30m-epsg5070-512-uint8raw', + 'nlcd-2006-30m-epsg5070-512-uint8raw', + 'nlcd-2001-30m-epsg5070-512-uint8raw', 'nlcd-2011-30m-epsg5070-512-int8', ]) LAYER_OVERRIDES = Schema( @@ -209,12 +209,12 @@ properties={ '__LAND__': Schema( type=TYPE_STRING, - example='nlcd-2019-30m-epsg5070-512-byte', + example='nlcd-2019-30m-epsg5070-512-uint8raw', description='The NLCD layer to use. Valid options are: ' - f'"{nlcd_override_allowed_values}". All "-byte" ' + f'"{nlcd_override_allowed_values}". All "-uint8raw" ' '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".', + 'is NLCD19 2019 "nlcd-2019-30m-epsg5070-512-uint8raw".' ), '__STREAMS__': Schema( type=TYPE_STRING, diff --git a/src/mmw/apps/geoprocessing_api/views.py b/src/mmw/apps/geoprocessing_api/views.py index 830840ffd..9a7385d10 100644 --- a/src/mmw/apps/geoprocessing_api/views.py +++ b/src/mmw/apps/geoprocessing_api/views.py @@ -426,7 +426,7 @@ def start_analyze_land(request, nlcd_year, format=None): nlcd, year = nlcd_year.split('_') if nlcd == '2019' and year in ['2019', '2016', '2011', '2006', '2001']: - layer_overrides['__LAND__'] = f'nlcd-{year}-30m-epsg5070-512-byte' + layer_overrides['__LAND__'] = f'nlcd-{year}-30m-epsg5070-512-uint8raw' return start_celery_job([ geoprocessing.run.s('nlcd_ara', geop_input, wkaoi, diff --git a/src/mmw/apps/modeling/calcs.py b/src/mmw/apps/modeling/calcs.py index bf383863d..383588516 100644 --- a/src/mmw/apps/modeling/calcs.py +++ b/src/mmw/apps/modeling/calcs.py @@ -400,7 +400,7 @@ def get_layer_value(layer, layer_overrides=dict): If the default config is something like: { - '__LAND__': 'nlcd-2019-30m-epsg5070-512-byte', + '__LAND__': 'nlcd-2019-30m-epsg5070-512-uint8raw', '__SOIL__': 'ssurgo-hydro-groups-30m-epsg5070-512-int8', '__STREAMS__': 'nhd', } diff --git a/src/mmw/js/src/modeling/utils.js b/src/mmw/js/src/modeling/utils.js index bee17dd24..4d893eb29 100644 --- a/src/mmw/js/src/modeling/utils.js +++ b/src/mmw/js/src/modeling/utils.js @@ -64,11 +64,11 @@ module.exports = { layerOverrideToDefaultLandCoverType: function(layer_overrides) { var raster = layer_overrides && _.get(layer_overrides, "__LAND__"), mapping = { - "nlcd-2019-30m-epsg5070-512-byte": "land_2019_2019", - "nlcd-2016-30m-epsg5070-512-byte": "land_2019_2016", - "nlcd-2011-30m-epsg5070-512-byte": "land_2019_2011", - "nlcd-2006-30m-epsg5070-512-byte": "land_2019_2006", - "nlcd-2001-30m-epsg5070-512-byte": "land_2019_2001", + "nlcd-2019-30m-epsg5070-512-uint8raw": "land_2019_2019", + "nlcd-2016-30m-epsg5070-512-uint8raw": "land_2019_2016", + "nlcd-2011-30m-epsg5070-512-uint8raw": "land_2019_2011", + "nlcd-2006-30m-epsg5070-512-uint8raw": "land_2019_2006", + "nlcd-2001-30m-epsg5070-512-uint8raw": "land_2019_2001", "nlcd-2011-30m-epsg5070-512-int8": "land_2011_2011", }; diff --git a/src/mmw/mmw/settings/base.py b/src/mmw/mmw/settings/base.py index ec56aecb9..c91c80f12 100644 --- a/src/mmw/mmw/settings/base.py +++ b/src/mmw/mmw/settings/base.py @@ -477,7 +477,7 @@ def get_env_setting(setting): '__BFI__': 'bfi48grd-epsg5070', '__GWN__': 'us-groundwater-nitrogen-30m-epsg5070-512', '__KFACTOR__': 'us-ssugro-kfactor-30m-epsg5070-512', - '__LAND__': 'nlcd-2019-30m-epsg5070-512-byte', + '__LAND__': 'nlcd-2019-30m-epsg5070-512-uint8raw', '__NED__': 'ned-nhdplus-30m-epsg5070-512', '__PROTECTED_LANDS__': 'protected-lands-30m-epsg5070-512', '__SLOPE__': 'us-percent-slope-30m-epsg5070-512', From 3fd4244dbfd33bbf2fa369d81756e82b1cf1c467 Mon Sep 17 00:00:00 2001 From: Terence Tuhinanshu Date: Mon, 17 Oct 2022 13:56:55 +0000 Subject: [PATCH 2/2] Clear out unaligned NLCD19 GWLF-E results Adds a migration that clears out all stored results for GWLF-E projects created on or after 2022-01-17, which is when 1.33.0 was released with incorrectly aligned NLCD19 layers, which had also been made the default. Thus, every project made after then had slighly incorrect results. This migration clears out those bad results. The next time that project is loaded in the UI, all its results will be recalculated. This allows us to rebuild the results over time, and not overload the system all at once. --- .../0041_clear_nlcd2019_gwlfe_results.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/mmw/apps/modeling/migrations/0041_clear_nlcd2019_gwlfe_results.py diff --git a/src/mmw/apps/modeling/migrations/0041_clear_nlcd2019_gwlfe_results.py b/src/mmw/apps/modeling/migrations/0041_clear_nlcd2019_gwlfe_results.py new file mode 100644 index 000000000..58def7406 --- /dev/null +++ b/src/mmw/apps/modeling/migrations/0041_clear_nlcd2019_gwlfe_results.py @@ -0,0 +1,45 @@ +# Generated by Django 3.2.13 on 2022-10-17 13:47 + +from django.db import migrations + + +def clear_nlcd2019_gwlfe_results(apps, schema_editor): + """ + Clear the results for all scenarios belonging to GWLF-E projects made after + the release of 1.33.0, which had incorrectly aligned NLCD19 2019 on + 2022-01-17: + https://github.com/WikiWatershed/model-my-watershed/releases/tag/1.33.0 + + These results will be recalculated with the correclty aligned NLCD19 values + when these projects are accessed again. + """ + Project = apps.get_model('modeling', 'Project') + Scenario = apps.get_model('modeling', 'Scenario') + + Project.objects.filter( + model_package='gwlfe', + created_at__gte='2022-01-17', + ).update( + gis_data=None, + mapshed_job_uuid=None, + subbasin_mapshed_job_uuid=None, + ) + + Scenario.objects.filter( + project__model_package='gwlfe', + project__created_at__gte='2022-01-17', + ).update( + results='[]', + modification_hash='', + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ('modeling', '0040_clear_nlcd2019_tr55_results'), + ] + + operations = [ + migrations.RunPython(clear_nlcd2019_gwlfe_results), + ]