@@ -170,6 +170,65 @@ def shape_native(self) -> Tuple[int, int]:
170170 region = self .region
171171 return (region [1 ] - region [0 ], region [3 ] - region [2 ])
172172
173+ def extent_from (self , buffer : int = 1 ) -> np .ndarray :
174+ """
175+ For an extracted zoomed array computed from the method *zoomed_around_mask* compute its extent in scaled
176+ coordinates.
177+
178+ The extent of the grid in scaled units returned as an ``ndarray`` of the form [x_min, x_max, y_min, y_max].
179+
180+ This is used visualize zoomed and extracted arrays via the imshow() method.
181+
182+ Parameters
183+ ----------
184+ buffer
185+ The number pixels around the extracted array used as a buffer.
186+ """
187+ from autoarray .mask .mask_2d import Mask2D
188+
189+ extracted_array_2d = array_2d_util .extracted_array_2d_from (
190+ array_2d = np .array (self .mask ),
191+ y0 = self .region [0 ] - buffer ,
192+ y1 = self .region [1 ] + buffer ,
193+ x0 = self .region [2 ] - buffer ,
194+ x1 = self .region [3 ] + buffer ,
195+ )
196+
197+ mask = Mask2D .all_false (
198+ shape_native = extracted_array_2d .shape ,
199+ pixel_scales = self .mask .pixel_scales ,
200+ origin = self .centre ,
201+ )
202+
203+ return mask .geometry .extent
204+
205+ def mask_2d_from (self , buffer : int = 1 ) -> "Mask2D" :
206+ """
207+ Extract the 2D region of a mask corresponding to the rectangle encompassing all unmasked values.
208+
209+ This is used to extract and visualize only the region of an image that is used in an analysis.
210+
211+ Parameters
212+ ----------
213+ buffer
214+ The number pixels around the extracted array used as a buffer.
215+ """
216+ from autoarray .mask .mask_2d import Mask2D
217+
218+ extracted_mask_2d = array_2d_util .extracted_array_2d_from (
219+ array_2d = np .array (self .mask ),
220+ y0 = self .region [0 ] - buffer ,
221+ y1 = self .region [1 ] + buffer ,
222+ x0 = self .region [2 ] - buffer ,
223+ x1 = self .region [3 ] + buffer ,
224+ )
225+
226+ return Mask2D (
227+ mask = extracted_mask_2d ,
228+ pixel_scales = self .mask .pixel_scales ,
229+ origin = self .mask .origin ,
230+ )
231+
173232 def array_2d_from (self , array : Array2D , buffer : int = 1 ) -> Array2D :
174233 """
175234 Extract the 2D region of an array corresponding to the rectangle encompassing all unmasked values.
0 commit comments