Skip to content

Commit

Permalink
feat(pipeline): add soil moisture anomaly
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashelms committed Feb 5, 2024
1 parent e41a893 commit 92512b4
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions data/downloads/owncloud-soil-moisture-anomaly.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash

BASE_URL="https://owncloud.tuwien.ac.at/index.php/s/bY8j2kBgZlkqFYC/download?path=%2F&files=ESA_CCI_SM_v06.2_COMBINED_Anomalies.nc"
BASE_URL="https://owncloud.tuwien.ac.at/index.php/s/bY8j2kBgZlkqFYC/download?path=%2F&files=ESA_CCI_SM_v07.1_COMBINED_Anomalies.nc"
OUTPUT_FOLDER=./download/soil_moisture_anomaly

mkdir -p $OUTPUT_FOLDER

FILENAME=$OUTPUT_FOLDER/sma.nc
curl --silent $BASE_URL > $FILENAME

python ./data/split-time-dim.py --file $FILENAME --folder $OUTPUT_FOLDER --variable Anomaly
python /data/split-time-dim.py --file $FILENAME --folder $OUTPUT_FOLDER --variable Anomaly

66 changes: 66 additions & 0 deletions pipeline/dags/soil_moisture.Anomaly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from datetime import datetime
import task_factories
from airflow import DAG
from airflow.models.param import Param

# layer
LAYER_ID = 'soil_moisture'
LAYER_VARIABLE = 'Anomaly'
LAYER_VERSION = '1.14.1'
RESOLUTION = '1440 720'
METADATA = {
"id": f'{LAYER_ID}.{LAYER_VARIABLE}',
"version": LAYER_VERSION,
"timestamps": [], # will be injected
"min_value": -0.1,
"max_value": 0.1,
"type": "image", # 'tiles' or 'image'
"zoom_levels": '0-3',
"units": 'm3 m-3',
"basemap": None,
"legend_values": ["> 100 l/m³", "-100"],
"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

dag_params = {
"max_files": Param(2, type=["null", "integer"], minimum=0,),
"output_bucket": Param("esa-cfs-pipeline-output", 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(
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', dry_run=False)
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, LAYER_VERSION, 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()
4 changes: 4 additions & 0 deletions pipeline/plugins/colors/soil_moisture.Anomaly.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.1 0 0 255
0 255 255 255
-0.1 255 0 0
nv 0 0 0 0

0 comments on commit 92512b4

Please sign in to comment.