Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 104 additions & 11 deletions examples/2024_yr4_impact_risk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"\n",
"orbit = query_sbdb([\"2024 YR4\"])\n",
"\n",
"print(orbit.to_dataframe())"
"orbit.to_dataframe()"
]
},
{
Expand All @@ -48,7 +48,52 @@
"approx_impact_date = Timestamp.from_iso8601([\"2032-12-22\"], scale=\"tdb\")\n",
"thirty_days_after_impact = approx_impact_date.add_days(30)\n",
"days_until_thirty_days_after_impact, _ = thirty_days_after_impact.difference(orbit.coordinates.time)\n",
"print(days_until_thirty_days_after_impact)"
"days_until_thirty_days_after_impact"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's propagate the nominal orbit to about 30 days before the impact time and do a quick minimum orbit intersection distance (MOID) calculation. The propagation we do before hand is important because the MOID calculation uses 2-body dynamics (a simple Keplerian orbit) and that approximation does not hold for long periods of time."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from adam_assist import ASSISTPropagator\n",
"\n",
"propagator = ASSISTPropagator()\n",
"propagated_orbit = propagator.propagate_orbits(orbit, approx_impact_date.add_days(-30), covariance=True)\n",
"propagated_orbit.to_dataframe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from adam_core.dynamics.moid import calculate_perturber_moids\n",
"from adam_core.coordinates import OriginCodes\n",
"\n",
"moids = calculate_perturber_moids(propagated_orbit, OriginCodes.EARTH)\n",
"moids.to_dataframe()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from adam_core.constants import KM_P_AU\n",
"\n",
"# Compute moid in KM\n",
"moids.select(\"perturber.code\", \"EARTH\").moid[0].as_py() * KM_P_AU"
]
},
{
Expand All @@ -60,9 +105,7 @@
"# Now we initialize our propagator, and pass it to our calculate_impacts function\n",
"from adam_core.dynamics.impacts import calculate_impacts, CollisionConditions\n",
"from adam_core.coordinates import Origin\n",
"from adam_assist import ASSISTPropagator\n",
"\n",
"propagator = ASSISTPropagator()\n",
"\n",
"# Define the collision conditions including a potential impact on the Moon\n",
"conditions = CollisionConditions.from_kwargs(\n",
Expand All @@ -77,11 +120,52 @@
" days_until_thirty_days_after_impact[0].as_py(),\n",
" propagator,\n",
" num_samples=10000,\n",
" processes=60, # Multiprocessing speeds things up if you have the CPUs\n",
" processes=10, # Multiprocessing speeds things up if you have the CPUs\n",
" conditions=conditions,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"variants.to_dataframe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"impacts.to_dataframe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Alternatively, if we don't know the impact date (which is the case in reality at discovery)\n",
"from adam_core.orbits import VariantOrbits\n",
"\n",
"variants_orbits = VariantOrbits.create(\n",
" orbit,\n",
" method=\"monte-carlo\",\n",
" num_samples=10000,\n",
" seed=612,\n",
")\n",
"\n",
"print(variants, impacts)"
"variants, impacts = propagator.detect_collisions(\n",
" variants_orbits,\n",
" 8 * 365, # Propagate for 8 years\n",
" conditions=conditions,\n",
" max_processes=10,\n",
")\n",
"impacts.to_dataframe()"
]
},
{
Expand All @@ -91,7 +175,7 @@
"outputs": [],
"source": [
"# Now we can summarize the returns, a simple ratio in our case\n",
"# with only 1 orbit considered\n",
"# with only 1 orbit considered/\n",
"from adam_core.dynamics.impacts import calculate_impact_probabilities\n",
"ip = calculate_impact_probabilities(variants, impacts, conditions=conditions)\n",
"ip.to_dataframe()"
Expand All @@ -118,7 +202,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -148,11 +232,11 @@
" propagated_best_fit_orbit, \n",
" propagated_variants, \n",
" impacts, \n",
" title=\"2024 YR4 Impact Simulation (Simulated on 2025-03-14)\",\n",
" title=\"2024 YR4 Impact Simulation (Simulated on 2025-04-03)\",\n",
" sample_impactors=None,\n",
" sample_non_impactors=0.1\n",
")\n",
"fig.write_html(\"2024YR4_impact_simulation.html\")"
"fig.write_html(\"2024YR4_impact_simulation_20250403.html\")"
]
},
{
Expand All @@ -162,6 +246,15 @@
"And there you have it. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -184,7 +277,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
Loading
Loading