Analyzing NEOs

NEO stands for near-Earth object. The Center for NEO Studies (CNEOS) defines NEOs as comets and asteroids that have been nudged by the gravitational attraction of nearby planets into orbits that allow them to enter the Earth’s neighborhood.

And what does “near” exactly mean? In terms of orbital elements, asteroids and comets can be considered NEOs if their perihelion (orbit point which is nearest to the Sun) is less than 1.3 au = 1.945 * 108 km from the Sun.

[1]:
from astropy import time

from poliastro.twobody.orbit import Orbit
from poliastro.bodies import Earth
from poliastro.frames import Planes
from poliastro.plotting import StaticOrbitPlotter

Small Body Database (SBDB)

[2]:
eros = Orbit.from_sbdb("Eros")
eros.plot(label="Eros");
[2]:
[<matplotlib.lines.Line2D at 0x7fd9578d8c18>,
 <matplotlib.lines.Line2D at 0x7fd9554b0780>]
../_images/examples_Using_NEOS_package_4_1.png

You can also search by IAU number or SPK-ID (there is a faster neows.orbit_from_spk_id() function in that case, although):

[3]:
ganymed = Orbit.from_sbdb("1036")  # Ganymed IAU number
amor = Orbit.from_sbdb("2001221")  # Amor SPK-ID
eros = Orbit.from_sbdb("2000433")  # Eros SPK-ID

frame = StaticOrbitPlotter(plane=Planes.EARTH_ECLIPTIC)
frame.plot(ganymed, label="Ganymed")
frame.plot(amor, label="Amor")
frame.plot(eros, label="Eros");
[3]:
[<matplotlib.lines.Line2D at 0x7fd954ec1438>,
 <matplotlib.lines.Line2D at 0x7fd954ec17f0>]
../_images/examples_Using_NEOS_package_6_1.png

You can use the wildcards from that browser: * and ?.

Keep it in mind that from_sbdb() can only return one Orbit, so if several objects are found with that name, it will raise an error with the different bodies.

[4]:
try:
    Orbit.from_sbdb("*alley")
except ValueError as err:
    print(err)
6 different objects found:
903 Nealley (A918 RH)
2688 Halley (1982 HG1)
14182 Alley (1998 WG12)
21651 Mission Valley (1999 OF1)
36445 Smalley (2000 QU)
1P/Halley

Note that epoch is provided by the service itself, so if you need orbit on another epoch, you have to propagate it:

[5]:
eros.epoch.iso
[5]:
'2020-05-31 00:01:09.185'
[6]:
epoch = time.Time(2458000.0, scale="tdb", format="jd")
eros_november = eros.propagate(epoch)
eros_november.epoch.iso
[6]:
'2017-09-03 12:00:00.000'

DASTCOM5 module

This module can also be used to get NEOs orbit, in the same way that neows, but it have some advantages (and some disadvantages).

It relies on DASTCOM5 database, a NASA/JPL maintained asteroid and comet database. This database has to be downloaded at least once in order to use this module. According to its README, it is updated typically a couple times per day, but potentially as frequently as once per hour, so you can download it whenever you want the more recently discovered bodies. This also means that, after downloading the file, you can use the database offline.

The file is a ~230 MB zip that you can manually download and unzip in ~/.poliastro or, more easily, you can use

dastcom5.download_dastcom5()

The main DASTCOM5 advantage over NeoWs is that you can use it to search not only NEOs, but any asteroid or comet. The easiest function is orbit_from_name():

[7]:
from poliastro.neos import dastcom5

# We might require to download the database if not already downloaded
try:
    dastcom5.download_dastcom5()
except:
    print("Download is not required as file already exists.")
306.76 MB / 306.76 MB
[8]:
atira = dastcom5.orbit_from_name("atira")[0]  # NEO
wikipedia = dastcom5.orbit_from_name("wikipedia")[0]  # Asteroid, but not NEO.

