
{"id":807,"date":"2008-02-01T02:39:00","date_gmt":"2008-02-01T02:39:00","guid":{"rendered":"https:\/\/www.starcoder.com\/wordpress\/?p=807"},"modified":"2026-05-09T02:50:52","modified_gmt":"2026-05-09T02:50:52","slug":"grib2-migration","status":"publish","type":"post","link":"https:\/\/www.starcoder.com\/wordpress\/2008\/02\/grib2-migration\/","title":{"rendered":"GRIB2 Migration"},"content":{"rendered":"\n<p>A few days ago I started having a problem with the previous GFS forecast data source I was using for Seasonality forecasts. Just as a bit of background, Seasonality will download forecasts for U.S. locations from the NWS&#8217;s&nbsp;<a href=\"http:\/\/www.weather.gov\/ndfd\/\">NDFD<\/a>&nbsp;service. For locations outside the U.S., I have to get the data from somewhere else, and the best data source I&#8217;ve been able to find is 0.5 degree GFS model output, also available from the NWS. Because the GFS model data is in GRIB format and&nbsp;<em>very<\/em>&nbsp;large, I first download it to a &#8220;forecast&#8221; server that I host, and throw it all into a database. Then Seasonality will contact my forecast server to get the forecast for its configured locations.<\/p>\n\n\n\n<p>With the old GFS data source offline, I had to find a new one. I came across a production server at NCEP that hosted 0.5 degree GFS model output, but the data was in GRIB2 format, which presented a problem because up until this point, all of my forecast data was in GRIB (or GRIB1) format.<\/p>\n\n\n\n<p>Fortunately, there were very few modifications because of the format change, but there are some adjustments that needed to be made. I am using the\u00a0<a href=\"http:\/\/www.cpc.ncep.noaa.gov\/products\/wesley\/wgrib.html\">wgrib<\/a>\u00a0and\u00a0<a href=\"http:\/\/www.cpc.ncep.noaa.gov\/products\/wesley\/wgrib2\/\">wgrib2<\/a>\u00a0tools to convert the GRIB data to ASCII format first, so it&#8217;s easier to parse when importing it into the database. With wgrib, I would use a command like this to convert the data to ASCII:<\/p>\n\n\n\n<p><code>wgrib -s &lt;grib_file> | egrep \\\":&lt;variable>:&lt;level>\\\" | wgrib -i -grib &lt;grib_file> -text -o &lt;txt_file><\/code><\/p>\n\n\n\n<p>The authors of wgrib2 changed things a bit, and actually made the command a little bit easier:<\/p>\n\n\n\n<p><code>wgrib2 -s &lt;grib_file> | egrep \\\":&lt;variable>:&lt;level>\\\" | wgrib2 -i &lt;grib_file> -text &lt;txt_file><\/code><\/p>\n\n\n\n<p>The first two commands in the string don&#8217;t change at all, but the third one does. The -grib and -o flags are no longer needed. wgrib2 assumes that the input file is in GRIB2 format, and if you specify -text, the next argument is assumed to be the output file. The problem was that my output data wasn&#8217;t right. For some reason, my forecasts were just all screwed up, even though the ASCII files themselves looked okay. I ended up finding\u00a0<a href=\"http:\/\/www.cpc.ncep.noaa.gov\/products\/wesley\/wgrib2\/text.html\">some documentation<\/a>\u00a0on the -text flag, and it seems that the default output order has been changed from the original North->South to South->North, so all of my data was being inverted. This was somewhat problematic, since I don&#8217;t really want to return a forecast for the southern hemisphere when someone asks for a location in the northern hemisphere. The fix is fairly simple, just pass -order raw to the wgrib2 command&#8230;<\/p>\n\n\n\n<p><code>wgrib2 -s &lt;grib_file> | egrep \\\":&lt;variable>:&lt;level>\\\" | wgrib2 -i &lt;grib_file> -order raw -text &lt;txt_file><\/code><\/p>\n\n\n\n<p>In general, it looks like most of the NWS datasets will&nbsp;<a href=\"http:\/\/www.nco.ncep.noaa.gov\/pmb\/docs\/GRIB1_to_GRIB2.shtml\">only be available in GRIB2<\/a>&nbsp;in the near future, so I hope this information saves other wgrib users some time when doing their own GRIB -&gt; GRIB2 migrations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago I started having a problem with the previous GFS forecast data source I was using for Seasonality forecasts. Just as a bit of background, Seasonality will download forecasts for U.S. locations from the NWS&#8217;s&nbsp;NDFD&nbsp;service. For locations outside the U.S., I have to get the data from somewhere else, and the best [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-807","post","type-post","status-publish","format-standard","hentry","category-uncategorized","post-preview"],"_links":{"self":[{"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/posts\/807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/comments?post=807"}],"version-history":[{"count":1,"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/posts\/807\/revisions"}],"predecessor-version":[{"id":808,"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/posts\/807\/revisions\/808"}],"wp:attachment":[{"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/media?parent=807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/categories?post=807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.starcoder.com\/wordpress\/wp-json\/wp\/v2\/tags?post=807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}