Re: ind of any or any of any?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Sep 17 2013 - 21:42:25 MDT

Hi Kristina,

I get what you are asking for, but I'm not sure there's any easy way to do this.

It might help if you can describe what kind of array you are trying to subset (i.e. what are its dimensions, and how is the time dimension structured), because there may be other ways you can subset it.

Sometimes "reshape" can be useful in a case like this.

For example, say you have an array x that is dimensioned time x lat x lon, that contains monthly data across several years, starting in January and ending in December. Assume that you want to subset the array for January, February, and March.

You can first use "reshape" to reshape the array into years x months x lat x lon:

  nyears = ntim/12
  x4d = reshape(x,(/nyears,12,nlat,nlon/))

and then subset the array for Jan-Mar and reshape again:

  xjfm = reshape(x4d(:,0:2,:,:),(/nyears*3,nlat,nlon/))

Maybe something like this will work for you, if you have a "nice" array with values for every month of every year.

--Mary

On Sep 17, 2013, at 7:18 AM, Kristina Fröhlich <kristina_froehlich@yahoo.de> wrote:

> Dear all,
>
> I wonder if there is a functionality that allows me to use the functions ind or any by using a list of values.
>
> At the moment, its possible to select a specific value of or a well defined portion out of a field like in the example
>
>
> x = new(5,float,-999)
> x = (/1.,2.,-999,4.,5./)
>
>
> print(any
> (x.ge.4)) ; should be True
>
> print(any
> (x.lt.0)) ; should be False
>
> print(any(x.gt.2.and.x.lt.4)) ; should be False
>
>
> but what happens if I want to select a (bigger) list of values which are not necessarily
> ordered monotonically increasing or decreasing?
>
> For instance, I have a time series of monthly means over several years and now want to get out specific months
> (e.g. monlist=(/5,6,7,8,9,10,11/) ) per year. At the moment I need to write
>
>
> SEASlist=ind( ( (omonth .ge. 5) .and. (omonth .le. 11))
> )
>
>
> or
>
> monlist=(/11,12,1,2,3,4,5/)
> SEASlist=ind( ( (omonth .le. 5) .or.( omonth .ge. 11)) )
>
>
> but you see, that the procedure is crucially dependent on which months I do start with my timeseries and how
> many months I want to have.
>
> Trying the function "all" like
> " mylist = ind(omonth .eq. all(monlist))"
>
> unfortunately does not help.
>
>
> I would be happy if something would work
> like
>
>
> monlist=(/11,12,1,2,3,4/)
> SEASlist=ind( ( omonth .eq. any/all(monlist) )
>
>
> Is there an elegant way to do this?
>
>
> best regards, Kristina
>
>
>
> _______________________________________________
> 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 Sep 17 21:42:35 2013

This archive was generated by hypermail 2.1.8 : Wed Sep 18 2013 - 17:07:30 MDT