Re: create array of max value in vertical for multi-dimensional array

From: Chris Herbster <herbstec_at_nyahnyahspammersnyahnyah>
Date: Tue Jan 10 2012 - 14:11:18 MST

Thanks Dave/Dennis,

Sorry, it is always a bad idea to try to ask a question just before
going to bed. (-:

Dave figured out what I was trying to say, thanks!

I don't know how I missed the dim_max_n function! That is exactly what
I needed. Thanks again!

I'll ask my next question in a new thread.

Chris H.

-- 
  Dr. Christopher G. Herbster
  Associate Professor
  Director of Science and Technology
  for the ERAU Weather Center
  Applied Aviation Sciences
  Embry-Riddle Aeronautical Univ.
  600 S. Clyde Morris Blvd.
  Daytona Beach, FL 32114-3900
  386.226.6444 Office
  386.226.6446 Weather Center
  http://wx.erau.edu/
Schedule at:  http://wx.erau.edu/faculty/herbster/Schedules/
On 01/10/2012 10:42 AM, Dennis Shea wrote:
> Like DA, I had trouble understanding the question.
>
>
> As DA suggested,
> http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_max_n.shtml
>
>    x(time,level,lat,lon)
>        0    1    2   3
>
> Is this what you want:
>
>   xmax = dim_max_n( x, (/2,3/))    ; (ntim,klev)
>
>   printVarSummary(xmax)
>
>
>
> On 1/9/12 11:28 PM, Dave Allured wrote:
>> So you are inside a loop over jj, and you want to repeat this
>> calculation for each jj?  In other words, you want a 2-D result, but
>> you want to repeat that 2-D result for the number of time steps?
>>
>> If so, I think you want this inside the time loop. Note that maxZ will
>> be overwritten with new values on each iteration:
>>
>> dim_level = 1
>> maxZ = dim_max_n (x (jj,0:29,:,:), dim_level)
>>
>> Or perhaps this would be simpler if you are not really trying to
>> constrain to the first 30 levels:
>>
>> dim_level = 1
>> maxZ = dim_max_n (x (jj,:,:,:), dim_level)
>>
>> Reference:
>> http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_max_n.shtml
>>
>> --Dave
>>
>> On Mon, Jan 9, 2012 at 10:14 PM, Chris Herbster<herbstec@erau.edu>  
>> wrote:
>>> Hi folks,
>>>
>>> I may have tried the wrong search terms while looking for this in the
>>> archives, but perhaps I can get a quick solution to my quest.
>>>
>>> I would like to obtain the max value at each horizontal point in a
>>> multi-dimensional array for each time.
>>>
>>> The array is x(time,level,lat,lon) and I am looking for the max value
>>> for a given time (set with an index value) for each lat/lon location.
>>> Obviously when I use the max function on the array I get a scalar
>>> result.  I'd like the scalar result for each location in the 
>>> horizontal.
>>>
>>> I want to obtain a 2D array out of a 4D array, but I have a loop (on 
>>> jj)
>>> that sets the time element to a specific index.  I tried:
>>>
>>> maxZ(:,:) = max (x (jj,0:29,:,:)
>>>      where jj is a loop over the 24 hours, the second index is Z, the
>>> range I want the max value out of, and the last two are the lat and 
>>> long
>>> index values.
>>>
>>> That gave an error about maxZ not existing.  Is the fix as simple as
>>> creating the array with the correct dimensions?
>>>
>>> Of course when I tried to do this without an index placeholder then 
>>> maxZ
>>> is a scalar and I can't plot that on a map.
>>>
>>> I'm almost certain there is a way to do this without having nested 
>>> loops
>>> on the x and y variables.
>>>
>>> Thanks for the help!
>>>
>>> Chris Herbster
>>>
>>> -- 
>>>
>>>   Dr. Christopher G. Herbster
>>>   Associate Professor
>>>   Director of Science and Technology
>>>   for the ERAU Weather Center
>>>   Applied Aviation Sciences
>>>   Embry-Riddle Aeronautical Univ.
>>>   600 S. Clyde Morris Blvd.
>>>   Daytona Beach, FL 32114-3900
>>>
>>>   386.226.6444 Office
>>>   386.226.6446 Weather Center
>>>   http://wx.erau.edu/
>>>
>>> Schedule at:  http://wx.erau.edu/faculty/herbster/Schedules/
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jan 10 14:11:28 2012

This archive was generated by hypermail 2.1.8 : Wed Jan 18 2012 - 09:21:55 MST