Skip to content

Commit c4bca0e

Browse files
Jammy2211Jammy2211
authored andcommitted
add new functions to Zoom2D
1 parent ff27742 commit c4bca0e

File tree

18 files changed

+136
-73
lines changed

18 files changed

+136
-73
lines changed

autoarray/geometry/geometry_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def convert_pixel_scales_2d(pixel_scales: ty.PixelScales) -> Tuple[float, float]
182182

183183
@numba_util.jit()
184184
def central_pixel_coordinates_2d_from(
185-
shape_native: Tuple[int, int]
185+
shape_native: Tuple[int, int],
186186
) -> Tuple[float, float]:
187187
"""
188188
Returns the central pixel coordinates of a 2D geometry (and therefore a 2D data structure like an ``Array2D``)
@@ -737,7 +737,7 @@ def grid_pixel_centres_2d_from(
737737

738738

739739
def extent_symmetric_from(
740-
extent: Tuple[float, float, float, float]
740+
extent: Tuple[float, float, float, float],
741741
) -> Tuple[float, float, float, float]:
742742
"""
743743
Given an input extent of the form (x_min, x_max, y_min, y_max), this function returns an extent which is

autoarray/inversion/inversion/abstract.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,12 @@ def reconstruction(self) -> np.ndarray:
509509

510510
solutions = np.zeros(np.shape(self.curvature_reg_matrix)[0])
511511

