Skip to content

Commit 50d2dc5

Browse files
committed
post-indicator generation and output fetching workflow
1 parent 3dcf1db commit 50d2dc5

8 files changed

+459
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ wheels/
1010
.venv
1111

1212
.idea
13+
generated-indicators*
14+
output*
15+
inputs*

Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM amazonlinux:latest
2+
3+
# Install dependencies
4+
RUN yum install -y awscli
5+
6+
# Set working directory
7+
WORKDIR /app
8+
9+
# Copy the Bash script into the container
10+
COPY prepare-output.sh /prepare-output.sh
11+
12+
# Ensure script is executable
13+
RUN chmod +x /prepare-output.sh
14+
15+
# Set entrypoint to use the script
16+
ENTRYPOINT ["bash", "/prepare-output.sh"]

fetch_hazard_indicator.cwl

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
cwlVersion: v1.2
2+
$graph:
3+
- class: Workflow
4+
id: fetch-hazard-indicator
5+
label: Fetch a hazard indicator from S3
6+
doc: Fetch a hazard indicator produced with os_climate_hazard
7+
requirements:
8+
ResourceRequirement:
9+
coresMax: 2
10+
ramMax: 4096
11+
12+
inputs:
13+
hazard_indicator_key:
14+
type: string
15+
default: ""
16+
aws_access_key_id:
17+
type: string
18+
default: ""
19+
aws_secret_access_key:
20+
type: string
21+
default: ""
22+
aws_session_token:
23+
type: string
24+
default: ""
25+
26+
outputs:
27+
- id: fetched-indicator
28+
type: Directory
29+
outputSource:
30+
- fetch-indicator-step/indicator-results
31+
32+
steps:
33+
fetch-indicator-step:
34+
run: "#fetch-indicator-command"
35+
in:
36+
hazard_indicator_key: hazard_indicator_key
37+
aws_access_key_id: aws_access_key_id
38+
aws_secret_access_key: aws_secret_access_key
39+
aws_session_token: aws_session_token
40+
out:
41+
- indicator-results
42+
43+
44+
- class: CommandLineTool
45+
id: fetch-indicator-command
46+
47+
hints:
48+
DockerRequirement:
49+
dockerPull: indicator-fetching:latest
50+
51+
requirements:
52+
ResourceRequirement:
53+
coresMax: 2
54+
ramMax: 4096
55+
NetworkAccess:
56+
networkAccess: true
57+
EnvVarRequirement:
58+
envDef:
59+
AWS_ACCESS_KEY_ID: $(inputs.aws_access_key_id)
60+
AWS_SECRET_ACCESS_KEY: $(inputs.aws_secret_access_key)
61+
AWS_SESSION_TOKEN: $(inputs.aws_session_token)
62+
AWS_DEFAULT_REGION: "eu-west-2"
63+
64+
inputs:
65+
hazard_indicator_key:
66+
type: string
67+
aws_access_key_id:
68+
type: string
69+
aws_secret_access_key:
70+
type: string
71+
aws_session_token:
72+
type: string
73+
74+
outputs:
75+
indicator-results:
76+
type: Directory
77+
outputBinding:
78+
glob: output
79+
80+
baseCommand: ["prepare-output.sh"]
81+
82+
arguments:
83+
- valueFrom: $(inputs.hazard_indicator_key)

json-to-command.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import json
2+
import sys
3+
4+
def main(input_path):
5+
with open(input_path, "r") as f:
6+
jase = json.load(f)
7+
print('"' + json.dumps(jase).replace('"', '\\"') + '"')
8+
9+
if __name__ == '__main__':
10+
main(sys.argv[1])

prepare-output.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
VALUE="$2"
4+
SRC_BUCKET="ukri-eodh-hazard-tiles-test"
5+
SRC_PATH="indicator-generation/$VALUE"
6+
DEST_DIR="output"
7+
8+
# Create output directory if it doesn't exist
9+
mkdir -p "$DEST_DIR"
10+
11+
# Sync data from S3
12+
aws s3 cp "s3://$SRC_BUCKET/$SRC_PATH/" "$DEST_DIR/" --recursive --exclude "*" \
13+
--include "cubified/*" \
14+
--include "days_tas_above_*.json" \
15+
--include "degree_days_*.json" \
16+
--include "collection.json"
17+
18+
echo "Files have been organized into '$DEST_DIR'."

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ dependencies = [
99
"stactools-osc-hazard",
1010
"typer>=0.15.2",
1111
"cf-xarray==0.9.4",
12-
"xarray==2023.1.0"
12+
"xarray==2023.1.0",
13+
"cwltool>=3.1.20250110105449",
1314
]
1415

1516
[tool.uv.sources]

0 commit comments

Comments
 (0)