summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple/nomads-cloud
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2020-04-21 21:50:59 +0200
committermakefu <github@syntax-fehler.de>2020-04-21 21:50:59 +0200
commitc96504d9a0f8f9f5c80c9630906c177ff3667e55 (patch)
tree7b763ca595967bfcc5d8307751091f373fd38e47 /krebs/5pkgs/simple/nomads-cloud
parent4fc2235ab0a8a11ea21965c86e5ba17279384db4 (diff)
parentcabaf519b5970cbe5c1e57832d3bd12da4f47371 (diff)
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'krebs/5pkgs/simple/nomads-cloud')
-rw-r--r--krebs/5pkgs/simple/nomads-cloud/default.nix43
1 files changed, 43 insertions, 0 deletions
diff --git a/krebs/5pkgs/simple/nomads-cloud/default.nix b/krebs/5pkgs/simple/nomads-cloud/default.nix
new file mode 100644
index 000000000..6e4ace484
--- /dev/null
+++ b/krebs/5pkgs/simple/nomads-cloud/default.nix
@@ -0,0 +1,43 @@
+{ writers, coreutils, grib2json, curl, jq, findutils, imagemagick }:
+writers.writeDashBin "nomads-cloud" ''
+ prefix=$(mktemp -d)
+ grib_path=$prefix.grib
+ json_path=$prefix.json
+ pgm_path=$prefix.pgm
+ png_path="$1"
+
+ mkdir -p "$prefix"
+
+ date=$(${coreutils}/bin/date +%Y%m%d)
+ for hour in 18 12 06 00; do
+ url="https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?file=gfs.t''${hour}z.pgrb2.0p25.anl&lev_entire_atmosphere_%5C%28considered_as_a_single_layer%5C%29=on&var_CWAT=on&leftlon=-180&rightlon=180&toplat=90&bottomlat=-90&dir=%2Fgfs.$date%2F$hour"
+ ${curl}/bin/curl -fsS "$url" > "$grib_path"
+ if [ "$?" -eq 0 ]; then
+ break
+ fi
+ done
+ ${grib2json}/bin/grib2json --data "$grib_path" > "$json_path"
+
+ width=$(${jq}/bin/jq '.[0].header.nx' < "$json_path")
+ height=$(${jq}/bin/jq '.[0].header.ny' < "$json_path")
+
+ # The maximum gray value. Must be bigger than 0 and less than 65536.
+ maxval=1000
+
+ # pgm - Netpbm grayscale image format
+ # http://netpbm.sourceforge.net/doc/pgm.html
+ {
+ echo P2
+ echo "$width $height"
+ echo "$maxval"
+ cat "$json_path" |
+ ${jq}/bin/jq --argjson maxval "$maxval" -c '
+ ((.[0].data[]) * $maxval | round)
+ ' |
+ ${findutils}/bin/xargs -n "$width"
+ } > "$pgm_path"
+
+ ${imagemagick}/bin/convert -roll +50% "$pgm_path" "$png_path"
+
+ rm -r "$prefix"
+''