예제 #1
0
파일: test_utils.py 프로젝트: zimmaz/sunpy
def test_great_arc_points_differentiates(aia171_test_map):
    coordinate_frame = aia171_test_map.coordinate_frame
    a = SkyCoord(600 * u.arcsec, -600 * u.arcsec, frame=coordinate_frame)
    b = SkyCoord(-100 * u.arcsec, 800 * u.arcsec, frame=coordinate_frame)
    gc = GreatArc(a, b)
    coordinates = gc.coordinates(10)
    inner_angles = gc.inner_angles(11)
    distances = gc.distances(12)
    assert len(coordinates) == 10 and len(gc.coordinates()) == 100
    assert len(inner_angles) == 11 and len(gc.inner_angles()) == 100
    assert len(distances) == 12 and len(gc.distances()) == 100
예제 #2
0
def test_great_arc_points_differentiates():
    m = sunpy.map.Map(sunpy.map.Map(sunpy.data.test.get_test_filepath('aia_171_level1.fits')))
    coordinate_frame = m.coordinate_frame
    a = SkyCoord(600*u.arcsec, -600*u.arcsec, frame=coordinate_frame)
    b = SkyCoord(-100*u.arcsec, 800*u.arcsec, frame=coordinate_frame)
    gc = GreatArc(a, b)
    coordinates = gc.coordinates(10)
    inner_angles = gc.inner_angles(11)
    distances = gc.distances(12)
    assert len(coordinates) == 10 and len(gc.coordinates()) == 100
    assert len(inner_angles) == 11 and len(gc.inner_angles()) == 100
    assert len(distances) == 12 and len(gc.distances()) == 100
예제 #3
0
def test_great_arc_points_differentiates():
    m = sunpy.map.Map(sunpy.map.Map(sunpy.data.test.get_test_filepath('aia_171_level1.fits')))
    coordinate_frame = m.coordinate_frame
    a = SkyCoord(600*u.arcsec, -600*u.arcsec, frame=coordinate_frame)
    b = SkyCoord(-100*u.arcsec, 800*u.arcsec, frame=coordinate_frame)
    gc = GreatArc(a, b)
    coordinates = gc.coordinates(10)
    inner_angles = gc.inner_angles(11)
    distances = gc.distances(12)
    assert len(coordinates) == 10 and len(gc.coordinates()) == 100
    assert len(inner_angles) == 11 and len(gc.inner_angles()) == 100
    assert len(distances) == 12 and len(gc.distances()) == 100
예제 #4
0
def map_box(amap, bl_arc, tr_arc, img=None, c='c'):
    color = c
    if type(bl_arc) != SkyCoord:
        bl_arc = SkyCoord(bl_arc[0] * u.arc,
                          bl_arc[1] * u.arc,
                          frame=amap.coordinate_frame)
        tr_arc = SkyCoord(tr_arc[0] * u.arc,
                          tr_arc[1] * u.arc,
                          frame=amap.coordinate_frame)
    br_arc = SkyCoord(tr_arc.Tx, bl_arc.Ty, frame=amap.coordinate_frame)
    tl_arc = SkyCoord(bl_arc.Tx, tr_arc.Ty, frame=amap.coordinate_frame)
    blbr = GreatArc(bl_arc, br_arc)
    brtr = GreatArc(br_arc, tr_arc)
    tltr = GreatArc(tl_arc, tr_arc)
    bltl = GreatArc(bl_arc, tl_arc)
    if not img:
        img = amap.plot()

    img.axes.plot_coord(blbr.coordinates(), color=color)
    img.axes.plot_coord(brtr.coordinates(), color=color)
    img.axes.plot_coord(tltr.coordinates(), color=color)
    img.axes.plot_coord(bltl.coordinates(), color=color)

    return img
