python netcdf

S

Sudheer Joseph

Dear Members,
Is there a way to get the time:eek:rigin attribute from a netcdf file as string using the Python netcdf?
with best regards,
Sudheer
 
J

Jason Swails

Dear Members,
Is there a way to get the time:eek:rigin 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
 
S

Sudheer Joseph

Thank you very much Jason
With best regards
Sudheer

Dear Members,
Is there a way to get the time:eek:rigin 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

netcdF4 variables 2
Using MFDataset to combine netcdf files in python 0
netcdf4-python 1
len() of unsized object - ks test 3
Python - modules and netCDF 0
SciPy and NetCDF 9
Memory error 3
netCDF4 usage issues 0

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top