The function computes the range of indices based on the selected energy range and parameters for the energy axis. Parameters ---------- e_low, e_high: float or None Energy values (in keV) that set the selected range n_indexes: int
(self, *, e_low=None, e_high=None, n_indexes=None, margin=2.0)
| 1381 | # Functions for plotting spectrum preview |
| 1382 | |
| 1383 | def selected_range_indices(self, *, e_low=None, e_high=None, n_indexes=None, margin=2.0): |
| 1384 | """ |
| 1385 | The function computes the range of indices based on the selected energy range |
| 1386 | and parameters for the energy axis. |
| 1387 | |
| 1388 | Parameters |
| 1389 | ---------- |
| 1390 | e_low, e_high: float or None |
| 1391 | Energy values (in keV) that set the selected range |
| 1392 | n_indexes: int |
| 1393 | Total number of indexes in the energy array (typically 4096) |
| 1394 | margin: float |
| 1395 | The displayed energy range is extended by the value of `margin` in both directions. |
| 1396 | |
| 1397 | Returns |
| 1398 | ------- |
| 1399 | n_low, n_high: int |
| 1400 | The range of indices of the energy array (n_low..n_high-1) that cover the selected energy range |
| 1401 | """ |
| 1402 | # The range of energy selected for analysis |
| 1403 | if e_low is None: |
| 1404 | e_low = self.param_model.param_new["non_fitting_values"]["energy_bound_low"]["value"] |
| 1405 | if e_high is None: |
| 1406 | e_high = self.param_model.param_new["non_fitting_values"]["energy_bound_high"]["value"] |
| 1407 | # Protection for the case if e_high < e_low |
| 1408 | e_high = e_high if e_high > e_low else e_low |
| 1409 | # Extend the range (by the value of 'margin') |
| 1410 | e_low, e_high = e_low - margin, e_high + margin |
| 1411 | |
| 1412 | # The following calculations ignore quadratic term, which is expected to be small |
| 1413 | c0 = self.param_model.param_new["e_offset"]["value"] |
| 1414 | c1 = self.param_model.param_new["e_linear"]["value"] |
| 1415 | # If more precision if needed, then implement more complicated algorithm using |
| 1416 | # the quadratic term: c2 = self.param_model.param_new['e_quadratic']['value'] |
| 1417 | |
| 1418 | n_low = int(np.clip(int((e_low - c0) / c1), a_min=0, a_max=n_indexes - 1)) |
| 1419 | n_high = int(np.clip(int((e_high - c0) / c1) + 1, a_min=1, a_max=n_indexes)) |
| 1420 | |
| 1421 | return n_low, n_high |
| 1422 | |
| 1423 | def _datasets_max_size(self, *, only_displayed=True): |
| 1424 | """ |
no outgoing calls
no test coverage detected