{ "cells": [ { "cell_type": "markdown", "id": "20bbc12a", "metadata": { "papermill": { "duration": 0.004399, "end_time": "2026-06-30T01:15:50.175864+00:00", "exception": false, "start_time": "2026-06-30T01:15:50.171465+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-06-30T01:15:50.184260Z", "iopub.status.busy": "2026-06-30T01:15:50.183972Z", "iopub.status.idle": "2026-06-30T01:15:52.476749Z", "shell.execute_reply": "2026-06-30T01:15:52.475678Z" }, "papermill": { "duration": 2.297661, "end_time": "2026-06-30T01:15:52.477494+00:00", "exception": false, "start_time": "2026-06-30T01:15:50.179833+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.002921, "end_time": "2026-06-30T01:15:52.483754+00:00", "exception": false, "start_time": "2026-06-30T01:15:52.480833+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-06-30T01:15:52.491090Z", "iopub.status.busy": "2026-06-30T01:15:52.490685Z", "iopub.status.idle": "2026-06-30T01:15:52.495132Z", "shell.execute_reply": "2026-06-30T01:15:52.494408Z" }, "papermill": { "duration": 0.009345, "end_time": "2026-06-30T01:15:52.496128+00:00", "exception": false, "start_time": "2026-06-30T01:15:52.486783+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.002994, "end_time": "2026-06-30T01:15:52.502500+00:00", "exception": false, "start_time": "2026-06-30T01:15:52.499506+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-06-30T01:15:52.513197Z", "iopub.status.busy": "2026-06-30T01:15:52.512984Z", "iopub.status.idle": "2026-06-30T01:15:52.516781Z", "shell.execute_reply": "2026-06-30T01:15:52.516021Z" }, "papermill": { "duration": 0.008537, "end_time": "2026-06-30T01:15:52.517533+00:00", "exception": false, "start_time": "2026-06-30T01:15:52.508996+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.003086, "end_time": "2026-06-30T01:15:52.524002+00:00", "exception": false, "start_time": "2026-06-30T01:15:52.520916+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-06-30T01:15:52.531384Z", "iopub.status.busy": "2026-06-30T01:15:52.531145Z", "iopub.status.idle": "2026-06-30T01:15:52.535821Z", "shell.execute_reply": "2026-06-30T01:15:52.534909Z" }, "papermill": { "duration": 0.009329, "end_time": "2026-06-30T01:15:52.536494+00:00", "exception": false, "start_time": "2026-06-30T01:15:52.527165+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.003118, "end_time": "2026-06-30T01:15:52.543160+00:00", "exception": false, "start_time": "2026-06-30T01:15:52.540042+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-06-30T01:15:52.550866Z", "iopub.status.busy": "2026-06-30T01:15:52.550661Z", "iopub.status.idle": "2026-06-30T01:15:52.554583Z", "shell.execute_reply": "2026-06-30T01:15:52.553596Z" }, "papermill": { "duration": 0.008963, "end_time": "2026-06-30T01:15:52.555332+00:00", "exception": false, "start_time": "2026-06-30T01:15:52.546369+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.003108, "end_time": "2026-06-30T01:15:52.561705+00:00", "exception": false, "start_time": "2026-06-30T01:15:52.558597+00:00", "status": "completed" }, "tags": [] }, "source": [ "## Astropy Quantity inputs\n", "\n", "You can also initialize with astropy Quantities directly.\n", "\n", "