Difference between revisions of "Combine rebinning schemes"
Jump to navigation
Jump to search
(Created page with "In case you want to combine several rebinning schemes one can proceed as follows: <syntaxhighlight lang="c"> rebin_data(id, 0); % reset all binning lo = get_data(id).bin_lo;...") |
|||
Line 3: | Line 3: | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
rebin_data(id, 0); % reset all binning | rebin_data(id, 0); % reset all binning | ||
− | lo = | + | lo = get_rmf_data_grid(get_data_info(id).rmfs[0]).bin_lo; % get original data grid |
− | w = where(lo>_A(50), &nw); % get where grid is larger than 50keV and complement | + | w = where(lo>_A(50), &nw); % get where grid is larger than 50keV and complement, ATTENTION: do not apply _A() to 'lo', this will change the order |
rebin_data(id, 10); % rebin to at least 10 counts per bin | rebin_data(id, 10); % rebin to at least 10 counts per bin | ||
min10 = get_data_info(id).rebin; % store the binning | min10 = get_data_info(id).rebin; % store the binning | ||
rebin_dataset_optimal(id); % rebin optimal | rebin_dataset_optimal(id); % rebin optimal | ||
opt = get_data_info(id).rebin; % store binning | opt = get_data_info(id).rebin; % store binning | ||
− | rebin_data(id, [opt[nw] | + | % set combined binning, the array has to be in angstrom grid so pay attention to the ordering |
+ | rebin_data(id, [-sign(opt[nw][0]*min10[w][-1])*min10[w], opt[nw]]); % swap sign to keep regions distinct | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 20:48, 17 March 2021
In case you want to combine several rebinning schemes one can proceed as follows:
rebin_data(id, 0); % reset all binning
lo = get_rmf_data_grid(get_data_info(id).rmfs[0]).bin_lo; % get original data grid
w = where(lo>_A(50), &nw); % get where grid is larger than 50keV and complement, ATTENTION: do not apply _A() to 'lo', this will change the order
rebin_data(id, 10); % rebin to at least 10 counts per bin
min10 = get_data_info(id).rebin; % store the binning
rebin_dataset_optimal(id); % rebin optimal
opt = get_data_info(id).rebin; % store binning
% set combined binning, the array has to be in angstrom grid so pay attention to the ordering
rebin_data(id, [-sign(opt[nw][0]*min10[w][-1])*min10[w], opt[nw]]); % swap sign to keep regions distinct
In this case rebin_dataset_optimal is used together with the 'standard' rebinning to at least n counts per bin. It is to say that rebin_dataset_optimal uses a numerically optimized way to reduce data size vs data loss and should *not* be changed for analyses purposes. But, e.g., for plotting the resulting spectrum might not look nice. Note also that this only works for schemes and data that where not rebinned on a new grid. In that case the original binning can not be restored.