[ncl-talk] how can I avoid dividing by zero?

Barry Lynn barry.h.lynn at gmail.com
Wed Aug 22 02:46:56 MDT 2018


Hello Sri:

I would try it this way.

Set *y* to a _FillValue value where it is equal to 0, and then can do the
divide:
   y at _FillValue = 1.E36 ; or something like this.
   print(where(y.ne.0,y, at _FillValue)) ;  I am assuming this works.
If nothing prints then maybe you have no values.
In any case, try the next two lines.
   y = *where*(y.ne.0,y,y at _FillValue)

  yinv = 1. / y

However, just to check, I would



On Wed, Aug 22, 2018 at 11:39 AM Sri Nandini <snandini at marum.de> wrote:

> Hello
>
> how can I remove the zero values to avoid dividing by zero the error I got
> is as the following:
>
>  fatal:divide: Division by 0, Can't continue
>  fatal:Div: operator failed, can't continue
>
> I have tried using   yinv = 1. / where(y.ne.0, y, y at _FillValue) but now
> it gives me all nan values
>
> Heres the bit of my code
>
>    T41    = f->Z3(:,{850},:,:)
>
>    printVarSummary(T41)
>    T41 at _FillValue = -9.96921e+36
>
>    aveX    = dim_avg_n_Wrap(T41,0)
>    printVarSummary(aveX)                      ; (lat,lon)
>    T41 at _FillValue = -9.96921e+36
>
>    aveX = 1. / where(aveX.ne.0, aveX, aveX at _FillValue)
>
> aveX1 and aveX2 below are of same type as aveX.
>    XLAT = conform ( aveX2 , xlat , 0 )
>    printVarSummary(XLAT)
>
>    egr = eady_growth_rate(aveX2, aveX1, aveX, XLAT, 0,  1)
>
> Output
> ===========================
> Variable: egr
> Type: double
> Total Size: 110592 bytes
>             13824 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat | 96] x [lon | 144]
> Coordinates:
>             lat: [ -90..  90]
>             lon: [   0..357.5]
> Number Of Attributes: 3
>   _FillValue :  -9.969209968386869e+36
>   long_name :   maximum eady growth rate
>   units :
> (0)     maximum eady growth rate : min=nan   max=nan
>
>
> Any advice is much appreciated
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>


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

C.E.O, Weather It Is, LTD
Weather and Climate Focus
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: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180822/037ecf8f/attachment.html>


More information about the ncl-talk mailing list