예제 #5
0
def test_pick_hole_extremes():

    PCH_Detection.pch_mask(test_map)
    holes = measure.label(np.logical_not(test_map.mask).astype(int),
                          connectivity=1,
                          background=0)

    plot_map = map.Map(sunpy.data.sample.AIA_171_IMAGE)

    fig = plt.figure()
    ax = plt.subplot(projection=plot_map)
    plot_map.plot(axes=ax)

    for r_number in range(1, np.max(holes) + 1, 1):
        hole_coords = test_map.pixel_to_world(
            np.where(holes == r_number)[1] * u.pixel,
            np.where(holes == r_number)[0] * u.pixel, 0)
        hole_start, hole_end = PCH_Detection.pick_hole_extremes(hole_coords)
        great_arc = GreatArc(hole_start, hole_end)
        ax.plot_coord(great_arc.coordinates(), color='c')
        print(hole_start, hole_end)

    plt.show()
예제 #6
0
파일: test_utils.py 프로젝트: zimmaz/sunpy
def test_great_arc_coordinates(points_requested, points_expected, first_point,
                               last_point, last_inner_angle, last_distance,
                               aia171_test_map):
    coordinate_frame = aia171_test_map.coordinate_frame
    a = SkyCoord(600 * u.arcsec, -600 * u.arcsec, frame=coordinate_frame)
    b = SkyCoord(-100 * u.arcsec, 800 * u.arcsec, frame=coordinate_frame)
    gc = GreatArc(a, b, points=points_requested)
    coordinates = gc.coordinates()
    inner_angles = gc.inner_angles()
    distances = gc.distances()

    # Ensure a GreatArc object is returned
    assert isinstance(gc, GreatArc)

    # Test the properties of the GreatArc object
    a_trans = a.transform_to(frames.Heliocentric)
    assert gc.start.x == a_trans.x
    assert gc.start.y == a_trans.y
    assert gc.start.z == a_trans.z
    b_trans = b.transform_to(frames.Heliocentric(observer=a.observer))
    assert gc.end.x == b_trans.x
    assert gc.end.y == b_trans.y
    assert gc.end.z == b_trans.z
    assert gc.distance_unit == u.m
    assert gc.observer == a.observer
    assert gc.center.x == 0 * u.m
    assert gc.center.y == 0 * u.m
    assert gc.center.z == 0 * u.m

    assert u.allclose(
        gc.start_cartesian * u.m,
        np.asarray([428721.0913539, -428722.9051924, 341776.0910214]) * u.km)
    assert u.allclose(
        gc.end_cartesian * u.m,
        np.asarray([-71429.5229381, 571439.071248, 390859.5797815]) * u.km)
    assert u.allclose(gc.center_cartesian * u.m, np.asarray([0, 0, 0]) * u.km)

    assert u.allclose(
        gc.v1 * u.m,
        np.asarray([428721.0913539, -428722.9051924, 341776.0910214]) * u.km)
    assert u.allclose(gc._r, 696000000.0015007)
    assert u.allclose(
        gc.v2 * u.m,
        np.asarray([-71429.5229381, 571439.071248, 390859.5797815]) * u.km)
    assert u.allclose(
        gc.v3 * u.m,
        np.asarray([56761.6265851, 466230.7005856, 513637.0815867]) * u.km)

    # Inner angle
    assert gc.inner_angle.unit == u.rad
    np.testing.assert_almost_equal(gc.inner_angle.value, 1.8683580432741789)

    # Distance
    assert gc.distance.unit == u.m
    np.testing.assert_approx_equal(gc.distance.value, 1300377198.1299164)

    # Radius of the sphere
    assert gc.radius.unit == u.m
    assert u.isclose(gc.radius.value * u.m, 696000.000001501 * u.km)

    # Test the calculation of the SkyCoords
    # Coordinates method
    # Number of points
    assert len(coordinates) == points_expected

    # Start and end coordinates
    np.testing.assert_almost_equal(coordinates[0].Tx.value, first_point[0])
    np.testing.assert_almost_equal(coordinates[0].Ty.value, first_point[1])
    np.testing.assert_almost_equal(coordinates[-1].Tx.value, last_point[0])
    np.testing.assert_almost_equal(coordinates[-1].Ty.value, last_point[1])

    # Inner angles method
    # Inner angles
    assert len(inner_angles) == points_expected
    np.testing.assert_almost_equal(inner_angles[-1].value, last_inner_angle)

    # Distances method
    assert len(distances) == points_expected
    assert u.isclose(distances[-1].value * u.m, last_distance * u.km)
