def test_rectangle_all_parameters_passed(rectangle_args): bottom_left, top_right, width, height = rectangle_args with pytest.raises(ValueError): get_rectangle_coordinates(bottom_left, width=width, top_right=top_right, height=height)
def test_rectangle_bottom_left_different_types(rectangle_args): bottom_left, top_right, width, height = rectangle_args bottom_left_1, top_right_1 = get_rectangle_coordinates( bottom_left.frame, width=width, height=height) assert bottom_left.spherical.lon + width == top_right_1.spherical.lon assert bottom_left.spherical.lat + height == top_right_1.spherical.lat assert type(bottom_left_1) == type(top_right_1) == type(bottom_left.frame) bottom_left_2, top_right_2 = get_rectangle_coordinates(bottom_left, width=width, height=height) assert bottom_left.spherical.lon + width == top_right_2.spherical.lon assert bottom_left.spherical.lat + height == top_right_2.spherical.lat assert type(bottom_left_2) == type(top_right_2) == type(bottom_left)
def __init__(self, bottom_left, top_right=None, width: u.arcsec = None, height: u.arcsec = None, tracking=False, register=False, nan_off_limb=False): super().__init__() bl, tr = get_rectangle_coordinates(bottom_left, top_right=top_right, width=width, height=height) self.value = { 't_ref': bl.obstime.isot, # JSOC input is disable tracking so take the negative 't': int(not tracking), 'r': int(register), 'c': int(nan_off_limb), 'locunits': 'arcsec', 'boxunits': 'arcsec', 'x': ((bl.Tx + tr.Tx) / 2).to('arcsec').value, 'y': ((bl.Ty + tr.Ty) / 2).to('arcsec').value, 'width': (tr.Tx - bl.Tx).to('arcsec').value, 'height': (tr.Ty - bl.Ty).to('arcsec').value, }
def draw_quadrangle(self, m, bottom_left, *, width: u.deg = None, height: u.deg = None, axes=None, top_right=None, **kwargs): bottom_left, top_right = get_rectangle_coordinates(bottom_left, top_right=top_right, width=width, height=height) width = Longitude(top_right.spherical.lon - bottom_left.spherical.lon) height = top_right.spherical.lat - bottom_left.spherical.lat if not axes: axes = plt.gca() kwergs = { "transform": axes.get_transform(bottom_left.frame.replicate_without_data()), "edgecolor": "white", "fill": False, } kwergs.update(kwargs) quad = Quadrangle(m._get_lon_lat(bottom_left), width, height, **kwergs) corners = self._convert_to_Skycoord(m, quad) nodes = self._coords_to_xyz(corners) return nodes
def test_rectangle_width_height(rectangle_args): bottom_left, top_right, width, height = rectangle_args bottom_left_1, top_right_1 = get_rectangle_coordinates(bottom_left, width=width, height=height) assert bottom_left.spherical.lon + width == top_right_1.spherical.lon assert bottom_left.spherical.lat + height == top_right_1.spherical.lat
def test_heliographic_rectangle_top_right(heliographic_test_map): heliographic_test_map.plot() bottom_left = SkyCoord( 60 * u.deg, 50 * u.deg, frame=heliographic_test_map.coordinate_frame) w = 13 * u.deg h = 13 * u.deg bottom_left, top_right = get_rectangle_coordinates(bottom_left, width=w, height=h) heliographic_test_map.draw_rectangle(bottom_left, width=w, height=h, color='cyan')
def test_rectangle_aia171_top_right(aia171_test_map): aia171_test_map.plot() bottom_left = SkyCoord( 0 * u.arcsec, 0 * u.arcsec, frame=aia171_test_map.coordinate_frame) w = 100 * u.arcsec h = 100 * u.arcsec bottom_left, top_right = get_rectangle_coordinates(bottom_left, width=w, height=h) aia171_test_map.draw_rectangle(bottom_left, top_right=top_right)
def test_rectangle_mismatching_frames_missing_parameters(rectangle_args): bottom_left, top_right, width, height = rectangle_args top_right = SkyCoord(10 * u.arcsec, 10 * u.arcsec, frame='heliographic_carrington') with pytest.raises(ConvertError): bottom_left, top_right = get_rectangle_coordinates(bottom_left, top_right=top_right)
def draw_rectangles(mas, bottom_left, *, width: u.deg = None, height: u.deg = None, axes=None, top_right=None, resolution=100, **kwargs): bottom_left, top_right = get_rectangle_coordinates( bottom_left, top_right=top_right, width=width, height=height) width = Longitude(top_right.spherical.lon - bottom_left.spherical.lon) height = top_right.spherical.lat - bottom_left.spherical.lat if not axes: axes = plt.gca() kwergs = { "transform": axes.get_transform(bottom_left.frame.replicate_without_data()), "edgecolor": "white", "fill": False, } kwergs.update(kwargs) print('in rectangle', mas._get_lon_lat(bottom_left), width, height) quad = Rect(mas._get_lon_lat(bottom_left), width, height, **kwergs) corners = convert_to_Skycoord(mas, quad) return corners # def draw_rectangle(mas, bottom_left, *, width: u.deg = None, height: u.deg = None, # axes=None, top_right=None, **kwargs): # bottom_left, top_right = get_rectangle_coordinates(bottom_left, # top_right=top_right, # width=width, # height=height) # bottom_left = bottom_left.transform_to(mas.coordinate_frame) # top_right = top_right.transform_to(mas.coordinate_frame) # width = Longitude(top_right.spherical.lon - bottom_left.spherical.lon) # height = top_right.spherical.lat - bottom_left.spherical.lat # if not axes: # axes = plt.gca() # if wcsaxes_compat.is_wcsaxes(axes): # axes_unit = u.deg # else: # axes_unit = mas.spatial_units[0] # bottom_left = u.Quantity(mas._get_lon_lat(bottom_left), unit=axes_unit).value # width = width.to(axes_unit).value # height = height.to(axes_unit).value # kwergs = {'transform': wcsaxes_compat.get_world_transform(axes), # 'edgecolor': 'white', # 'fill': False} # kwergs.update(kwargs) # rect = plt.Rectangle(bottom_left, width, height, **kwergs) # print(rect.get_bbox()) # axes.add_patch(rect) # return [rect]
def test_rectangle_bottom_left_vector(): 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) assert bottom_left.spherical.lon == bottom_left_vector[0].spherical.lon assert bottom_left.spherical.lat == bottom_left_vector[0].spherical.lat assert top_right.spherical.lon == bottom_left_vector[1].spherical.lon assert top_right.spherical.lat == bottom_left_vector[1].spherical.lat
def __init__(self, bottom_left, *, top_right=None, width: u.deg = None, height: u.deg = None, search="containing"): bottom_left, top_right = get_rectangle_coordinates(bottom_left, top_right=top_right, width=width, height=height) bottom_left = bottom_left.transform_to( Helioprojective(observer="earth")) top_right = top_right.transform_to(Helioprojective(observer="earth")) self.hpc_bounding_box_arcsec = ((bottom_left.Tx.to_value(u.arcsec), bottom_left.Ty.to_value(u.arcsec)), (top_right.Tx.to_value(u.arcsec), top_right.Ty.to_value(u.arcsec))) self.search_type = search
def test_rectangle_invalid_input(rectangle_args): bottom_left, top_right, width, height = rectangle_args with pytest.raises(TypeError): get_rectangle_coordinates(width, height=height)
def test_rectangle_incomplete_input(rectangle_args): bottom_left, top_right, width, height = rectangle_args with pytest.raises(ValueError): get_rectangle_coordinates(bottom_left, height=height)