def solar_angle_equivalency(observer): """ Return the equivalency to convert between a physical distance on the Sun and an angular separation as seen by a specified observer. .. note:: This equivalency assumes that the physical distance is perpendicular to the Sun-observer line. That is, the tangent of the angular separation is equal to the ratio of the physical distance to the Sun-observer distance. For large physical distances, a different assumption may be more appropriate. Parameters ---------- observer : `~astropy.coordinates.SkyCoord` Observer location for which the equivalency is calculated. Returns ------- equiv : equivalency function that can be used as keyword `equivalencies` for astropy unit conversion. Examples -------- >>> import astropy.units as u >>> from sunpy.coordinates import get_body_heliographic_stonyhurst >>> earth_observer = get_body_heliographic_stonyhurst("earth", "2013-10-28") >>> distance_in_km = 725*u.km >>> distance_in_km.to(u.arcsec, equivalencies=solar_angle_equivalency(earth_observer)) INFO: Apparent body location accounts for 495.82 seconds of light travel time [sunpy.coordinates.ephemeris] <Quantity 1.00603718 arcsec> """ if not isinstance(observer, (SkyCoord, BaseCoordinateFrame)): raise TypeError( "Invalid input, observer must be of type SkyCoord or BaseCoordinateFrame." ) if observer.obstime is None: raise ValueError("Observer must have an observation time, `obstime`.") obstime = observer.obstime sun_coord = get_body_heliographic_stonyhurst("sun", time=obstime, observer=observer) sun_observer_distance = sun_coord.separation_3d(observer).to_value(u.m) equiv = [(u.radian, u.meter, lambda x: np.tan(x) * sun_observer_distance, lambda x: np.arctan(x / sun_observer_distance))] return equiv
from astropy.coordinates import SkyCoord from sunpy.coordinates import get_body_heliographic_stonyhurst from astropy.time import Time import matplotlib.pyplot as plt import numpy as np obstime = Time('2020-05-15T07:54:00.005') planet_list = ['earth', 'venus', 'mars', 'mercury', 'jupiter', 'neptune', 'uranus'] planet_coord = [get_body_heliographic_stonyhurst(this_planet, time=obstime) for this_planet in planet_list] fig = plt.figure() ax1 = plt.subplot(1, 1, 1, projection='polar') for this_planet, this_coord in zip(planet_list, planet_coord): plt.polar(np.deg2rad(this_coord.lon), this_coord.radius, 'o', label=this_planet) plt.legend() plt.show()
aiamap = sunpy.map.Map(AIA_171_IMAGE) ############################################################################### # You can access the observer coordinate with: print(aiamap.observer_coordinate) ############################################################################### # This provides the location of the SDO as defined in the header and is # necessary to fully define the helioprojective coordinate system which # depends on where the observer is. Let's see where this is with respect # to Earth. SDO is a geosynchronous orbit with a semi-major axis of # 42,164.71 km and an inclination of 28.05 deg. # We will convert it to Geocentric Celestial Reference System (GCRS) # whose center is at the Earth's center-of-mass. sdo_gcrs = aiamap.observer_coordinate.gcrs sun = get_body_heliographic_stonyhurst('sun', aiamap.date) ############################################################################## # Let's plot the results. The green circle represents the Earth. # This looks like the Earth is in the way of SDO's # field of view but remember that it is also above the plane of this plot # by its declination. ax = plt.subplot(projection='polar') circle = plt.Circle((0.0, 0.0), 1.0, transform=ax.transProjectionAffine + ax.transAxes, color="green", alpha=0.4, label="Earth") ax.add_artist(circle) plt.text(0.48, 0.5, "Earth", transform=ax.transAxes)
aiamap = sunpy.map.Map(files[0]) ############################################################################### # For this example, we require high-precision ephemeris information. The built-in # ephemeris provided by astropy is not accurate enough. This call requires ``jplephem`` # to be installed. This will also trigger a download of about ~10 MB. solar_system_ephemeris.set('de432s') ############################################################################### # Now we get the position of Venus and convert it into the SDO/AIA coordinates. # The apparent position of Venus accounts for the time it takes for light to # travel from Venus to SDO. venus = get_body_heliographic_stonyhurst('venus', aiamap.date, observer=aiamap.observer_coordinate) venus_hpc = venus.transform_to(aiamap.coordinate_frame) ############################################################################### # Let's crop the image with Venus at its center. fov = 200 * u.arcsec bottom_left = SkyCoord(venus_hpc.Tx - fov / 2, venus_hpc.Ty - fov / 2, frame=aiamap.coordinate_frame) smap = aiamap.submap(bottom_left, width=fov, height=fov) ############################################################################### # Let's plot the results.
fig = plt.figure() ax1 = fig.add_subplot(1, 2, 1, projection=map_aia) map_aia.plot(axes=ax1) ax2 = fig.add_subplot(1, 2, 2, projection=outmap) outmap.plot(axes=ax2) ###################################################################### # AIA as Seen from Mars # ===================== # # We can also change the observer of the AIA image to any observer # coordinate. SunPy provides a function which can get the observer # coordinate for any known body. In this example we are going to use Mars. mars = get_body_heliographic_stonyhurst('mars', map_aia.date) ###################################################################### # We now generate a target WCS, to do this we need to generate a reference # coordinate, which is similar to the aia frame, but scaled down by 4x and # with the observer at Mars. To do this we generate a new reference # coordinate. mars_ref_coord = SkyCoord(map_aia.reference_coordinate.Tx, map_aia.reference_coordinate.Ty, obstime=map_aia.reference_coordinate.obstime, observer=mars, frame="helioprojective") ###################################################################### # then a header
############################################################################### # Now we load each star into a coordinate and transform it into the COR2 # image coordinates. Since we don't know the distance to each of these stars # we will just put them very far away. hpc_coords = [] for this_object in result[0]: tbl_crds = SkyCoord(this_object['RA_ICRS'] * u.deg, this_object['DE_ICRS'] * u.deg, 1e12 * u.km, frame='icrs', obstime=cor2.date) hpc_coords.append(tbl_crds.transform_to(cor2.coordinate_frame)) ############################################################################### # One of the bright features is actually Mars so let's also get that coordinate. # get the location of Mars. mars = get_body_heliographic_stonyhurst('mars', cor2.date, observer=cor2.observer_coordinate) mars_hpc = mars.transform_to(frames.Helioprojective(observer=cor2.observer_coordinate)) ############################################################################### # Let's plot the results. ax = plt.subplot(projection=cor2) # Let's tweak the axis to show in degrees instead of arcsec lon, lat = ax.coords lon.set_major_formatter('d.dd') lat.set_major_formatter('d.dd') cor2.plot(axes=ax, vmin=0, vmax=600) cor2.draw_limb()
def test_planets(): kg2Em = 1.67443e-25 #earth mass sec2day = 1.15741e-5 m2Au = 6.68459e-12 #Astronomical unit G = 6.67408 * numpy.power(10.0, -11) * kg2Em * (sec2day**2) / (m2Au**2) obstime = Time('2014-05-15T07:54:00.005') planet_list = [ 'sun', 'earth', 'venus', 'mars', 'mercury', 'jupiter', 'neptune', 'uranus' ] planet_coord = [ get_body_heliographic_stonyhurst(this_planet, time=obstime, include_velocity=True) for this_planet in planet_list ] planet_masses = [ 1.988e30 * kg2Em, 5.972e24 * kg2Em, 4.867e24 * kg2Em, 6.417e23 * kg2Em, 3.301e23 * kg2Em, 1.899e27 * kg2Em, 1.024e26 * kg2Em, 8.682e25 * kg2Em ] myData = [] for count, planet in enumerate(planet_coord): myData.append( Body( numpy.array([planet_masses[count]]), numpy.array([ planet.data.x.to('au').value, planet.data.y.to('au').value ]), numpy.array([ planet.velocity.d_x.to('au/day').value, planet.velocity.d_y.to('au/day').value ]))) endtime = 370 t = numpy.linspace(0, endtime, endtime + 1) sol0 = test(myData, len(myData), 2, G, t) sol = solve1(myData, len(myData), 2, G, t) sol2 = solve2(myData, len(myData), 2, 4, G, t) sol3 = solve3(myData, len(myData), 2, 4, G, t) sol4 = Verlet1.solve4(myData, len(myData), 2, G, t) sol5 = solve5(myData, len(myData), 2, G, t) error1 = abs(sol - sol0) error2 = abs(sol2 - sol0) error3 = abs(sol3 - sol0) error4 = abs(sol4 - sol0) error5 = abs(sol5 - sol0) table = plt.figure(1) plt.plot(t, error1.mean(1), label="default") plt.plot(t, error2.mean(1), label="threading") plt.plot(t, error3.mean(1), label="multiprocessing") plt.plot(t, error4.mean(1), label="cython") plt.plot(t, error5.mean(1), label="CUDA") plt.legend() fig = plt.figure(2) ax1 = plt.subplot(1, 1, 1, projection='polar') position = [] kmToAU = 6.68459e-9 for instance in sol: tmp = [] for i in range(0, 16, 2): tmp.append( numpy.sqrt( numpy.power(instance[i], 2) + numpy.power(instance[i + 1], 2))) tmp.append(numpy.arctan2(instance[i + 1], instance[i])) position.append(tmp) def update_plot(value): ax1.cla() for i, name in zip(range(0, 16, 2), planet_list): plt.polar(position[value][i + 1], position[0][i], 'o', label=name) plt.legend() fig.canvas.draw_idle() for i, name in zip(range(0, 16, 2), planet_list): plt.polar(position[0][i + 1], position[0][i], 'o', label=name) plt.legend() ax2 = plt.axes([0.25, 0.05, 0.5, 0.03]) slider1 = Slider(ax2, 'time(years)', 0, endtime, valstep=1) slider1.on_changed(update_plot) plt.show()
maps = [m.resample((1024, 1024)*u.pix) for m in maps] ###################################################################### # When combining these images all three need to assume the same radius of # the Sun for the data. The AIA images specify a slightly different value # than the IAU 2015 constant. To avoid coordinate transformation issues we # reset this here. maps[0].meta['rsun_ref'] = sunpy.sun.constants.radius.to_value(u.m) ###################################################################### # Next we will plot the locations of the three spacecraft with respect to # the Sun so we can easily see the relative separations. earth = get_body_heliographic_stonyhurst('earth', maps[0].date) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(projection='polar') circle = plt.Circle((0.0, 0.0), (10*u.Rsun).to_value(u.AU), transform=ax.transProjectionAffine + ax.transAxes, color="yellow", alpha=1, label="Sun") ax.add_artist(circle) ax.text(earth.lon.to_value("rad")+0.05, earth.radius.to_value(u.AU), "Earth") for this_satellite, this_coord in [(m.observatory, m.observer_coordinate) for m in maps]: ax.plot(this_coord.lon.to('rad'), this_coord.radius.to(u.AU), 'o', label=this_satellite) ax.set_theta_zero_location("S") ax.set_rlim(0, 1.3) ax.legend()
screen.fill((0, 0, 0)) # Creating the solar system solarSystem = SolarSystem(screen) solarSystem.sun.setPosition([screenWidth / 2, screenHeight / 2]) # print("Sun position: " + str(solarSystem.sun.getPosition()[0]) + ", " + str(solarSystem.sun.getPosition()[1])) # Array with the initial positions of the planets # obstime = Time('2014-05-15T07:54:00.005') obstime = Time(datetime.datetime.now()) planet_list = [ 'mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune' ] planet_coord = [ get_body_heliographic_stonyhurst(this_planet, time=obstime) for this_planet in planet_list ] i = 100 # Used for when we want to start all planets in a single line for this_planet, this_coord in zip(planet_list, planet_coord): # Angle at which the planet can be found longitude = float(str(deg2rad(this_coord.lon)).split('rad')[0]) # Distance from the sun radius = float(str(this_coord.radius).split(' AU') [0]) # Get the first 5 character positions, so 3 decimals # The previous radius was in AU. We want to adjust this number so that all the planets fit on the screen radius = math.log(radius + 1, baseController) # print(radius)
import sunpy.map from sunpy.coordinates import get_body_heliographic_stonyhurst from sunpy.visualization.limb import draw_limb ############################################################################### # Let's download a magnetic field synoptic map and read it into a Map. syn_map = sunpy.map.Map( 'http://jsoc.stanford.edu/data/hmi/synoptic/hmi.Synoptic_Mr.2191.fits') syn_map.plot_settings['cmap'] = 'hmimag' syn_map.plot_settings['norm'] = plt.Normalize(-1500, 1500) ############################################################################### # Get coordinates for Earth and Mars at the date of the synoptic map coords = { body: get_body_heliographic_stonyhurst(body, syn_map.date) for body in ['Earth', 'Mars'] } ############################################################################### # Now we can plot the map the the solar limb seen from these two coordinates. # To create a legend for these limbs, we need to keep the patches returned by # :func:`~sunpy.visualization.draw_limb` and provide them to # :meth:`~matplotlib.axes.Axes.legend`. fig = plt.figure(figsize=(12, 5)) ax = fig.add_subplot(projection=syn_map) im = syn_map.plot(axes=ax) visible_limbs = [] for (body, coord), color in zip(coords.items(), ['tab:blue', 'tab:red']): v, _ = draw_limb(ax,