Re: Missing values in PyNIO

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Wed, 20 Aug 2008 20:04:40 -0600

PyNIO (currently) treats an assignment to a _FillValue just like any
attribute assignment, meaning that it does not try to convert the
type it is handed.
But NetCDF requires the _FillValue type to be the same type as the
it is attached to (for good reason).

If your data variable is a 'float' in NetCDF you must assign the
_FillValue as a numpy.float32.
If you assign it with the literal value '-999', it will become an
integer, which will not work.
Unfortunately, even if you use the value '-999.0', specifying a float
type, it will not work,
because the default float type in Python (and NumPy) is float64,
known as 'double' in
NetCDF. So you must explicitly create a numpy float32 value. Make
sure numpy has been
imported then:

data._FillValue = numpy.array(-999.0,dtype=numpy.float32)
data._FillValue = numpy.array(-999.0,dtype='f')

This could be shortened a bit more if you do 'import numpy as np' or
something similar.

It would be good if PyNIO could do some reasonable type conversion
for the _FillValue
attribute on assignment. Perhaps we should consider it a bug that it
doesn't. Then we could fix it
for the release version. Otherwise at least we should document this
behavior more fully.

On Aug 20, 2008, at 1:29 PM, Seth McGinnis wrote:

> I'm using PyNGL/PyNIO to process data from an ascii file
> format into NetCDF.
> How do I set _FillValue / missing_value on a variable and
> ensure that the variable is pre-filled with that value?
> From the documentation, it seems like most of that happens
> automatically, but my resulting NetCDF files don't have a
> _FillValue defined, and "data._FillValue = -999" generates
> the error message:
> ncendef: ncid 65536: NetCDF: Not a valid data type or
> _FillValue type mismatch
> Help? Thanks!
> --Seth
> ----
> Seth McGinnis
> Associate Scientist
> ----
> _______________________________________________
> pyngl-talk mailing list

pyngl-talk mailing list
Received on Wed Aug 20 2008 - 20:04:40 MDT

This archive was generated by hypermail 2.2.0 : Thu Aug 21 2008 - 22:13:03 MDT