Re: Missing values in PyNIO

From: Seth McGinnis <mcginnis_at_nyahnyahspammersnyahnyah>
Date: Thu, 21 Aug 2008 15:19:09 -0600

Thanks, Dave!

That was a big help. Knowing that the data had a weird
type, I just set data.missing_value = data[0,0,0] and
data._FillValue = data.missing_value after the initial
array construction and it worked fine.

--Seth

>
>PyNIO (currently) treats an assignment to a _FillValue
>just like any other
>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 variable
>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)
>or
>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.
> -dave
>
>
>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
>> ISSE / NCAR
>> ----
>> _______________________________________________
>> 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 Thu Aug 21 2008 - 15:19:09 MDT

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