예제 #7
0
###############################################################################
# Let's define the start and end coordinates of the arc.
start = SkyCoord(735 * u.arcsec, -471 * u.arcsec, frame=m.coordinate_frame)
end = SkyCoord(-100 * u.arcsec, 800 * u.arcsec, frame=m.coordinate_frame)

###############################################################################
# Create the great arc between the start and end points.
great_arc = GreatArc(start, end)

###############################################################################
# Plot the great arc on the Sun.
fig = plt.figure()
ax = plt.subplot(projection=m)
m.plot(axes=ax)
ax.plot_coord(great_arc.coordinates(), color='c')
plt.show()

###############################################################################
# Now we can calculate the nearest integer pixels of the data that correspond
# to the location of arc.
pixels = np.asarray(np.rint(m.world_to_pixel(great_arc.coordinates())),
                    dtype=int)
x = pixels[0, :]
y = pixels[1, :]

###############################################################################
# Get the intensity along the arc from the start to the end point.
intensity_along_arc = m.data[y, x]

###############################################################################
예제 #8
0
def test_great_arc_coordinates(points_requested, points_expected, first_point,
                               last_point, last_inner_angle, last_distance):

    m = sunpy.map.Map(
        sunpy.map.Map(
            sunpy.data.test.get_test_filepath('aia_171_level1.fits')))
    coordinate_frame = m.coordinate_frame
    a = SkyCoord(600 * u.arcsec, -600 * u.arcsec, frame=coordinate_frame)
    b = SkyCoord(-100 * u.arcsec, 800 * u.arcsec, frame=coordinate_frame)
    gc = GreatArc(a, b, points=points_requested)
    coordinates = gc.coordinates()
    inner_angles = gc.inner_angles()
    distances = gc.distances()

    # Ensure a GreatArc object is returned
    assert isinstance(gc, GreatArc)

    # Test the properties of the GreatArc object
    assert gc.start == a
    assert gc.end == b
    assert gc.distance_unit == u.km
    assert gc.observer == a.observer
    assert gc.center.x == 0 * u.km
    assert gc.center.y == 0 * u.km
    assert gc.center.z == 0 * u.km

    np.testing.assert_almost_equal(
        gc.start_cartesian,
        np.asarray([428721.0913539, -428722.9051924, 341776.0910214]))
    np.testing.assert_almost_equal(
        gc.end_cartesian,
        np.asarray([-71429.5229381, 571439.071248, 390859.5797815]))
    np.testing.assert_almost_equal(gc.center_cartesian, np.asarray([0, 0, 0]))

    np.testing.assert_almost_equal(
        gc.v1, np.asarray([428721.0913539, -428722.9051924, 341776.0910214]))
    np.testing.assert_almost_equal(gc._r, 696000.000001501)
    np.testing.assert_almost_equal(
        gc.v2, np.asarray([-71429.5229381, 571439.071248, 390859.5797815]))
    np.testing.assert_almost_equal(
        gc.v3, np.asarray([56761.6265851, 466230.7005856, 513637.0815867]))

    # Inner angle
    assert gc.inner_angle.unit == u.rad
    np.testing.assert_almost_equal(gc.inner_angle.value, 1.8683580432741789)

    # Distance
    assert gc.distance.unit == u.km
    np.testing.assert_almost_equal(gc.distance.value, 1300377.1981298963)

    # Radius of the sphere
    assert gc.radius.unit == u.km
    np.testing.assert_almost_equal(gc.radius.value, 696000.000001501)

    # Test the calculation of the SkyCoords
    # Coordinates method
    # Number of points
    assert len(coordinates) == points_expected

    # Start and end coordinates
    np.testing.assert_almost_equal(coordinates[0].Tx.value, first_point[0])
    np.testing.assert_almost_equal(coordinates[0].Ty.value, first_point[1])
    np.testing.assert_almost_equal(coordinates[-1].Tx.value, last_point[0])
    np.testing.assert_almost_equal(coordinates[-1].Ty.value, last_point[1])

    # Inner angles method
    # Inner angles
    assert len(inner_angles) == points_expected
    np.testing.assert_almost_equal(inner_angles[-1].value, last_inner_angle)

    # Distances method
    assert len(distances) == points_expected
    np.testing.assert_almost_equal(distances[-1].value, last_distance)
