[ncl-talk] sub: netcdf write 2dlat/2dlon
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Fri May 8 11:28:54 MDT 2020
Dale, Rick:
Please ignore my previous message, I hit send by accident.
The scheme for storing 2-D coordinates in Netcdf files is described by an
external convention, and is not part of the core Netcdf structure. A full
description is in CF Conventions (1.8) section 5.1. By conforming to the
convention, you enable the 2-D coordinates to be properly understood by a
wide range of generic software, not just NCL. This also overcomes the
structural problem that 2-D attributes are allowed in NCL memory variables,
but not in Netcdf files.
Here is an example of the bare minimum Netcdf structure needed to conform.
There is a more complicated example in the CF document.
dimensions:
> j = 384 ;
> i = 320 ;
> variables:
> integer VRH(j,i) ;
> VRH:coordinates = "lon lat" ;
> float lon(j,i) ;
> lon:units = "degrees_east" ;
> float lat(j,i) ;
> lat:units = "degrees_north" ;
All variable names and dimension names are arbitrary. You can use any
names you want. But notice the special "coordinates" attribute which lists
the names of the two 2-D coordinate variables. This is required by the CF
convention.
1-D coordinates are handled automatically by NCL, but not 2-D coordinates.
It is always necessary to have a little extra code to separately read and
write the 2-D coordinate variables.
On Fri, May 8, 2020 at 8:33 AM Rick Brownrigg via ncl-talk <
ncl-talk at ucar.edu> wrote:
> Hi Dale,
>
> You seem to be doing the proper things to attach coordinate variables to a
> variable. But by NetCDF convention (not due to NCL), "coordinate variables"
> are by definition !D arrays with a dimension name the same as the variable
> name.
>
> If you have 2D coordinates, the technique is generally to assign those to
> special lat2d/lon2d *attributes* of the variable. Check out the quote
> below and the web page it was taken from.
>
> Rick
>
> "To plot data on a curvilinear grid, you must read these 2D lat/lon
> variables from the file and attach them to the data variable as special
> attributes called "lat2d" and "lon2d":"
> ,,,
>
> temp at lat2d = a->gridlat_236 ; 113 x 151
> temp at lon2d = a->gridlon_236 ; 113 x 151
>
> http://ncl.ucar.edu/Applications/plot_data_on_map.shtml
>
>
> On Fri, May 8, 2020 at 3:33 AM dale zuri via ncl-talk <ncl-talk at ucar.edu>
> wrote:
>
>> Hi NCL user,
>> I have been trying to write a variable that is function of 2dlat/lon to
>> the netcdf file.
>> I'm getting following error. I would appreciate any help to fix this
>> error.
>>
>> Thanks
>>
>> VRH!0 = "lat2d" ; assign named dimensions
>>
>> VRH!1 = "lon2d"
>>
>>
>> VRH&lat2d = lat2d ; copy lat from T to ORO
>>
>> VRH&lat2d = lon2d
>>
>>
>> ncdf->VRH = VRH
>>
>>
>> Variable: VRH
>>
>> Type: integer
>>
>> Total Size: 491520 bytes
>>
>> 122880 values
>>
>> Number of Dimensions: 2
>>
>> Dimensions and sizes: [nj | 384] x [ni | 320]
>>
>> Coordinates:
>>
>> Number Of Attributes: 3
>>
>> lat2d : <ARRAY of 122880 elements>
>>
>> lon2d : <ARRAY of 122880 elements>
>>
>> _FillValue : -2147483647
>>
>> fatal:Coordinate variables must have one dimension only
>>
>> fatal:No coordinate variable exists for dimension (lat2d) in variable
>> (VRH)
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200508/db9cc743/attachment.html>
More information about the ncl-talk
mailing list