Automated Weather Model Processing With FOSS4G: Lessons Learned - by Thomas Horner - The Startup - Medium
Automated Weather Model Processing With FOSS4G: Lessons Learned - by Thomas Horner - The Startup - Medium
!"7&'7&'9#:)'!"#$';)++'$+$<+)=#*-9'&>#)9'>"7&'$#*>"?
@7A*':B';#)'C+87:$'%*8'A+>'%*'+D>)%'#*+
!"#$%&#'()*'&#+',)-$('.
/,$0'11234)*2#+)567789:
;'11$31);'&,3'(
!"#$%&'(#)*+) ,#--#.
/#0'12'3451'·'56'$7*')+%8
!"+'/EF,@'.+%>"+)'$#8+-2')+*8+)+8'<9'C%B@+)0+)'%*8'G#*&:$+8'%&'%'HC@'-%9+)'7*
I+%;-+>?
!"#$"%#&
The National Oceanic and Atmospheric Administration of the
U.S. Department of Commerce is responsible for creating and
freely distributing a large number of weather models on the
web. These weather models range from older, low resolution
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 2 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 3 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
!"+'A-#)7#:&'/JFK'&:B+)G#$B:>+)&'LB"#>#'G)+87>M'/JFKN?'!"+'&%;+>9'G#*+&'B)+&:$%<-9
<##&>'G-#GO'&B++8&'<9'%';+.'C(P?
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 4 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
'(%)*+,-#+./,/
Q7&:%-7P7*A'>"+'&B)+%8'L:*G+)>%7*>9N'#;'%'.+%>"+)'$#8+-'7*'J"%)>?R&?
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 5 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
E*'+DG+)B>'#;%&'"!()*+%#:>B:>';#)'%'A)7<3';7-+';)#$'>"+'/EC'$#8+-?
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 6 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
For the most part, GDAL is able to identify what parameter and
level each band pertains to, if you’re able to sift through the
distracting amount of metadata to get to it. The Ile can then be
converted to a standard geospatial raster Ile format, such as
GeoTIFF, with a standardized projection like EPSG:4326.
(Note: For parameters dependent on rastercell orientation, like
wind vectors in some models, you need to be aware of how this
reprojection impacts the data!). The GeoTIFF has an identical
number of bands matching those in the GRIB2.
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 7 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
01,$/2,%)*+,-#+3%*-,+./,/
Before we can really dig into the technical architecture, we
need to know how to get the desired data in the Irst place. This
was the more diecult issue as mentioned previously.
S;'9#:'&>%)>'8707*A'7*>#'>"+'$#8+-&2'9#:T--'<+'>)+%>+8'>#'>"+'B7**%G-+'#;'14&'.+<'8+&7A*2
G#$B-+>+'.7>"'<)#O+*'-7*O&?'F0+*'%'&#-78'<%GOA)#:*8'7*'$+>+#)#-#A9'.#*>'"+-B'9#:'8+G7B"+)
&#$+'#;'>"+'%G)#*9$&'#*'>"+'-+;>?
…If only. There are two major problems, the Irst being that
NCEP doesn’t provide inventories for a large number of its
models, and even if they do they are likely out-of-date or
inaccurate. This can be circumvented by looking at the
metadata itself, such as with gdalinfo, from which the correct
band number can usually be gleaned — as long as the desired
data doesn’t have screwed up metadata.
U#--7*A'#:)'#.*')%&>+)&':&7*A'>"+'#&A+#VA8%-'B%GO%A+';#)'B9>"#*?
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 10 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
S':&+8'%'W@X/';7-+'>#'B)#078+'>"+'0%)7%<-+'%*8'-+0+-';#)'+%G"'#:>B:>'<%*8'S'.%*>+8?
This assumes you are downloading one full raster per forecast
hour. There are ways to make things even easier, such as using
.idx Iles (for some models) to directly download just the bands
you want, or use NCEP’s gribIlter web application to do
basically the same thing. I will cover both of these in a bit.
There’s also the chance that some models (the SREF comes to
mind) provide every single forecast hour, variable, and level in
one monolithic grib2 Ile. Good luck with that!
.4&)54/6%)*+,-#+./,/
With a strategy in place for at least getting data out of GRIB2
Iles, it’s time to obtain them from the web. NCEP is responsible
for coordinating and centralizing the distribution of weather
models, no matter which center manages it. All models are
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 11 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 12 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
!"+)+'7&'*#'&"#)>%A+'#;'7$B+*+>)%<-+2'87PP97*A'%G)#*9$&?
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 13 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
https://www.ftp.ncep.noaa.gov/data/nccf/com/gens/prod/gefs.
%D/%H/pgrb2ap5/gespr.t%Hz.pgrb2a.0p50.f%T
https://www.ftp.ncep.noaa.gov/data/nccf/com/naefs/prod/nae
fs.%D/%H/ndgd_gb2/naefs.t%Hz.geavg.f%T.conus_ext_2p5.gri
b2
https://ftp.wpc.ncep.noaa.gov/pwpf/conus_2.5km/2.5kmpwpf_
12hr/2.5kmprcntil_12hsnow_50pt_%D%Hf0%T.grb
Note that despite the three dijerent Ile extensions, all of the
above products are GRIB2 Iles. Also, if you look carefully, you
can see that the WPC is alone from the other NOAA centers in
that their GRIB2 Iles come oj of their own servers and not on
NOMADS. Go a directory up and you’ll Ind yourself in a
magical land of old powerpoints, temporary folders, and
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 14 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
employee dropboxes.
75%88%)*+%,+.4&)
Anyways, remember how NOMADS serves Ive terabytes of
data per month? (Likely more these days!) It’s unlikely you’ll
encounter any issues when downloading low resolution rasters
with low band counts, but the Hagship high resolution models
present a big problem — for example, each forecast hour of the
3km NAM NEST is over a gigabyte in size, and there are sixty
forecast hours per model run, four of which are available per
day. This requires a couple hundred gigabytes of data transfer if
you’re accessing these daily. NCEP’s download speeds leave
much to be desired, to the point that the next NAM-NEST run
will almost be starting before the last one has even been
downloaded.
If that wasn’t enough, the servers are cranky and will often just
stop sending data, especially with large downloads. This often
occurs without the connection being closed, which means you
need to account for that in your scripts lest they hang forever,
waiting for data that will never come. Be wary of writing loops
and other highly-structured logic for retrieving this data, as it is
prone to failure.
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 15 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
NCEP is aware of this and thus has made .idx Iles available for
many of the more bloated models. These Iles contain byte
ranges for each band, including the variable name and level.
Remember the issues above with pulling those variables and
levels out of the GRIB2 Iles and making sure they are written
in the correct order? The .idx Ile can not only make your
downloads far more reasonable in size, but address the
uncertainty with the Inal order of bands in the raster.
FDG+)B>'#;'%*'?78D';7-+?
9$%:;%5,#$
Finally, it should be mentioned that NCEP has a web-based
utility called grib_Vlter available for most models, which lets
you clip to an extent and download only speciIc variables and
levels. The URL is programmatic which allows you to automate
the download of various models and forecast hours via the
application. However, after extensive use I was less than
enthused with its purported utility. Grib_Vlter tends to be slow
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 17 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
and a little buggy — not all variables are available for some
models, or some levels are just “empty”. Most importantly, it is
not possible to be speciIc enough unless you want just one
band. Levels and variables are independent, so if you want
“geopotential height at 850mb” and “temperature at 2m” you’ll
get those in addition to “temperature at 850mb” and
“geopotential height at 2m.”
/JFK'7&'G+)>%7*-9'*#>'.%&>7*A'>%D'8#--%)&'#*'&7--9'>"7*A&'-7O+'B-+%&%*>'YSVYZ?
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 18 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
<#"#$/*%)*+,-#+./,/
The above information should hopefully provide enough
guidance for the savvy scripter to write an automated means of
acquiring weather model data on a regular basis, without too
many issues. The next question is: What is the best way to
distribute the data? If you have a raster, you should know what
you can do with it — visualize it as a layer in GIS applications
or web maps via WMS, distribute in its raw form as a WCS,
query it on the server, etc. Things get a little more tricky since
we’re likely dealing with hundreds of rasters.
E'>9B7G%-'&G+*+'."+*'#B+*7*A'%'[US\3';7-+'7*'][S@?'\9'8+;%:->2'>"+';7)&>'>")++'<%*8&'%)+
>)+%>+8'%&'U[\'G#$B#*+*>&2'."7G"'-##O&'7*>+)+&>7*A^
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 19 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
Do I cram all the variables into one raster per forecast hour?
Do I cram all the forecast hours into one raster per variable?
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 20 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
=4(,9>7
But that’s not very mature, is it? A sprawling directory of
GeoTIFF Iles doesn’t sound very web scale now does it? The
“enterprise” choice was of course to host them in a Postgres
PostGIS database, which can store rasters directly in a table
column. Sure, leisurely loading these Iles into the database
slowed down automated model processing drastically. And
sure, the sheer number of timestamps, bands, variables, and
other attributes that were needed for querying resulted in non-
standard table schemas that dijered from typical
implementations in MapServer and GeoServer. That was Ine.
All I had to do was write a convoluted, ill-advised query in my
mapIle to actually get the data back out of PostGIS. It only took
the help of the MapServer listserv community, a fresh page of
documentation, and couple stij drinks to pull that one oj.
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 21 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
9#4?>@@+=#$;4$8/)2#
That said, performance with a GeoTIFF library still wasn’t that
great. For instance, I had an endpoint that would return the
surface temperature from a certain model from forecast hour
zero to forecast hour 60. The initial architecture of one raster
per forecast hour (with a bunch of bands pertaining to each
variable) meant that 61 raster Iles would need to be opened
and queried to return the list of results. Even if the rasters were
cropped to a small geographic area, and contained a sensible
number of bands, this would take 5–10 seconds under average
conditions for my server. If I wanted to compare those
temperatures against the same forecast hours from other
models, the client would just sit there for an unbearable
amount of time, waiting for everything to Inish processing.
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 22 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
\)7*A7*A'7>'#*'"#$+'_'E*'7*>+)%G>70+2'`:+)9%<-+'.+<'$%B'<:7->'7*'E*A:-%)'>"%>'G%*'07&:%-7P+
$#8+-'):*&'%&'&##*'%&'>"+9'%)+'%0%7-%<-+?'L/#>+M'W:&>'%'.#)O'7*'B)#A)+&&?N
745A,%4)%)*
The simplistic end result of all these painful iterations
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 23 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 24 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
B4)25A(%4)
I hope this gave you some ideas on how to leverage the wealth
of weather model data that is available. I believe that we
haven’t seen anywhere close to the full potential of what can be
done with that data, and I have no doubt that some powerful
new ideas will come out of the FOSS4G sphere. We’ve seen
smart, talented developers come out with wonderful weather
data tools like SHARPpy and Earth Wind Map. What’s next?
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 25 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
E*':*;7*7&"+8'>7$+';#)+G%&>7*A'B)#8:G>'<:7->'7*'E*A:-%)?'!"+'G%-G:-%>7#*&'%*8'07&:%-7P%>7#*&
%)+'B+);#)$+8'+*>7)+-9'#*'>"+'G-7+*>'&78+'<9'.+7A"7*A'0%)7#:&'$#8+-&'%*8'+*&+$<-+&'<%&+8
#*'>"+7)'&:7>%<7-7>9';#)'&B+G7;7G'>7$+')%*A+&'%*8'G#*87>7#*&?
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 26 de 27
Automated Weather Model Processing With FOSS4G: Lessons Learned | by Thomas Horner | The Startup | Medium 17/02/2021 14:18
https://medium.com/swlh/automated-weather-model-processing-with-foss4g-lessons-learned-8aaaeda1e3bc Página 27 de 27