Skip to content

Commit

Permalink
Always set the bounding box on the forward transform.
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Nov 21, 2024
1 parent bd9ba38 commit e7f299f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions gwcs/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,20 @@ def set_transform(self, from_frame, to_frame, transform):
def forward_transform(self):
"""
Return the total forward transform - from input to output coordinate frame.
"""

if self._pipeline:
#return functools.reduce(lambda x, y: x | y, [step[1] for step in self._pipeline[: -1]])
return functools.reduce(lambda x, y: x | y, [step.transform for step in self._pipeline[:-1]])
else:
if not self._pipeline:
return None

transform = functools.reduce(lambda x, y: x | y, [step.transform for step in self._pipeline[:-1]])

if self.bounding_box is not None:
# Currently compound models do not attempt to combine individual model
# bounding boxes. Get the forward transform and assign the bounding_box to it
# before evaluating it. The order Model.bounding_box is reversed.
transform.bounding_box = self.bounding_box

return transform

@property
def backward_transform(self):
"""
Expand Down Expand Up @@ -354,12 +359,6 @@ def __call__(self, *args, **kwargs):
if 'fill_value' not in kwargs:
kwargs['fill_value'] = np.nan

if self.bounding_box is not None:
# Currently compound models do not attempt to combine individual model
# bounding boxes. Get the forward transform and assign the bounding_box to it
# before evaluating it. The order Model.bounding_box is reversed.
transform.bounding_box = self.bounding_box

result = transform(*args, **kwargs)

if with_units:
Expand Down Expand Up @@ -1287,6 +1286,10 @@ def bounding_box(self):

frames = self.available_frames
transform_0 = self.get_transform(frames[0], frames[1])

if transform_0 is None:
return None

try:
bb = transform_0.bounding_box
except NotImplementedError:
Expand Down

0 comments on commit e7f299f

Please sign in to comment.