frame = StaticOrbitPlotter()
frame.plot(atira, label="Atira (NEO)")
frame.plot(wikipedia, label="Wikipedia (asteroid)");
[8]:
[<matplotlib.lines.Line2D at 0x7fd957ed30b8>,
 <matplotlib.lines.Line2D at 0x7fd95782dd68>]
../_images/examples_Using_NEOS_package_16_1.png

Keep in mind that this function returns a list of orbits matching your string. This is made on purpose given that there are comets which have several records in the database (one for each orbit determination in history) what allow plots like this one:

[9]:
halleys = dastcom5.orbit_from_name("1P")

frame = StaticOrbitPlotter()
frame.plot(halleys[0], label="Halley")
frame.plot(halleys[5], label="Halley")
frame.plot(halleys[10], label="Halley")
frame.plot(halleys[20], label="Halley")
frame.plot(halleys[-1], label="Halley");
[9]:
[<matplotlib.lines.Line2D at 0x7fd957edb0f0>,
 <matplotlib.lines.Line2D at 0x7fd957edbba8>]
../_images/examples_Using_NEOS_package_18_1.png

While neows can only be used to get Orbit objects, dastcom5 can also provide asteroid and comet complete database. Once you have this, you can get specific data about one or more bodies. The complete databases are ndarrays, so if you want to know the entire list of available parameters, you can look at the dtype, and they are also explained in documentation API Reference:

[10]:
ast_db = dastcom5.asteroid_db()
comet_db = dastcom5.comet_db()
ast_db.dtype.names[
    :20
]  # They are more than 100, but that would be too much lines in this notebook :P
[10]:
('NO',
 'NOBS',
 'OBSFRST',
 'OBSLAST',
 'EPOCH',
 'CALEPO',
 'MA',
 'W',
 'OM',
 'IN',
 'EC',
 'A',
 'QR',
 'TP',
 'TPCAL',
 'TPFRAC',
 'SOLDAT',
 'SRC1',
 'SRC2',
 'SRC3')

Asteroid and comet parameters are not exactly the same (although they are very close)

With these ndarrays you can classify asteroids and comets, sort them, get all their parameters, and whatever comes to your mind.

For example, NEOs can be grouped in several ways. One of the NEOs group is called Atiras, and is formed by NEOs whose orbits are contained entirely with the orbit of the Earth. They are a really little group, and we can try to plot all of these NEOs using asteroid_db():

Talking in orbital terms, Atiras have an aphelion distance, Q < 0.983 au and a semi-major axis, a < 1.0 au. Visiting documentation API Reference, you can see that DASTCOM5 provides semi-major axis, but doesn’t provide aphelion distance. You can get aphelion distance easily knowing perihelion distance (q, QR in DASTCOM5) and semi-major axis Q = 2*a - q, but there are probably many other ways.

[11]:
aphelion_condition = 2 * ast_db["A"] - ast_db["QR"] < 0.983
axis_condition = ast_db["A"] < 1.3
atiras = ast_db[aphelion_condition & axis_condition]

The number of Atira NEOs we use using this method is:

[12]:
len(atiras)
[12]:
27

Which is consistent with the stats published by CNEOS

Now we’re gonna plot all of their orbits, with corresponding labels, just because we love plots :)

We only need to get the 16 orbits from these 16 ndarrays.

There are two ways:

  • Gather all their orbital elements manually and use the Orbit.from_classical() function.

  • Use the NO property (logical record number in DASTCOM5 database) and the dastcom5.orbit_from_record() function.

The second one seems easier and it is related to the current notebook, so we are going to use that one, using the ASTNAM property of DASTCOM5 database:

[13]:
from poliastro.bodies import Earth

frame = StaticOrbitPlotter()
frame.plot_body_orbit(Earth, time.Time.now().tdb)

for record in atiras["NO"]:
    ss = dastcom5.orbit_from_record(record)
    if ss.ecc < 1:
        frame.plot(ss, color="#666666")
    else:
        print(f"Skipping hyperbolic orbit: {record}")
