def yarray(shape, yx=[0, 0], th=None):
"""2D array of y values.
Parameters
----------
shape : tuple of int
The shape of the resulting array, (y, x).
yx : tuple of float
Offset the array to align with this y, x center.
th : Quantity, optional
Place the y-axis along this position angle, measured
counterclockwise from the original y-axis.
Returns
-------
y : ndarray
An array of y values.
>>> from sbpy.imageanalysis.utils import yarray
>>> y = yarray((10, 10))
>>> y[3, 0]
3
"""
import numpy as np
import astropy.units as u
y, x = np.indices(shape)[-2:]
y = y - yx[0]
x = x - yx[1]
if th is not None:
y = -x * np.sin(th.to(u.rad).value) + y * np.cos(th.to(u.rad).value)
return y
评论列表
文章目录