Modules

Main class

class mpcorbfile.mpcorb_file(file=None)[source]

Read and write MPCORB files ussing the format stated in https://www.minorplanetcenter.net/iau/info/MPOrbitFormat.html on march 4, 2025

format:

Export Format for Minor-Planet Orbits
This document describes the format used for both unperturbed and perturbed orbits of minor planets,
as used in the Extended Computer Service and in the Minor Planet Ephemeris Service.

Orbital elements for minor planets are heliocentric.

The column headed `F77' indicates the Fortran 77/90/95/2003/2008 format specifier
that should be used to read the specified value.

Columns   F77    Use

 1 -   7  a7     Number or provisional designation
                 (in packed form)
 9 -  13  f5.2   Absolute magnitude, H
15 -  19  f5.2   Slope parameter, G

21 -  25  a5     Epoch (in packed form, .0 TT)
27 -  35  f9.5   Mean anomaly at the epoch, in degrees

38 -  46  f9.5   Argument of perihelion, J2000.0 (degrees)
49 -  57  f9.5   Longitude of the ascending node, J2000.0
                 (degrees)
60 -  68  f9.5   Inclination to the ecliptic, J2000.0 (degrees)

71 -  79  f9.7   Orbital eccentricity
81 -  91  f11.8  Mean daily motion (degrees per day)
93 - 103  f11.7  Semimajor axis (AU)

106        i1     Uncertainty parameter, U
        or a1     If this column contains `E' it indicates
                  that the orbital eccentricity was assumed.
                  For one-opposition orbits this column can
                  also contain `D' if a double (or multiple)
                  designation is involved or `F' if an e-assumed
                  double (or multiple) designation is involved.

108 - 116  a9     Reference
118 - 122  i5     Number of observations
124 - 126  i3     Number of oppositions

    For multiple-opposition orbits:
    128 - 131  i4     Year of first observation
    132        a1     '-'
    133 - 136  i4     Year of last observation

    For single-opposition orbits:
    128 - 131  i4     Arc length (days)
    133 - 136  a4     'days'

