Re: how to know the (i,j)or (lat,lon) of the max

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Jul 01 2014 - 09:18:17 MDT

To get the max index out of a 2D array, you need to use a combination of
ndtooned, maxind, and ind_resolve.

If "qi" is the variable you want the maximum from, then here's a three-step
process.

    dims = dimsizes(qi) ; 1D array containing the three dimension sizes

    qi1d = ndtooned(qi(it,:,:)) ; convert to one-dimensional array
    ii = maxind(qi1d) ; get index where first maximum value
occurs
    ij= ind_resolve(ii,dims) ; resolve back to original 2D array ind=
ex
locations

The "ij" should be a 1 x 2 array, where ij(0,0) is the index of the middle
dimension, and ij(0,1) is the index of the rightmost dimension of "qi"

Here's one-step process you can use:

    ij= ind_resolve(maxind(ndtooned(qi(it,:,:))),dims(1:2))

You can print the results with:

    print("max qi = " + qi(it,ij(0,0),ij(0,1)) + " at indexes " + ij(0,0)=
 +
"," + ij(0,1))

To then get the lat,lon location of this ij location, use wrf_user_ij_to_ll

    latlon = wrf_user_ij_to_ll(a, ij(0,0), ij(0,1), True)

    print("lon location is: " + latlon(0))

    print("lat location is: " + latlon(1))

--Mary


On Tue, Jul 1, 2014 at 2:25 AM, grace <313695096@qq.com> wrote:

> Hi,all
> I have calculated the max Qgraup of each time from the wrfout data with
> the following program,
> but how can I know the (i,j)or (lat,lon) of the max ‍Qgraup of e=
ach time?
> ‍
> any information will be appreciated!
>
> ascii_file = "shishidataGRAUP1B333.txt"
> str = new(ntimes, "string")
> ‍ do it =0, ntimes-1,1 ; TIME LOOP
>
> print("Working on time: " + times(it) )
> res@TimeLabel = times(it) ; Set Valid time to use on plots
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ; First get the variables we will need
> if(isfilevar(a,"QGRAUP"))
> qi = wrf_user_getvar(a,"QGRAUP",it)
> qi = qi*1000.
> qi@units = "g/kg"
> qis=dim_max_n_Wrap(qi(13:15,:,:),0)
> end if
> ;print(qis)
> printVarSummary(qis)
> wmax1 = dim_max_n_Wrap(qis(:,:),0)
> ;print(wmax1)
> printVarSummary(wmax1)
> wmax2 = dim_max_n_Wrap(qis,0)
> ;print(wmax2)
> printVarSummary(wmax2)
> wmax=max(wmax2)‍
> str(it) = sprintf("%12.8f", wmax)‍
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

Received on Tue Jul 01 03:18:17 2014

This archive was generated by hypermail 2.1.8 : Wed Jul 23 2014 - 15:33:46 MDT