[Thread Prev][Thread Next][Index]

Re: @max function



Hi Jimmy,
If you're looking for just a single value at one point in X and Y (and T, if there's a time variation), you can get the K value as

let varmax =var[i=1:350,j=1:308,k=1:31@max]
list varmax

! this is a list in Z, all missing except at the level where val is its max.

let k_at_max = if var[i=1:350,j=1:308] eq varmax then K[gz=var] list k_at_max[k=@max]

! k_at_max contains the index where var is its max, but it is still a list in Z.
! take the maximum value of this list, and we have the single K you want.

let a=var[i=1:350,j=1:308,k=1:31@max]*rho[i=1:350,j=1:308,k=`k_at_max[k=@max]`]

If you wanted to do this for a field of values, to get the values of RHO at the levels where VAR is its max, then this can be done with a mask. I'll show an example using the levitus_climatology dataset, which comes with the Ferret distribution and has variation in depth. We'll compute SALT[k=@max] * TEMP[k="where salt is max"] -- equivalent to what you're trying to do.

Define a variable which is SALT at its maximum over depth, at each x,y location

use levitus_climatology
let saltmax = salt[k=@max]

We want the value of TEMP at the depths where salt is its max. The following mask is 1 where SALT is max, and missing everywhere else (in X, Y, and Z)

let mask = if salt eq saltmax then 1
let masked_temp = mask* temp

Take a look at these, in a slice along the equator

shade/y=0 mask
shade/y=0 masked_temp

masked_temp has the value of temp at each x and y, and at the depth where salt is at its max. But it still depends on depth. The variable saltmax we defined above does not depend on Z. We can use the function COMPRESSK to bring the good data in masked_temp to level K=1, and we're done.

let compressed_masked_temp = compressk(masked_temp)
let myvar = saltmax * compressed_masked_temp[k=1]
shade myvar

Note you can look at what the values of K are where SALT is its max,

let kdepths = if salt eq saltmax then k[g=salt] ! or try z[g=salt]
shade/k=1 compressk( kdepths)
Ansley

jimmyc@iastate.edu wrote:

Hello-
I am searching over a 2d grid and defining the maximum value of a variable in the 3rd dimension.
let a=var[i=1:350,j=1:308,k=1:31@max]

how do I then use the k level that has the max value for variable var as an arguement for another variable to do this:
let a=var[i=1:350,j=1:308,k=1:31@max]*rho[i=1:350,j=1:308,k= ??]

any ideas are greatly appreciated.
Thanks for reading








[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement