Re: speed up maxind loop?

From: Hobbs, Will R (3244-CalTech) <William.R.Hobbs_at_nyahnyahspammersnyahnyah>
Date: Fri Dec 17 2010 - 11:36:31 MST

Axel

You have a couple of options; the first being to write your own dim_maxind_n function!

The second would be to remove as many operations as possible from the loop; for example the statement ' zcdepth(j,i) = (/ zctop(j,i) - zcbase(j,i) /)' would be better after the loop has closed. There are a few places where you could do similar things (another example is subtracting 1e-6 from cwc before the loop starts; that's one operation as opposed to xdim*ydim operations).

I also notice an error in one of your lines that might be really slowing you down:

     ktop(j,i) = kwmax(j,i) - minind(cwc(kwmax(j,i):0,j,i) - 1e-6)

SHOULD read:

     ktop(j,i) = kwmax(j,i) - minind(cwc(0:kwmax(j,i),j,i) - 1e-6) ;order of the zero in indexing cwc has changed.

I 'speculate' that because the indexing has been inverted, NCL might be doing an unnecessary reversal at every time step

Will

On 12/17/10 6:57 AM, "Axel Seifert" <Axel.Seifert@dwd.de> wrote:

Hi NCL folks:

I am using maxind and minind to measure cloud depth in CRM data. This
works fine, but it is kind of slow. Unfortunately, maxind and minind do
not support multidimensional arrays. There is no dim_maxind_n available,
is there?

This is the loop that I want to speed up (I have some TB of data to analyze):

      print(" calculate convective cloud depth (please be patient, this can be slow)")
      do i=0,xdim-1
        do j=0,ydim-1

; find maximum of vertical velocity in the updraft
          kwmax(j,i) = maxind(w(:,j,i))

          if (.not.ismissing(kwmax(j,i))) then
; find cloud top and cloud base starting from max updraft position
            ktop(j,i) = kwmax(j,i) - minind(cwc(kwmax(j,i):0,j,i) - 1e-6)
            kbase(j,i) = kwmax(j,i) + minind(cwc(kwmax(j,i):,j,i) - 1e-6)

; store geometric height of cloud base, top and depth
            zctop(j,i) = (/ z(ktop(j,i),j,i) /)
            zcbase(j,i) = (/ z(kbase(j,i),j,i) /)
            zcdepth(j,i) = (/ zctop(j,i) - zcbase(j,i) /)
          end if

        end do
      end do

Cheers, Axel

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

**********************************************************
Will Hobbs, Ph.D. William.R.Hobbs@jpl.nasa.gov
Jet Propulsion Laboratory
4800 Oak Grove Dr. office: 300-324a
M/S 300-323 phone: (818) 354-0466
Pasadena, CA 91109 fax: (818) 354-0966
**********************************************************

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Dec 17 11:36:41 2010

This archive was generated by hypermail 2.1.8 : Wed Dec 22 2010 - 16:10:23 MST