Skip to content

Commit 45a35f4

Browse files
committed
mask_1d_util
1 parent bb30c04 commit 45a35f4

2 files changed

Lines changed: 5 additions & 60 deletions

File tree

autoarray/mask/mask_1d_util.py

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,6 @@
11
import numpy as np
22

3-
from autoarray import numba_util
43

5-
6-
@numba_util.jit()
7-
def total_pixels_1d_from(mask_1d: np.ndarray) -> int:
8-
"""
9-
Returns the total number of unmasked pixels in a mask.
10-
11-
Parameters
12-
----------
13-
mask_1d
14-
A 2D array of bools, where `False` values are unmasked and included when counting pixels.
15-
16-
Returns
17-
-------
18-
int
19-
The total number of pixels that are unmasked.
20-
21-
Examples
22-
--------
23-
24-
mask = np.array([[True, False, True],
25-
[False, False, False]
26-
[True, False, True]])
27-
28-
total_regular_pixels = total_regular_pixels_from(mask=mask)
29-
"""
30-
31-
total_regular_pixels = 0
32-
33-
for x in range(mask_1d.shape[0]):
34-
if not mask_1d[x]:
35-
total_regular_pixels += 1
36-
37-
return total_regular_pixels
38-
39-
40-
@numba_util.jit()
414
def native_index_for_slim_index_1d_from(
425
mask_1d: np.ndarray,
436
) -> np.ndarray:
@@ -62,22 +25,12 @@ def native_index_for_slim_index_1d_from(
6225
6326
Examples
6427
--------
65-
mask_2d = np.array([[True, True, True],
66-
[True, False, True]
67-
[True, True, True]])
68-
69-
native_index_for_slim_index_1d = native_index_for_slim_index_1d_from(mask_2d=mask_2d)
28+
>>> mask_1d = np.array([True, False, True, False, False, True])
29+
>>> native_index_for_slim_index_1d_from(mask_1d)
30+
array([1, 3, 4])
7031
7132
"""
72-
73-
total_pixels = total_pixels_1d_from(mask_1d=mask_1d)
74-
native_index_for_slim_index_1d = np.zeros(shape=total_pixels)
75-
76-
slim_index = 0
77-
78-
for x in range(mask_1d.shape[0]):
79-
if not mask_1d[x]:
80-
native_index_for_slim_index_1d[slim_index] = x
81-
slim_index += 1
33+
# Create an array of native indexes corresponding to unmasked pixels
34+
native_index_for_slim_index_1d = np.flatnonzero(~mask_1d)
8235

8336
return native_index_for_slim_index_1d

test_autoarray/mask/test_mask_1d_util.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
from autoarray import exc
21
from autoarray import util
32

43
import numpy as np
5-
import pytest
6-
7-
8-
def test__total_image_pixels_1d_from():
9-
mask_1d = np.array([False, True, False, False, False, True])
10-
11-
assert util.mask_1d.total_pixels_1d_from(mask_1d=mask_1d) == 4
124

135

146
def test__native_index_for_slim_index_1d_from():

0 commit comments

Comments
 (0)