Synopsis
Group into a fixed number of bins.
Syntax
group_bins(id, num=None, bkg_id=None, tabStops=None) id - int or str, optional num - int bkg_id - int or str, optional tabStops - str or array of int or bool, optional
Description
Combine the data so that there `num` equal-width bins (or groups). The binning scheme is, by default, applied to only the noticed data range. It is suggested that filtering is done before calling group_bins.
Examples
Example 1
Group the default data set so that there are 50 bins.
>>> group_bins(50)
Example 2
Group the 'jet' data set to 50 bins and plot the result, then re-bin to 100 bins and overplot the data:
>>> group_bins('jet', 50) >>> plot_data('jet') >>> group_bins('jet', 100) >>> plot_data('jet', overplot=True)
Example 3
The grouping is applied to only the data within the 0.5 to 8 keV range (this behaviour is new in 4.16):
>>> set_analysis('energy') >>> notice() >>> notice(0.5, 8) >>> group_bins(50) >>> plot_data()
Example 4
Group the full channel range and then apply the existing filter (0.5 to 8 keV) so that the noticed range may be larger (this was the default behaviour before 4.16):
>>> group_bins(50, tabStops="nofilter")
Example 5
Do not group any channels numbered less than 20 or 800 or more. Since there are 780 channels to be grouped, the width of each bin will be 20 channels and there are no "left over" channels:
>>> notice() >>> channels = get_data().channel >>> ign = (channels <= 20) | (channels >= 800) >>> group_bins(39, tabStops=ign) >>> plot_data()
PARAMETERS
The parameters for this function are:
Parameter | Definition |
---|---|
id | The identifier for the data set to use. If not given then the default identifier is used, as returned by `get_default_id` . |
num | The number of bins in the grouped data set. Each bin will contain the same number of channels. |
bkg_id | Set to group the background associated with the data set. When bkg_id is None (which is the default), the grouping is applied to all the associated background data sets as well as the source data set. |
tabStops | If not set then it will be based on the filtering of the data set, so that the grouping only uses the filtered data. If set it can be the string "nofilter", which means that no filter is applied (and matches the behavior prior to the 4.16 release), or an array of booleans where True indicates that the channel should not be used in the grouping (this array must match the number of channels in the data set). |
Notes
The function does not follow the normal Python standards for parameter use, since it is designed for easy interactive use. When called with a single un-named argument, it is taken to be the `num` parameter. If given two un-named arguments, then they are interpreted as the `id` and `num` parameters, respectively. The remaining parameters are expected to be given as named arguments.
Unlike `group` , it is possible to call `group_bins` multiple times on the same data set without needing to call `ungroup` .
Since the bin width is an integer number of channels, it is likely that some channels will be "left over". This is even more likely when the tabstops parameter is set. If this happens, a warning message will be displayed to the screen and the quality value for these channels will be set to 2. This information can be found with the `get_quality` command.
Changes in CIAO
Changed in CIAO 4.16
Grouping now defaults to only using the noticed channel range. The tabStops argument can be set to "nofilter" to use the previous behaviour.
The filter is now reported, noting any changes the new grouping scheme has made.
Bugs
See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.
See Also
- data
- copy_data, dataspace1d, dataspace2d, datastack, delete_data, fake, get_axes, get_bkg_chisqr_plot, get_bkg_delchi_plot, get_bkg_fit_plot, get_bkg_model_plot, get_bkg_plot, get_bkg_ratio_plot, get_bkg_resid_plot, get_bkg_source_plot, get_counts, get_data, get_data_contour, get_data_contour_prefs, get_data_image, get_data_plot, get_data_plot_prefs, get_dep, get_dims, get_error, get_grouping, get_quality, get_specresp, get_staterror, get_syserror, group, group_adapt, group_adapt_snr, group_counts, group_snr, group_width, load_ascii, load_data, load_grouping, load_quality, set_data, set_grouping, set_quality, ungroup, unpack_ascii, unpack_data
- filtering
- get_filter, ignore, ignore2d, ignore2d_id, ignore_bad, ignore_id, load_filter, notice, notice2d, notice2d_id, notice_id, set_filter, show_filter
- info
- get_default_id, list_data_ids, list_response_ids
- modeling
- clean
- plotting
- plot_data, set_xlinear, set_xlog, set_ylinear, set_ylog
- saving
- save_error, save_filter, save_grouping, save_quality, save_staterror, save_syserror
- utilities
- calc_data_sum, calc_data_sum2d, calc_ftest, calc_kcorr, calc_mlr, calc_model_sum2d, calc_source_sum2d, get_rate
- visualization
- contour, contour_data, contour_ratio, histogram1d, histogram2d, image_data, rebin