Skip to content

Commit

Permalink
feat(pipeline): fire burned area
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Helms authored and Andreas Helms committed Mar 13, 2024
1 parent 0f66e96 commit 42b8cb0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
73 changes: 73 additions & 0 deletions pipeline/dags/fire.burned_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from datetime import datetime
import task_factories
from airflow import DAG
from airflow.models.param import Param
from helper import get_default_layer_version

# layer
LAYER_ID = 'fire'
LAYER_VARIABLE = 'burned_area'
RESOLUTION = '1440 720'
METADATA = {
"id": f'{LAYER_ID}.{LAYER_VARIABLE}',
"timestamps": [], # will be injected
"min_value": 0,
"max_value": 400000000,
"type": "image", # 'tiles' or 'image'
"zoom_levels": '0-3',
"units": "m2",
"basemap": 'dark',
"legend_values": [
"300 km\u00b2",
"200",
"100",
"0"
],
"time_format": {
"year": "numeric",
"month": "long"
}
}

# dev
BUCKET_ORIGIN = 'esa-cfs-cate-data'
BUCKET_TMP = 'esa-cfs-pipeline-tmp'
WORKDIR = '/workdir/files'
COLOR_FILE = f'/opt/airflow/plugins/colors/{LAYER_ID}.{LAYER_VARIABLE}.txt'
DEBUG = False

default_layer_version = get_default_layer_version()
dag_params = {
"max_files": Param(2, type=["null", "integer"], minimum=0,),
"output_bucket": Param("esa-cfs-pipeline-output", type=["string"], enum=['esa-cfs-pipeline-output', 'esa-cfs-tiles']),
"skip_downloads": Param(False, type="boolean"),
"layer_version": Param(default_layer_version, type="string")
}

with DAG(dag_id=METADATA["id"], start_date=datetime(2022, 1, 1), schedule=None, catchup=False, params=dag_params) as dag:

# create tasks
clean_workdir = task_factories.clean_dir_skippable(
task_id='clean_workdir', dir=WORKDIR)()
list_files = task_factories.gcs_list_files(
bucket_name=BUCKET_ORIGIN, layer_id=LAYER_ID, layer_variable=LAYER_VARIABLE)
download = task_factories.gcs_download_file(
bucket_name=BUCKET_ORIGIN, dir=WORKDIR, appendix='_downloaded')
legend_image = task_factories.legend_image(
workdir=WORKDIR, color_file=COLOR_FILE)
metadata = task_factories.metadata(workdir=WORKDIR, metadata=METADATA)
gdal_transforms = task_factories.gdal_transforms(
layer_variable=LAYER_VARIABLE, color_file=COLOR_FILE, layer_type=METADATA['type'], zoom_levels=METADATA['zoom_levels'], gdal_ts=RESOLUTION)
upload = task_factories.upload(
WORKDIR, LAYER_ID, LAYER_VARIABLE, METADATA['type'])

# connect tasks
files = list_files()
clean_workdir >> files
downloads = download.expand(filename=files)
gdal_transforms(downloads) >> upload()
clean_workdir >> legend_image
metadata(files)

if DEBUG:
downloads >> task_factories.gdal_info()
6 changes: 6 additions & 0 deletions pipeline/plugins/colors/fire.burned_area.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
300000000 51 26 26 255
150000000 160 40 55 255
25000000 255 124 27 255
10000000 255 237 38 255
1 255 237 38 0
0 255 255 255 0
Binary file added pipeline/plugins/layer-icons/fire.burned_area.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 42b8cb0

Please sign in to comment.