-
Notifications
You must be signed in to change notification settings - Fork 0
/
getAWSgefsv12_unifiedOutputFranges.sh
executable file
·118 lines (97 loc) · 3.8 KB
/
getAWSgefsv12_unifiedOutputFranges.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Shell script to dowload GEFSv12 from AWS
# https://noaa-gefs-retrospective.s3.amazonaws.com/index.html
# Only 10m wind components (10u and 10v)
# two arguments: year and output-path
# examples:
# ./getAWSgefsv12.sh 2000 /home/name/Downloads
# nohup ./getAWSgefsv12.sh 2000 /home/name/Downloads >> nohupout_getAWSgefsv12_2000.txt 2>&1 &
year=$1
dpath=$2
module load intel/2021.2 cdo/1.9.8 nco
cd $dpath
SERVER="http://noaa-gefs-retrospective.s3.amazonaws.com/GEFSv12/reforecast"
# variables
vars=(u v)
# float array resolution (decimals)
dp=3
for month in `seq 1 12`; do
for day in `seq 1 31`; do
date=$year`printf %2.2d $month``printf %2.2d $day`
# forecast range
wday=$(date -d "$year-`printf %2.2d $month`-`printf %2.2d $day`" +%u)
if [ "$wday" -eq 3 ]; then
frg=(1-10 10-35)
else
frg=(1-10 10-16)
fi
for em in `seq 0 10`; do
if [ ${em} -eq 0 ]; then
# Control Member
sem="c00"
else
# Ensemble Members
sem="p`printf %2.2d $em`"
fi
# two slices of forecast ranges
for fg in ${frg[*]}; do
# variables U and V
for var in ${vars[*]}; do
fname=${var}"grd_hgt_"${date}"00_"${sem}
wget --no-check-certificate --no-proxy -l1 -H -t1 -nd -N -np -erobots=off --tries=3 ${SERVER}/${year}/${date}"00/"${sem}"/Days:"${fg}"/"${fname}".grib2" &&
sleep 1
test -f ${var}"grd_hgt_"${date}"00_"${sem}".grib2" &&
TE=$?
if [ "$TE" -eq 0 ]; then
# convert from grib2 to netcdf
cdo -f nc copy ${fname}".grib2" ${fname}".aux1.nc" &&
# remove wind at 100m
ncks -x -v 100${var} ${fname}".aux1.nc" ${fname}".aux2.nc" &&
ncpdq -O -a -lat ${fname}".aux2.nc" ${fname}".D"${fg}".nc" &&
sleep 1
rm *.aux*.nc
rm ${fname}".grib2"
fi
done
# join u v into a singe netcdf file
test -f ${vars[0]}"grd_hgt_"${date}"00_"${sem}".D"${fg}".nc"
TE=$?
if [ "$TE" -eq 0 ]; then
test -f ${vars[1]}"grd_hgt_"${date}"00_"${sem}".D"${fg}".nc"
TE=$?
if [ "$TE" -eq 0 ]; then
rname="wnd10m_"${date}"00_"${sem}".D"${fg}
cp ${vars[0]}"grd_hgt_"${date}"00_"${sem}".D"${fg}".nc" ${rname}".nc"
ncks -A ${vars[1]}"grd_hgt_"${date}"00_"${sem}".D"${fg}".nc" ${rname}".nc" &&
sleep 1
rm ${vars[0]}"grd_hgt_"${date}"00_"${sem}".D"${fg}".nc"
rm ${vars[1]}"grd_hgt_"${date}"00_"${sem}".D"${fg}".nc"
fi
fi
done
# Interpolate second segment (forecast lead time 10 to 16) to the same resolution as 1 to 10
# and append to form a single file 1 to 16 days
test -f "wnd10m_"${date}"00_"${sem}".D"${frg[1]}".nc"
TE=$?
if [ "$TE" -eq 0 ]; then
# Interpolation
cdo remapbil,r1440x721 "wnd10m_"${date}"00_"${sem}".D"${frg[1]}".nc" "wnd10m_"${date}"00_"${sem}".D"${frg[1]}".aux.nc" &&
# Append
rm "wnd10m_"${date}"00_"${sem}".D"${frg[1]}".nc"
ncrcat "wnd10m_"${date}"00_"${sem}".D"${frg[0]}".nc" "wnd10m_"${date}"00_"${sem}".D"${frg[1]}".aux.nc" "wnd10m_"${date}"00_"${sem}".nc" &&
rm "wnd10m_"${date}"00_"${sem}".D"${frg[0]}".nc"
# reduce size
ncks -4 -L 1 "wnd10m_"${date}"00_"${sem}".nc" "wnd10m_"${date}"00_"${sem}".aux1.nc" &&
rm "wnd10m_"${date}"00_"${sem}".nc"
ncks --ppc default=.$dp "wnd10m_"${date}"00_"${sem}".aux1.nc" "wnd10m_"${date}"00_"${sem}".nc" &&
sleep 1
rm *.aux*.nc
chmod +775 "wnd10m_"${date}"00_"${sem}".nc"
fi
done
echo " Ok "${date}
done
done
# remove empty files (errors)
find -empty -type f -delete
echo "Download GEFSv12 AWS wind (U10,V10) for "$year" is complete, at "$dpath