[gradsusr] How to write a GrADS data descriptor (.ctl) file for NetCDF files with variables of multiple (>4) dimensions

Jennifer M Adams jadams21 at gmu.edu
Tue Sep 25 19:07:20 EDT 2018


Dear Hailan — 
Please have a look at the grads doc page for netcdf descriptor files (http://cola.gmu.edu/grads/gadoc/SDFdescriptorfile.html), espeically Usage Note #4. Figure out which of the dimensions you’re going to map to the X,Y,Z,T, and E dimenions, then give integer array indices for the remaining dimenions and declare multiple variables for each different index. 

In your case, you’ve got time, latitude, longitude, and pressure to map to T, Y, X, and Z. You could use the E dimension for ‘hour’, then the rest will have to be individually indexed. A variable declaration for 

>     double dF_sfc(dX, sw_lw, up_down, all_clear, hour, latitude, longitude, time) ;

might look like this (although you might want to give the aliases more meaningful names):

…
edef 8 linear 0 1 2 3 4 5 6 7 8
dF_sfc=>dfsfc0000 0  0,0,0,0,e,y,x,t  description for 0 0 0 0
dF_sfc=>dfsfc0001 0  0,0,0,1,e,y,x,t  description for 0 0 0 1
dF_sfc=>dfsfc1001 0  1,0,0,1,e,y,x,t  description for 1 0 0 1
…

—Jennifer



> On Sep 25, 2018, at 10:25 AM, Hailan Wang <hailanw at gmail.com> wrote:
> 
> Dear all,
> 
> I am wondering if you have any suggestions on how to open and read NetCDF files with variables of multiple dimensions (# of dimension > 4). Please see below for an example of such NetCDF file (CldAll.nc):
> 
> netcdf CldAll {
> dimensions:
>         sw_lw = 2 ;
>         up_down = 2 ;
>         time = UNLIMITED ; // (1 currently)
>         all_clear = 2 ;
>         latitude = 90 ;
>         longitude = 72 ;
>         pressure_level = 30 ;
>         hour = 8 ;
>         dX = 1 ;
>         aer_wavelength = 1 ;
>         aer_type = 7 ;
>         pressure_layer = 29 ;
>         cloud_condition = 12 ;
> variables:
>         int time(time) ;
>                 time:long_name = "Time in UNIX" ;
>                 time:units = "Seconds since 1970-1-1 0:00:00 0:00" ;
>                 time:comment = "15th day of the month" ;
>         float pressure_level(pressure_level) ;
>                 pressure_level:long_name = "Level Pressure" ;
>                 pressure_level:units = "mb" ;
>         float latitude(latitude) ;
>                 latitude:long_name = "Latitude" ;
>                 latitude:units = "degrees north" ;
>         float longitude(longitude) ;
>                 longitude:long_name = "Longitude" ;
>                 longitude:units = "degrees east" ;
>         double sfc_pressure(hour, latitude, longitude, time) ;
>                 sfc_pressure:long_name = "Surface pressure" ;
>                 sfc_pressure:units = "mb" ;
>         float hour(hour) ;
>                 hour:units = "UTC" ;
>                 hour:comment = ">=0 -> UTC hour; =-1 -> single mean value; =-2 -> daytime mean; =-3 -> nighttime mean;" ;
>                 hour:long_name = "Hour" ;
>         double dF_toa(dX, sw_lw, up_down, all_clear, hour, latitude, longitude, time) ;
>                 dF_toa:_FillValue = -9999. ;
>                 dF_toa:long_name = "Partial derivative of the flux at the top of the atmosphere" ;
>                 dF_toa:units = "W/m^2" ;
>         double dF_sfc(dX, sw_lw, up_down, all_clear, hour, latitude, longitude, time) ;
>                 dF_sfc:_FillValue = -9999. ;
>                 dF_sfc:long_name = "Partial derivative of the flux at the surface" ;
>                 dF_sfc:units = "W/m^2" ;
>         double dX01_aer_tau(aer_wavelength, aer_type, latitude, longitude, time) ;
>                 dX01_aer_tau:_FillValue = -9999. ;
>                 dX01_aer_tau:long_name = "Partial derivative of the aerosol optical depth" ;
>                 dX01_aer_tau:units = "unitless" ;
>         double dX01_aer_vertdist(aer_type, pressure_layer, latitude, longitude, time) ;
>                 dX01_aer_vertdist:_FillValue = -9999. ;
>                 dX01_aer_vertdist:long_name = "Partial derivative of the aerosol vertical distribution" ;
>                 dX01_aer_vertdist:units = "percent" ;
>                 dX01_aer_vertdist:comment = "Fraction of aer_tau in each layer" ;
>         double dX01_aer_vertdist_sfc(aer_type, latitude, longitude, time) ;
>                 dX01_aer_vertdist_sfc:_FillValue = -9999. ;
>                 dX01_aer_vertdist_sfc:long_name = "Partial derivative of the aerosol vertical distribution in the layer adjacent to the surface" ;
>                 dX01_aer_vertdist_sfc:units = "percent" ;
>                 dX01_aer_vertdist_sfc:comment = "Fraction of aer_tau in the layer adjacent to the surface" ;
>         double dX01_aer_rh(pressure_level, latitude, longitude, time) ;
>                 dX01_aer_rh:_FillValue = -9999. ;
>                 dX01_aer_rh:long_name = "Partial derivative of the relative humidity for computing aerosol ssps" ;
>                 dX01_aer_rh:units = "%" ;
>         double dX01_aer_sfc_rh(latitude, longitude, time) ;
>                 dX01_aer_sfc_rh:_FillValue = -9999. ;
>                 dX01_aer_sfc_rh:long_name = "Partial derivative of the surface relative humidity for computing aerosol ssps" ;
>                 dX01_aer_sfc_rh:units = "%" ;
> 
> // global attributes:
>                 :_NCProperties = "version=1|netcdflibversion=4.4.1|hdf5libversion=1.8.17" ;
>                 :cloud_condition = "=1 -> High+Thin; =2 -> High+Medium; =3 -> High+Thick; =4 -> UpperMid+Thin; =5 -> UpperMid+Medium; =6 -> UpperMid+Thick; =7 -> LowerMid+Thin; =8 -> LowerMid+Medium; =9 -> LowerMid+Thick; =10 -> Low+Thin; =11 -> Low+Medium; =12 -> Low+Thick; " ;
>                 :High = "50-300 mb" ;
>                 :UpperMid = "300-500 mb" ;
>                 :LowerMid = "500-700 mb" ;
>                 :Low = "700 mb-Surface" ;
>                 :Thin = "optical depth < 1" ;
>                 :Medium = "optical depth 1-5" ;
>                 :Thick = "optical depth > 5" ;
>                 :contact = "Tyler Thorsen (tyler.thorsen at nasa.gov)" ;
>                 :input_Month_file = "/SCF5/ADF/tthorsen/data/hiatus/PRPIN/PRPIN-Month/CERES_PRPIN-Month_SYN3HR-GEOS3HR-MATCH-SZAGEOS3HR_Edition4_2x5/CERES_PRPIN-Month_SYN3HR-GEOS3HR-MATCH-SZAGEOS3HR_Edition4_2x5_201701.nc" ;
>                 :start_date_for_climatology = 200007 ;
>                 :end_date_for_climatology = 201706 ;
> data:
> 
>  time = 1484438400 ;
> 
>  pressure_level = 1000, 950, 900, 850, 800, 750, 700, 650, 600, 550, 500,
>     450, 400, 350, 300, 250, 200, 150, 100, 70, 50, 30, 15, 7, 4, 2, 1, 0.7,
>     0.4, 0.1 ;
> 
>  latitude = 89, 87, 85, 83, 81, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61, 59,
>     57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33, 31, 29, 27, 25, 23,
>     21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, -1, -3, -5, -7, -9, -11, -13, -15,
>     -17, -19, -21, -23, -25, -27, -29, -31, -33, -35, -37, -39, -41, -43,
>     -45, -47, -49, -51, -53, -55, -57, -59, -61, -63, -65, -67, -69, -71,
>     -73, -75, -77, -79, -81, -83, -85, -87, -89 ;
> 
>  longitude = -177.5, -172.5, -167.5, -162.5, -157.5, -152.5, -147.5, -142.5,
>     -137.5, -132.5, -127.5, -122.5, -117.5, -112.5, -107.5, -102.5, -97.5,
>     -92.5, -87.5, -82.5, -77.5, -72.5, -67.5, -62.5, -57.5, -52.5, -47.5,
>     -42.5, -37.5, -32.5, -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
>     12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5,
>     72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5,
>     127.5, 132.5, 137.5, 142.5, 147.5, 152.5, 157.5, 162.5, 167.5, 172.5,
>     177.5 ;
> 
>  hour = 0, 3, 6, 9, 12, 15, 18, 21 ;
> }
> 
> 
> I cannot directly open the NetCDF file using the command "sdfopen", with the following error message:
> 
> ga-> sdfopen CldAll.nc
> Scanning self-describing file:  CldAll.nc
> gadsdf: SDF file has no discernable X coordinate.
>   To open this file with GrADS, use a descriptor file with an XDEF entry.
>   Documentation is at http://iges.org/grads/gadoc/SDFdescriptorfile.html
> 
> 
> In order to open the NetCDF file, I need to write a GrADS data descriptor (.ctl) file for it. Here I only need to extract the sw (Shortwave) and lw (Longwave) components of "dF_toa". My current .ctl file reads:
> 
> dset ^CldAll.nc
> title test
> dtype netcdf
> UNDEF -9999.
> options yrev
> xdef   72 linear  -177.5 5.0
> ydef   90 linear  -89 2
> zdef   1 linear 1 1
> tdef   8 linear  0z1jan2001 3hr
> edef   2 names sw lw
> vars   1
> dF_toa=>p1 1 t,x,y,e  p1
> endvars
> 
> 
> It apparently does not work – see below for the error message: 
> 
> ga-> open aa.ctl
> Scanning description file:  aa.ctl
> Data file CldAll.nc is open as file 1
> LON set to 0 360 
> LAT set to -89 89 
> LEV set to 1 1 
> Time values set: 2001:1:1:0 2001:1:1:0 
> E set to 1 1 
> ga-> d p1
> gancgrid error: nc_get_vara_double failed; NetCDF: Start+count exceeds dimension bound
> Data Request Error:  Error for variable 'p1'
>   Error ocurred at column 1
> DISPLAY error:  Invalid expression 
>   Expression = p1
> 
> 
> Any suggestions on how to write the .ctl file are much appreciated!
> 
> Thanks,
> Hailan
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://secure-web.cisco.com/15rgb3WeCnX1mak5oUf3v_23o12IEJTgoowMPl-nlBlLzH9QCM8gf6evaqiMVlYtSqmngkBzTv3yvhwUbx6Us8ToamwJSJlyYiwfiKYpcXJfyIPaLLG7YjpxoPzjtTGgRPHFnlPyB7L6IYiwfV_b-sNx9bZ5w2kWHw3avQaTJvSOSDkljTJVnFKni9FCDhzOeZ4j91cR0oLU-ZgRQuTAqycNfIA1wBF0-N1c8oe9uvUgmls2pnC2gL3LzYv1HxQknp5R3pILpy_oNzLGTMnynzJxTinWnDuP77EfZyIu9QorbkyxgeaSKSyOgwlCC0WyuL9ibIIjZFHylhnqCXyC37XpaO4-o36U5iFpfYxrbERP_7gXkpaNPI-ZHXdDxaC-dUqnGyFXAFF02lgL9cjpZ9wkDu3U9J2Vag-2xG_zw2eJJzUMGQhp4kvL4HgSzlc-0/http%3A%2F%2Fgradsusr.org%2Fmailman%2Flistinfo%2Fgradsusr

--
Jennifer Miletta Adams
Center for Ocean-Land-Atmosphere Studies (COLA)
George Mason University






More information about the gradsusr mailing list