Skipping hyperbolic orbit: 50206487
Skipping hyperbolic orbit: 50412516
Skipping hyperbolic orbit: 50431928
Skipping hyperbolic orbit: 50448117
../_images/examples_Using_NEOS_package_29_1.png

If we needed also the names of each asteroid, we could do:

[14]:
frame = StaticOrbitPlotter()
frame.plot_body_orbit(Earth, time.Time.now().tdb)

for i in range(len(atiras)):
    record = atiras["NO"][i]
    label = atiras["ASTNAM"][i].decode().strip()  # DASTCOM5 strings are binary
    ss = dastcom5.orbit_from_record(record)

    if ss.ecc < 1:
        frame.plot(ss, label=label)
    else:
        print(f"Skipping hyperbolic orbit: {label}")
Skipping hyperbolic orbit: 2013 CA134
Skipping hyperbolic orbit: 'Oumuamua
Skipping hyperbolic orbit: A/2019 G4
Skipping hyperbolic orbit: A/2020 M4
../_images/examples_Using_NEOS_package_31_1.png

We knew beforehand that there are no Atira comets, only asteroids (comet orbits are usually more eccentric), but we could use the same method with com_db if we wanted.

Finally, another interesting function in dastcom5 is entire_db(), which is really similar to ast_db and com_db, but it returns a Pandas dataframe instead of a numpy ndarray. The dataframe has asteroids and comets in it, but in order to achieve that (and a more manageable dataframe), a lot of parameters were removed, and others were renamed:

[15]:
db = dastcom5.entire_db()
db.columns
[15]:
Index(['NUMBER', 'NOBS', 'OBSFRST', 'OBSLAST', 'EPOCH', 'CALEPOCH', 'MA', 'W',
       'OM', 'IN', 'EC', 'A', 'QR', 'TP', 'TPCAL', 'TPFRAC', 'SOLDAT', 'DESIG',
       'IREF', 'NAME'],
      dtype='object')

Also, in this function, DASTCOM5 data (specially strings) is ready to use (decoded and improved strings, etc):

