-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmask_1d.py
More file actions
134 lines (94 loc) · 3.78 KB
/
mask_1d.py
File metadata and controls
134 lines (94 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from __future__ import annotations
import logging
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from autoarray.mask.mask_2d import Mask1D
from autoarray.mask.mask_2d import Mask2D
logging.basicConfig()
logger = logging.getLogger(__name__)
class DeriveMask1D:
def __init__(self, mask: Mask1D):
"""
Derives ``Mask1D`` objects from a ``Mask1D``.
A ``Mask1D`` masks values which are associated with a 1D uniform grid of pixels, where unmasked
entries (which are ``False``) are used in subsequent calculations and masked values (which are ``True``) are
omitted (for a full description see
the :meth:`Mask1D class API documentation <autoarray.mask.mask_1d.Mask1D.__new__>`).
From a ``Mask1D`` other ``Mask1D``s can be derived, which represent a subset of pixels with significance.
For example:
- An ``all_false`` ``Mask1D``: the same shape as the original ``Mask1D`` but has unmasked ``False`` values
everywhere.
Parameters
----------
mask
The ``Mask1D`` from which new ``Mask1D`` objects are derived.
Examples
--------
.. code-block:: python
import autoarray as aa
mask_1d = aa.Mask1D(
mask=[True, False, False, False, True],
pixel_scales=1.0,
)
derive_mask_1d = aa.DeriveMask1D(mask=mask_1d)
print(derive_mask_1d.edge)
"""
self.mask = mask
@property
def all_false(self) -> Mask1D:
"""
Returns a ``Mask1D`` which has the same
geometry (``shape_native`` / ``pixel_scales`` / ``origin``) as this ``Mask1D`` but all
entries are unmasked (given by``False``).
For example, for the following ``Mask1D``:
::
[True, False, False, False, True]
The unmasked mask (given via ``mask_1d.derive_mask.all_false``) is:
::
[False, False, False, False, False]
Examples
--------
.. code-block:: python
import autoarray as aa
mask_1d = aa.Mask1D(
mask[True, False, False, False, True],
pixel_scales=1.0,
)
derive_mask_1d = aa.DeriveMask1D(mask=mask_1d)
print(derive_mask_1d.all_false)
"""
from autoarray.mask.mask_1d import Mask1D
return Mask1D.all_false(
shape_slim=self.mask.shape_slim,
pixel_scales=self.mask.pixel_scales,
origin=self.mask.origin,
)
@property
def to_mask_2d(self) -> Mask2D:
"""
Map the ``Mask1D`` to a Mask2D of shape [total_mask_1d_pixel, 1].
The change in shape and dimensions of the mask is necessary for mapping results from 1D to 2D data
structures (e.g. an ``Array1D`` to ``Array2D``).
For example, for the following ``Mask1D``:
::
[True, False, False, False, True]
The corresponding ``Mask2D`` (given via ``mask_1d.derive_mask.to_mask_2d``) is:
::
[[False, False, False, False, False]]
Examples
--------
.. code-block:: python
import autoarray as aa
mask_1d = aa.Mask1D(
mask[True, False, False, False, True],
pixel_scales=1.0,
)
derive_mask_1d = aa.DeriveMask1D(mask=mask_1d)
print(derive_mask_1d.to_mask_2d)
"""
from autoarray.mask.mask_2d import Mask2D
return Mask2D(
[self.mask],
pixel_scales=(self.mask.pixel_scale, self.mask.pixel_scale),
origin=(0.0, 0.0),
)