{ "cells": [ { "cell_type": "markdown", "id": "20bbc12a", "metadata": { "papermill": { "duration": 0.003999, "end_time": "2026-05-16T13:49:06.781351+00:00", "exception": false, "start_time": "2026-05-16T13:49:06.777352+00:00", "status": "completed" }, "tags": [] }, "source": [ "# Orbit Initialization\n", "\n", "This tutorial covers all the ways to initialize orbits in galpy, from\n", "raw phase-space coordinates to observed sky positions and astropy SkyCoord objects." ] }, { "cell_type": "code", "execution_count": 1, "id": "8a50e972", "metadata": { "execution": { "iopub.execute_input": "2026-05-16T13:49:06.789187Z", "iopub.status.busy": "2026-05-16T13:49:06.788901Z", "iopub.status.idle": "2026-05-16T13:49:09.168302Z", "shell.execute_reply": "2026-05-16T13:49:09.167355Z" }, "papermill": { "duration": 2.384677, "end_time": "2026-05-16T13:49:09.169362+00:00", "exception": false, "start_time": "2026-05-16T13:49:06.784685+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy\n", "from astropy import units\n", "from galpy.orbit import Orbit\n", "from galpy.potential import MWPotential2014\n", "import warnings\n", "\n", "warnings.filterwarnings(\"ignore\", category=RuntimeWarning)\n", "warnings.filterwarnings(\"ignore\", category=UserWarning)" ] }, { "cell_type": "markdown", "id": "0073a55a", "metadata": { "papermill": { "duration": 0.003126, "end_time": "2026-05-16T13:49:09.176068+00:00", "exception": false, "start_time": "2026-05-16T13:49:09.172942+00:00", "status": "completed" }, "tags": [] }, "source": [ "## Standard 3D initialization\n", "\n", "The most basic way to create an orbit is by specifying\n", "phase-space coordinates in galactocentric cylindrical coordinates\n", "`[R, vR, vT, z, vz, phi]` (in natural units where $R_0 = 1$, $V_0 = 1$)." ] }, { "cell_type": "code", "execution_count": 2, "id": "7906bb52", "metadata": { "execution": { "iopub.execute_input": "2026-05-16T13:49:09.183605Z", "iopub.status.busy": "2026-05-16T13:49:09.183250Z", "iopub.status.idle": "2026-05-16T13:49:09.188089Z", "shell.execute_reply": "2026-05-16T13:49:09.186919Z" }, "papermill": { "duration": 0.00951, "end_time": "2026-05-16T13:49:09.188818+00:00", "exception": false, "start_time": "2026-05-16T13:49:09.179308+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Orbit dimension = 3, phase-space dimension = 6\n", "R = 1.0, vT = 1.0\n" ] } ], "source": [ "# Full 3D orbit with azimuth\n", "o = Orbit([1.0, 0.1, 1.0, 0.0, 0.05, 0.0])\n", "print(f\"Orbit dimension = {o.dim()}, phase-space dimension = {o.phasedim()}\")\n", "print(f\"R = {o.R()}, vT = {o.vT()}\")" ] }, { "cell_type": "markdown", "id": "c9d840aa", "metadata": { "papermill": { "duration": 0.003267, "end_time": "2026-05-16T13:49:09.195628+00:00", "exception": false, "start_time": "2026-05-16T13:49:09.192361+00:00", "status": "completed" }, "tags": [] }, "source": [ "If the orbit is in an axisymmetric potential, the azimuth `phi` can be omitted:" ] }, { "cell_type": "code", "execution_count": 3, "id": "feaa6dc1", "metadata": { "execution": { "iopub.execute_input": "2026-05-16T13:49:09.203507Z", "iopub.status.busy": "2026-05-16T13:49:09.203310Z", "iopub.status.idle": "2026-05-16T13:49:09.207202Z", "shell.execute_reply": "2026-05-16T13:49:09.206256Z" }, "papermill": { "duration": 0.008978, "end_time": "2026-05-16T13:49:09.208168+00:00", "exception": false, "start_time": "2026-05-16T13:49:09.199190+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Orbit dimension = 3, phase-space dimension = 5\n" ] } ], "source": [ "# 3D orbit without azimuth (axisymmetric potentials)\n", "o_noaz = Orbit([1.0, 0.1, 1.0, 0.0, 0.05])\n", "print(f\"Orbit dimension = {o_noaz.dim()}, phase-space dimension = {o_noaz.phasedim()}\")" ] }, { "cell_type": "markdown", "id": "ae879c5a", "metadata": { "papermill": { "duration": 0.003217, "end_time": "2026-05-16T13:49:09.214828+00:00", "exception": false, "start_time": "2026-05-16T13:49:09.211611+00:00", "status": "completed" }, "tags": [] }, "source": [ "## 2D and 1D orbits\n", "\n", "galpy also supports planar (2D) and linear (1D) orbits." ] }, { "cell_type": "code", "execution_count": 4, "id": "856f6a2d", "metadata": { "execution": { "iopub.execute_input": "2026-05-16T13:49:09.222693Z", "iopub.status.busy": "2026-05-16T13:49:09.222481Z", "iopub.status.idle": "2026-05-16T13:49:09.227529Z", "shell.execute_reply": "2026-05-16T13:49:09.226711Z" }, "papermill": { "duration": 0.010339, "end_time": "2026-05-16T13:49:09.228562+00:00", "exception": false, "start_time": "2026-05-16T13:49:09.218223+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2D with phi: orbit dimension = 2, phase-space dimension = 4\n", "2D no phi: orbit dimension = 2, phase-space dimension = 3\n", "1D: orbit dimension = 1, phase-space dimension = 2\n" ] } ], "source": [ "# 2D orbit with azimuth: [R, vR, vT, phi]\n", "o2d = Orbit([1.0, 0.1, 1.0, 0.0])\n", "print(\n", " f\"2D with phi: orbit dimension = {o2d.dim()}, phase-space dimension = {o2d.phasedim()}\"\n", ")\n", "\n", "# 2D orbit without azimuth: [R, vR, vT]\n", "o2d_noaz = Orbit([1.0, 0.1, 1.0])\n", "print(\n", " f\"2D no phi: orbit dimension = {o2d_noaz.dim()}, phase-space dimension = {o2d_noaz.phasedim()}\"\n", ")\n", "\n", "# 1D orbit: [x, vx]\n", "o1d = Orbit([1.0, 0.1])\n", "print(f\"1D: orbit dimension = {o1d.dim()}, phase-space dimension = {o1d.phasedim()}\")" ] }, { "cell_type": "markdown", "id": "049c963f", "metadata": { "papermill": { "duration": 0.003285, "end_time": "2026-05-16T13:49:09.235361+00:00", "exception": false, "start_time": "2026-05-16T13:49:09.232076+00:00", "status": "completed" }, "tags": [] }, "source": [ "## Physical units with `ro=` and `vo=`\n", "\n", "By setting `ro` (distance scale in kpc) and `vo` (velocity scale in km/s),\n", "the orbit will return quantities in physical units." ] }, { "cell_type": "code", "execution_count": 5, "id": "fc6de36b", "metadata": { "execution": { "iopub.execute_input": "2026-05-16T13:49:09.243201Z", "iopub.status.busy": "2026-05-16T13:49:09.242927Z", "iopub.status.idle": "2026-05-16T13:49:09.247409Z", "shell.execute_reply": "2026-05-16T13:49:09.246535Z" }, "papermill": { "duration": 0.009311, "end_time": "2026-05-16T13:49:09.248070+00:00", "exception": false, "start_time": "2026-05-16T13:49:09.238759+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "R = 8.0 kpc\n", "vT = 220.0 km/s\n", "vz = 11.0 km/s\n" ] } ], "source": [ "o_phys = Orbit([1.0, 0.1, 1.0, 0.0, 0.05, 0.0], ro=8.0, vo=220.0)\n", "print(\"R =\", o_phys.R(), \"kpc\")\n", "print(\"vT =\", o_phys.vT(), \"km/s\")\n", "print(\"vz =\", o_phys.vz(), \"km/s\")" ] }, { "cell_type": "markdown", "id": "f868c39f", "metadata": { "papermill": { "duration": 0.003292, "end_time": "2026-05-16T13:49:09.257459+00:00", "exception": false, "start_time": "2026-05-16T13:49:09.254167+00:00", "status": "completed" }, "tags": [] }, "source": [ "## Astropy Quantity inputs\n", "\n", "You can also initialize with astropy Quantities directly.\n", "\n", "