Skip Navigation Links www.nws.noaa.gov 
NOAA logo - Click to go to the NOAA home page National Weather Service   NWS logo - Click to go to the NWS home page
Climate Prediction Center
 
 

 
About Us
   Our Mission
   Who We Are

Contact Us
   CPC Information
   CPC Web Team

 
HOME > Monitoring_and_Data > Oceanic and Atmospheric Data > Reanalysis: Atmospheric Data > wgrib2-csv
 

wgrib2: -csv (comma separated values)

Introduction

The -csv option writes the grid values to a specified file as a comma separated values (text) which can be imported into a spread sheet. This function is similar to -spread and -csv_long with a different output format.

   "time0","time1","field","level",longitude,latitude,grid-value

For an analysis that is valid at a specific time, time0 and time1 will have the same value. For a temporal average or accumulation of analyses, time0 will be the start and time1 will be end of the average or accumulation.

For a forecast, time0 will be the start of the forecast (i.e, date of the initial conditions). For a forecast for a specific time, then time1 will be time that the forecast is valid. For a forecast of a temporal average or accumulation, time1 wll be the end of the average or accumulation.

In grib speak, time0 is the reference time and time1 is the verification time. Here are some examples,

1:0:d=2009062900:TMP:surface:anl:     (default inventory)

   This an analysis (anl) of the surface temperature.
   This analysis is valid for 2009062900.
   Time0 = 2009062900    Time1 = 2009062900
   field=TMP             level=surface

29:1155322:d=2009060500:UGRD:925 mb:180 hour fcst:ENS+19     (default inventory)
   This is a 180 hour forecast of the 925 hPa zonal wind.
   The forecast run uses initial conditions at 2009060500
   and verifies 180 hours laster at 2009061212.  
   Time0 = 2009060500    Time1 = 2009060500
   field=UGRD            level = 925 mb

43:1844451:d=2009060500:APCP:surface:174-180 hour acc fcst:ENS=+19     (default inventory)
   This is a forecast of accumulated precipitation from 174 to 180 hours.
   The forecast run uses initial conditions at 2009060500 and 
   accumulates the precip from 2009061206 to 2009061212.  The
   verification time is defined as the end of the accumulation period
   Time0 = 2009060500    Time1 = 2009060500
   field= APCP           level= surface

The -csv option only works on the grids for which wgrib2 can derive latitude and longitudes values. Otherwise no output is generated. The undefined value is 9.999e20.

The size of a CSV file can be overwhelming. One technique is to only generate the CSV for variables that you need. This can be done with the -match option. Even with the -match option, the high-resolution models can stil generate huge files. The next technique is to undefine the grid points that you don't want. For example, you are only interested in Hawaii (its 0C outside as I write this). Then you can use the the -undefine option to set the grid points outside of the Hawaii domain to undefined. Since -csv doesn't print undefined grid points, the CSV files is much smaller.

Extended Variable Names

The default field value (see above) is the grib name such as TMP or HGT. However, the grib name may not be unique. For example, the field could be the HGT from the 19th ensemble member. A better field name may be "HGT.ENS=+19". You enable the extended variable name by adding the option -set_ext_name 1.

Usage

-csv output_file_name
   the field is the grib name
   output_file_name cannot be a memory file
-set_ext_name 1 -csv output_file_name
   the field is the extended grib name
   output_file_name cannot be a memory file

Example

$ wgrib2 fcst.grb2 -csv junk 
1:0:d=2007032600:HGT:1000 mb:anl:
2:125535:d=2007032600:HGT:1000 mb:3 hour fcst:
$ cat junk 
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",0,-90,164.1
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",0.5,-90,164.1
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",1,-90,164.1
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",1.5,-90,164.1
...
"2007-03-26 00:00:00","2007-03-26 03:00:00","HGT","1000 mb",-1.5,90,-91.7
"2007-03-26 00:00:00","2007-03-26 03:00:00","HGT","1000 mb",-1,90,-91.7
"2007-03-26 00:00:00","2007-03-26 03:00:00","HGT","1000 mb",-0.5,90,-91.7

Warning

The options -csv, -csv_long, -spread and -text do not support memory files. You can blame sloth or lack of need. I like to think that text files with grid point values are are insanely large and shouldn't be saved in memory.

See also: -spread, -csv_long, -text, -bin, -ieee, -set_ext_name, -undefine


NOAA/ National Weather Service
National Centers for Environmental Prediction
Climate Prediction Center
5830 University Research Court
College Park, Maryland 20740
Climate Prediction Center Web Team
Page last modified: Nov 19, 2015
Disclaimer Privacy Policy