Re: GRIB to netCDF

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 09 2012 - 14:41:27 MDT

OK, sorry I should have told you to print grib_in[0] (which will give you the contents of the first file) rather than grib_in (which only gives an abbreviated summary of each file in the file list).
You are correct that the variable you should use is initial_time0_hours.
If you look at the contents of the first file, you will probably see that now that there is a dimension for the initial_time, the number associated with the subsequent dimensions has been increased by 1. In other words, g0_lat_0 is now g0_lat_1, g0_lon_1 is now g0_lon_2, etc.
 -dave

On Apr 9, 2012, at 2:24 PM, Guo Zhang wrote:

> Sorry, I still can't figure it out.
>
> gribfil = systemfunc("ls *.grb")
> setfileoption("grb","SingleElementDimensions","Initial_time")
> grib_in = addfiles(gribfil, "r")
> print(grib_in) ; file overview
> ; print(gribfil(0))
> TIME = grib_in[:]->initial_time_0 ; time as "hours since"
> lat = grib_in[:]->g0_lat_0 ; latitude
> lon = grib_in[:]->g0_lon_1 ; longitude
>
> fatal:No valid instance of variable initial_time_0 found in file list
>
> If I change initial_time_0 to TIME = grib_in->initial_time0_hours, I got this error:
> fatal:No valid instance of variable g0_lat_0 found in file list
>
> By the way, I got a lot of these warning every time, 'warning:NclGRIB: Unknown grib parameter number detected (155, center 221, table version 1 grib record 5), using default variable name (VAR_155)'. I don't know what's going on here and whether it would affect the results. Thanks.
>
> Guo
>
> Variable: grib_in
> Type: list
> Total items: 8
> List Item 0: NclFileVarClass
> Variable: unnamed
> Type: file
> File path: GLDAS_NOAH025SUBP_3H.A2008001.0000.001.2008197115712.grb
> Number of global attributes: 0
> Number of dimensions: 5
> Number of variables: 32
> List Item 1: NclFileVarClass
> Variable: unnamed
> Type: file
> File path: GLDAS_NOAH025SUBP_3H.A2008001.0300.001.2008197115712.grb
> Number of global attributes: 0
> Number of dimensions: 5
> Number of variables: 32
>
>
> From: David Brown <dbrown@ucar.edu>
> To: Guo Zhang <wswzg6666@yahoo.com.cn>
> Cc: "ncl-talk@ucar.edu" <ncl-talk@ucar.edu>
> Sent: Monday, April 9, 2012 1:13 PM
> Subject: Re: GRIB to netCDF
>
> Since (presumably) each file has only one time step a time dimension is not created by default. Instead the time is attached to the variable as an attribute. You can get NCL to create an initial time dimension using the setfileoption "SingleElementDimensions". Try putting this before your addfiles call:
>
> setfileoption("grb","SingleElementDimensions","Initial_time")
>
> Be sure to look at the contents of the the aggregated file by uncommenting your "print(grib_in)" statement. The name of the time coordinate variable will be inital_time_x, where x is a number.
> -dave
>
>
>
> On Apr 9, 2012, at 12:47 PM, Guo Zhang wrote:
>
>> Hi,
>>
>> I have 3-hourly grib files and want to extract variables from these files.
>> I use the example efficient GRIB to nc: http://www.ncl.ucar.edu/Applications/gribeff.shtml. But I cannot figure out how to assign time attribute. 'fatal:No valid instance of variable initial_time found in file list'.
>>
>> Please see my script and data information below. Also can access my some data and script via bluefire: /glade/home/zhangg/gld/nc.ncl GLDAS*.grb. Thanks.
>>
>> -Guo Zhang
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> ;************************************************
>> undef("rdVar4D")
>> function rdVar4D (f:file, vName:string, time:integer)
>> ; read GRIB 4D variable and assign new dimension names
>> begin
>> var = f->$vName$; read variable
>> var!0 = "time" ; assign 'conventional' dimension names
>> var!1 = "lat"
>> var!2 = "lon"
>> var&time = time ; assign time coord variable
>> return(var)
>> end
>> begin
>> ;***********************************************
>> ; read in data from GRIB file
>> ;***********************************************
>> gribfil = systemfunc("ls *.grb")
>> grib_in = addfiles(gribfil, "r")
>> ; print(grib_in) ; file overview
>> ; print(gribfil(0))
>> TIME = grib_in[:]->initial_time ; time as "hours since"
>> lat = grib_in[:]->g0_lat_0 ; latitude
>> lon = grib_in[:]->g0_lon_1 ; longitude
>> lat!0 = "lat" ; assign new dimension name
>> lon!0 = "lon"
>> TIME!0= "time"
>>
>> time = cd_calendar(TIME, -3) ; change to date syntax
>> time!0= "time"
>> time@units = "yyyymmddhh"
>> snowf = rdVar4D (grib_in, "VAR_131_GDS0_SFC" ,time)
>> rainf = rdVar4D (grib_in, "VAR_132_GDS0_SFC" ,time)
>> ....
>>
>>
>>
>>
>> file global attributes:
>> dimensions:
>> g0_lat_0 = 600
>> g0_lon_1 = 1440
>> lv_DBLY2 = 4
>> variables:
>> float PRES_GDS0_SFC ( g0_lat_0, g0_lon_1 )
>> center : Zagreb
>> long_name : Pressure
>> units : Pa
>> _FillValue : 1e+20
>> level_indicator : 1
>> gds_grid_type : 0
>> parameter_table_version : 1
>> parameter_number : 1
>> forecast_time : 0
>> forecast_time_units : hours
>> initial_time : 01/01/2008 (00:00)
>> float TMP_GDS0_SFC ( g0_lat_0, g0_lon_1 )
>> center : Zagreb
>> long_name : Temperature
>> units : K
>> _FillValue : 1e+20
>> level_indicator : 1
>> gds_grid_type : 0
>> parameter_table_version : 1
>> parameter_number : 11
>> forecast_time : 0
>> forecast_time_units : hours
>> initial_time : 01/01/2008 (00:00)
>> float WIND_GDS0_SFC ( g0_lat_0, g0_lon_1 )
>> center : Zagreb
>> long_name : Wind speed
>> units : m/s
>> _FillValue : 1e+20
>> level_indicator : 1
>> gds_grid_type : 0
>> parameter_table_version : 1
>> parameter_number : 32
>> forecast_time : 0
>> forecast_time_units : hours
>> initial_time : 01/01/2008 (00:00)
>> float SPF_H_GDS0_SFC ( g0_lat_0, g0_lon_1 )
>> center : Zagreb
>> long_name : Specific humidity
>> units : kg/kg
>> _FillValue : 1e+20
>> level_indicator : 1
>> gds_grid_type : 0
>> parameter_table_version : 1
>> parameter_number : 51
>> forecast_time : 0
>> forecast_time_units : hours
>> initial_time : 01/01/2008 (00:00)
>> float EVP_GDS0_SFC ( g0_lat_0, g0_lon_1 )
>> center : Zagreb
>> long_name : Evaporation
>> units : kg/m^2
>> _FillValue : 1e+20
>> level_indicator : 1
>> gds_grid_type : 0
>> parameter_table_version : 1
>> parameter_number : 57
>> forecast_time : 0
>> forecast_time_units : hours
>> initial_time : 01/01/2008 (00:00)
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Apr 9 14:41:41 2012

This archive was generated by hypermail 2.1.8 : Fri Apr 13 2012 - 13:37:52 MDT