[SciPy-User] help in starting with netCDF

Timmie timmichelsen@gmx-topmail...
Tue Aug 10 10:41:32 CDT 2010


Hello,
I am finally diving into netCDF.

I need some assistance in defining coordinate variables such as
"humidity:coordinates"

May someone please help me creating a python file with this CDL:

dimensions:
  station = 10 ;  // measurement locations
  pressure = 11 ; // pressure levels
  time = UNLIMITED ;
variables:
  float humidity(time,pressure,station) ;
    humidity:long_name = "specific humidity" ;
    humidity:coordinates = "lat lon" ;
 
 double time(time) ;
    time:long_name = "time of measurement" ;
    time:units = "days since 1970-01-01 00:00:00" ;

	float lon(station) ;
    lon:long_name = "station longitude";
    lon:units = "degrees_east";
  float lat(station) ;
    lat:long_name = "station latitude" ;
    lat:units = "degrees_north" ;
  float pressure(pressure) ;
    pressure:long_name = "pressure" ;
    pressure:units = "hPa" ;

Source: http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.4/ch05s04.html#id3141969

Here is my start:

from netCDF4 import Dataset

ncfile = Dataset('station_data.nc','w') 

ncfile.createDimension('station', 10)
ncfile.createDimension('pressure', 11)
ncfile.createDimension('time',None)

hum = ncfile.createVariable('hum',dtype('float32'), 
                            ('lat', 'lon', 'time', 'pressure', 'station'))
hum.long_name = 'specific humidity'

timevar = ncfile.createVariable('time',dtype('float32'), ('time'))
timevar.long_name = 'time of measurement'
timevar.units = 'days since 1970-01-01 00:00:00'

lon = ncfile.createVariable('lon',dtype('float32'), ('station'))
lon.long_name = 'station longitude'
lon.units = 'degrees_east'

lat = ncfile.createVariable('lat',dtype('float32'), ('station'))
lat.long_name = 'station latitude'
lat.units = 'degrees_west'

pressure = ncfile.createVariable('pressure',dtype('float32'), ('pressure'))
pressure.long_name = 'pressure'
pressure.units = 'hPa'

ncfile.close()

I also have the following question:
Is it possible with some python library to convert cdl or ncml into a nc file?

I would like to use this NC file in order to stort 4D data: network of
measurements stations with a corresponding time series for each station.

Thanks a lot in advance,
Timmie



More information about the SciPy-User mailing list