Skip to the navigation links
Last modified: December 2009

AHELP for CIAO 4.2


Context: group


Apply the supplied grouping to an array.


Array_Type grpdata = grpGetGroupSum( Array_Type dataArray, Array_Type
grouping )


This function applies the grouping information from the grouping parameter to the dataArray parameter. The return value is an array whose length equals that of the input data (the dataArray argument) and each element within a group contains the same value. As an example,

grpGetGroupSum( [1,2,3,4,5,6], [1,-1,1,-1,1,1] )

will return the array


since the groups consist of the first two elements, then the next two elements, with the last two elements being un-grouped.

The group module is not available by default; to use it in a S-Lang program, it must be loaded using the S-Lang require() function:


Example 1

slsh> ysum = grpGetGroupSum( y, grp );

The ysum array will contain the data from the y array after the grouping scheme stored in the grp array is applied to it. The ysum array will have the same size as the y array. The following code shows you how you can convert ysum into an array in which each element corresponds to one group.

slsh> i = where( grp == 1 );
slsh> ygrp = ysum[i];

Here we created an array i whose elements correspond to those elements in the grp array with a value of 1 (this marks the start of a group). The ygrp array is then created by using this array to extract the corresponding elements from the ysum array. It could have been written in one line as:

slsh> ygrp = ysum[ where( grp == 1 ) ];

Example 2

slsh> x = [0.5:6.0:0.05];
slsh> y = 3 + 30 * exp( - (x-2.0)^2 / 0.1 );
slsh> ( grp, qual ) = grpNumCounts( y, 15 );
slsh> ysum = grpGetGroupSum( y, grp );
slsh> nchan = grpGetChansPerGroup( grp );
slsh> i = where( grp == 1 and qual == 0 );
slsh> xstart = x[i];
slsh> yavg = ysum[i] / nchan[i];

Here we take the function

y = 3 + 30 * exp( -(x-2)^2 / 0.1 )

and group it by 15 counts per group. We then filter the summed array (ysum) so that it corresponds to only those elements at the start of a group - the

grp == 1

condition - and for which the quality flag is "good" - which is given by

qual == 1

This array is divided by the number of elements in each group to calculate the average value in the group. Note that the xstart array gives the start position of each group.


See the bugs page for the group library on the CIAO website for an up-to-date listing of known bugs.

See Also

grpadaptive, grpadaptivesnr, grpbin, grpbinfile, grpbinwidth, grpgetchanspergroup, grpgetgroupsum, grpgetgrpnum, grpmaxslope, grpminslope, grpnumbins, grpnumcounts, grpsnr

Last modified: December 2009