get_rectangle_coordinates#
- sunpy.coordinates.utils.get_rectangle_coordinates(bottom_left, *, top_right=None, width: Unit('deg') = None, height: Unit('deg') = None)[source]#
Specify a rectangular region of interest in longitude and latitude in a given coordinate frame.
- Parameters:
bottom_left (
BaseCoordinateFrame
orSkyCoord
) – The bottom-left coordinate of the rectangle. Supports passing both the bottom left and top right coordinates by passing with a shape of(2,)
.top_right (
BaseCoordinateFrame
orSkyCoord
) – The top-right coordinate of the rectangle. If in a different frame thanbottom_left
and all required metadata for frame conversion is present,top_right
will be transformed tobottom_left
frame.width (
Quantity
) – The width of the rectangle. Must be omitted if the coordinates of both corners have been specified.height (
Quantity
) – The height of the rectangle. Must be omitted if the coordinates of both corners have been specified.
- Returns:
BaseCoordinateFrame
orSkyCoord
– The bottom left coordinate of the rectangular region of interest.BaseCoordinateFrame
orSkyCoord
– The top right coordinate of the rectangular region of interest.
Examples
>>> import astropy.units as u >>> from astropy.coordinates import SkyCoord >>> from sunpy.coordinates.frames import HeliographicStonyhurst >>> from sunpy.coordinates.utils import get_rectangle_coordinates
>>> # With bottom left as a SkyCoord, width and height >>> bottom_left = SkyCoord(0 * u.arcsec, 0 * u.arcsec, frame='heliographic_stonyhurst') >>> width = 10 * u.arcsec >>> height = 10 * u.arcsec >>> bottom_left, top_right = get_rectangle_coordinates(bottom_left, width=width, height=height)
>>> # With bottom left of shape (2,) >>> bottom_left_vector = SkyCoord([0 * u.arcsec, 10 * u.arcsec], [0 * u.arcsec, 10 * u.arcsec], frame='heliographic_stonyhurst') >>> bottom_left, top_right = get_rectangle_coordinates(bottom_left_vector)
>>> # With bottom left as a BaseCoordinateFrame instance, width and height >>> bottom_left = HeliographicStonyhurst(0 * u.arcsec, 0 * u.arcsec) >>> width = 10 * u.arcsec >>> height = 10 * u.arcsec >>> bottom_left, top_right = get_rectangle_coordinates(bottom_left, width=width, height=height)
Notes
width
is always treated as an increase in longitude, butbottom_left
may have a higher value of longitude thantop_right
due to the wrapping of the longitude angle. Appropriate care should be taken when using this function’s output to define a range of longitudes.height
is always treated as an increase in latitude, but this function does not enforce thatbottom_left
has a lower value of latitude thantop_right
, in case that orientation is valid for the intended use.