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; 'thursday,': 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; 'mini': 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; 'thank': 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.91; 'ipad': 0.95; '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=e9SucvJ/c4ITxlUdvMpiKuypVOwWFlu4rUEsZKGhxS8=; b=gahJ2GY/0JNs9cSJR24LLUQuyu7qCiGbGfsQz/pMHD6P8Leqn10asbAFkrlWdTs8av Pz39WDzxJdEzDejzO0dBRGiDjjyAKtwhaU+J+9wUbpvqDlVokTXXg149SysuzdTboWy+ GJcbH84gScF+4mNnLc53HY2p1NUdTtRIZBTb8HQSfH9KvfYFX7bryx6b5PZhI2a6/xAt pYfsZacSylhZApKP7Pq604JF1ldo/ULwmd3PJ/4Hy6wJr+j0RXeQ5qNi4NO9rduEroKe b1j20towzS0HQkdfYUVLdytdX7e/GEbZE3WRRcIu3LEHbHGA1+hEbaG7YI7jDsGe6VAh C8tQ== MIME-Version: 1.0 X-Received: by 10.67.4.129 with SMTP id ce1mr36585032pad.107.1370483534339; Wed, 05 Jun 2013 18:52:14 -0700 (PDT) In-Reply-To: References: Date: Thu, 6 Jun 2013 07:22:14 +0530 Subject: Re: python netcdf From: Sudheer Joseph To: Jason Swails Content-Type: multipart/alternative; boundary=047d7b16018b3c23b304de72904b 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: 131 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370483543 news.xs4all.nl 15896 [2001:888:2000:d::a6]:60318 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47175 --047d7b16018b3c23b304de72904b Content-Type: text/plain; charset=ISO-8859-1 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 > > 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 --047d7b16018b3c23b304de72904b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thank you very much Jason
With best regards
Sudheer

On Thursday, June 6, 2013, Jason Swails wrote:



On Wed, Jun 5, 2013 at 9:0= 7 PM, Sudheer Joseph <sjo.india@g= mail.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 Net= CDF file and attributes of each of the variables can be accessed via the do= t-operator, as per standard Python.

For instance, suppose that your NetCDF file has a Conventions attribut= e, you can access it via:

ncfile.Conventions

S= uppose that your variable, time, has an attribute "origin", you c= an get it via:

ncfile.variables['time'].origin

Of course there's the question of wh= at NetCDF bindings you're going to use. =A0The options that I'm fam= iliar with are the ScientificPython's NetCDFFile class (Scientific.IO.N= etCDF.NetCDFFile), pynetcdf (which is just the ScientificPython's class= in a standalone format), and the netCDF4 package. =A0Each option has a sim= ilar API with attributes accessed the same way.

An example with netCDF4 (which is newer, has NetCDF 4 capabilities, an= d appears to be more supported):

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

origin =3D ncfile.va= riables['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 retur= ns a numpy ndarray.

HTH,
Jason


--
Sent from my iPad Mini
--047d7b16018b3c23b304de72904b--