@@ -49,7 +49,7 @@ def __init__(self, **kwargs):
4949 "wave_key" : "WAVE0" ,
5050 "normalise_kernel" : True ,
5151 "rounded_edges" : True ,
52- "rotational_blur_angle" : 0 ,
52+ "rotational_blur_angle" : 0 * u . deg ,
5353 }
5454 self .meta .update (params )
5555 self .meta .update (kwargs )
@@ -76,7 +76,7 @@ def apply_to(self, obj, **kwargs):
7676
7777 # apply rotational blur for field-tracking observations
7878 rot_blur_angle = self .meta ["rotational_blur_angle" ]
79- if abs (rot_blur_angle ) > 0 :
79+ if abs (rot_blur_angle << u . deg ) > 0 * u . deg :
8080 # makes a copy of kernel
8181 kernel = rotational_blur (kernel , rot_blur_angle )
8282
@@ -150,35 +150,41 @@ def plot(self, obj=None, **kwargs):
150150 return fig
151151
152152
153- def rotational_blur (image , angle ):
153+ @u .quantity_input
154+ def rotational_blur (image , angle : u .Quantity [u .deg ]):
154155 """
155156 Rotate and coadd an image over a given angle to imitate a blur.
156157
157158 Parameters
158159 ----------
159- image : array
160- Image to blur
161- angle : float
162- [deg] Angle over which the image should be rotationally blurred
160+ image : array-like
161+ Image to blur.
162+ angle : u.Quantity["angle"]
163+ Angle over which the image should be rotationally blurred.
164+
165+ .. versionchanged:: PLACEHOLDER_NEXT_RELEASE_VERSION
166+
167+ Require `angle` to be a Quantity.
163168
164169 Returns
165170 -------
166- image_rot : array
171+ image_rot : np.ndarray
167172 Blurred image
168173
169174 """
170175 image_rot = np .copy (image )
171176
172- n_angles = 1
173- rad_to_deg = 57.29578
174- edge_pixel_unit_angle = np .arctan2 (1 , (image .shape [0 ] // 2 )) * rad_to_deg
175- while abs (angle ) > edge_pixel_unit_angle and n_angles < 25 :
176- angle /= 2.
177- image_rot += rotate (image_rot , angle , reshape = False , order = 1 )
177+ edge_pixel_unit_angle = np .arctan2 (1 , (image .shape [0 ] // 2 )) * u .rad
178+ n_steps = np .ceil (np .log2 (abs (angle ) / edge_pixel_unit_angle ))
179+ n_steps = int (min (n_steps , 8 )) # avoid overrun
180+
181+ current_angle = angle .copy ()
182+ for _ in range (n_steps ):
183+ current_angle /= 2.
184+ image_rot += rotate (image_rot , current_angle , reshape = False , order = 3 )
178185 # each time kernel is rotated and added, the frame total doubles
179- n_angles *= 2
180186
181- return image_rot / n_angles
187+ return image_rot / image_rot . sum () * image . sum ()
182188
183189
184190def get_bkg_level (obj , bg_w ):
0 commit comments