Chandra X-Ray Observatory
	(CXC)
Skip to the navigation links
Last modified: December 2013

URL: http://cxc.harvard.edu/ciao/ahelp/grpgetchanspergroup.html
Jump to: Description · Examples · Bugs · See Also


AHELP for CIAO 4.9

grpGetChansPerGroup

Context: group

Synopsis

Calculate the number of channels (elements) in each group.

Syntax

PyArray_Type chanspergrp = grpGetChansPerGroup( PyArray_Type grouping )

Description

This function returnes the number of channels (i.e. elements) in each group. 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,

grpGetChansPerGroup( [1,-1,1,-1,1,1] )

will return the array

[2,2,2,2,1,1]

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 Python program, it must be loaded using the Python import function:

  from group import *, or import group

Example 1

>>> nchan = grpGetChansPerGroup( grp )

The nchan array will contain the number of elements in each group, as given in the grouping scheme stored in the grp array. The nchan array will have the same size as the grp array. The following code shows you how you can convert nchan into an array in which each element corresponds to one group.

>>> i = numpy.where( grp == 1 );
>>> nelem = nchan[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 nelem array is then created by using this array to extract the corresponding elements from the ncham array. It could have been written in one line as:

>>> nelem = nchan[ numpy.where( grp == 1 ) ];

Example 2

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

Here we take the function

y = 3 + 30 * numpy.exp( - (x-2.0)**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.

Example 3

To see more examples of optional parameters and keywords in the parameter list, please see ahelp grpadaptive

Bugs

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

Refer to the CIAO bug pages for an up-to-date listing of known issues.

See Also

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

Last modified: December 2013
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email:   cxchelp@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2017. All rights reserved.