[16]:
db[
    db.NAME == "Halley"
]  # As you can see, Halley is the name of an asteroid too, did you know that?
[16]:
NUMBER NOBS OBSFRST OBSLAST EPOCH CALEPOCH MA W OM IN EC A QR TP TPCAL TPFRAC SOLDAT DESIG IREF NAME
2687 2688 2846 19500814 20200609 2456758.5 20140411.0 203.430297 186.723581 95.342619 3.453876 0.141815 3.179621 2.728702 2.457659e+06 2.016093e+07 0.171892 2.459024e+06 1982 HG1 35 Halley
995165 90000001 161 0 0 1633920.5 -2390607.0 0.165294 88.110000 30.810000 163.470000 0.967600 18.067901 0.585400 1.633908e+06 -2.390525e+06 0.620000 0.000000e+00 1P SAO/-239 Halley
995166 90000002 161 0 0 1661840.5 -1631115.0 0.031113 89.110000 32.060000 163.700000 0.967700 18.095975 0.584500 1.661838e+06 -1.631113e+06 0.070000 0.000000e+00 1P SAO/-163 Halley
995167 90000003 161 0 0 1689880.5 -860823.0 0.211345 90.778000 34.018000 163.340000 0.967680 18.118812 0.585600 1.689864e+06 -8.608065e+05 0.962000 0.000000e+00 1P SAO/-86 Halley
995168 90000004 161 0 0 1717320.5 -111008.0 359.963217 92.559000 35.904000 163.589000 0.967370 17.995709 0.587200 1.717323e+06 -1.110108e+05 0.349000 0.000000e+00 1P SAO/-11 Halley
995169 90000005 161 0 0 1745200.5 660206.0 0.142118 92.652000 36.129000 163.577000 0.967550 18.030817 0.585100 1.745189e+06 6.601260e+05 0.460000 0.000000e+00 1P SAO/66 Halley
995170 90000006 161 0 0 1772640.5 1410324.0 0.019990 93.694000 37.219000 163.437000 0.967840 18.132463 0.583140 1.772639e+06 1.410322e+06 0.934000 0.000000e+00 1P SAO/141 Halley
995171 90000007 161 0 0 1800800.5 2180429.0 359.761537 94.147000 37.908000 163.574000 0.967980 18.159588 0.581470 1.800819e+06 2.180518e+06 0.223000 0.000000e+00 1P SAO/218 Halley
995172 90000008 161 0 0 1828920.5 2950425.0 0.057332 95.241000 39.111000 163.367000 0.968750 18.429120 0.575910 1.828916e+06 2.950420e+06 0.898000 0.000000e+00 1P SAO/295 Halley
995173 90000009 161 0 0 1857720.5 3740301.0 0.158377 96.510000 40.579000 163.542000 0.968590 18.375995 0.577190 1.857708e+06 3.740216e+06 0.842000 0.000000e+00 1P SAO/374 Halley
995174 90000010 161 0 0 1885960.5 4510625.0 359.959606 97.028000 41.210000 163.479000 0.968910 18.454165 0.573740 1.885964e+06 4.510628e+06 0.749000 0.000000e+00 1P SAO/451 Halley
995175 90000011 161 0 0 1914920.5 5301008.0 0.135791 97.582000 41.974000 163.394000 0.968710 18.395334 0.575590 1.914910e+06 5.300927e+06 0.630000 0.000000e+00 1P SAO/530 Halley
995176 90000012 161 0 0 1942840.5 6070318.0 0.032109 98.799000 43.261000 163.476000 0.968040 18.173655 0.580830 1.942838e+06 6.070315e+06 0.976000 0.000000e+00 1P SAO/607 Halley
995177 90000013 161 0 0 1971160.5 6840929.0 359.952171 99.149000 43.800000 163.418000 0.968150 18.197174 0.579580 1.971164e+06 6.841003e+06 0.267000 0.000000e+00 1P SAO/684 Halley
995178 90000014 161 0 0 1998800.5 7600602.0 0.157833 99.997000 44.687000 163.443000 0.967850 18.097667 0.581840 1.998788e+06 7.600521e+06 0.171000 0.000000e+00 1P SAO/760 Halley
995179 90000015 161 0 0 2026840.5 8370310.0 0.124640 100.101000 44.930000 163.447000 0.967810 18.090090 0.582320 2.026831e+06 8.370228e+06 0.770000 0.000000e+00 1P SAO/837 Halley
995180 90000016 161 0 0 2054360.5 9120714.0 359.940520 100.777000 45.646000 163.311000 0.968070 18.169746 0.580160 2.054365e+06 9.120719e+06 0.174000 0.000000e+00 1P SAO/912 Halley
995181 90000017 161 0 0 2082520.5 9890819.0 359.774025 101.484000 46.561000 163.399000 0.967890 18.122392 0.581910 2.082538e+06 9.890906e+06 0.188000 0.000000e+00 1P SAO/989 Halley
995182 90000018 161 0 0 2110480.5 10660308.0 359.839206 102.473000 47.624000 163.112000 0.968870 18.454867 0.574500 2.110493e+06 1.066032e+07 0.434000 0.000000e+00 1P SAO/1066 Halley
995183 90000019 161 0 0 2139360.5 11450402.0 359.793477 103.704000 49.054000 163.224000 0.968790 18.416854 0.574790 2.139377e+06 1.145042e+07 0.061000 0.000000e+00 1P SAO/1145 Halley
995184 90000020 161 0 0 2167680.5 12221015.0 0.201554 103.849000 49.304000 163.192000 0.968840 18.427792 0.574210 2.167664e+06 1.222093e+07 0.323000 0.000000e+00 1P SAO/1222 Halley
995185 90000021 161 0 0 2196560.5 13011109.0 0.179564 104.500000 50.152000 163.076000 0.968930 18.432893 0.572710 2.196546e+06 1.301103e+07 0.082000 0.000000e+00 1P SAO/1301 Halley
995186 90000022 161 0 0 2224680.5 13781105.0 359.927910 105.295000 51.020000 163.113000 0.968370 18.216883 0.576200 2.224686e+06 1.378111e+07 0.187000 0.000000e+00 1P SAO/1378 Halley
995187 90000023 161 0 0 2253040.5 14560628.0 0.234781 105.835000 51.866000 162.890000 0.968000 18.115625 0.579700 2.253022e+06 1.456061e+07 0.133000 0.000000e+00 1P SAO/1456 Halley
995188 90000024 161 0 0 2280480.5 15310814.0 359.842327 106.976000 53.057000 162.917000 0.967750 18.021705 0.581200 2.280493e+06 1.531083e+07 0.739000 0.000000e+00 1P SAO/1531 Halley
995189 90000025 161 0 0 2308300.5 16071024.0 359.954121 107.550300 53.770100 162.905500 0.967490 17.951861 0.583615 2.308304e+06 1.607103e+07 0.040600 0.000000e+00 1P H593/0 Halley
995190 90000026 161 0 0 2308300.5 16071024.0 359.954121 107.550300 53.770100 162.905500 0.967490 17.951861 0.583615 2.308304e+06 1.607103e+07 0.040600 0.000000e+00 1P SAO/1607 Halley
995191 90000027 278 0 0 2335640.5 16820831.0 359.805545 109.221400 55.566900 162.264900 0.967933 18.168865 0.582621 2.335656e+06 1.682092e+07 0.779400 0.000000e+00 1P I353/0 Halley
995192 90000028 278 0 0 2335640.5 16820831.0 359.805545 109.221400 55.566900 162.264900 0.967933 18.168865 0.582621 2.335656e+06 1.682092e+07 0.779400 0.000000e+00 1P SAO/1682 Halley
995193 90000029 718 0 0 2363600.5 17590321.0 0.101706 110.709300 57.245800 162.372500 0.967686 18.087083 0.584466 2.363593e+06 1.759031e+07 0.562300 0.000000e+00 1P J103/0 Halley
995194 90000030 718 0 0 2363600.5 17590321.0 0.101706 110.709300 57.245800 162.372500 0.967686 18.087083 0.584466 2.363593e+06 1.759031e+07 0.562300 0.000000e+00 1P SAO/1759 Halley
995195 90000031 653 0 0 2391600.5 18351118.0 0.020156 110.704300 57.518500 162.258800 0.967394 17.989419 0.586563 2.391599e+06 1.835112e+07 0.939600 0.000000e+00 1P SAO/1835 Halley
995196 90000032 653 0 0 2418800.5 19100509.0 0.243754 111.737100 58.562900 162.218600 0.967302 17.958530 0.587208 2.418782e+06 1.910042e+07 0.678500 0.000000e+00 1P SAO/1910 Halley
995197 90000033 7428 18350821 19940111 2449400.5 19940217.0 38.384264 111.332485 58.420081 162.262691 0.967143 17.834144 0.585978 2.446467e+06 1.986021e+07 0.395317 2.452124e+06 1P J863/77 Halley

Panda offers many functionalities, and can also be used in the same way as the ast_db and comet_db functions:

[17]:
aphelion_condition = (2 * db["A"] - db["QR"]) < 0.983
axis_condition = db["A"] < 1.3
atiras = db[aphelion_condition & axis_condition]
[18]:
len(atiras)
[18]:
408

What? I said they can be used in the same way!

Dont worry :) If you want to know what’s happening here, the only difference is that we are now working with comets too, and some comets have a negative semi-major axis!

[19]:
len(atiras[atiras.A < 0])
[19]:
385

So, rewriting our condition:

[20]:
axis_condition = (db["A"] < 1.3) & (db["A"] > 0)
atiras = db[aphelion_condition & axis_condition]
len(atiras)
[20]:
23