def test_angular_separation(self): time = sunset_and_rise_for_date(self.data, 2020, 12, 17)[0] moon = self.data.ephemeris['moon'] mercury = self.data.get_body("Mercury") sep, pos = angular_separation(self.data, moon, mercury, time) self.assertLessEqual(abs(sep.degrees - 39.1), 1.0) self.assertEqual(pos, EclipticPosition.BEHIND) sep, pos = angular_separation(self.data, mercury, moon, time) self.assertEqual(pos, EclipticPosition.AHEAD) self.assertLessEqual(abs(sep.degrees - 39.1), 1.0) dablin = Star.from_dataframe(self.data.stars.loc[100345]) sep, pos = angular_separation(self.data, moon, dablin, time) self.assertEqual(pos, EclipticPosition.BELOW) self.assertLessEqual(abs(sep.degrees - 8.9), 1.0) sep, pos = angular_separation(self.data, dablin, moon, time) self.assertEqual(pos, EclipticPosition.ABOVE) self.assertLessEqual(abs(sep.degrees - 8.9), 1.0) fomalhaut = Star.from_dataframe(self.data.stars.loc[113368]) sep, pos = angular_separation(self.data, fomalhaut, mercury, time) self.assertEqual(pos, EclipticPosition.BEHIND) self.assertLessEqual(abs(sep.degrees - 70.45), 1.0) sep, pos = angular_separation(self.data, mercury, fomalhaut, time) self.assertEqual(pos, EclipticPosition.AHEAD) self.assertLessEqual(abs(sep.degrees - 70.45), 1.0)
def parse(line): """Return a `Star` build by parsing a Hipparcos catalog entry `line`.""" # See ftp://cdsarc.u-strasbg.fr/cats/I/239/ReadMe star = Star( ra=Angle(degrees=float(line[51:63])), dec=Angle(degrees=float(line[64:76])), ra_mas_per_year=float(line[87:95]), dec_mas_per_year=float(line[96:104]), parallax_mas=float(line[79:86]), names=[('HIP', int(line[8:14]))], ) star._position_au += star._velocity_au_per_d * days distance, dec, ra = to_polar(star._position_au) star.ra = Angle(radians=ra, preference='hours') star.dec = Angle(radians=dec) return star
def test_cirs_sofa(): ts = api.load.timescale() earth = api.load('de421.bsp')['earth'] test_data = [ [45.0, 46.0, 2458327], [200.0, -22.0, 2458327], [45.0, 46.0, 2459327] ] # Results output by SOFA. Calculated using the source code above. sofa_results = [ [45.074343838325, 46.067831092355], [200.013551320030, -22.096008994214], [45.077698288877, 46.082296559677] ] tol = 1e-5 / 3600.0 # 10 micro arc-seconds for ((ra_icrs, dec_icrs, tdb), (ra_sofa, dec_sofa)) in zip(test_data, sofa_results): ss = Star(ra_hours=(ra_icrs / 15.0), dec_degrees=dec_icrs) st = ts.tdb(jd=tdb) with low_precision_ERA(): ra_cirs, dec_cirs, _ = earth.at(st).observe(ss).apparent().cirs_radec(st) assert np.allclose(ra_cirs._degrees, ra_sofa, rtol=0.0, atol=tol) assert np.allclose(dec_cirs._degrees, dec_sofa, rtol=0.0, atol=tol)
def parse(line): "DEPRECATED; see :func:`~skyfield.data.hipparcos.load_dataframe() instead." # See ftp://cdsarc.u-strasbg.fr/cats/I/239/ReadMe star = Star( ra=Angle(degrees=float(line[51:63])), dec=Angle(degrees=float(line[64:76])), ra_mas_per_year=float(line[87:95]), dec_mas_per_year=float(line[96:104]), parallax_mas=float(line[79:86]), names=[('HIP', int(line[8:14]))], ) star._position_au += star._velocity_au_per_d * days distance, dec, ra = to_polar(star._position_au) star.ra = Angle(radians=ra, preference='hours') star.dec = Angle(radians=dec) return star
def run(location, t, target): """ Assumes location is dict with "latitude", "longitude" keys in decimal degres, and "elevation" key in meters Assumes t is datetime obj Assumes target is astropy SkyCoord with ICRS RA and DE """ planets = load("de421.bsp") earth = planets["earth"] moon = planets["moon"] # convert from astropy SkyCoord to skyfield "Star" target = Star(ra_hours=target.ra.hour, dec_degrees=target.dec.degree) loc = earth + Topos(location["latitude"], location["longitude"], elevation_m=location["elevation"]) moon_app_pos = loc.at(t).observe(moon).apparent() app_pos = loc.at(t).observe(target).apparent() alt, _, _ = app_pos.altaz() alt = alt.degrees # convert from skyfield.units.Angle to float degrees moondiff = moon_app_pos.separation_from(app_pos).degrees return alt, moondiff
def star(self, ref: Union[str, int], culture: Optional[str] = None) -> CelestialObject: """Fetch a star by its name or Hipparcos catalogue number. Args: ref: Either the string common name, or the int catalogue number, e.g. 87937 for Barnard's Star. culture: If given, use as a hint to understand the common name. """ number = ref if isinstance(ref, int) else self.starNumber(ref) data = self._stars.loc[number] names = self._starNames.allNames(number) primaryName = (ref if isinstance(ref, str) else names["western"] if "western" in names else names["hip"]) star = Star.from_dataframe(data) return makeObject( type=ObjectType.STAR, name=primaryName, position=star, dataFrame=data, names=names, )
def get_body(self, name: str): name = name.lower() if name == MERCURY.name: return self.ephemeris["MERCURY BARYCENTER"] if name == VENUS.name: return self.ephemeris["VENUS BARYCENTER"] if name == EARTH: return self.ephemeris["EARTH"] if name == MARS.name: return self.ephemeris["MARS BARYCENTER"] if name == SATURN.name: return self.ephemeris["SATURN BARYCENTER"] if name == JUPITER.name: return self.ephemeris["JUPITER BARYCENTER"] if name == MOON: return self.ephemeris["MOON"] if name == SUN: return self.ephemeris["SUN"] if name == ALCYONE: return Star.from_dataframe(self.stars.loc[17702]) if name == ANTARES: return Star.from_dataframe(self.stars.loc[80763]) if name == BETA_CAPRICORNI: return Star.from_dataframe(self.stars.loc[100345]) if name == BETA_GEMINORUM: return Star.from_dataframe(self.stars.loc[37826]) if name == BETA_LIBRAE: return Star.from_dataframe(self.stars.loc[74785]) if name == BETA_VIRGINIS: return Star.from_dataframe(self.stars.loc[57757]) if name == EPSILON_LEONIS: return Star.from_dataframe(self.stars.loc[47908]) if name == EPSILON_PISCIUM: return Star.from_dataframe(self.stars.loc[4906]) if name == FORTY_TWO_CANCRI: return Star.from_dataframe(self.stars.loc[42578]) if name == REGULUS: return Star.from_dataframe(self.stars.loc[49669]) if name == THETA_LEONIS: return Star.from_dataframe(self.stars.loc[54879]) if name == SHERATAN: return Star.from_dataframe(self.stars.loc[8903]) if name == NU_ARIETIS: return Star.from_dataframe(self.stars.loc[12332]) if name == NU_AURIGAE: return Star.from_dataframe(self.stars.loc[27673]) if name == THETA_CANCRI: return Star.from_dataframe(self.stars.loc[41822]) if name == ETA_CAPRICORNI: return Star.from_dataframe(self.stars.loc[104019]) if name == OMEGA_GEMINORUM: return Star.from_dataframe(self.stars.loc[33927]) if name == FIFTY_TWO_LEONIS: return Star.from_dataframe(self.stars.loc[52689]) if name == NU_LIBRAE: return Star.from_dataframe(self.stars.loc[73945]) if name == THIRTY_SIX_PERSEI: return Star.from_dataframe(self.stars.loc[16499]) if name == FIFTY_EIGHT_PISCIUM: return Star.from_dataframe(self.stars.loc[3675]) if name == ASCELLA: return Star.from_dataframe(self.stars.loc[93506]) if name == EPSILON_TAURI: return Star.from_dataframe(self.stars.loc[20889]) if name == THETA_VIRGINIS: return Star.from_dataframe(self.stars.loc[64238]) raise ValueError