[ncl-talk] replace_zerovalue_or_negativevalue_to_NaN

Mary Haley haley at ucar.edu
Mon Jun 13 08:35:42 MDT 2016


I want to add that NCL cannot handle NaN values, and you will get undefined
behavior if you try to use them in an NCL script.

We have two functions explicitly for dealing with NaN values:

isnan_ieee
<http://www.ncl.ucar.edu/Document/Functions/Built-in/isnan_ieee.shtml> -
returns True for every element of an array that is a NaN, and False
otherwise
replace_ieeenan
<http://www.ncl.ucar.edu/Document/Functions/Built-in/replace_ieeenan.shtml>
- replaces all NaN values with a valid value

This piece of code will replace all your NaN's using a _FillValue:

  if (any <http://www.ncl.ucar.edu/Document/Functions/Built-in/any.shtml>(isnan_ieee
<http://www.ncl.ucar.edu/Document/Functions/Built-in/isnan_ieee.shtml>(x)))
then
      if(.not.isatt(x,"_FillValue")) then
        x at _FillValue = default_fillvalue(typeof(x))
      end if
      replace_ieeenan (x, x at _FillValue, 0)  end if

--Mary


On Sun, Jun 12, 2016 at 4:26 AM, Guido Cioni <guidocioni at gmail.com> wrote:

> Kunal,
> you can easily achieve that with the *where* function
> http://www.ncl.ucar.edu/Document/Functions/Built-in/where.shtml.
> Assuming that var is your variable and var_mod the new one, you can do
> this (var need an attribute _FillValue, which is equivalent to NaN):
>
>    var_mod = *where*(var.le.0, var at _FillValue, var)
>
> There’s a method to do the same in CDO and NCO but it is more complicated.
> If you just need the variable in NCL I would suggest you to use the where
> function, while if you need to write another file you can try to load it in
> NCL with the “w” option. If that doesn’t work then you will have to use CDO
> and NCO, but that would be a question not relevant to ncl-talk :)
>
> Guido Cioni
> http://guidocioni.altervista.org
>
> On 12 Jun 2016, at 11:16, Kunal Bali <kunal.bali9 at gmail.com> wrote:
>
> Dear NCL users
>
> I have a file having zero and negative values. I need to replace it with
> NaN values.
> Could anyone let me know how to do it ?
>
> Regards
> Kunal Bali
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160613/a2fcba02/attachment.html 


More information about the ncl-talk mailing list