Exemple #1
0
def get_lon_lat(center, theta, radius=1, resolution=100):

    longitude, latitude = center

    # #longitude values restricted on domain of (-180,180]
    # if longitude.to_value(u.deg) > 180. :
    # 	longitude = -360. * u.deg + longitude.to(u.deg)

    # Start off by generating the circle around the North pole
    lon = np.linspace(0.0, 2 * np.pi, resolution + 1)[:-1] * u.radian
    # lat = np.repeat(0.5 * np.pi - radius.to_value(u.radian), resolution) * u.radian
    lat = np.repeat(0.5 * np.pi - theta.to_value(u.radian), resolution) * u.radian

    lon, lat = _rotate_polygon(lon, lat, longitude, latitude)

    return lon, lat
Exemple #2
0
def convert_to_polygon(center_ra, center_dec, radius, resolution=16):
    """
    Convert a circle to a polygon

    :param center_ra: astropy.units.Quantity
    :param center_dec: astropy.units.Quantity
    :param radius: astropy.units.Quantity
    :param resolution: int
    :return:
    """
    lon = np.linspace(0., 2 * np.pi, resolution + 1)[:-1] * u.radian
    lat = np.repeat(0.5 * np.pi - radius.to_value(u.radian),
                    resolution) * u.radian
    lon, lat = _rotate_polygon(lon, lat, center_ra, center_dec)
    lon = lon.to_value(u.deg).tolist()
    lat = lat.to_value(u.deg).tolist()
    return lon, lat
    def __init__(self,
                 ra,
                 dec,
                 radius,
                 resolution=100,
                 vertex_unit=u.degree,
                 **kwargs):

        # Extract longitude/latitude, either from a tuple of two quantities, or
        # a single 2-element Quantity.

        longitude, latitude = ra, dec

        # #longitude values restricted on domain of (-180,180]
        # if longitude.to_value(u.deg) > 180. :
        # 	longitude = -360. * u.deg + longitude.to(u.deg)

        # Start off by generating the circle around the North pole
        lon = np.linspace(0.0, 2 * np.pi, resolution + 1)[:-1] * u.radian
        lat = np.repeat(0.5 * np.pi - np.deg2rad(radius),
                        resolution) * u.radian

        lon, lat = _rotate_polygon(lon, lat, longitude, latitude)

        # Extract new longitude/latitude in the requested units
        lon = lon.to_value(vertex_unit)
        lat = lat.to_value(vertex_unit)
        # Create polygon vertices
        vertices = np.array([lon, lat]).transpose()

        # split path into two sections if circle crosses -180, 180 bounds
        codes = []
        last = (4000.4 * u.degree).to_value(
            vertex_unit
        )  # 400.4 is a random number large enough so first element is "MOVETO"
        for v in vertices:
            if np.absolute(v[0] - last) > (300 *
                                           u.degree).to_value(vertex_unit):
                codes.append(Path.MOVETO)
            else:
                codes.append(Path.LINETO)
            last = v[0]

        circle_path = Path(vertices, codes)

        super().__init__(circle_path, **kwargs)