sunpy.image.transform.add_rotation_function(name, *, allowed_orders, handles_clipping, handles_image_nans, handles_nan_missing)[source]#

Decorator to add a rotation function to the registry of selectable implementations.

Each registered rotation function becomes a selectable option for sunpy.image.transform.affine_transform() and Those two routines are required to handle clipping the output image, NaNs in the input image, and NaN as the value to use for pixels in the output image that are beyond the extent of the input image. If the supplied rotation function cannot provide one or more of these capabilities, the decorator is able to provide them instead.

The decorator requires the parameters listed under Parameters. The decorated rotation function must accept the parameters listed under Other Parameters in that order and return the rotated image.

  • name (str) – The name that will be used to select the rotation function

  • allowed_orders (set) – The allowed values for the order parameter.

  • handles_clipping (bool) – Specifies whether the rotation function will internally perform clipping. If False, the rotation function will always receive False for the clip input parameter.

  • handles_image_nans (bool) – Specifies whether the rotation function will internally handle NaNs in the input image. If False, the rotation function is guaranteed to be provided an image without any NaNs.

  • handles_nan_missing (bool) – Specifies whether the rotation function will internally handle NaN as the missing value. If False, the rotation function will never receive NaN, but instead receive a value in the input range of the image.

Other Parameters:
  • image (numpy.ndarray) – The image, which could be integers or floats

  • matrix (numpy.ndarray that is 2x2) – The linear transformation matrix (e.g., rotation+scale+skew)

  • shift (2-element numpy.ndarray) – The translational shift to apply to the image in each axis

  • order (int) – The numerical parameter that controls the degree of interpolation

  • missing (float) – The value to use for outside the bounds of the original image

  • clip (bool) – Whether to clip the output image to the range of the input image


The docstring of the rotation function should be a bulleted list of notes specific to the rotation function. It will be appended to Notes section of the docstring for affine_transform().

The rotation function is supplied the input image directly, so the function should not modify the image in place.

Setting any of the handles_* parameters to False means that computation will be performed to modify the image returned by the rotation function before it is returned to affine_transform().

If the decorator is handling image NaNs on behalf of the rotation function (i.e., handles_image_nans=False), pixels in the output image will be set to NaN if they are within a certain neighborhood size that depends on the order parameter. This step requires an additional image convolution, which might be avoidable if the rotation function were able to internally handle image NaNs. This convolution normally uses scipy.signal.convolve2d(), but if OpenCV is installed, the faster cv2.filter2D() is used instead.