Пример #1
0
def test_cartesian():
    # Test a north pole specified in Cartesian coordinates
    s = SkyCoord(1, 2, 3, unit=u.m,
                 representation_type='cartesian', frame='heliographic_stonyhurst')
    off = NorthOffsetFrame(north=s)
    assert_longitude_allclose(off.origin.lon, np.arctan2(s.y, s.x))
    assert_quantity_allclose(off.origin.lat, np.arctan2(s.z, np.sqrt(s.x**2 + s.y**2)) - 90*u.deg)
Пример #2
0
def test_null():
    """
    test init of a frame where the origins are the same.
    """
    off = NorthOffsetFrame(
        north=SkyCoord(0 * u.deg, 90 * u.deg, frame='heliographic_stonyhurst'))
    assert isinstance(off, SkyOffsetFrame)
    assert off.origin.lat == 0 * u.deg
    assert off.origin.lon == 0 * u.deg
Пример #3
0
def test_transform(lon, lat):
    """
    Test that the north pole in the new frame transforms back to the given
    north argument.
    """
    north = SkyCoord(lon=lon, lat=lat, frame='heliographic_stonyhurst')
    off = NorthOffsetFrame(north=north)
    t_north = SkyCoord(lon=0 * u.deg, lat=90 * u.deg, frame=off)
    t_north = t_north.transform_to('heliographic_stonyhurst')
    assert_quantity_allclose(north.lon, t_north.lon, atol=1e6 * u.deg)
    assert_quantity_allclose(north.lat, t_north.lat, atol=1e6 * u.deg)
Пример #4
0
######################################################################
# We can perform various mathematical operations on the extracted segment such
# as averaging the pixel values or finding the sum of the segment.

masked_data = np.ma.array(new_frame_map.data, mask=new_frame_map.mask)

print(f"Original Map : mean = {smap.data.mean()}, sum = {smap.data.sum()}")
print(f"Segment : mean = {masked_data.mean()}, sum = {masked_data.sum()}")

######################################################################
# Using `sunpy.coordinates.NorthOffsetFrame`
# ------------------------------------------
# Let us offset the north pole and create the frame.

north = SkyCoord(20 * u.deg, 20 * u.deg, frame="heliographic_stonyhurst")
offset_frame = NorthOffsetFrame(north=north)

######################################################################
# We then transform coordinates to the offsetted frame and segment the data
# based on conditions.

all_hpc = sunpy.map.all_coordinates_from_map(smap)
offsetted_coords = all_hpc.transform_to(offset_frame)
segment_mask = np.logical_or(offsetted_coords.lon >= 30 * u.deg,
                             offsetted_coords.lon <= -20 * u.deg)

######################################################################
# Masking out the NaN values of ``offsetted_coords.lon``, we get:

segment_mask |= np.isnan(offsetted_coords.lon)
Пример #5
0
def test_error():
    with pytest.raises(TypeError):
        NorthOffsetFrame()
Пример #6
0
def test_south_pole():
    s = SkyCoord(-10 * u.deg, 0 * u.deg, frame='heliographic_stonyhurst')
    off = NorthOffsetFrame(north=s)
    assert_quantity_allclose(off.origin.lon, 170 * u.deg)
    assert_quantity_allclose(off.origin.lat, -90 * u.deg)