2020-03-23 08:55:58 +00:00
|
|
|
{ writers, coreutils, grib2json, curl, jq, findutils, imagemagick }:
|
|
|
|
writers.writeDashBin "nomads-cloud" ''
|
|
|
|
prefix=$(mktemp -d)
|
2021-10-24 18:17:32 +00:00
|
|
|
grib_path=$prefix/clouds.grib
|
|
|
|
json_path=$prefix/clouds.json
|
|
|
|
pgm_path=$prefix/clouds.pgm
|
|
|
|
png_path=$1
|
2020-03-23 08:55:58 +00:00
|
|
|
|
|
|
|
mkdir -p "$prefix"
|
|
|
|
|
|
|
|
date=$(${coreutils}/bin/date +%Y%m%d)
|
|
|
|
for hour in 18 12 06 00; do
|
2021-04-27 19:43:18 +00:00
|
|
|
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}%2Fatmos"
|
|
|
|
echo "$url"
|
2020-03-23 08:55:58 +00:00
|
|
|
${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.
|
2020-03-23 17:47:23 +00:00
|
|
|
maxval=1000
|
2020-03-23 08:55:58 +00:00
|
|
|
|
|
|
|
# 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 '
|
2020-03-23 19:28:29 +00:00
|
|
|
((.[0].data[]) * $maxval | round)
|
2020-03-23 08:55:58 +00:00
|
|
|
' |
|
|
|
|
${findutils}/bin/xargs -n "$width"
|
|
|
|
} > "$pgm_path"
|
|
|
|
|
|
|
|
${imagemagick}/bin/convert -roll +50% "$pgm_path" "$png_path"
|
|
|
|
|
|
|
|
rm -r "$prefix"
|
|
|
|
''
|