[ncl-talk] Fill Values in NCL and Python

Barry Lynn barry.h.lynn at gmail.com
Sun Mar 3 01:43:25 MST 2024


Karen:

Thank you.  I think you need the additional line so that the "invalid"
values will be masked out.

 threshold = 1.

 radar_max = np.where(radar_max < threshold, np.nan, radar_max)

 radar_max = np.ma.masked_invalid(radar_max)

On Wed, Feb 28, 2024 at 5:12 PM Karin Meier-Fleischer via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> NCL:
>
>     xsqrt = *where*(arr .gt. 0,* sqrt*
> <https://www.ncl.ucar.edu/Document/Functions/Built-in/sqrt.shtml>(arr),
> arr at _FillValue)
>
> Python:
>
>     xsqrt = np.where(arr > 0, np.sqrt(arr), np.nan)
>
>
>
> Am 28.02.24 um 16:02 schrieb Karin Meier-Fleischer via ncl-talk:
>
> Hi Barry,
>
> the following two Python examples demonstrate how to set values in a NumPy
> and an Xarray array to NaN using a condition.
>
> arr = np.arange(0., 10.)
> arr[arr >= 7.] = np.nan
> print(arr)
>
> -----> output: [ 0. 1. 2. 3. 4. 5. 6. nan nan nan]
>
> xarr = xr.DataArray(np.arange(10))
> xarr = xarr.where(xarr < 7, np.nan)
> print(xarr.values)
>
> -----> output: [ 0. 1. 2. 3. 4. 5. 6. nan nan nan]
>
> Regards,
> Karin
>
> Am 28.02.24 um 15:10 schrieb Barry Lynn via ncl-talk:
>
> Hi:
>
> I know how to change an array value to fillvalue in NCL using a where
> statement.
>
> How do I do the same in python, please?
>
> Barry
> --
>
> Barry H. Lynn, Ph.D
> Senior Scientist, Lecturer,
> The Institute of Earth Sciences,
> The Hebrew University of Jerusalem,
> Givat Ram, Jerusalem 91904, Israel
> Tel: 972 547 231 170
> Fax: (972)-25662581
>
> Weather It Is, LTD
> Weather and Climate Focus
> https://weather-it-is.com <http://weather-it-is.com>
> Jerusalem, Israel
> Local: 02 930 9525
> Cell: 054 7 231 170
> Int-IS: x972 2 930 9525
>
>
> _______________________________________________
> ncl-talk mailing listncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
> _______________________________________________
> ncl-talk mailing listncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>


-- 

Barry H. Lynn, Ph.D
Senior Scientist, Lecturer,
The Institute of Earth Sciences,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581

Weather It Is, LTD
Weather and Climate Focus
https://weather-it-is.com <http://weather-it-is.com>
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20240303/dca23dd8/attachment.htm>


More information about the ncl-talk mailing list