def test_compound_bounding_box_pass_with_ignored(): model = models.Shift(1) & models.Shift(2) & models.Identity(1) model.inputs = ('x', 'y', 'slit_id') bbox = {(0,): (-0.5, 1047.5), (1,): (-0.5, 2047.5), } cbbox = CompoundBoundingBox.validate(model, bbox, selector_args=[('slit_id', True)], ignored=['y'], order='F') model.bounding_box = cbbox model = models.Shift(1) & models.Shift(2) & models.Identity(1) model.inputs = ('x', 'y', 'slit_id') bind_compound_bounding_box(model, bbox, selector_args=[('slit_id', True)], ignored=['y'], order='F') assert model.bounding_box == cbbox
def test_bind_compound_bounding_box_using_with_bounding_box_select(): """ This demonstrates how to bind multiple bounding_boxes which are selectable using the `with_bounding_box`, note there must be a fall-back to implicit. """ model = models.Gaussian1D() truth = models.Gaussian1D() bbox = (0, 1) with pytest.raises(AttributeError): bind_compound_bounding_box(model, bbox, 'x') bbox = {0: (-1, 0), 1: (0, 1)} bind_compound_bounding_box(model, bbox, [('x', False)]) # No bounding box assert model(-0.5) == truth(-0.5) assert model(0.5) == truth(0.5) assert model(0) == truth(0) assert model(1) == truth(1) # `with_bounding_box` selects as `-0.5` will not be a key assert model(-0.5, with_bounding_box=0) == truth(-0.5) assert np.isnan(model(-0.5, with_bounding_box=1)) # `with_bounding_box` selects as `0.5` will not be a key assert model(0.5, with_bounding_box=1) == truth(0.5) assert np.isnan(model(0.5, with_bounding_box=(0,))) # Fall back onto implicit selector assert model(0, with_bounding_box=True) == truth(0) assert model(1, with_bounding_box=True) == truth(1) # Attempt to fall-back on implicit selector, but no bounding_box with pytest.raises(RuntimeError): model(0.5, with_bounding_box=True) # Override implicit selector assert np.isnan(model(1, with_bounding_box=0))