Skip to content

Commit

Permalink
Merge pull request #179 from nismod/fix/storm-fixed-global
Browse files Browse the repository at this point in the history
Fix/storm fixed global
  • Loading branch information
tomalrussell authored Apr 5, 2024
2 parents c9ea5c0 + 07c58a5 commit 88dc522
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://data.4tu.nl/ndownloader/files/35110321
https://data.4tu.nl/file/504c838e-2bd8-4d61-85a1-d495bdc560c3/2a3759e8-f4ad-4190-abb3-434ad5c4679b
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://data.4tu.nl/ndownloader/files/35110318
https://data.4tu.nl/file/504c838e-2bd8-4d61-85a1-d495bdc560c3/c460a0c8-f918-4ede-a734-75e77e99b102
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://data.4tu.nl/ndownloader/files/35110312
https://data.4tu.nl/file/504c838e-2bd8-4d61-85a1-d495bdc560c3/304d1441-bd71-47c7-8231-b20253c1cc2a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://data.4tu.nl/ndownloader/files/35110309
https://data.4tu.nl/file/504c838e-2bd8-4d61-85a1-d495bdc560c3/856f9530-56d7-489e-8005-18ae36db4804
2 changes: 1 addition & 1 deletion config/hazard_resource_locations/storm_fixed_constant.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://data.4tu.nl/ndownloader/files/35423735
https://data.4tu.nl/file/0ea98bdd-5772-4da8-ae97-99735e891aff/0b98c6f5-c7af-45bb-bb6e-dac53e1b8d55
46 changes: 38 additions & 8 deletions workflow/tropical-cyclone/STORM.smk
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,19 @@ rule extract_storm_fixed_future:
STORM_MODEL_UPPER = lambda wildcards: wildcards.STORM_MODEL_FUTURE.upper()
shell:
"""
# first try STORM_MODEL_FUTURE, otherwise fall back to trying the uppercase version
unzip -o {input} STORM_FIXED_RETURN_PERIODS_{wildcards.STORM_MODEL_FUTURE}_{wildcards.STORM_BASIN}_{wildcards.STORM_RP}_YR_RP.tif \
-d {wildcards.OUTPUT_DIR}/input/STORM/fixed/{wildcards.STORM_MODEL_FUTURE}/{wildcards.STORM_BASIN}/ \
|| \
unzip -o {input} STORM_FIXED_RETURN_PERIODS_{params.STORM_MODEL_UPPER}_{wildcards.STORM_BASIN}_{wildcards.STORM_RP}_YR_RP.tif \
-d {wildcards.OUTPUT_DIR}/input/STORM/fixed/{wildcards.STORM_MODEL_FUTURE}/{wildcards.STORM_BASIN}/ \
unpack_dir="{wildcards.OUTPUT_DIR}/input/STORM/fixed/{wildcards.STORM_MODEL_FUTURE}/{wildcards.STORM_BASIN}/"
uppercase_filename="STORM_FIXED_RETURN_PERIODS_{params.STORM_MODEL_UPPER}_{wildcards.STORM_BASIN}_{wildcards.STORM_RP}_YR_RP.tif"
desired_filename="STORM_FIXED_RETURN_PERIODS_{wildcards.STORM_MODEL_FUTURE}_{wildcards.STORM_BASIN}_{wildcards.STORM_RP}_YR_RP.tif"
# try extracting filename with STORM_MODEL_FUTURE, fall back to STORM_MODEL_UPPER
unzip -o {input} $desired_filename -d $unpack_dir || unzip -o {input} $uppercase_filename -d $unpack_dir
# if we unpacked the uppercase version and its different to STORM_MODEL_FUTURE, rename it
pushd $unpack_dir
if [ -f $uppercase_filename ] && [ $uppercase_filename != $desired_filename ]; then
mv $uppercase_filename $desired_filename
fi
popd
"""


Expand All @@ -195,7 +202,7 @@ rule wrap_storm_fixed:
temp("{OUTPUT_DIR}/input/STORM/fixed/{STORM_MODEL}/{STORM_BASIN}/STORM_FIXED_RETURN_PERIODS_{STORM_MODEL}_{STORM_BASIN}_{STORM_RP}_YR_RP.wrapped.tif")
shell:
"""
gdalwarp -te -180 -60 180 60 {input} {output}
gdalwarp -te -179.85 -60.15 180.15 59.95 -co COMPRESS=LZW -co PREDICTOR=2 -co TILED=YES {input} {output}
"""


Expand Down Expand Up @@ -223,5 +230,28 @@ rule mosaic_storm_fixed:
-F {input.basin_tif_wp} \
--outfile={output} \
--calc="numpy.max((A,B,C,D,E,F),axis=0)" \
--NoDataValue=0
--NoDataValue=0 \
--creation-option="COMPRESS=LZW" \
--creation-option="PREDICTOR=2" \
--creation-option="TILED=YES"
"""

rule mosaic_storm_fixed_all:
input:
tiffs=expand(
"{{OUTPUT_DIR}}/input/STORM/fixed/{STORM_MODEL}/STORM_FIXED_RETURN_PERIODS_{STORM_MODEL}_{STORM_RP}_YR_RP.tif",
STORM_MODEL=[
"constant",
"CMCC-CM2-VHR4",
"CNRM-CM6-1-HR",
"EC-Earth3P-HR",
"HadGEM3-GC31-HM",
],
STORM_RP=(
list(range(10, 100, 10))
+ list(range(100, 1000, 100))
+ list(range(1000, 10001, 1000))
),
)
output:
touch("{OUTPUT_DIR}/input/STORM/fixed/mosaic.done")

0 comments on commit 88dc522

Please sign in to comment.