예제 #9
0
ax.plot(pixel_coord[0], pixel_coord[1], 'x', color='w',
        label=f'Pixel coordinate [{pixel_coord[0]}, {pixel_coord[1]}]')

###############################################################################
# As well as defining a point and using `.GenericMap.plot()`, you can also plot
# a point with WCSAxes using the `~astropy.visualization.wcsaxes.WCSAxes.plot_coord`
# functionality using a coordinate as a SkyCoord.
# We can demonstrate this by plotting a point and an arc on a map using two separate SkyCoords.
# Here we will plot a point (at -250,-250) on the map using a SkyCoord.

# sphinx_gallery_defer_figures

ax.plot_coord(SkyCoord(-250*u.arcsec, -250*u.arcsec, frame=my_map.coordinate_frame), "o",
              label=f'SkyCoord [{-250*u.arcsec}, {-250*u.arcsec}]')

###############################################################################
# Finally, let's create a great arc between a start and end point defined as SkyCoords.

start = SkyCoord(723 * u.arcsec, -500 * u.arcsec, frame=my_map.coordinate_frame)
end = SkyCoord(-100 * u.arcsec, 900 * u.arcsec, frame=my_map.coordinate_frame)

great_arc = GreatArc(start, end)

my_map.plot(axes=ax, clip_interval=(1, 99.99)*u.percent)
ax.plot_coord(great_arc.coordinates(), color='c',
              label=f'SkyCoord [{723*u.arcsec}, {-500*u.arcsec}],\n \
                               [{-100*u.arcsec}, {900*u.arcsec}]')
ax.legend(loc="lower center")

plt.show()
예제 #10
0
# functionality using a coordinate as a SkyCoord.
# We can demonstrate this by plotting a point and an arc on a map using two separate SkyCoords.
# Here we will plot a point (at -250,-250) on the map using a SkyCoord.

# sphinx_gallery_defer_figures

ax.plot_coord(SkyCoord(-250 * u.arcsec,
                       -250 * u.arcsec,
                       frame=my_map.coordinate_frame),
              "o",
              label=f'SkyCoord [{-250*u.arcsec}, {-250*u.arcsec}]')

###############################################################################
# Finally, let's create a great arc between a start and end point defined as SkyCoords.

start = SkyCoord(723 * u.arcsec,
                 -500 * u.arcsec,
                 frame=my_map.coordinate_frame)
end = SkyCoord(-100 * u.arcsec, 900 * u.arcsec, frame=my_map.coordinate_frame)

great_arc = GreatArc(start, end)

my_map.plot(axes=ax, clip_interval=(1, 99.99) * u.percent)
ax.plot_coord(great_arc.coordinates(),
              color='c',
              label=f'SkyCoord [{723*u.arcsec}, {-500*u.arcsec}],\n \
                               [{-100*u.arcsec}, {900*u.arcsec}]')
plt.legend(loc="lower center")

