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 use_DE440s(): # This class is for test functions that need the Astropy ephemeris to be set to DE432s pytest.importorskip("astroquery") old_ephemeris = solar_system_ephemeris.get() try: solar_system_ephemeris.set('de440s') except ValueError: pytest.skip( "The installed version of Astropy cannot set the ephemeris to DE440s" ) yield solar_system_ephemeris.set(old_ephemeris)
def astropy_ephemeris_de432s(): # Temporarily set Astropy's ephemeris to DE432s old_ephemeris = solar_system_ephemeris.get() solar_system_ephemeris.set('de432s') yield solar_system_ephemeris.get() solar_system_ephemeris.set(old_ephemeris)
def setup_class(cls): cls.old_ephemeris = solar_system_ephemeris.get() solar_system_ephemeris.set('de432s')
def do_stage(self, image) -> ObservationFrame: if image.classification is None: logger.warning('No classification to use for an RV template', image=image) return image phoenix_loader = phoenix.PhoenixModelLoader(self.runtime_context) template = phoenix_loader.load(image.classification) # Pick orders near the center of the detector that have a high Signal to noise and are free of tellurics. orders_to_use = np.arange( self.runtime_context.MIN_ORDER_TO_CORRELATE, self.runtime_context.MAX_ORDER_TO_CORRELATE + 1, 1) rv_measured, rv_err, coarse_ccfs, ccfs = calculate_rv( image, orders_to_use, template) # Compute the barycentric RV and observing time corrections rv_correction, bjd_tdb = barycentric_correction( image.dateobs, image.exptime, image.ra, image.dec, dbs.get_site(image.instrument.site, self.runtime_context.db_address)) # Correct the RV per Wright & Eastman (2014) and save in the header rv_correction += rv_measured * rv_correction / constants.c rv = rv_measured + rv_correction image.meta['RV'] = rv.to( 'm / s').value, 'Radial Velocity in Barycentric Frame [m/s]' # The following assumes that the uncertainty on the barycentric correction is negligible w.r.t. that # on the RV measured from the CCF, which should generally be true image.meta['RVERR'] = rv_err.to( 'm / s').value, 'Radial Velocity Uncertainty [m/s]' image.meta['BARYCORR'] = rv_correction.to( 'm / s').value, 'Barycentric Correction Applied to the RV [m/s]' image.meta['TCORR'] = bjd_tdb.to_value( 'jd'), 'Exposure Mid-Time (Barycentric Julian Date)' image.meta[ 'TCORVERN'] = 'astropy.time.light_travel_time', 'Time correction code version' # TODO: verify that the following are in fact the time corrections done by astropy; # this isn't completely obvious from the online documentation image.meta['TCORCOMP'] = 'ROMER, CLOCK', 'Time corrections done' image.meta['TCOREPOS'] = 'ERFA', 'Source of Earth position' image.meta[ 'TCORSYST'] = 'BJD_TDB ', 'Ref. frame_timesystem of TCORR column' image.meta['PLEPHEM'] = solar_system_ephemeris.get( ), 'Source of planetary ephemerides' # save the fine + coarse ccfs together # sort the coarse and fine ccf's coarse_ccfs.sort('order') ccfs.sort('order') # remove entries from the coarse ccf's that fall within the velocity range of the fine ccf's ccf_range = (np.min(ccfs['v'][0]), np.max(ccfs['v'][0])) entries_to_keep = np.logical_or(coarse_ccfs['v'][0] < min(ccf_range), coarse_ccfs['v'][0] > max(ccf_range)) coarse_ccfs['v'] = coarse_ccfs['v'][:, entries_to_keep] coarse_ccfs['xcor'] = coarse_ccfs['xcor'][:, entries_to_keep] # final_ccfs = Table({ 'order': ccfs['order'], 'v': np.hstack([coarse_ccfs['v'], ccfs['v']]), 'xcor': np.hstack([coarse_ccfs['xcor'], ccfs['xcor']]) }) # sorting xcor by the velocity grid so that things are in order sort_array = np.argsort(final_ccfs['v'][0]) final_ccfs['xcor'] = final_ccfs['xcor'][:, sort_array] final_ccfs['v'] = final_ccfs['v'][:, sort_array] image.add_or_update(DataTable(final_ccfs, name='CCF')) return image