{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "colab-badge" }, "source": [ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/seap-udea/MultiNEAs/blob/main/examples/population_asteroid_tutorial.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# MultiNEAs: The `population.Asteroid` Class Tutorial\n", "\n", "This notebook demonstrates how to use the `multineas.population.Asteroid` class for converting between asteroid diameter and absolute magnitude." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Installation\n", "\n", "If you're running this in Google Colab or need to install the package, uncomment and run the following cell:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "try:\n", " from google.colab import drive\n", " %pip install -Uq multineas\n", "except ImportError:\n", " print(\"Not running in Colab, skipping installation\")\n", "\n", "# Uncomment to install from GitHub (development version)\n", "# !pip install git+https://github.com/seap-udea/MultiNEAs.git" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load the Package\n", "\n", "Import `multineas.population` and `matplotlib.pyplot`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from multineas.population import Asteroid\n", "import warnings\n", "%matplotlib inline\n", "\n", "warnings.filterwarnings(\"ignore\")\n", "from multineas.plot import multineas_watermark" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Convert Absolute Magnitude to Diameter\n", "\n", "We can use `Asteroid.hmag_to_diameter` to convert absolute magnitude ($H$) to diameter ($D$). The default albedo is 0.15." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "H = 18.0\n", "diameter = Asteroid.hmag_to_diameter(H)\n", "print(f\"For H = {H}, Diameter = {diameter:.3f} km\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also specify a different albedo:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "albedo = 0.05\n", "diameter_low_albedo = Asteroid.hmag_to_diameter(H, albedo=albedo)\n", "print(f\"For H = {H} and albedo = {albedo}, Diameter = {diameter_low_albedo:.3f} km\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Convert Diameter to Absolute Magnitude\n", "\n", "Conversely, use `Asteroid.diameter_to_hmag` to convert diameter to absolute magnitude." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "D = 1.0 # km\n", "H_calc = Asteroid.diameter_to_hmag(D)\n", "print(f\"For Diameter = {D} km, H = {H_calc:.3f}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualization\n", "\n", "Let's plot the relationship between H and Diameter for different albedos." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "H_values = np.linspace(10, 30, 100)\n", "albedos = [0.05, 0.15, 0.25]\n", "\n", "fig, ax = plt.subplots(figsize=(8, 6))\n", "\n", "for p_v in albedos:\n", " D_values = Asteroid.hmag_to_diameter(H_values, albedo=p_v)\n", " ax.plot(H_values, D_values, label=f\"Albedo = {p_v}\")\n", "\n", "ax.set_xlabel(\"Absolute Magnitude (H)\")\n", "ax.set_ylabel(\"Diameter (km)\")\n", "ax.set_yscale(\"log\")\n", "ax.set_title(\"Diameter vs. Absolute Magnitude\")\n", "ax.legend()\n", "ax.grid(True, which=\"both\", ls=\"-\", alpha=0.5)\n", "\n", "multineas_watermark(ax)\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Attribution\n", "\n", "The `Asteroid` class is part of the `multineas` package." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }