{ "cells": [ { "cell_type": "markdown", "id": "7fb27b941602401d91542211134fc71a", "metadata": { "papermill": { "duration": 0.006327, "end_time": "2026-06-30T01:16:46.737199+00:00", "exception": false, "start_time": "2026-06-30T01:16:46.730872+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-06-30T01:16:46.748294Z", "iopub.status.busy": "2026-06-30T01:16:46.748057Z", "iopub.status.idle": "2026-06-30T01:16:49.063446Z", "shell.execute_reply": "2026-06-30T01:16:49.062615Z" }, "papermill": { "duration": 2.32273, "end_time": "2026-06-30T01:16:49.064832+00:00", "exception": false, "start_time": "2026-06-30T01:16:46.742102+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.004706, "end_time": "2026-06-30T01:16:49.075420+00:00", "exception": false, "start_time": "2026-06-30T01:16:49.070714+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-06-30T01:16:49.089594Z", "iopub.status.busy": "2026-06-30T01:16:49.089184Z", "iopub.status.idle": "2026-06-30T01:16:49.094525Z", "shell.execute_reply": "2026-06-30T01:16:49.093422Z" }, "papermill": { "duration": 0.011643, "end_time": "2026-06-30T01:16:49.095126+00:00", "exception": false, "start_time": "2026-06-30T01:16:49.083483+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.004557, "end_time": "2026-06-30T01:16:49.104799+00:00", "exception": false, "start_time": "2026-06-30T01:16:49.100242+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-06-30T01:16:49.115450Z", "iopub.status.busy": "2026-06-30T01:16:49.115241Z", "iopub.status.idle": "2026-06-30T01:16:49.119053Z", "shell.execute_reply": "2026-06-30T01:16:49.118194Z" }, "papermill": { "duration": 0.010152, "end_time": "2026-06-30T01:16:49.119704+00:00", "exception": false, "start_time": "2026-06-30T01:16:49.109552+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.004502, "end_time": "2026-06-30T01:16:49.128955+00:00", "exception": false, "start_time": "2026-06-30T01:16:49.124453+00:00", "status": "completed" }, "tags": [] }, "source": [ "