138 - 141  f4.2   r.m.s residual (")
143 - 145  a3     Coarse indicator of perturbers
                  (blank if unperturbed one-opposition object)
147 - 149  a3     Precise indicator of perturbers
                  (blank if unperturbed one-opposition object)
151 - 160  a10    Computer name

There may sometimonth be additional information beyond column 160
as follows:

162 - 165  z4.4   4-hexdigit flags

                    The bottom 6 bits (bits 0 to 5) are used to encode
                    a value representing the orbit type (other
                    values are undefined):

                    Value
                        1  Atira
                        2  Aten
                        3  Apollo
                        4  Amor
                        5  Object with q < 1.665 AU
                        6  Hungaria
                        7  Unused or internal MPC use only
                        8  Hilda
                        9  Jupiter Trojan
                    10  Distant object

                    Additional information is conveyed by
                    adding in the following bit values:

            Bit  Value
                6     64  Unused or internal MPC use only
                7    128  Unused or internal MPC use only
                8    256  Unused or internal MPC use only
                9    512  Unused or internal MPC use only
                10   1024  Unused or internal MPC use only
                11   2048  Object is NEO
                12   4096  Object is 1-km (or larger) NEO
                13   8192  1-opposition object seen at
                        earlier opposition
                14  16384  Critical list numbered object
                15  32768  Object is PHA

                    Note that the orbit classification is
                    based on cuts in osculating element
                    space and is not 100% reliable.

                    Note also that certain of the flags
                    are for internal MPC use and are
                    not documented.

167 - 194  a      Readable designation

195 - 202  i8     Date of last observation included in
                    orbit solution (YYYYMMDD format)
add(body_dict: dict)[source]

Add new body from a dict.

compressed_epoch_to_datetime(epoch: str) datetime[source]

Convert compressed epoch to python datetime following the below rules:

Dates of the form YYYYMMDD may be packed into five characters to conserve space.

The first two digits of the year are packed into a single character in 
column 1 (I = 18, J = 19, K = 20).
Columns 2-3 contain the last two digits of the year.
Column 4 contains the month and column 5 contains the day, coded as detailed below:

Month     Day      Character         Day      Character
                    in Col 4 or 5              in Col 4 or 5
Jan.       1           1             17           H
Feb.       2           2             18           I
Mar.       3           3             19           J
Apr.       4           4             20           K
May        5           5             21           L
June       6           6             22           M
July       7           7             23           N
Aug.       8           8             24           O
Sept.      9           9             25           P
Oct.      10           A             26           Q
Nov.      11           B             27           R
Dec.      12           C             28           S
          13           D             29           T
          14           E             30           U
          15           F             31           V
          16           G

Examples:

1996 Jan. 1    = J9611
1996 Jan. 10   = J961A
1996 Sept.30   = J969U
1996 Oct. 1    = J96A1
2001 Oct. 22   = K01AM

This system can be extended to dates with non-integral days. The decimal fraction of 
the day is simply appended to the five characters defined above.

Examples:

1998 Jan. 18.73     = J981I73
2001 Oct. 22.138303 = K01AM138303
datetime_to_julian_date(my_date: datetime) float[source]

Convert a datetime to julian date

expand_packed_designation(packed: str) str[source]

Convert the packed designation format to formal designation following format: https://www.minorplanetcenter.net/iau/info/PackedDes.html

get_chunks(n: int) list[source]

return a n list of lists with len(list)/n bodies each

orbit_type(a: float, e: float, i: float) str[source]

Classify asteroid orbit type following http://en.wikipedia.org/wiki/Near-Earth_object

pack_designation(designation: str) str[source]

Create packed designation from designation following format: https://www.minorplanetcenter.net/iau/info/PackedDes.html

read(filename: str) list[source]

Read the MPCORB.DAT file.

read_json(filename: str) list[source]

read json files https://minorplanetcenter.net/Extended_Files/mpcorb_extended.json.gz

write(filename: str, header: str = '') bool[source]

Write a file formated as MPCORB with the bodies data

write_json(filename: str)[source]

Write json file compatible with https://minorplanetcenter.net/Extended_Files/mpcorb_extended.json.gz” files

Ancillary functions

Class and ancillary functions to read and write MPCORB files.

mpcorbfile.add_asteroids_to_rebound(simulation, bodies=None)[source]

Add asteroids to a REBOUND simulation.

Example:

import rebound
import mpcorbfile
import numpy as np

sim=rebound.Simulation()
rebound.data.add_solar_system(sim)

mpcorb = 'MPCORB_TEST.DAT'
f = mpcorbfile.mpcorb_file(mpcorb)
mpcorbfile.add_asteroids_to_rebound(sim)
mpcorbfile.set_elliptical_body_elements(eliptical_body, body)[source]

Set orbital elements of eliptical_body for futher calculation using pyephem:

pyephem parameters:

_inc        — Inclination (°)
_Om         — Longitude of ascending node (°)
_om         — Argument of perihelion (°)
_a          — Mean distance from sun (AU)
_M          — Mean anomaly from the perihelion (°)
_epoch_M    — Date for measurement _M
_size       — Angular size (arcseconds at 1 AU)
_e          — Eccentricity
_epoch      — Epoch for _inc, _Om, and _om
_H, _G      — Parameters for the H/G magnitude model
_g, _k      — Parameters for the g/k magnitude model

eliptical_body._H = body["H"]
eliptical_body._G = body["G"]
eliptical_body._a = body["a"]
eliptical_body._M = body["M"]
eliptical_body._om = body["Peri"]
eliptical_body._Om = body["Node"]
eliptical_body._inc = body["i"]
eliptical_body._e = body["e"]
eliptical_body._epoch = body["Epoch"].strftime("%Y/%m/%d %H:%M:%S")
eliptical_body._epoch_M = body["Epoch"].strftime("%Y/%m/%d %H:%M:%S")