Hi Gary,
Ordinary NumPy arrays do not support the concept of missing values.
To get support for missing data you need to use the NumPy MaskedArray
subclass. The paradigm is a little different from the NetCDF
_FillValue concept. Associated with the masked array is a 'mask'
array, a Boolean array with the same dimensions as the data array. It
is set to True for values that need to be masked and false otherwise.
It also includes a fill_value attribute, which is only used when
converting to a 'filled' array.
In your case one way you could get a masked array is as follows
(assume that you don't know that the array actually contains no
values equal to the filled value):
from numpy import ma
y= numpy.zeros((plot_len+15),'f')
y = ma.masked_where(y == -999.9, y, copy = 0) # avoids data copy
# set the fill value
y.set_fill_value(-999.9)
You can also create a masked array directly using ma.array() or its
equivalent ma.MaskedArray().
The function signature is
x = MaskedArray(data, mask=nomask, dtype=None, copy=True,
fill_value=None, keep_mask=True, hard_mask=False, shrink=True)
PyNgl (and PyNio) understand masked arrays and will behave
appropriately when given one.
PyNIo has various options when reading data from a file concerning
how or whether to create a masked array.
To get a pure NumPy array that has the masked elements replaced by
the fill value use:
y_notmasked = y.filled(fill_value)
Hope this helps.
-dave
On Dec 8, 2008, at 5:12 PM, Gary Bates wrote:
> How does one assign a fill value to an array in PyNGL?
>
> Here's what I tried and the error I got:
>
> y= numpy.zeros((plot_len+15),'f')
> y._FillValue = -999.9
>
> AttributeError: 'numpy.ndarray' object has no attribute '_FillValue'
>
> -Gary
> _______________________________________________
> pyngl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Mon Dec 08 2008 - 17:53:06 MST
This archive was generated by hypermail 2.2.0 : Thu Jan 01 2009 - 08:39:20 MST