{ "cells": [ { "cell_type": "markdown", "id": "7fb27b941602401d91542211134fc71a", "metadata": { "papermill": { "duration": 0.005682, "end_time": "2026-05-16T13:49:55.352050+00:00", "exception": false, "start_time": "2026-05-16T13:49:55.346368+00:00", "status": "completed" }, "tags": [] }, "source": [ "# Introduction to Potentials\n", "\n", "galpy provides a large library of gravitational potentials. This notebook covers how to\n", "initialize potentials, evaluate them, combine them, and compute useful dynamical quantities.\n", "\n", "See also: [Potential Wrappers](wrappers.ipynb) for time-dependent and rotating potentials,\n", "[SCF and Multipole Expansions](scf_and_multipole.ipynb) for basis-function representations,\n", "[Dissipative Forces](dissipative.ipynb) for working with dissipative forces such as dynamical friction, \n", "[Milky Way Potentials](milky_way_potentials.ipynb) for pre-built MW models, [N-body snapshots](nbody_snapshots.ipynb) for working with N-body simulation data, and [Other codes](other_codes.ipynb) for info on how to use galpy potentials with a host of other codes." ] }, { "cell_type": "code", "execution_count": 1, "id": "acae54e37e7d407bbb7b55eff062a284", "metadata": { "execution": { "iopub.execute_input": "2026-05-16T13:49:55.363198Z", "iopub.status.busy": "2026-05-16T13:49:55.362930Z", "iopub.status.idle": "2026-05-16T13:49:57.727765Z", "shell.execute_reply": "2026-05-16T13:49:57.726774Z" }, "papermill": { "duration": 2.371384, "end_time": "2026-05-16T13:49:57.728506+00:00", "exception": false, "start_time": "2026-05-16T13:49:55.357122+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy\n", "from matplotlib import pyplot as plt\n", "from galpy import potential\n", "from galpy.potential import (\n", " MiyamotoNagaiPotential,\n", " NFWPotential,\n", " HernquistPotential,\n", " LogarithmicHaloPotential,\n", " MWPotential2014,\n", ")\n", "from galpy.util import conversion\n", "import warnings\n", "\n", "warnings.filterwarnings(\"ignore\", category=RuntimeWarning)\n", "warnings.filterwarnings(\"ignore\", category=UserWarning)" ] }, { "cell_type": "markdown", "id": "9a63283cbaf04dbcab1f6479b197f3a8", "metadata": { "papermill": { "duration": 0.004869, "end_time": "2026-05-16T13:49:57.738893+00:00", "exception": false, "start_time": "2026-05-16T13:49:57.734024+00:00", "status": "completed" }, "tags": [] }, "source": [ "## Initializing a potential\n", "\n", "Let's start by creating a Miyamoto-Nagai disk potential. In galpy's natural units,\n", "velocities are normalized to the circular velocity at the Sun, and distances to the\n", "Sun's Galactocentric radius." ] }, { "cell_type": "code", "execution_count": 2, "id": "8dd0d8092fe74a7c96281538738b07e2", "metadata": { "execution": { "iopub.execute_input": "2026-05-16T13:49:57.750030Z", "iopub.status.busy": "2026-05-16T13:49:57.749701Z", "iopub.status.idle": "2026-05-16T13:49:57.754963Z", "shell.execute_reply": "2026-05-16T13:49:57.753984Z" }, "papermill": { "duration": 0.011579, "end_time": "2026-05-16T13:49:57.755650+00:00", "exception": false, "start_time": "2026-05-16T13:49:57.744071+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "MiyamotoNagaiPotential with internal parameters: amp=1.4632953564490085, a=0.5, b=0.0375 and physical outputs off" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mp = MiyamotoNagaiPotential(a=0.5, b=0.0375, normalize=1.0)\n", "mp" ] }, { "cell_type": "markdown", "id": "72eea5119410473aa328ad9291626812", "metadata": { "papermill": { "duration": 0.004998, "end_time": "2026-05-16T13:49:57.765817+00:00", "exception": false, "start_time": "2026-05-16T13:49:57.760819+00:00", "status": "completed" }, "tags": [] }, "source": [ "## Evaluating potential values and forces\n", "\n", "Evaluate the potential at (R, z) = (1, 0), i.e., the solar position in natural units. Calling the potential object directly returns the potential value:" ] }, { "cell_type": "code", "execution_count": 3, "id": "8edb47106e1a46a883d545849b8ab81b", "metadata": { "execution": { "iopub.execute_input": "2026-05-16T13:49:57.779918Z", "iopub.status.busy": "2026-05-16T13:49:57.779696Z", "iopub.status.idle": "2026-05-16T13:49:57.783955Z", "shell.execute_reply": "2026-05-16T13:49:57.782957Z" }, "papermill": { "duration": 0.013647, "end_time": "2026-05-16T13:49:57.784600+00:00", "exception": false, "start_time": "2026-05-16T13:49:57.770953+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Phi(R=1, z=0) = -1.2889062500000001\n" ] } ], "source": [ "# Potential value at (R, z) = (1, 0)\n", "print(\"Phi(R=1, z=0) =\", mp(1.0, 0.0))" ] }, { "cell_type": "markdown", "id": "9fb04a61", "metadata": { "papermill": { "duration": 0.005004, "end_time": "2026-05-16T13:49:57.794882+00:00", "exception": false, "start_time": "2026-05-16T13:49:57.789878+00:00", "status": "completed" }, "tags": [] }, "source": [ "