@@ -82,60 +82,50 @@ def mask_2d_circular_from(
8282 return distances_squared >= radius ** 2
8383
8484
85- @numba_util .jit ()
8685def mask_2d_circular_annular_from (
87- shape_native : Tuple [int , int ],
88- pixel_scales : ty . PixelScales ,
86+ shape_native : tuple [int , int ],
87+ pixel_scales : tuple [ float , float ] ,
8988 inner_radius : float ,
9089 outer_radius : float ,
91- centre : Tuple [float , float ] = (0.0 , 0.0 ),
90+ centre : tuple [float , float ] = (0.0 , 0.0 ),
9291) -> np .ndarray :
9392 """
94- Returns an circular annular mask from an input inner and outer mask radius and shape .
93+ Create a circular annular mask within a 2D array .
9594
96- This creates a 2D array where all values within the inner and outer radii are unmasked and therefore `False`.
95+ This generates a 2D array where all values within the specified inner and outer radii are unmasked (set to `False`) .
9796
9897 Parameters
9998 ----------
10099 shape_native
101- The (y,x) shape of the mask in units of pixels.
100+ The shape of the mask array in pixels.
102101 pixel_scales
103- The scaled units to pixel units conversion factor of each pixel .
102+ The conversion factors from pixels to scaled units .
104103 inner_radius
105- The radius (in scaled units) of the inner circle outside of which pixels are unmasked .
104+ The inner radius of the annular mask in scaled units .
106105 outer_radius
107- The radius (in scaled units) of the outer circle within which pixels are unmasked .
106+ The outer radius of the annular mask in scaled units .
108107 centre
109- The centre of the annulus used to mask pixels .
108+ The central coordinate of the annulus in scaled units .
110109
111110 Returns
112111 -------
113- ndarray
114- The 2D mask array whose central pixels are masked as a annulus.
112+ The 2D mask array with the region between the inner and outer radii unmasked (False).
115113
116114 Examples
117115 --------
118- mask = mask_annnular_from(
119- shape=(10, 10), pixel_scales=0.1, inner_radius=0.5, outer_radius=1.5, centre=(0.0, 0.0))
120- """
121-
122- mask_2d = np .full (shape_native , True )
123-
124- centres_scaled = mask_2d_centres_from (
125- shape_native = mask_2d .shape , pixel_scales = pixel_scales , centre = centre
116+ mask = mask_2d_circular_annular_from(
117+ shape_native=(10, 10), pixel_scales=(0.1, 0.1), inner_radius=0.5, outer_radius=1.5, centre=(0.0, 0.0)
126118 )
119+ """
120+ centres_scaled = mask_2d_centres_from (shape_native , pixel_scales , centre )
127121
128- for y in range (mask_2d .shape [0 ]):
129- for x in range (mask_2d .shape [1 ]):
130- y_scaled = (y - centres_scaled [0 ]) * pixel_scales [0 ]
131- x_scaled = (x - centres_scaled [1 ]) * pixel_scales [1 ]
132-
133- r_scaled = np .sqrt (x_scaled ** 2 + y_scaled ** 2 )
122+ y , x = np .ogrid [:shape_native [0 ], :shape_native [1 ]]
123+ y_scaled = (y - centres_scaled [0 ]) * pixel_scales [0 ]
124+ x_scaled = (x - centres_scaled [1 ]) * pixel_scales [1 ]
134125
135- if outer_radius >= r_scaled >= inner_radius :
136- mask_2d [y , x ] = False
126+ distances_squared = x_scaled ** 2 + y_scaled ** 2
137127
138- return mask_2d
128+ return ~ (( distances_squared >= inner_radius ** 2 ) & ( distances_squared <= outer_radius ** 2 ))
139129
140130
141131@numba_util .jit ()
0 commit comments