## Re: [Matplotlib-users] help creating a netcdf file with an irregular grid projection (stereographic)

 Re: [Matplotlib-users] help creating a netcdf file with an irregular grid projection (stereographic) From: Benjamin Root - 2010-10-30 00:19:04 Attachments: Message as HTML ```On Fri, Oct 29, 2010 at 7:04 PM, John wrote: > Any good tutorials or examples that people could point me to on > creating a netcdf file for a grid projected with a stereographic > projection? It's not clear to me how you would create the lat / lon > dimensions. > > Thanks, > john > > > Be careful of saying "irregular" grid when what you really mean is non-rectilinear. If the data can be represented in a matrix, then chances are it is regular in some way. There are a number of schemes for how to organize your data in netcdf. One way I have seen is to represent the data in a 1D array and then have parallel arrays of lat and lon coordinates. This works no matter how irregular the data grid is (particularly nice with sparse data). If the data can be represented in a regular grid, then you can represent the data in 2D in the netcdf file, and have parallel arrays of 2-D lat and lon arrays. The key point of these two methods is that you would have all three arrays use an index (or two) as the common dimension. Does that help? Ben Root ```

 [Matplotlib-users] help creating a netcdf file with an irregular grid projection (stereographic) From: John - 2010-10-30 00:04:22 ```Any good tutorials or examples that people could point me to on creating a netcdf file for a grid projected with a stereographic projection? It's not clear to me how you would create the lat / lon dimensions. Thanks, john -- Configuration `````````````````````````` Basemap: 1.0 Matplotlib: 1.0.0 ```
 Re: [Matplotlib-users] help creating a netcdf file with an irregular grid projection (stereographic) From: Benjamin Root - 2010-10-30 00:19:04 Attachments: Message as HTML ```On Fri, Oct 29, 2010 at 7:04 PM, John wrote: > Any good tutorials or examples that people could point me to on > creating a netcdf file for a grid projected with a stereographic > projection? It's not clear to me how you would create the lat / lon > dimensions. > > Thanks, > john > > > Be careful of saying "irregular" grid when what you really mean is non-rectilinear. If the data can be represented in a matrix, then chances are it is regular in some way. There are a number of schemes for how to organize your data in netcdf. One way I have seen is to represent the data in a 1D array and then have parallel arrays of lat and lon coordinates. This works no matter how irregular the data grid is (particularly nice with sparse data). If the data can be represented in a regular grid, then you can represent the data in 2D in the netcdf file, and have parallel arrays of 2-D lat and lon arrays. The key point of these two methods is that you would have all three arrays use an index (or two) as the common dimension. Does that help? Ben Root ```
 Re: [Matplotlib-users] help creating a netcdf file with an irregular grid projection (stereographic) From: Jeff Whitaker - 2010-10-30 01:08:01 ``` On 10/29/10 6:04 PM, John wrote: > Any good tutorials or examples that people could point me to on > creating a netcdf file for a grid projected with a stereographic > projection? It's not clear to me how you would create the lat / lon > dimensions. > > Thanks, > john > > > John: The nice thing about netcdf is there are conventions for almost any kind of geophysical variable and/or grid. See http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.4/apf.html -Jeff ```
 [Matplotlib-users] Fwd: help creating a netcdf file with an irregular grid projection (stereographic) From: John - 2010-11-02 19:02:19 ```I have a file now, that I created from a NCEP grib file. I'm trying to get the land sea mask and the veg types into 0.5x0.5 lat/lon regular grids. However, they are still in Gaussian Grids, but at least I have it assembled into netcdf files! I'll follow up on a post about the conversion. but I would be interested in knowing if what I have done below fits the 'Convention 1.4' definitions: In [64]: vegtype = grbs.select(name='Vegetation Type')[0] In [65]: vlats,vlons = vegtype.latlons() In [67]: vtypes = vegtype.values In [70]: vtypes.shape Out[70]: (880, 1760) In [89]: nco = NetCDFFile('/wrk/jfb/DATASETS_TEMPLATES/JFB_vegtypes.nc','w',format='NETCDF4',zlib=True) In [91]: nco.createDimension('nrows', 880) Out[91]: In [92]: nco.createDimension('ncols',1760) Out[92]: In [93]: lat = nco.createVariable('lat','f8',('nrows','ncols'),zlib=True) In [94]: lat[:] = vlats In [95]: lon = nco.createVariable('lon','f8',('nrows','ncols'),zlib=True) In [96]: lon[:] = vlons In [97]: data = nco.createVariable('data','int',('nrows','ncols'),zlib=True) In [98]: data[:] = vtypes In [99]: nco.history="Creating a vegetation types mask from the NCEP ncep.sfluxgrbf03.grb file" In [100]: nco.units="Integer(0-13)" In [101]: nco.close() In [102]: nco = NetCDFFile('/wrk/jfb/DATASETS_TEMPLATES/JFB_vegtypes.nc',format='NETCDF4',zlib=True) In [103]: nco.variables.keys() Out[103]: ['lat', 'lon', 'data'] In [104]: nco.close() I guess officially, I should add something along the lines of: float lat(lat) ;  lat:long_name = "latitude" ;  lat:units = "degrees_north" ;  lat:standard_name = "latitude" ; Thank you, john -- Configuration `````````````````````````` Plone 2.5.3-final, CMF-1.6.4, Zope (Zope 2.9.7-final, python 2.4.4, linux2), Python 2.6 PIL 1.1.6 Mailman 2.1.9 Postfix 2.4.5 Procmail v3.22 2001/09/10 Basemap: 1.0 Matplotlib: 1.0.0 ```