Rebound format test¶
[1]:
import rebound
import mpcorbfile
import numpy as np
sim = rebound.Simulation()
rebound.data.add_solar_system(sim)
[2]:
# Cargar el archivo MPCORB.DAT
archivo_mpcorb = "MPCORB_TEST.DAT"
f = mpcorbfile.mpcorb_file(archivo_mpcorb)
reading: 100%|██████████| 13.2k/13.2k [00:00<00:00, 132k bodies/s]
[3]:
f.bodies[0]
[3]:
{'packed_designation': 'a7943',
'H': 24.19,
'G': 0.15,
'Epoch': datetime.datetime(2025, 5, 5, 0, 0),
'M': 184.7538,
'Peri': 195.63684,
'Node': 146.91033,
'i': 11.6102,
'e': 0.0894684,
'n': 1.13494811,
'a': 0.9102319,
'U': '2',
'Ref': 'E2024-JU2',
'Num_obs': 1055,
'Num_opps': 2,
'Arc_length': '2012-2013',
'rms': 0.36,
'Perturbers': 'M-v',
'Perturbers_2': '3Ek',
'Computer': 'Veres',
'Hex_flags': 2049,
'Number': '(367943)',
'Name': 'Duende',
'Last_obs': '20130221',
'epochJD': 2460800.5,
'designation': '367943',
'discover_date': nan,
'orbit_type': 'NEO;Athen'}
mpcorbfile has a convenient fn to add asteroids to as simulation¶
[4]:
# Only first 10 asteroids
n = 10
mpcorbfile.add_asteroids_to_rebound(sim, bodies=f.bodies[0:n])
# All asteroids
# f.add_asteroids_to_rebound(sim)
[5]:
# sim.integrator='whfast'
sim.status(showAllFields=False)
---------------------------------
REBOUND version: 4.4.6
REBOUND built on: Dec 30 2024 23:43:16
Number of particles: 19
Selected integrator: ias15
Simulation time: 0.0000000000000000e+00
Current timestep: 0.001000
---------------------------------
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=1.0 x=-0.005837616616786662 y=0.006600361081881469 z=8.090699630593683e-05 vx=-0.00043778026915688127 vy=-0.0002768834056732778 vz=1.289781032896905e-05>
<rebound.particle.Particle object at 0x7fe0dc7fd1d0, m=1.6601141530543e-07 x=-0.29485531126658365 y=-0.3433423322595738 z=-0.0020026458683662014 vx=0.9289643225822997 vy=-0.9659457911951687 vz=-0.16415293821738913>
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=2.44783828778477e-06 x=0.47227261050357944 y=0.5481920502357726 z=-0.020076801470085514 vx=-0.8855348179427942 vy=0.7727916469867526 vz=0.06169738346121213>
<rebound.particle.Particle object at 0x7fe0dc7fd1d0, m=3.04043264802264e-06 x=0.9754193642876818 y=-0.22011750964499116 z=8.866761098092638e-05 vx=0.20842772535763168 vy=0.970428882274706 vz=-3.307038073776142e-05>
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=3.227156037555e-07 x=1.3848978641706091 y=-0.003736554645617639 z=-0.03425238653564357 vx=0.0368083881043789 vy=0.8826719283977713 vz=0.017601885159394735>
<rebound.particle.Particle object at 0x7fe0dc7fd1d0, m=0.0009547919152112404 x=2.317934412293975 y=-4.5727821688157695 z=-0.03288979300198136 vx=0.38587103958050273 vy=0.2191645714297282 vz=-0.009541428281833318>
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=0.0002858856727222417 x=4.979840633509913 y=-8.666308422815424 z=-0.04756566088166766 vx=0.26314427785251254 vy=0.16073015466677915 vz=-0.013273263957685355>
<rebound.particle.Particle object at 0x7fe0dc7fd1d0, m=4.36624373583127e-05 x=15.624351779211002 y=12.138928232772567 z=-0.15733112984491793 vx=-0.14195568334904266 vy=0.1698992031315441 vz=0.0024700645029080734>
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=5.151383772628674e-05 x=29.39189844361884 y=-5.578342796401342 z=-0.5624901221788907 vx=0.03281663353639149 vy=0.18036894277947277 vz=-0.004470616198709565>
<rebound.particle.Particle object at 0x7fe0dc7fd1d0, m=0.0 x=-0.9604681310472365 y=0.23653425120194196 z=0.0670189428548428 vx=-0.2068537631668745 vy=-0.918810885501313 vz=0.18136171307528315>
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=0.0 x=2.771131732271319 y=-0.9640727738162029 z=-0.5410254680767606 vx=0.17398808782123928 vy=0.5279515604294743 vz=-0.015344239804899873>
<rebound.particle.Particle object at 0x7fe0dc7fd1d0, m=0.0 x=1.5855472712150824 y=-2.535318049009574 z=1.6197236434232634 vx=0.42856830042372807 vy=0.15277173662545848 vz=-0.1428621810547551>
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=0.0 x=-1.9999367012251124 y=-2.6026818272036705 z=0.6722390451923012 vx=0.37028013556976164 vy=-0.28835348487037543 vz=0.05037722243691792>
<rebound.particle.Particle object at 0x7fe0dc7fd1d0, m=0.0 x=-1.5924332718027088 y=-1.4658813898464773 z=0.23743022669388844 vx=0.49546612609982316 vy=-0.498153218401691 vz=-0.04554149257425167>
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=0.0 x=-0.9679759506278904 y=-2.4392692669680027 z=0.2355364828641887 vx=0.5141903866476821 vy=-0.32716796275294074 vz=-0.006053922389883797>
<rebound.particle.Particle object at 0x7fe0dc7fd1d0, m=0.0 x=1.0234892993820763 y=-2.0055993363204245 z=0.2177959844153489 vx=0.53145958841038 vy=0.40082102630989797 vz=-0.1715028132480298>
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=0.0 x=0.962108298154546 y=1.5753655986886936 z=0.06366812471146083 vx=-0.6724074116512477 vy=0.45536613756666455 vz=-0.07190903454797644>
<rebound.particle.Particle object at 0x7fe0dc7fd1d0, m=0.0 x=-2.457487193453494 y=-0.21598721669668083 z=0.24487001476479137 vx=-0.0014253215977714517 vy=-0.5936406335551203 vz=0.021931426840128946>
<rebound.particle.Particle object at 0x7fe0dc7fcb50, m=0.0 x=-1.7781641742344614 y=-1.946656239851854 z=0.09345108090675658 vx=0.40164745649119815 vy=-0.41898372357701485 vz=-0.05133990872540425>
---------------------------------
[6]:
for orbit in sim.orbits():
print(orbit)
<rebound.Orbit instance, a=0.38709873488039565 e=0.20563425743114355 inc=0.1222376145886529 Omega=0.8430838381492695 omega=0.5093941264318138 f=2.66985638111655>
<rebound.Orbit instance, a=0.7233231806491239 e=0.006789378655887465 inc=0.059246163609261916 Omega=1.3373251998759481 omega=0.9629526117449929 f=4.829751018157969>
<rebound.Orbit instance, a=1.0000001983666864 e=0.016711159827985017 inc=4.6953426513209986e-05 Omega=3.0804552590548058 omega=5.000799929638195 f=4.258050047659895>
<rebound.Orbit instance, a=1.5236188858422628 e=0.09335870466461238 inc=0.03225220589056631 Omega=0.8638493743951475 omega=5.0022278304877945 f=0.40941884688157604>
<rebound.Orbit instance, a=5.203770080632829 e=0.04863902473779274 inc=0.022751678453263476 Omega=1.7543456825123547 omega=4.771887521263915 f=4.938993957255633>
<rebound.Orbit instance, a=9.539684939565669 e=0.05489760052159024 inc=0.04342249633050542 Omega=1.9827291270345913 omega=5.917899089011026 f=3.616800414342635>
<rebound.Orbit instance, a=19.19265128299375 e=0.04723165219911814 inc=0.013475526721277055 Omega=1.2916740015134998 omega=1.6914218946372976 f=3.9604985667936963>
<rebound.Orbit instance, a=30.076046335613285 e=0.008748518832749956 inc=0.03089623544496438 Omega=2.3000415819651865 omega=4.754875875867041 f=5.324122615520933>
<rebound.Orbit instance, a=0.9102318999999992 e=0.0894684000000007 inc=0.20263621681504568 Omega=2.5640689636914007 omega=3.414506996197343 f=3.2112252794077243>
<rebound.Orbit instance, a=2.7660512000000006 e=0.0794012999999999 inc=0.18479197054265592 Omega=1.4006652965019186 omega=1.2788626077295895 f=3.2716103475197302>
<rebound.Orbit instance, a=2.7701937 e=0.23054039999999995 inc=0.6095391370323501 Omega=3.017592246223352 omega=5.426409635093802 f=3.0157638238470206>
<rebound.Orbit instance, a=2.670669600000001 e=0.2559471999999998 inc=0.22665735784316896 Omega=2.964091621464418 omega=4.32596819707124 f=3.0608307615422774>
<rebound.Orbit instance, a=2.3613975 e=0.09010710000000006 inc=0.12468527456492275 Omega=1.809958270596904 omega=2.6456285487029465 f=5.709940771508056>
<rebound.Orbit instance, a=2.5767618000000017 e=0.1874407 inc=0.09352992568634828 Omega=2.4688298370685744 omega=6.271277798357866 f=1.8764794866855574>
<rebound.Orbit instance, a=2.4258792000000016 e=0.20233560000000006 inc=0.25718159566422266 Omega=2.419277670676428 omega=4.183033236248686 f=4.8535527653954205>
<rebound.Orbit instance, a=2.3863213999999986 e=0.22997809999999985 inc=0.0963344952613778 Omega=-1.7540843471211087 omega=2.539963523260406 f=0.2350998936765869>
<rebound.Orbit instance, a=2.2010413000000013 e=0.15647629999999982 inc=0.10280512893022171 Omega=1.9346178888218233 omega=4.981545978178548 f=2.5976638815634665>
<rebound.Orbit instance, a=2.386377000000001 e=0.12264659999999983 inc=0.09735498927501862 Omega=1.2020072086509435 omega=0.10219304196154866 f=2.6663867220567354>
[7]:
# sim.widget(size=(400,400))
[8]:
# tiempo estimado en horas para calcular una año
# toda la base de datos con 32 cores
(1500000 / (1000 / (4 * 60))) / 3600 / 32
[8]:
3.125
[9]:
s = sim
sim.integrator = "whfast"
%timeit
sim.integrate(-0.001)
%timeit
sim.status(showAllFields=False)
---------------------------------
REBOUND version: 4.4.6
REBOUND built on: Dec 30 2024 23:43:16
Number of particles: 19
Selected integrator: whfast
Simulation time: -1.0000000000000000e-03
Current timestep: -0.001000
---------------------------------
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=1.0 x=-0.005837178824704646 y=0.006600637949040866 z=8.089409830233754e-05 vx=-0.0004378038948276794 vy=-0.0002768509117490171 vz=1.2898196875534082e-05>
<rebound.particle.Particle object at 0x7fe0dc7ff250, m=1.6601141530543e-07 x=-0.2957827277581057 y=-0.34237451611561304 z=-0.0018384820766825889 vx=0.9258664802271479 vy=-0.9696854052963347 vz=-0.16417435596621532>
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=2.44783828778477e-06 x=0.4731575116640523 y=0.5474185415547899 z=-0.02013847212671882 vx=-0.8842671194574143 vy=0.77422536548114 vz=0.06164390287627055>
<rebound.particle.Particle object at 0x7fe0dc7ff250, m=3.04043264802264e-06 x=0.9752104562974715 y=-0.22108782741675312 z=8.870067729218386e-05 vx=0.20938821374652947 vy=0.9702065045456331 vz=-3.306223432659626e-05>
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=3.227156037555e-07 x=1.38486079752254 y=-0.004619224625500338 z=-0.03426998204346714 vx=0.03732491132235684 vy=0.8826679766687084 vz=0.017589129260823306>
<rebound.particle.Particle object at 0x7fe0dc7ff250, m=0.0009547919152112404 x=2.317548532678834 y=-4.57300131648479 z=-0.0328802514520023 vx=0.3858881901915775 vy=0.21913076641085746 vz=-0.009541671664024476>
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=0.0002858856727222417 x=4.979577486731336 y=-8.666469148621866 z=-0.04755238759385776 vx=0.26314927925785625 vy=0.16072145819428832 vz=-0.013273311659876014>
<rebound.particle.Particle object at 0x7fe0dc7ff250, m=4.36624373583127e-05 x=15.62449373388481 y=12.138758332785308 z=-0.15733359989925477 vx=-0.14195366426523837 vy=0.16990077138483256 vz=0.0024700441706930224>
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=5.151383772628674e-05 x=29.391865626436093 y=-5.578523165239926 z=-0.5624856515521811 vx=0.03281773195383081 vy=0.18036873438839052 vz=-0.004470637220566137>
<rebound.particle.Particle object at 0x7fe0dc7ff250, m=0.0 x=-0.9602607766520553 y=0.2374529413230688 z=0.06683754606763688 vx=-0.20785498844927403 vy=-0.9185692002229785 vz=0.18143183004636523>
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=0.0 x=2.7709576922937122 y=-0.9646007072732992 z=-0.54101011372149 vx=0.17409186619002548 vy=0.5279153504830982 vz=-0.015364470618526135>
<rebound.particle.Particle object at 0x7fe0dc7ff250, m=0.0 x=1.5851186828394488 y=-2.5354707886970544 z=1.6198664851114366 vx=0.42860844913099494 vy=0.15270763751807948 vz=-0.14282119457758755>
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=0.0 x=-2.0003069548681274 y=-2.6023934390924115 z=0.6721886590442624 vx=0.3702271487133936 vy=-0.2884227365033155 vz=0.050395073451929416>
<rebound.particle.Particle object at 0x7fe0dc7ff250, m=0.0 x=-1.5929286610777378 y=-1.465383165347734 z=0.2374757566915938 vx=0.49531241708330087 vy=-0.4982957699865449 vz=-0.04551850226939525>
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=0.0 x=-0.9684901148010792 y=-2.4389420324700644 z=0.23554253037719128 vx=0.5141379538975651 vy=-0.3273010330131202 vz=-0.00604110328246426>
<rebound.particle.Particle object at 0x7fe0dc7ff250, m=0.0 x=1.0229577958692482 y=-2.006000071459481 z=0.2179674779231903 vx=0.5315474270131283 vy=0.40064925106561666 vz=-0.171484200510073>
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=0.0 x=0.9627806284199635 y=1.574910107541491 z=0.0637400286768403 vx=-0.6722530999006638 vy=0.45561614718808674 vz=-0.0718988942088245>
<rebound.particle.Particle object at 0x7fe0dc7ff250, m=0.0 x=-2.457485687155832 y=-0.2153935687271096 z=0.24484807525340513 vx=-0.001587275511304856 vy=-0.5936552992426688 vz=0.021947595871551644>
<rebound.particle.Particle object at 0x7fe0dc7ff150, m=0.0 x=-1.7785657734595521 y=-1.9462372030129238 z=0.09350241827467967 vx=0.4015509893664555 vy=-0.41908995121181764 vz=-0.05133482661880026>
---------------------------------
[10]:
for orbit in sim.orbits():
print(orbit)
<rebound.Orbit instance, a=0.38709873406594103 e=0.2056342592398552 inc=0.12223761484344615 Omega=0.843083838224904 omega=0.50939411842353 f=2.6668996126999094>
<rebound.Orbit instance, a=0.7233231749527597 e=0.006789373578352251 inc=0.05924616370198127 Omega=1.3373251990380874 omega=0.9629536835746011 f=4.828121710614439>
<rebound.Orbit instance, a=1.0000002203576208 e=0.016711152908861805 inc=4.695320188330009e-05 Omega=3.080456063304129 omega=5.00079785845695 f=4.257065528086359>
<rebound.Orbit instance, a=1.5236189581891006 e=0.09335875132104032 inc=0.03225220507517767 Omega=0.8638494044803751 omega=5.0022277789717275 f=0.40878386952795864>
<rebound.Orbit instance, a=5.203770063665339 e=0.04863904354963696 inc=0.02275167858396886 Omega=1.7543456842021852 omega=4.771887717402741 f=4.938907319809445>
<rebound.Orbit instance, a=9.53968501797442 e=0.05489756075794991 inc=0.043422495859426945 Omega=1.9827291258370494 omega=5.917900020873617 f=3.6167686187295556>
<rebound.Orbit instance, a=19.19265125013383 e=0.04723165434100854 inc=0.013475526726731312 Omega=1.2916740012177823 omega=1.691421906242483 f=3.9604873727124303>
<rebound.Orbit instance, a=30.076046362754262 e=0.0087485195261408 inc=0.030896235441302128 Omega=2.3000415818743587 omega=4.754875806627225 f=5.32411655622845>
<rebound.Orbit instance, a=0.9102400389795878 e=0.08945761718258094 inc=0.20263565204496858 Omega=2.5640679644847486 omega=3.4146443592413833 f=3.21012152252068>
<rebound.Orbit instance, a=2.7660505016523698 e=0.07940175406333642 inc=0.18479196089582975 Omega=1.400664975273827 omega=1.2788482661486142 f=3.2714386276617535>
<rebound.Orbit instance, a=2.7701939087787117 e=0.23054012863594697 inc=0.6095390976794787 Omega=3.017592349306573 omega=5.426405779394946 f=3.015627464611251>
<rebound.Orbit instance, a=2.6706708041545775 e=0.25594659470849135 inc=0.22665733315459805 Omega=2.9640914037049217 omega=4.32596741828927 f=3.060690927157111>
<rebound.Orbit instance, a=2.361403967399344 e=0.0901094752740303 inc=0.12468524674088165 Omega=1.8099586787538655 omega=2.6456181912966024 f=5.709627705665541>
<rebound.Orbit instance, a=2.576763727653266 e=0.1874394974446861 inc=0.09352992970766044 Omega=2.468829694684645 omega=6.271282331668118 f=1.8762478129405036>
<rebound.Orbit instance, a=2.4258835852590175 e=0.20233851219698737 inc=0.25718160879780416 Omega=2.4192776495518054 omega=4.183032327915635 f=4.853255448116435>
<rebound.Orbit instance, a=2.386309373039782 e=0.22997438424716957 inc=0.09633463012942076 Omega=-1.7540848857320581 omega=2.539957606221824 f=0.23466536497341028>
<rebound.Orbit instance, a=2.2010441353025385 e=0.15647557134430984 inc=0.10280513609815542 Omega=1.9346181364769768 omega=4.981554309221311 f=2.5974167154980634>
<rebound.Orbit instance, a=2.3863797393901773 e=0.12264523828389427 inc=0.09735493491170377 Omega=1.2020074275894501 omega=0.10219485731714606 f=2.6661642632079143>
[11]:
rebound.OrbitPlot(
sim,
color=True,
)
[11]:
<rebound.plotting.OrbitPlot at 0x7fe0b87c12b0>
[12]:
from IPython.display import display, clear_output
import matplotlib.pyplot as plt
sim.move_to_com()
for i in range(30):
sim.integrate(sim.t + 0.1)
fig = rebound.OrbitPlot(
sim, color=True, unitlabel="[AU]", xlim=[-2, 2.0], ylim=[-2, 2.0]
).fig
display(fig)
plt.close(fig)
clear_output(wait=True)
[13]:
sim.particles["Duende"]
[13]:
<rebound.particle.Particle object at 0x7fe05f1c79d0, m=0.0 x=0.7845014904206495 y=0.18868850848010096 z=-0.11979461056838468 vx=-0.23392027324829737 vy=1.1133511321594092 vz=-0.16586310131338722>
Create a new MPCORB file with propagate orbits¶
[14]:
# This only shows the general procedure. The data is not correct i.e. the epoch is not correct
import datetime
ff = mpcorbfile.mpcorb_file()
for b in f.bodies[0:n]:
print(b["Name"])
particle = sim.particles[b["Name"]]
orbit = particle.orbit()
body = {
"packed_designation": b["packed_designation"],
"a": orbit.a,
"e": orbit.e,
"i": np.degrees(orbit.inc),
"Peri": np.degrees(orbit.omega),
"Node": np.degrees(orbit.Omega),
"M": np.degrees(orbit.M),
"Epoch": datetime.datetime(2025, 5, 5, 0, 0),
"G": np.nan,
"H": np.nan,
"n": orbit.f,
"U": 0,
"Ref": "REBOUND",
"Num_obs": 0,
"Num_opps": 0,
"Arc_length": "",
"rms": np.nan,
"Perturbers": "",
"Perturbers_2": "",
"Computer": "bernoulli",
"Hex_flags": 0x0,
"Number": b["Number"],
"Name": b["Name"],
"Last_obs": "",
}
ff.add(body)
ff.write("kk.DAT", header=" DATA FROM REBOUND SIMULATION ")
Duende
Ceres
Pallas
Juno
Vesta
Astraea
Hebe
Iris
Flora
Metis
writting: 100%|██████████| 10.0/10.0 [00:00<00:00, 45.4k bodies/s]
[14]:
True
[ ]: