MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / _clip_selection

Function _clip_selection

pyxrf/gui_module/tests/test_useful_widgets.py:331–345  ·  view source on GitHub ↗

Clip the selection values to compute the expected selection. Reproduces the clipping performed by the RangeManager.

(sel, rng, selection_to_range_min)

Source from the content-addressed store, hash-verified

329 rman.set_range(full_range[0], full_range[1])
330
331 def _clip_selection(sel, rng, selection_to_range_min):
332 """
333 Clip the selection values to compute the expected selection.
334 Reproduces the clipping performed by the RangeManager.
335 """
336 sel = [max(min(_, rng[1]), rng[0]) for _ in sel]
337 if value_type == "float":
338 min_diff = (rng[1] - rng[0]) * selection_to_range_min
339 else:
340 min_diff = 1
341 if sel[1] - sel[0] < min_diff:
342 sel[1] = sel[0] + min_diff
343 if sel[1] > rng[1]:
344 sel = [rng[1] - min_diff, rng[1]]
345 return sel
346
347 sel = _clip_selection(selection, full_range, selection_to_range_min)
348

Callers 2

test_RangeManager_3Function · 0.85
test_RangeManager_5Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected