[Numpy-discussion] blank values '--'

Benjamin Root ben.root@ou....
Thu Feb 24 12:10:44 CST 2011


On Thu, Feb 24, 2011 at 12:00 PM, Bryan Woods <bwoods@aer.com> wrote:

> Hello,
>
> I am loading in data from the GRIB2 files using PyNIO. Once I load them
> into numpy arrays I am left with a halo of values near the array boundaries
> that appear to be empty. When I print them or use them in conditional
> statements I see values of '--'. I'd like to turn these values into zeroes
> at the very least.
>
> As an example if I print the array I see:
>
> [[-- -- -- ..., -- -- --]
>  [-- -- -- ..., -- -- --]
>  [-- -- -- ..., -- -- --]
>  ...,
>  [-- -- -- ..., -- -- --]
>  [-- -- -- ..., -- -- --]
>  [-- -- -- ..., -- -- --]]
>
> though I know that there are valid values in the interior of the domain
> which plot properly.
>
> I can't find anything in the numpy documentation that addresses this type
> of missing value. Has anyone dealt with this before?
>
> Thanks,
> Bryan
>
>
This is called MaskedArrays, and they are a wonderful thing.

http://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html

This is better than using magic numbers to indicate missing data, and sort
of similiar in concept to using NaNs in place of missing data.  Most of
matplotlib's plotting functions support masked arrays (although we are still
improving in this regard).

You can easily get a regular numpy array like so:

unmasked = maskedData.filled(0.0)

I hope that helps!
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110224/b2f6b7de/attachment.html 


More information about the NumPy-Discussion mailing list