No problem.. just wanted to make sure it would work and is 'pythonic'.

I guess the biggest concern is that for others using the netcdf file, say
from matlab or somewhere else, will be able to access the attributes.

It seemed so easy to do it this way, I was curious why the tutorials suggest
using setattr(), and I wonder if perhaps what I'm setting is not 'global' or
perhaps wouldn't match some ISO or otherwise NetCDF standard??

Thanks!

On Wed, Nov 11, 2009 at 4:03 PM, Ryan May <rma...@gmail.com> wrote:

> On Wed, Nov 11, 2009 at 7:31 AM, John [H2O] <washa...@gmail.com> wrote:
> >
> > Hello, I'm trying to write a function to create a 'vanilla' NetCDF file
> to
> > which I can add data.
> >
> > So far I have created the following, which is designed to set up a netcdf
> > file for the addition of global or at least lat/lon datasets. My question
> > has to do with attribute setting. Is it valid to do what I'm doing below
> > "nco.attribute = attributevalue" or do you have to use the setattr
> function
> > as outlined in some tutorials?
> >
> > Thanks!
> >
> > def default_netcdf(nco_filename,
> >                   lon0=-179.5,lat0=-89.5,
> >                   nx=720,ny=360,
> >                   dx=0.5,dy=0.5):
> >    """ add default attributes and dimensions to the nc file """
> >    nco = NetCDFFile(nco_filename,'w')
> >    nco.author = "Some One"
> >    nco.createdate = dt.datetime.now().ctime()
> >    nco.contact = "some....@python.com"
> >    nco.Conventions = "CF-1.4"
> >
> >    nco.createDimension('lon',nx)
> >    nco.createDimension('lat',ny)
> >    nco.createVariable('lat','d',('lat',))
> >    nco.createVariable('lon','d',('lon',))
> >    lon = np.arange(lon0,lon0+(nx*dx),dx)
> >    lat = np.arange(lat0,lat0+(ny*dy),dy)
> >    nco.variables['lat'][:] = lat
> >    nco.variables['lon'][:] = lon
> >    nco.createVariable('data','d',('lon','lat'))
> >
> >    return nco
>
> That should work fine for settings attributes.  Are you having a
> problem? If so, can you paste the actual traceback?
>
> Ryan
>
> --
> Ryan May
> Graduate Research Assistant
> School of Meteorology
> University of Oklahoma
>



-- 
Configuration
``````````````````````````
Plone 2.5.3-final,
CMF-1.6.4,
Zope (Zope 2.9.7-final, python 2.4.4, linux2),
Five 1.4.1,
Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1 20070105 (Red Hat
4.1.1-51)],
PIL 1.1.6
Mailman 2.1.9
Postfix 2.4.5
Procmail v3.22 2001/09/10
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to