sodri126 / netcdf4-python

Automatically exported from code.google.com/p/netcdf4-python
Other
0 stars 0 forks source link

ncdump functionality in netcdf4-python #160

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be quite useful to have ncdump-like functionality in netcdf4-python 
that would give an overview of the entire dataset.  We have this function in 
the Matlab NCTOOLBOX and people have found it very useful. 

Could this be done by simply wrapping the ncdump.c code?

-Rich

Original issue reported on code.google.com by rsignell on 24 Jan 2013 at 12:24

GoogleCodeExporter commented 9 years ago
You can print Dataset objects and variables and get output like below. It would 
be pretty straightforward to write a command line utility to just dump the 
contents of a file by printing all the objects.

>>> from netCDF4 import Dataset
>>> 
f=Dataset('http://www.cdc.noaa.gov/cgi-bin/opendap/nph-nc/Datasets/noaa.oisst.v2
/sst.mnmean.nc')
print >>> print f
<type 'netCDF4.Dataset'>
root group (NETCDF3_64BIT file format):
    title: NOAA Optimum Interpolation (OI) SST V2
    Conventions: CF-1.0
    history: Wed Apr  6 13:47:45 2005: ncks -d time,0,278 SAVEs/sst.mnmean.nc sst.mnmean.nc
Created 10/2002 by RHS
    comments: Data described in  Reynolds, R.W., N.A. Rayner, T.M.
Smith, D.C. Stokes, and W. Wang, 2002: An Improved In Situ and Satellite
SST Analysis for Climate, J. Climate
    platform: Model
    source: NCEP Climate Modeling Branch
    institution: National Centers for Environmental Prediction
    references: http://www.esrl.noaa.gov/psd/data/gridded/data.noaa.oisst.v2.html
http://www.emc.ncep.noaa.gov/research/cmb/sst_analysis/
    _DODS_Unlimited_Dimension: time
    dimensions: time, lat, lon, nbnds
    variables: lat, lon, time, time_bnds, sst
    groups: 

>>> for v in f.variables:
...     print f.variables[v]
... 
<type 'netCDF4.Variable'>
float32 lat(lat)
    units: degrees_north
    long_name: Latitude
    actual_range: [ 89.5 -89.5]
    standard_name: latitude
    axis: Y
    coordinate_defines: center
unlimited dimensions: 
current shape = (180,)

<type 'netCDF4.Variable'>
float32 lon(lon)
    units: degrees_east
    long_name: Longitude
    actual_range: [   0.5  359.5]
    standard_name: longitude
    axis: X
    coordinate_defines: center
unlimited dimensions: 
current shape = (360,)

<type 'netCDF4.Variable'>
float64 time(time)
    units: days since 1800-1-1 00:00:00
    long_name: Time
    actual_range: [ 66443.  77797.]
    delta_t: 0000-01-00 00:00:00
    avg_period: 0000-01-00 00:00:00
    prev_avg_period: 0000-00-07 00:00:00
    standard_name: time
    axis: T
    bounds: time_bnds
unlimited dimensions: time
current shape = (374,)

<type 'netCDF4.Variable'>
float64 time_bnds(time, nbnds)
    long_name: Time Boundaries
unlimited dimensions: time
current shape = (374, 2)

<type 'netCDF4.Variable'>
int16 sst(time, lat, lon)
    long_name: Monthly Mean of Sea Surface Temperature
    unpacked_valid_range: [ -5.  40.]
    actual_range: [ -1.79999959  35.31000137]
    units: degC
    add_offset: 0.0
    scale_factor: 0.01
    missing_value: 32767
    precision: 2
    least_significant_digit: 2
    var_desc: Sea Surface Temperature
    dataset: NOAA Optimum Interpolation (OI) SST V2
    level_desc: Surface
    statistic: Mean
    parent_stat: Weekly Mean
    standard_name: sea_surface_temperature
    cell_methods: time: mean (monthly from weekly values interpolated to daily)
    valid_range: [-500 4000]
unlimited dimensions: time
current shape = (374, 180, 360)

Original comment by whitaker.jeffrey@gmail.com on 14 Feb 2013 at 4:13

GoogleCodeExporter commented 9 years ago
Cool, I didn't know you could print the dataset and variables like that.  I 
guess that is close enough.

Original comment by rsignell on 14 Feb 2013 at 11:46

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
There is a utility, ncinfo, that wraps this functionality.

Original comment by whitaker.jeffrey@gmail.com on 12 Jun 2014 at 10:58