Skip to content

Commit

Permalink
Add analyze task for global land cover
Browse files Browse the repository at this point in the history
This task takes the output of the STAC Histogram Query and
calculates the area and coverage percent from it, and
formats it into the standard MMW output.

We remove IO Class 0 NOADAT from the standard set of
outputs so that we don't include it in the final output.
  • Loading branch information
rajadain committed Jul 15, 2024
1 parent c2a5aba commit 8b4c6bd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/mmw/apps/geoprocessing_api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,46 @@ def area(dictionary, key, default=0):
}


@shared_task(throws=Exception)
def analyze_global_land(result, year):
if 'error' in result:
raise Exception(f'[analyze_global_land_{year}] {result["error"]}')

histogram = parse(result['result'])
pixel_size = result['pixel_size']

# Count up all the legitimate IO LULC classes
# This excludes NODATA which is IO LULC 0
total_count = sum(
[
count
for ioclass, count in histogram.items()
if ioclass in layer_classmaps.IO_LULC
]
)

categories = []

for ioclass, (code, name) in layer_classmaps.IO_LULC.items():
categories.append(
{
'area': histogram.get(ioclass, 0) * pixel_size,
'code': code,
'coverage': float(histogram.get(ioclass, 0)) / total_count,
'ioclass': ioclass,
'type': name,
}
)

return {
'survey': {
'name': f'global_land_io_{year}',
'displayName': f'Global Land Use/Cover {year}',
'categories': categories,
}
}


@shared_task(throws=Exception)
def analyze_soil(result, area_of_interest=None):
if 'error' in result:
Expand Down
2 changes: 1 addition & 1 deletion src/mmw/mmw/settings/layer_classmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Map for the Impact Observatory Land Use Land Classification scheme
# https://www.impactobservatory.com/maps-for-good/
IO_LULC = {
0: ['no_data', 'No Data'],
# 0: ['no_data', 'No Data'],
1: ['water', 'Water'],
2: ['trees', 'Trees'],
4: ['flooded_vegetation', 'Flooded vegetation'],
Expand Down

0 comments on commit 8b4c6bd

Please sign in to comment.