Re: writing netcdf files

From: David Ian Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Tue, 8 Aug 2006 19:18:06 -0600

Hi Wendi,
You don't show how you are creating the data variables 'lngData' and
'latData', but after
experimenting a bit, my guess is that you creating them as the
equivalent of python floats,
(or Numeric Floats) which are actually C doubles. I have discovered
that PyNIO is refusing
to coerce double data to NetCDF float type variables. It also is not
properly reporting an error when it
encounters this situation. These are definitely bugs that will be
addressed as soon as possible.

In the meantime, if you want NetCDF float variables make sure you
explicitly make the data 32bit float
before trying the assignments. I was able to get your code to produce a
NetCDF file with the
'lat' and 'lon' variables properly assigned using the following lines
of code to give the lngData and
latData variables some representative values:

import Numeric as N
lngData = N.arange(0,360,360./144,'f')
latData = N.arange(-90,90,180./73,'f')

On Aug 8, 2006, at 2:52 PM, Wendi Madsen wrote:

> Good Afternoon
>
> I am trying to write some netcdf files using Nio. I can create the
> file, and create the dimensions and variables and add attributes to
> the various variables, but I can't seem to get any data into the file.
> here is the code i am using:
>
> ncFileName = NCFileName[j] + "." + timeStr + "00" + ".nc"
> outNCFile = Nio.open_file(ncFileName, "c")
> outNCFile.create_dimension("lon", 144)
> outNCFile.create_dimension("lat", 73)
> outNCFile.create_dimension("level", 12)
> outNCFile.create_dimension("time", 0)
> outNCFile.create_dimension("chid", 4)
> outNCFile.create_variable("lon", 'f', ('lon',))
> outNCFile.variables['lon'].units = "degrees_east"
> outNCFile.variables['lon'].long_name = "Longitude"
> outNCFile.create_variable('lat', 'f', ('lat',))
> outNCFile.variables['lat'].units = "degrees_north"
> outNCFile.variables['lat'].long_name = "Latitude"
> outNCFile.create_variable('level', 'f', ('level',))
> outNCFile.variables['level'].units = "millibar"
> outNCFile.variables['level'].positive = "down"
> outNCFile.variables['level'].long_name = "Level"
> outNCFile.variables['level'].desc = "Level here actually
> describes an ensemble forescst identifer, (see levids variable)"
> outNCFile.create_variable('time', 'd', ('time',))
> outNCFile.variables['time'].units = "hours since 1-1-1
> 00:00:0.0"
> outNCFile.variables['time'].title = "Valid Time"
> outNCFile.variables['time'].delta_t = "000-00-00 12:00:00"
> outNCFile.create_variable('levids', 'c', ('level', 'chid'))
> outNCFile.variables['levids'].long_name = "Level Identifier"
> outNCFile.variables['levids'].desc = "Used to map Level with
> ensemble member Id"
> outNCFile.create_variable(NCVarName[j], 's', ('time', 'level',
> 'lat', 'lon'))
> outNCFile.variables['lon'].assign_value(lngData)
> outNCFile.variables['lat'][:] = latData
> outNCFile.close()
>
> thanks for your assistance
>
> Wendi Madsen
>
> <wendi.b.madsen.vcf>_______________________________________________
> pyngl-talk mailing list
> pyngl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk

_______________________________________________
pyngl-talk mailing list
pyngl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Tue Aug 08 2006 - 19:18:06 MDT

This archive was generated by hypermail 2.2.0 : Wed Aug 09 2006 - 08:42:58 MDT