plt.show()
예제 #11
0
def test_great_arc_coordinates(points_requested, points_expected, first_point,
                               last_point, last_inner_angle, last_distance):

    m = sunpy.map.Map(sunpy.map.Map(sunpy.data.test.get_test_filepath('aia_171_level1.fits')))
    coordinate_frame = m.coordinate_frame
    a = SkyCoord(600*u.arcsec, -600*u.arcsec, frame=coordinate_frame)
    b = SkyCoord(-100*u.arcsec, 800*u.arcsec, frame=coordinate_frame)
    gc = GreatArc(a, b, points=points_requested)
    coordinates = gc.coordinates()
    inner_angles = gc.inner_angles()
    distances = gc.distances()

    # Ensure a GreatArc object is returned
    assert isinstance(gc, GreatArc)

    # Test the properties of the GreatArc object
    assert gc.start == a
    assert gc.end == b
    assert gc.distance_unit == u.km
    assert gc.observer == a.observer
    assert gc.center.x == 0 * u.km
    assert gc.center.y == 0 * u.km
    assert gc.center.z == 0 * u.km

    np.testing.assert_almost_equal(gc.start_cartesian, np.asarray([428721.09135385, -428722.90519236, 341776.09102756]))
    np.testing.assert_almost_equal(gc.end_cartesian, np.asarray([-71429.52293813, 571439.07124801, 390859.57978693]))
    np.testing.assert_almost_equal(gc.center_cartesian, np.asarray([0, 0, 0]))

    np.testing.assert_almost_equal(gc.v1, np.asarray([428721.09135385, -428722.90519236, 341776.09102756]))
    np.testing.assert_almost_equal(gc._r, 696000.00000451738)
    np.testing.assert_almost_equal(gc.v2, np.asarray([-71429.52293813, 571439.07124801, 390859.57978693]))
    np.testing.assert_almost_equal(gc.v3, np.asarray([56761.62657985, 466230.70058902, 513637.08158833]))

    # Inner angle
    assert gc.inner_angle.unit == u.rad
    np.testing.assert_almost_equal(gc.inner_angle.value, 1.8683580432741789)

    # Distance
    assert gc.distance.unit == u.km
    np.testing.assert_almost_equal(gc.distance.value, 1300377.1981272686)

    # Radius of the sphere
    assert gc.radius.unit == u.km
    np.testing.assert_almost_equal(gc.radius.value, 696000.0000045174)

    # Test the calculation of the SkyCoords
    # Coordinates method
    # Number of points
    assert len(coordinates) == points_expected

    # Start and end coordinates
    np.testing.assert_almost_equal(coordinates[0].Tx.value, first_point[0])
    np.testing.assert_almost_equal(coordinates[0].Ty.value, first_point[1])
    np.testing.assert_almost_equal(coordinates[-1].Tx.value, last_point[0])
    np.testing.assert_almost_equal(coordinates[-1].Ty.value, last_point[1])

    # Inner angles method
    # Inner angles
    assert len(inner_angles) == points_expected
    np.testing.assert_almost_equal(inner_angles[-1].value, last_inner_angle)

    # Distances method
    assert len(distances) == points_expected
    np.testing.assert_almost_equal(distances[-1].value, last_distance)
예제 #12
0
###############################################################################
# Let's define the start and end co-ordinates of the arc on the Sun.
start = SkyCoord(735 * u.arcsec, -471 * u.arcsec, frame=m.coordinate_frame)
end = SkyCoord(-100 * u.arcsec, 800 * u.arcsec, frame=m.coordinate_frame)

###############################################################################
# Create the great arc between the start and end points.
great_arc = GreatArc(start, end)

###############################################################################
# Plot the great arc on the Sun.
fig = plt.figure()
ax = plt.subplot(projection=m)
m.plot(axes=ax)
ax.plot_coord(great_arc.coordinates(), color='c')
plt.show()

###############################################################################
# Now we can calculate the nearest integer pixels of the data that correspond
# to the location of arc.
pixels = np.asarray(np.rint(m.world_to_pixel(great_arc.coordinates())), dtype=int)
x = pixels[0, :]
y = pixels[1, :]

###############################################################################
# Get the intensity along the arc from the start to the end point.
intensity_along_arc = m.data[y, x]

###############################################################################
# Define the angular location of each pixel along the arc from the start point