utils.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:sbpy 作者: mommermi 项目源码 文件源码
def xarray(shape, yx=[0, 0], th=None):
    """2D array of x 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 : Quanitity, optional
      Place the x-axis along this position angle, measured
      counterclockwise from the original x-axis.

    Returns
    -------
    x : ndarray
      An array of x values.

    Examples
    --------
    >>> from sbpy.imageanalysis.utils import xarray
    >>> x = xarray((10, 10))
    >>> x[0, 3]
    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:
        x = x * np.cos(th.to(u.rad).value) + y * np.sin(th.to(u.rad).value)

    return x
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号