| 1 |
#!Jinja2 |
| 2 |
|
| 3 |
[meta] |
| 4 |
title = Weather Station Workflow |
| 5 |
description = """ |
| 6 |
This workflow demonstrates how to read in a data file for use in |
| 7 |
defining your workflow. |
| 8 |
|
| 9 |
We have a file called "stations.json" which contains a list of weather |
| 10 |
stations with some data for each. This workflow reads the |
| 11 |
"stations.json" file and creates a family for each weather station |
| 12 |
with an environment variable for each data field. |
| 13 |
|
| 14 |
You can load data in other formats too. Try changing "load_json" to |
| 15 |
"load_csv" and "stations.json" to "stations.csv" for a CSV example. |
| 16 |
""" |
| 17 |
|
| 18 |
|
| 19 |
{# Import a Python function to load our data. #} |
| 20 |
{% from "load_data" import load_json %} |
| 21 |
|
| 22 |
{# Load data from the specified file. #} |
| 23 |
{% set stations = load_json('stations.json') %} |
| 24 |
|
| 25 |
{# Extract a list of station names from the data file. #} |
| 26 |
{% set station_names = stations | map(attribute="name") | list %} |
| 27 |
|
| 28 |
|
| 29 |
{# Provide Cylc with a list of weather stations. #} |
| 30 |
[task parameters] |
| 31 |
station = {{ station_names | join(', ') }} |
| 32 |
|
| 33 |
|
| 34 |
[scheduling] |
| 35 |
initial cycle point = 2000-01-01 |
| 36 |
final cycle point = 2000-01-02 |
| 37 |
[[graph]] |
| 38 |
P1D = fetch<station> => process<station> => collate |
| 39 |
|
| 40 |
|
| 41 |
[runtime] |
| 42 |
{# Define a family for each weather station #} |
| 43 |
{% for station in stations %} |
| 44 |
[[STATION<station={{ station["name"] }}>]] |
| 45 |
[[[environment]]] |
| 46 |
{# Turn the <station> parameter into an environment variable #} |
| 47 |
{# NB: Just to show how, we could also have used `station["name"]`. #} |
| 48 |
name = %(station)s |
| 49 |
{# Turn the data for this station into environment variables. #} |
| 50 |
wmo = {{ station["wmo"] }} |
| 51 |
alt = {{ station["alt"] }} |
| 52 |
lat = {{ station["lat"] }} |
| 53 |
lon = {{ station["lon"] }} |
| 54 |
{% endfor %} |
| 55 |
|
| 56 |
# a task that gets data |
| 57 |
[[fetch<station>]] |
| 58 |
inherit = STATION<station> |
| 59 |
script = echo "fetch data for $name, WMO ID: $wmo" |
| 60 |
|
| 61 |
[[process<station>]] |
| 62 |
inherit = STATION<station> |
| 63 |
script = echo "process data for $name, location: $lat,$lon" |
| 64 |
|
| 65 |
[[collate]] |
| 66 |
script = "echo collate data for stations: {{ station_names }}" |