512-
solutions[
513-
values_to_solve
514-
] = inversion_util.reconstruction_positive_only_from(
515-
data_vector=data_vector_input,
516-
curvature_reg_matrix=curvature_reg_matrix_input,
517-
settings=self.settings,
512+
solutions[values_to_solve] = (
513+
inversion_util.reconstruction_positive_only_from(
514+
data_vector=data_vector_input,
515+
curvature_reg_matrix=curvature_reg_matrix_input,
516+
settings=self.settings,
517+
)
518518
)
519519
return solutions
520520
else:

autoarray/inversion/inversion/imaging/abstract.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ def operated_mapping_matrix_list(self) -> List[np.ndarray]:
104104
"""
105105

106106
return [
107-
self.convolver.convolve_mapping_matrix(
108-
mapping_matrix=linear_obj.mapping_matrix
107+
(
108+
self.convolver.convolve_mapping_matrix(
109+
mapping_matrix=linear_obj.mapping_matrix
110+
)
111+
if linear_obj.operated_mapping_matrix_override is None
112+
else self.linear_func_operated_mapping_matrix_dict[linear_obj]
109113
)
110-
if linear_obj.operated_mapping_matrix_override is None
111-
else self.linear_func_operated_mapping_matrix_dict[linear_obj]
112114
for linear_obj in self.linear_obj_list
113115
]
114116

@@ -156,9 +158,9 @@ def linear_func_operated_mapping_matrix_dict(self) -> Dict:
156158
mapping_matrix=linear_func.mapping_matrix
157159
)
158160

159-
linear_func_operated_mapping_matrix_dict[
160-
linear_func
161-
] = operated_mapping_matrix
161+
linear_func_operated_mapping_matrix_dict[linear_func] = (
162+
operated_mapping_matrix
163+
)
162164

163165
return linear_func_operated_mapping_matrix_dict
164166

autoarray/inversion/pixelization/border_relocator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ def sub_border_pixel_slim_indexes_from(
117117
int(border_pixel)
118118
]
119119

120-
sub_border_pixels[
121-
border_1d_index
122-
] = grid_2d_util.furthest_grid_2d_slim_index_from(
123-
grid_2d_slim=sub_grid_2d_slim,
124-
slim_indexes=sub_border_pixels_of_border_pixel,
125-
coordinate=mask_centre,
120+
sub_border_pixels[border_1d_index] = (
121+
grid_2d_util.furthest_grid_2d_slim_index_from(
122+
grid_2d_slim=sub_grid_2d_slim,
123+
slim_indexes=sub_border_pixels_of_border_pixel,
124+
coordinate=mask_centre,
125+
)
126126
)
127127

128128
return sub_border_pixels

autoarray/inversion/pixelization/mesh/mesh_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@numba_util.jit()
99
def rectangular_neighbors_from(
10-
shape_native: Tuple[int, int]
10+
shape_native: Tuple[int, int],
1111
) -> Tuple[np.ndarray, np.ndarray]:
1212
"""
1313
Returns the 4 (or less) adjacent neighbors of every pixel on a rectangular pixelization as an ndarray of shape

autoarray/inversion/plot/inversion_plotters.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,9 @@ def figures_2d_of_pixelization(
215215
"inversion"
216216
]["reconstruction_vmax_factor"]
217217

218-
self.mat_plot_2d.cmap.kwargs[
219-
"vmax"
220-
] = reconstruction_vmax_factor * np.max(
221-
self.inversion.reconstruction
218+
self.mat_plot_2d.cmap.kwargs["vmax"] = (
219+
reconstruction_vmax_factor
220+
* np.max(self.inversion.reconstruction)
222221
)
223222
vmax_custom = True
224223

autoarray/mask/derive/zoom_2d.py

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
if TYPE_CHECKING:
66
from autoarray.structures.arrays.uniform_2d import Array2D
7+
from autoarray.mask.mask_2d import Mask2D
78

89
from autoarray.structures.arrays import array_2d_util
910
from autoarray.structures.grids import grid_2d_util
@@ -18,7 +19,7 @@ def __init__(self, mask: Union[np.ndarray, List]):
1819
1920
A `Mask2D` masks values which are associated with a uniform 2D rectangular grid of pixels, where unmasked
2021
entries (which are `False`) are used in subsequent calculations and masked values (which are `True`) are
21-
omitted (for a full description see the :meth:`Mask2D` class API
22+
omitted (for a full description see the :meth:`Mask2D` class API
2223
documentation <autoarray.mask.mask_2d.Mask2D.__new__>`).
2324
2425
The `Zoom2D` object calculations many different zoomed in qu
@@ -170,7 +171,66 @@ def shape_native(self) -> Tuple[int, int]:
170171
region = self.region
171172
return (region[1] - region[0], region[3] - region[2])
172173

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

195-
mask = Mask2D.all_false(
196-
shape_native=extracted_array_2d.shape,
255+
extracted_mask_2d = array_2d_util.extracted_array_2d_from(
256+
array_2d=np.array(self.mask),
257+
y0=self.region[0] - buffer,
258+
y1=self.region[1] + buffer,
259+
x0=self.region[2] - buffer,
260+
x1=self.region[3] + buffer,
261+
)
262+
263+
mask = Mask2D(
264+
mask=extracted_mask_2d,
197265
pixel_scales=array.pixel_scales,
198266
origin=array.mask.mask_centre,
199267
)
200268

201-
arr = array_2d_util.convert_array_2d(
202-
array_2d=extracted_array_2d, mask_2d=mask
203-
)
269+
arr = array_2d_util.convert_array_2d(array_2d=extracted_array_2d, mask_2d=mask)
204270

205-
return Array2D(values=arr, mask=mask, header=array.header)
271+
return Array2D(values=arr, mask=mask, header=array.header)

autoarray/mask/mask_1d_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ def native_index_for_slim_index_1d_from(
8080
native_index_for_slim_index_1d[slim_index] = x
8181
slim_index += 1
8282

83-
return native_index_for_slim_index_1d
83+
return native_index_for_slim_index_1d

autoarray/mask/mask_2d_util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,7 @@ def elliptical_radius_from(
316316
y_scaled_elliptical = r_scaled * np.sin(theta_rotated)
317317
x_scaled_elliptical = r_scaled * np.cos(theta_rotated)
318318

319-
return np.sqrt(
320-
x_scaled_elliptical**2.0 + (y_scaled_elliptical / axis_ratio) ** 2.0
321-
)
319+
return np.sqrt(x_scaled_elliptical**2.0 + (y_scaled_elliptical / axis_ratio) ** 2.0)
322320

323321

324322
@numba_util.jit()

autoarray/operators/convolver.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ def __init__(self, mask, kernel):
215215
mask_index_array=self.mask_index_array,
216216
kernel_2d=np.array(self.kernel.native[:, :]),
217217
)
218-
self.image_frame_1d_indexes[
219-
mask_1d_index, :
220-
] = image_frame_1d_indexes
221-
self.image_frame_1d_kernels[
222-
mask_1d_index, :
223-
] = image_frame_1d_kernels
218+
self.image_frame_1d_indexes[mask_1d_index, :] = (
219+
image_frame_1d_indexes
220+
)
221+
self.image_frame_1d_kernels[mask_1d_index, :] = (
222+
image_frame_1d_kernels
223+
)
224224
self.image_frame_1d_lengths[mask_1d_index] = image_frame_1d_indexes[
225225
image_frame_1d_indexes >= 0
226226
].shape[0]
@@ -257,15 +257,15 @@ def __init__(self, mask, kernel):
257257
mask_index_array=np.array(self.mask_index_array),
258258
kernel_2d=np.array(self.kernel.native),
259259
)
260-
self.blurring_frame_1d_indexes[
261-
mask_1d_index, :
262-
] = image_frame_1d_indexes
263-
self.blurring_frame_1d_kernels[
264-
mask_1d_index, :
265-
] = image_frame_1d_kernels
266-
self.blurring_frame_1d_lengths[
267-
mask_1d_index
268-
] = image_frame_1d_indexes[image_frame_1d_indexes >= 0].shape[0]
260+
self.blurring_frame_1d_indexes[mask_1d_index, :] = (
261+
image_frame_1d_indexes
262+
)
263+
self.blurring_frame_1d_kernels[mask_1d_index, :] = (
264+
image_frame_1d_kernels
265+
)
266+
self.blurring_frame_1d_lengths[mask_1d_index] = (
267+
image_frame_1d_indexes[image_frame_1d_indexes >= 0].shape[0]
268+
)
269269
mask_1d_index += 1
270270

271271
@staticmethod

0 commit comments

Comments
 (0)