Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'attribute': 0.07; 'conventions': 0.07; 'suppose': 0.07; 'variables': 0.07; 'string': 0.09; 'attributes': 0.09; 'bindings': 0.09; 'variable,': 0.09; 'api': 0.11; 'cc:addr:python-list': 0.11; 'python': 0.11; 'stored': 0.12; 'attribute,': 0.16; 'cc:name:python list': 0.16; 'newer,': 0.16; 'numpy': 0.16; 'slicing:': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'appears': 0.22; 'example': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'package.': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'options': 0.25; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'dimensions': 0.31; 'origin': 0.31; 'file': 0.32; 'class': 0.32; 'option': 0.32; 'skip:d 20': 0.34; 'received:google.com': 0.35; 'there': 0.35; 'accessible': 0.36; 'similar': 0.36; 'skip:& 10': 0.38; 'jason': 0.38; 'pm,': 0.38; 'use.': 0.39; 'skip:n 30': 0.60; 'course': 0.61; "you're": 0.61; 'skip:n 10': 0.64; 'more': 0.64; 'dear': 0.65; 'to:addr:gmail.com': 0.65; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=vm6mPfzJdN6TJmJT9cw7i1ty1SiLN/+heNcSv0lRLLA=; b=X59du4qzz43nfiHw/hVwOhusJ3zyDdUgrTmQ7fvgukLiRGoeDpopieRZEYmymOAJrR mzHYR76lqd0cvTWK+oJUrr7aYfUM5IaaVV4oEKMja6omDLnqY9WfkZANnVZWf3Y9jppk GTmsTyK1CwalN21+ayh/k81xAjvTT/OHBOdE7YxrzliBPerK4qQYrA+Ow5z0nRqYbT8f Qr/ZxA5GeMgquSUsO+6Tnk/YhcyigI9t62d/pWx5HnYgZ45cAXt7LFPG+mcuha3PM0v4 h5g4YT5UehKsWTNRjRgTPfeYKERlBQbu1LwzGygUg/af2wjJdMkTHTpQaw3mg6PlAJob KdHw== MIME-Version: 1.0 X-Received: by 10.42.250.202 with SMTP id mp10mr16008881icb.21.1370482416568; Wed, 05 Jun 2013 18:33:36 -0700 (PDT) In-Reply-To: References: Date: Wed, 5 Jun 2013 21:33:36 -0400 Subject: Re: python netcdf From: Jason Swails To: Sudheer Joseph Content-Type: multipart/alternative; boundary=20cf3010e6c99c508604de724da4 Cc: python list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 114 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370482419 news.xs4all.nl 15926 [2001:888:2000:d::a6]:42507 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47167 --20cf3010e6c99c508604de724da4 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jun 5, 2013 at 9:07 PM, Sudheer Joseph 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 --20cf3010e6c99c508604de724da4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

<= /div>


On Wed, = Jun 5, 2013 at 9:07 PM, Sudheer Joseph <sjo.india@gmail.com> wrote:
Dear Members,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Is there a way to get the time:origin a= ttribute from a netcdf file as string using the Python netcdf?

= Attributes of the NetCDF file and attributes of each of the variables can b= e accessed via the dot-operator, as per standard Python.

For instance, suppose that y= our NetCDF file has a Conventions attribute, you can access it via:

ncfile.Co= nventions

=
Suppose that = your variable, time, has an attribute "origin", you can get it vi= a:

ncfile.variables['time&#= 39;].origin
Of course there'= ;s the question of what NetCDF bindings you're going to use. =A0The opt= ions that I'm familiar with are the ScientificPython's NetCDFFile c= lass (Scientific.IO.NetCDF.NetCDFFile), pynetcdf (which is just the Scienti= ficPython's class in a standalone format), and the netCDF4 package. =A0= Each option has a similar API with attributes accessed the same way.

An example with netCDF4 (whi= ch is newer, has NetCDF 4 capabilities, and appears to be more supported):<= /div>

from netCDF4 import Dataset<= /div>

ncfile =3D Dataset('my_netcdf_file= .nc', 'r')

origin =3D ncfile.variables['time'].origin

etc. etc.

The variables and dimensions of a NetCDF file are stored in dictionaries, a= nd the data from variables are accessible via slicing:

time_data =3D ncfile.variables['time'][:]

The slice returns a numpy ndarray.

HTH,
Jason
<= /div>
--20cf3010e6c99c508604de724da4--