{ "cells": [ { "cell_type": "markdown", "id": "20bbc12a", "metadata": { "papermill": { "duration": 0.002928, "end_time": "2026-11-02T15:12:00.030789+00:00", "exception": false, "start_time": "2026-11-02T15:12:00.027861+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-11-02T15:12:00.037264Z", "iopub.status.busy": "2026-11-02T15:12:00.037006Z", "iopub.status.idle": "2026-11-02T15:12:02.489895Z", "shell.execute_reply": "2026-11-02T15:12:02.488843Z" }, "papermill": { "duration": 2.457203, "end_time": "2026-11-02T15:12:02.490650+00:00", "exception": false, "start_time": "2026-11-02T15:12:00.033447+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.002231, "end_time": "2026-11-02T15:12:02.495594+00:00", "exception": false, "start_time": "2026-11-02T15:12:02.493363+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-11-02T15:12:02.501296Z", "iopub.status.busy": "2026-11-02T15:12:02.500929Z", "iopub.status.idle": "2026-11-02T15:12:02.505440Z", "shell.execute_reply": "2026-11-02T15:12:02.504437Z" }, "papermill": { "duration": 0.008214, "end_time": "2026-11-02T15:12:02.506157+00:00", "exception": false, "start_time": "2026-11-02T15:12:02.497943+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.002259, "end_time": "2026-11-02T15:12:02.510877+00:00", "exception": false, "start_time": "2026-11-02T15:12:02.508618+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-11-02T15:12:02.516559Z", "iopub.status.busy": "2026-11-02T15:12:02.516393Z", "iopub.status.idle": "2026-11-02T15:12:02.520088Z", "shell.execute_reply": "2026-11-02T15:12:02.518989Z" }, "papermill": { "duration": 0.007303, "end_time": "2026-11-02T15:12:02.520690+00:00", "exception": false, "start_time": "2026-11-02T15:12:02.513387+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.00232, "end_time": "2026-11-02T15:12:02.525546+00:00", "exception": false, "start_time": "2026-11-02T15:12:02.523226+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-11-02T15:12:02.531141Z", "iopub.status.busy": "2026-11-02T15:12:02.530974Z", "iopub.status.idle": "2026-11-02T15:12:02.535736Z", "shell.execute_reply": "2026-11-02T15:12:02.534777Z" }, "papermill": { "duration": 0.008437, "end_time": "2026-11-02T15:12:02.536403+00:00", "exception": false, "start_time": "2026-11-02T15:12:02.527966+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.002319, "end_time": "2026-11-02T15:12:02.541401+00:00", "exception": false, "start_time": "2026-11-02T15:12:02.539082+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-11-02T15:12:02.547056Z", "iopub.status.busy": "2026-11-02T15:12:02.546884Z", "iopub.status.idle": "2026-11-02T15:12:02.550805Z", "shell.execute_reply": "2026-11-02T15:12:02.549762Z" }, "papermill": { "duration": 0.007667, "end_time": "2026-11-02T15:12:02.551471+00:00", "exception": false, "start_time": "2026-11-02T15:12:02.543804+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.002357, "end_time": "2026-11-02T15:12:02.556376+00:00", "exception": false, "start_time": "2026-11-02T15:12:02.554019+00:00", "status": "completed" }, "tags": [] }, "source": [ "## Astropy Quantity inputs\n", "\n", "You can also initialize with astropy Quantities directly.\n", "\n", "