Re: function to calculate colormap index values from a data array and colormap?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Aug 22 2011 - 07:40:25 MDT

Hi Ryan,

We don't have a built-in function for this, but I think you could easily use the "ind" function for something like this, depending on how you want your values grouped.

For example, if your 2D array is called "x", and your levels are called "levels", then (untested):

;---Working with 1D arrays is easier
index_vals_1d = new(dimsizes(product(x)),integer) ; Start with 1D array
x1d = ndtooned(x)

;---Loop across rest of dimensions and assign index values for middle contour levels
nlevels = dimsizes(levels)
do i=0,nlevels-1
  if(i.eq.0) then
    ii = ind(
    if(i.eq.(nlevels-1)) then
      ii = ind(
      ii = ind(levels(i-1)
    end if
  end if
  if(.not.any(ismissing(ii))) then
    indes_vals_1d(ii) = i+2 ; or whatever color index you want
  end if
end do
delete(x1d) ; Don't need this any more.

index_vals_2d = onedtond(index_vals_1d,dimsizes(x)) ; Convert to 2D


On Aug 17, 2011, at 6:46 AM, Ryan Pavlick wrote:

> Hi,
> I was wondering if anyone on this list has written a function that
> takes a 2d data array and a colormap and produces a 2d array
> containing the corresponding colormap index values?
> Thanks,
> Ryan
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:

ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Mon Aug 22 07:40:33 2011

This archive was generated by hypermail 2.1.8 : Mon Aug 22 2011 - 08:13:37 MDT