Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #47167

Re: python netcdf

References <f39648d9-3d21-4186-8e79-c7aba935beb2@googlegroups.com>
Date 2013-06-05 21:33 -0400
Subject Re: python netcdf
From Jason Swails <jason.swails@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2776.1370482419.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Wed, Jun 5, 2013 at 9:07 PM, Sudheer Joseph <sjo.india@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

python netcdf Sudheer Joseph <sjo.india@gmail.com> - 2013-06-05 18:07 -0700
  Re: python netcdf Jason Swails <jason.swails@gmail.com> - 2013-06-05 21:33 -0400
  Re: python netcdf Sudheer Joseph <sjo.india@gmail.com> - 2013-06-06 07:22 +0530

csiph-web