def get_asteroid(name, timestamp): # https://rhodesmill.org/skyfield/example-plots.html#drawing-a-finder-chart-for-comet-neowise # https://astroquery.readthedocs.io/en/latest/mpc/mpc.html designation = name try: asteroids = Asteroid.objects.filter(designation__icontains=name) designation = asteroids[0].designation except: pass with load.open(settings.MY_ASTEROIDS_URL) as f: minor_planets = mpc.load_mpcorb_dataframe(f) bad_orbits = minor_planets.semimajor_axis_au.isnull() minor_planets = minor_planets[~bad_orbits] # Index by designation for fast lookup. minor_planets = minor_planets.set_index('designation', drop=False) row = minor_planets.loc[designation] ts = load.timescale() eph = load('de421.bsp') sun, earth = eph['sun'], eph['earth'] asteroid = sun + mpc.mpcorb_orbit(row, ts, GM_SUN) t = ts.utc(timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute) ra, dec, distance_from_sun = sun.at(t).observe(asteroid).radec() ra, dec, distance_from_earth = earth.at(t).observe(asteroid).radec() # https://towardsdatascience.com/space-science-with-python-a-very-bright-opposition-62e248abfe62 # how do I calculate the current phase_angle between sun and earth as seen from the asteroid ra_sun, dec_sun, d = asteroid.at(t).observe(sun).radec() ra_earth,dec_earth, d = asteroid.at(t).observe(earth).radec() phase_angle_in_degrees = abs(ra_sun.hours - ra_earth.hours) phase_angle = phase_angle_in_degrees * math.pi / 180 visual_magnitude = app_mag(abs_mag=row['magnitude_H'], \ phase_angle=phase_angle, \ slope_g=row['magnitude_G'], \ d_ast_sun=distance_from_sun.au, \ d_ast_earth=distance_from_earth.au) result = {} result['name'] = name result['designation'] = designation result['timestamp'] = str(timestamp) result['ra'] = str(ra) result['dec'] = str(dec) result['ra_decimal'] = str(ra.hours * 15) result['dec_decimal'] = str(dec.degrees) result['distance_from_earth'] = str(distance_from_earth.au) result['distance_from_sun'] = str(distance_from_sun.au) result['magnitude_h'] = row['magnitude_H'] result['magnitude_g'] = row['magnitude_G'] result['visual_magnitude'] = visual_magnitude result['last_observation_date'] = row['last_observation_date'] # result['row'] = row return result,asteroid
def _minorPlanets(self) -> DataFrame: with self.load.open(self._minorPlanetsPath()) as f: logging.info("Loading minor planets dataset") mp = mpc.load_mpcorb_dataframe(f) # Drop items without orbits badOrbits = mp.semimajor_axis_au.isnull() mp = mp[~badOrbits].set_index("designation", drop=False) return mp
def import_mpcorb_minor_planets(mpcorb_file): with load.open(mpcorb_file) as f: all_minor_planets = mpc.load_mpcorb_dataframe(f) bad_orbits = all_minor_planets.semimajor_axis_au.isnull() all_minor_planets = all_minor_planets[~bad_orbits] all_minor_planets['minor_planet_id'] = all_minor_planets[ 'designation_packed'] minor_planets = [] for index, mpc_mp in all_minor_planets.iterrows(): int_designation = int(mpc_mp['designation_packed']) minor_planet = MinorPlanet.query.filter_by( int_designation=int_designation).first() if minor_planet is None: minor_planet = MinorPlanet() minor_planet.int_designation = int_designation minor_planet.magnitude_H = mpc_mp['magnitude_H'] minor_planet.magnitude_G = mpc_mp['magnitude_G'] minor_planet.epoch = mpc_mp['epoch_packed'] minor_planet.mean_anomaly_degrees = mpc_mp['mean_anomaly_degrees'] minor_planet.argument_of_perihelion_degrees = mpc_mp[ 'argument_of_perihelion_degrees'] minor_planet.longitude_of_ascending_node_degrees = mpc_mp[ 'longitude_of_ascending_node_degrees'] minor_planet.inclination_degrees = mpc_mp['inclination_degrees'] minor_planet.eccentricity = mpc_mp['eccentricity'] minor_planet.mean_daily_motion_degrees = mpc_mp[ 'mean_daily_motion_degrees'] minor_planet.semimajor_axis_au = mpc_mp['semimajor_axis_au'] minor_planet.uncertainty = mpc_mp['uncertainty'] minor_planet.reference = mpc_mp['reference'] minor_planet.observations = mpc_mp['observations'] minor_planet.oppositions = mpc_mp['oppositions'] minor_planet.observation_period = mpc_mp['observation_period'] minor_planet.rms_residual_arcseconds = mpc_mp[ 'rms_residual_arcseconds'] minor_planet.coarse_perturbers = mpc_mp['coarse_perturbers'] minor_planet.precise_perturbers = mpc_mp['precise_perturbers'] minor_planet.computer_name = mpc_mp['computer_name'] minor_planet.hex_flags = mpc_mp['hex_flags'] minor_planet.designation = mpc_mp['designation'] minor_planet.last_observation_date = mpc_mp[ 'last_observation_date'] minor_planets.append(minor_planet) try: line_cnt = 1 for minor_planet in minor_planets: progress(line_cnt, len(minor_planets), 'Importing minor planets') line_cnt += 1 db.session.add(minor_planet) print('') db.session.commit() except IntegrityError as err: print('\nIntegrity error {}'.format(err)) db.session.rollback()
def _get_mpc_minor_planets(): global all_minor_planets if all_minor_planets is None: with load.open('data/MPCORB.9999.DAT') as f: all_minor_planets = mpc.load_mpcorb_dataframe(f) bad_orbits = all_minor_planets.semimajor_axis_au.isnull() all_minor_planets = all_minor_planets[~bad_orbits] all_minor_planets['minor_planet_id'] = all_minor_planets[ 'designation_packed'] return all_minor_planets
def test_minor_planet(): text = (b'00001 3.4 0.15 K205V 162.68631 73.73161 80.28698' b' 10.58862 0.0775571 0.21406009 2.7676569 0 MPO492748' b' 6751 115 1801-2019 0.60 M-v 30h Williams 0000 ' b'(1) Ceres 20190915\n') ts = load.timescale() t = ts.utc(2020, 6, 17) eph = load('de421.bsp') df = mpc.load_mpcorb_dataframe(BytesIO(text)) row = df.iloc[0] assert row.designation_packed == '00001' assert row.designation == '(1) Ceres' ceres = mpc.mpcorb_orbit(row, ts, GM_SUN) ra, dec, distance = eph['earth'].at(t).observe(eph['sun'] + ceres).radec() assert ceres.target == '(1) Ceres' assert abs(ra.hours - 23.1437) < 0.00005 assert abs(dec.degrees - -17.323) < 0.0005