@@ -136,11 +136,12 @@ def polar_radius(size, exponent=1, origin=None):
136136 return res
137137
138138
139- def polar_angle (size , phase = 0 , origin = None ):
139+ def polar_angle (size , phase = 0 , origin = None , direction = 'clockwise' ):
140140 '''make polar angle matrix (in radians)
141141
142- Compute a matrix of given size containing samples of the polar angle (in radians, CW from the
143- X-axis, ranging from -pi to pi), relative to given phase, about the given origin pixel.
142+ Compute a matrix of given size containing samples of the polar angle (in radians,
143+ increasing in user-defined direction from the X-axis, ranging from -pi to pi), relative to
144+ given phase, about the given origin pixel.
144145
145146 Arguments
146147 ---------
@@ -153,13 +154,20 @@ def polar_angle(size, phase=0, origin=None):
153154 the center of the image. if an int, we assume the origin is at `(origin, origin)`. if a
154155 tuple, must be a 2-tuple of ints specifying the origin (where `(0, 0)` is the upper left).
155156 if None, we assume the origin lies at the center of the matrix, `(size+1)/2`.
157+ direction : {'clockwise', 'counter-clockwise'}
158+ Whether the angle increases in a clockwise or counter-clockwise direction from
159+ the x-axis. The standard mathematical convention is to increase
160+ counter-clockwise, so that 90 degrees corresponds to the positive y-axis.
156161
157162 Returns
158163 -------
159164 res : `np.array`
160165 the polar angle matrix
161166
162167 '''
168+ if direction not in ['clockwise' , 'counter-clockwise' ]:
169+ raise ValueError ("direction must be one of {'clockwise', 'counter-clockwise'}, "
170+ f"but received { direction } !" )
163171 if not hasattr (size , '__iter__' ):
164172 size = (size , size )
165173
@@ -172,6 +180,8 @@ def polar_angle(size, phase=0, origin=None):
172180 np .arange (1 , size [0 ]+ 1 )- origin [0 ])
173181 xramp = np .array (xramp )
174182 yramp = np .array (yramp )
183+ if direction == 'counter-clockwise' :
184+ yramp = np .flip (yramp , 0 )
175185
176186 res = np .arctan2 (yramp , xramp )
177187
0 commit comments