Skip to content

Commit d33ab44

Browse files
committed
mask now also follows strictire typing rules
1 parent 15cd0b5 commit d33ab44

7 files changed

Lines changed: 27 additions & 30 deletions

File tree

autoarray/dataset/interferometer/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def w_tilde(self):
205205
return WTildeInterferometer(
206206
w_matrix=w_matrix,
207207
curvature_preload=curvature_preload,
208-
dirty_image=dirty_image,
208+
dirty_image=np.array(dirty_image.array),
209209
real_space_mask=self.real_space_mask,
210210
noise_map_value=self.noise_map[0],
211211
)

autoarray/geometry/geometry_util.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def central_scaled_coordinate_1d_from(
119119
return (x_pixel,)
120120

121121

122-
@numba_util.jit()
123122
def pixel_coordinates_1d_from(
124123
scaled_coordinates_1d: Tuple[float],
125124
shape_slim: Tuple[int],
@@ -137,7 +136,6 @@ def pixel_coordinates_1d_from(
137136
return (x_pixel,)
138137

139138

140-
@numba_util.jit()
141139
def scaled_coordinates_1d_from(
142140
pixel_coordinates_1d: Tuple[float],
143141
shape_slim: Tuple[int],

autoarray/mask/mask_1d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(
5959
mask = np.asarray(mask).astype("bool")
6060

6161
if invert:
62-
mask = np.invert(mask)
62+
mask = ~mask
6363

6464
if type(pixel_scales) is float:
6565
pixel_scales = (pixel_scales,)
@@ -153,7 +153,7 @@ def from_fits(
153153
"""
154154

155155
return cls(
156-
array_1d_util.numpy_array_1d_via_fits_from(file_path=file_path, hdu=hdu),
156+
mask=np.array(array_1d_util.numpy_array_1d_via_fits_from(file_path=file_path, hdu=hdu)),
157157
pixel_scales=pixel_scales,
158158
origin=origin,
159159
)

autoarray/mask/mask_2d.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,8 @@ def __init__(
200200
if type(mask) is list:
201201
mask = np.asarray(mask).astype("bool")
202202

203-
if not isinstance(mask, np.ndarray):
204-
mask = mask._array
205-
206203
if invert:
207-
mask = np.invert(mask)
204+
mask = ~mask
208205

209206
pixel_scales = geometry_util.convert_pixel_scales_2d(pixel_scales=pixel_scales)
210207

@@ -327,7 +324,7 @@ def circular(
327324
)
328325

329326
return cls(
330-
mask=mask,
327+
mask=np.array(mask),
331328
pixel_scales=pixel_scales,
332329
origin=origin,
333330
invert=invert,
@@ -381,7 +378,7 @@ def circular_annular(
381378
)
382379

383380
return cls(
384-
mask=mask,
381+
mask=np.array(mask),
385382
pixel_scales=pixel_scales,
386383
origin=origin,
387384
invert=invert,
@@ -438,7 +435,7 @@ def elliptical(
438435
)
439436

440437
return cls(
441-
mask=mask,
438+
mask=np.array(mask),
442439
pixel_scales=pixel_scales,
443440
origin=origin,
444441
invert=invert,
@@ -508,7 +505,7 @@ def elliptical_annular(
508505
)
509506

510507
return cls(
511-
mask=mask,
508+
mask=np.array(mask),
512509
pixel_scales=pixel_scales,
513510
origin=origin,
514511
invert=invert,
@@ -556,7 +553,7 @@ def from_pixel_coordinates(
556553
)
557554

558555
return cls(
559-
mask=mask,
556+
mask=np.array(mask),
560557
pixel_scales=pixel_scales,
561558
origin=origin,
562559
invert=invert,
@@ -594,7 +591,7 @@ def from_fits(
594591
mask = np.invert(mask.astype("bool"))
595592

596593
mask = Mask2D(
597-
mask=mask,
594+
mask=np.array(mask),
598595
pixel_scales=pixel_scales,
599596
origin=origin,
600597
)
@@ -743,7 +740,7 @@ def rescaled_from(self, rescale_factor) -> Mask2D:
743740
from autoarray.mask.mask_2d import Mask2D
744741

745742
rescaled_mask = mask_2d_util.rescaled_mask_2d_from(
746-
mask_2d=np.array(self),
743+
mask_2d=self.array,
747744
rescale_factor=rescale_factor,
748745
)
749746

@@ -802,7 +799,7 @@ def resized_from(self, new_shape, pad_value: int = 0.0) -> Mask2D:
802799
"""
803800

804801
resized_mask = array_2d_util.resized_array_2d_from(
805-
array_2d=np.array(self._array),
802+
array_2d=self.array,
806803
resized_shape=new_shape,
807804
pad_value=pad_value,
808805
).astype("bool")

autoarray/plot/visuals/two_d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def plot_via_plotter(self, plotter, grid_indexes=None, mapper=None, geometry=Non
6464
plotter.grid_scatter.scatter_grid(grid=self.grid.array)
6565

6666
if self.mesh_grid is not None:
67-
plotter.mesh_grid_scatter.scatter_grid(grid=self.mesh_grid)
67+
plotter.mesh_grid_scatter.scatter_grid(grid=self.mesh_grid.array)
6868

6969
if self.positions is not None:
7070
plotter.positions_scatter.scatter_grid(grid=self.positions)

autoarray/plot/wrap/base/figure.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ def open(self):
8282
"""
8383
Wraps the Matplotlib method 'plt.figure' for opening a figure.
8484
"""
85-
config_dict = self.config_dict
86-
config_dict.pop("aspect")
87-
fig = plt.figure(**config_dict)
88-
return fig, plt.gca()
85+
if not plt.fignum_exists(num=1):
86+
config_dict = self.config_dict
87+
config_dict.pop("aspect")
88+
fig = plt.figure(**config_dict)
89+
return fig, plt.gca()
90+
return None, None
8991

9092
def close(self):
9193
"""

test_autoarray/layout/test_region.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ def test__slice_1d__addition():
3131

3232
region = aa.Region1D(region=(0, 1))
3333

34-
arr_1d = arr_1d.array.at[region.slice].add(image[region.slice])
34+
arr_1d[region.slice] += image[region.slice]
3535

3636
assert (arr_1d == np.array([2.0, 2.0, 3.0, 4.0])).all()
3737

3838
arr_1d = aa.Array1D.no_mask(values=np.array([1.0, 2.0, 3.0, 4.0]), pixel_scales=1.0)
3939

4040
region = aa.Region1D(region=(2, 4))
4141

42-
arr_1d = arr_1d.array.at[region.slice].add(image[region.slice])
42+
arr_1d[region.slice] += image[region.slice]
4343

4444
assert (arr_1d == np.array([1.0, 2.0, 4.0, 5.0])).all()
4545

@@ -152,7 +152,7 @@ def test__slice_2d__addition():
152152
image = np.ones((2, 2))
153153
region = aa.Region2D(region=(0, 1, 0, 1))
154154

155-
array = array.at[region.slice].add(image[region.slice])
155+
array[region.slice] += image[region.slice]
156156

157157
assert (array == np.array([[1.0, 0.0], [0.0, 0.0]])).all()
158158

@@ -161,7 +161,7 @@ def test__slice_2d__addition():
161161
image = np.ones((2, 2))
162162
region = aa.Region2D(region=(0, 1, 0, 1))
163163

164-
array = array.at[region.slice].add(image[region.slice])
164+
array[region.slice] += image[region.slice]
165165

166166
assert (array == np.array([[2.0, 1.0], [1.0, 1.0]])).all()
167167

@@ -170,7 +170,7 @@ def test__slice_2d__addition():
170170
image = np.ones((3, 3))
171171
region = aa.Region2D(region=(1, 3, 2, 3))
172172

173-
array = array.at[region.slice].add(image[region.slice])
173+
array[region.slice] += image[region.slice]
174174

175175
assert (
176176
array == np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 2.0], [1.0, 1.0, 2.0]])
@@ -183,7 +183,7 @@ def test__slice_2d__set_to_zerose():
183183

184184
region = aa.Region2D(region=(0, 1, 0, 1))
185185

186-
array = array.at[region.slice].set(0)
186+
array[region.slice] = 0
187187

188188
assert (array == np.array([[0.0, 1.0], [1.0, 1.0]])).all()
189189

@@ -192,7 +192,7 @@ def test__slice_2d__set_to_zerose():
192192

193193
region = aa.Region2D(region=(1, 3, 2, 3))
194194

195-
array = array.at[region.slice].set(0)
195+
array[region.slice] = 0
196196

197197
assert (
198198
array == np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 0.0], [1.0, 1.0, 0.0]])
@@ -362,4 +362,4 @@ def test__exception__negative_coordinates_2d():
362362
aa.Region2D(region=(0, 0, -1, 2))
363363

364364
with pytest.raises(exc.RegionException):
365-
aa.Region2D(region=(0, 1, 2, -1))
365+
aa.Region2D(region=(0, 1, 2, -1))

0 commit comments

Comments
 (0)