Thank you very much Jason With best regards Sudheer On Thursday, June 6, 2013, Jason Swails wrote:
> > > > On Wed, Jun 5, 2013 at 9:07 PM, Sudheer Joseph > <sjo.in...@gmail.com<javascript:_e({}, 'cvml', 'sjo.in...@gmail.com');> > > wrote: > >> Dear Members, >> Is there a way to get the time:origin attribute from a >> netcdf file as string using the Python netcdf? >> > > Attributes of the NetCDF file and attributes of each of the variables can > be accessed via the dot-operator, as per standard Python. > > For instance, suppose that your NetCDF file has a Conventions attribute, > you can access it via: > > ncfile.Conventions > > Suppose that your variable, time, has an attribute "origin", you can get > it via: > > ncfile.variables['time'].origin > > Of course there's the question of what NetCDF bindings you're going to > use. The options that I'm familiar with are the ScientificPython's > NetCDFFile class (Scientific.IO.NetCDF.NetCDFFile), pynetcdf (which is just > the ScientificPython's class in a standalone format), and the netCDF4 > package. Each option has a similar API with attributes accessed the same > way. > > An example with netCDF4 (which is newer, has NetCDF 4 capabilities, and > appears to be more supported): > > from netCDF4 import Dataset > > ncfile = Dataset('my_netcdf_file.nc', 'r') > > origin = ncfile.variables['time'].origin > > etc. etc. > > The variables and dimensions of a NetCDF file are stored in dictionaries, > and the data from variables are accessible via slicing: > > time_data = ncfile.variables['time'][:] > > The slice returns a numpy ndarray. > > HTH, > Jason > -- Sent from my iPad Mini
-- http://mail.python.org/mailman/listinfo/python-list