def test_consistency_with_horizons(use_DE440s, obstime): # Check that the high-accuracy Astropy ephemeris has been set assert solar_system_ephemeris.get() == 'de440s' # Check whether the location of Earth is the same between Astropy and JPL HORIZONS e1 = get_earth(obstime) e2 = get_horizons_coord('Geocenter', obstime) assert_quantity_allclose(e2.separation_3d(e1), 0 * u.km, atol=50 * u.m) # Check whether the location of Mars is the same between Astropy and JPL HORIZONS e1 = get_body_heliographic_stonyhurst('mars', obstime) e2 = get_horizons_coord('Mars barycenter', obstime) assert_quantity_allclose(e2.separation_3d(e1), 0 * u.km, atol=500 * u.m)
def test_get_horizons_coord_dict_time(): # get_horizons_coord() depends on astroquery pytest.importorskip("astroquery") time_dict = {'start': '2013-03-01', 'stop': '2013-03-03', 'step': '1d'} time_ref = Time(['2013-03-01', '2013-03-02', '2013-03-03']) e = get_horizons_coord('Geocenter', time_dict) e_ref = get_horizons_coord('Geocenter', time_ref) assert_quantity_allclose(e.lon, e_ref.lon, atol=1e-9 * u.deg) assert_quantity_allclose(e.lat, e_ref.lat) assert_quantity_allclose(e.radius, e_ref.radius)
def test_consistency_with_horizons(astropy_ephemeris_de432s, obstime): # get_horizons_coord() depends on astroquery pytest.importorskip("astroquery") # Check whether the location of Earth is the same between Astropy and JPL HORIZONS e1 = get_earth(obstime) e2 = get_horizons_coord('Geocenter', obstime) assert_quantity_allclose(e2.separation_3d(e1), 0 * u.km, atol=50 * u.m) # Check whether the location of Mars is the same between Astropy and JPL HORIZONS e1 = get_body_heliographic_stonyhurst('mars', obstime) e2 = get_horizons_coord('Mars barycenter', obstime) assert_quantity_allclose(e2.separation_3d(e1), 0 * u.km, atol=500 * u.m)
def test_get_horizons_coord(): # get_horizons_coord() depends on astroquery pytest.importorskip("astroquery") # Validate against published values from the Astronomical Almanac (2013) e1 = get_horizons_coord('Geocenter', '2013-Jan-01') assert_quantity_allclose(e1.lon, 0 * u.deg, atol=5e-6 * u.deg) assert_quantity_allclose(e1.lat, -3.03 * u.deg, atol=5e-3 * u.deg) assert_quantity_allclose(e1.radius, 0.9832947 * u.AU, atol=5e-7 * u.AU) e2 = get_horizons_coord('Geocenter', '2013-Sep-01') assert_quantity_allclose(e1.lon, 0 * u.deg, atol=5e-6 * u.deg) assert_quantity_allclose(e2.lat, 7.19 * u.deg, atol=5e-3 * u.deg) assert_quantity_allclose(e2.radius, 1.0092561 * u.AU, atol=5e-7 * u.AU)
def get_position_heliographic_stonyhurst(body_name, time, observer): """ Get the position of one of the supported bodies as seen from the observer. If Parameters ---------- body_name : time : observer : Returns ------- `~astropy.coordinate.SkyCoord` """ _body_name = body_name.lower() # Check if the body is one of the supported spacecraft. Note that the if _body_name in spacecraft: coordinate = get_horizons_coord(_body_name, time).transform_to( frames.HeliographicStonyhurst) # Check if the body is one of the supported solar system objects elif _body_name in solar_system_objects: coordinate = get_body_heliographic_stonyhurst(_body_name, time=time, observer=observer) else: raise ValueError('The body name is not recognized.') return coordinate
def eitprep(fitsfile, return_map=False): hdul = fits.open(fitsfile) hdul[0].verify('silentfix') header = hdul[0].header data = hdul[0].data.astype(np.float64) new_coords = get_horizons_coord(header['TELESCOP'], parse_time(header['DATE_OBS'])) header['HGLN_OBS'] = new_coords.lon.to('deg').value header['HGLT_OBS'] = new_coords.lat.to('deg').value header['DSUN_OBS'] = new_coords.radius.to('m').value header.pop('hec_x') header.pop('hec_y') header.pop('hec_z') # Target scale is 2.63 arcsec/px target_scale = 2.63 scale_factor = header['CDELT1'] / target_scale # Center of rotation at reference pixel converted to a coordinate origin at 0 reference_pixel = [header['CRPIX1'] - 1, header['CRPIX2'] - 1] # Rotation angle with openCV uses coordinate origin at top-left corner. For solar images in numpy we need to invert the angle. angle = -header['SC_ROLL'] # Run scaled rotation. The output will be a rotated, rescaled, padded array. prepdata = scale_rotate(data, angle=angle, scale_factor=scale_factor, reference_pixel=reference_pixel) prepdata[prepdata < 0] = 0 prepdata[np.isnan(prepdata)] = 0 if return_map: prepdata = Map(prepdata, header) return prepdata
def test_get_horizons_coord_array_time(): # get_horizons_coord() depends on astroquery pytest.importorskip("astroquery") # Validate against published values from the Astronomical Almanac (2013, C8-C13) array_time = Time(['2013-05-01', '2013-06-01', '2013-04-01', '2013-03-01']) e = get_horizons_coord('Geocenter', array_time) assert_quantity_allclose(e[0].lon, 0 * u.deg, atol=5e-6 * u.deg) assert_quantity_allclose(e[0].lat, -4.17 * u.deg, atol=5e-3 * u.deg) assert_quantity_allclose(e[0].radius, 1.0075271 * u.AU, atol=5e-7 * u.AU) assert_quantity_allclose(e[1].lon, 0 * u.deg, atol=5e-6 * u.deg) assert_quantity_allclose(e[1].lat, -0.66 * u.deg, atol=5e-3 * u.deg) assert_quantity_allclose(e[1].radius, 1.0140013 * u.AU, atol=5e-7 * u.AU) assert_quantity_allclose(e[2].lon, 0 * u.deg, atol=5e-6 * u.deg) assert_quantity_allclose(e[2].lat, -6.54 * u.deg, atol=5e-3 * u.deg) assert_quantity_allclose(e[2].radius, 0.9992311 * u.AU, atol=5e-7 * u.AU) assert_quantity_allclose(e[3].lon, 0 * u.deg, atol=5e-6 * u.deg) assert_quantity_allclose(e[3].lat, -7.22 * u.deg, atol=5e-3 * u.deg) assert_quantity_allclose(e[3].radius, 0.9908173 * u.AU, atol=5e-7 * u.AU)
def get_position(body_name, time): """ Get the position of the body in space. Parameters ---------- body_name : time : Returns ------- `~astropy.coordinate.SkyCoord` """ _body_name = body_name.lower() # Check if the body is one of the supported spacecraft if _body_name in spacecraft: coordinate = get_horizons_coord(_body_name, time) elif _body_name in solar_system_objects: coordinate = get_body(_body_name, time=time) else: raise ValueError('The body name is not recognized.') return coordinate
's', color='white', fillstyle='none', markersize=12, label='Mercury') lasco.plot(axes=ax) plt.show() ############################################################################### # SOHO is actually a `halo orbit <https://en.wikipedia.org/wiki/Solar_and_Heliospheric_Observatory#Orbit>`__ # around the Sun–Earth L1 point, about 1 million km away from the Earth. # The following functions queries JPL HORIZONS which includes positions of major spacecraft. # This function requires an internet connection to fetch the ephemeris data. soho = get_horizons_coord('SOHO', lasco.date) ############################################################################### # For fun, let's see how far away from the Earth SOHO is by converting to # an Earth-centered coordinate system (GCRS). print(soho.transform_to('gcrs').distance.to('km')) ############################################################################### # Let's fix the header. lasco.meta['HGLN_OBS'] = soho.lon.to('deg').value lasco.meta['HGLT_OBS'] = soho.lat.to('deg').value lasco.meta['DSUN_OBS'] = soho.radius.to('m').value ###############################################################################