{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Defining a Milky Way potential model" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Third-party dependencies\n", "from astropy.io import ascii\n", "import astropy.units as u\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from scipy.optimize import leastsq\n", "\n", "# Gala\n", "from gala.mpl_style import mpl_style\n", "plt.style.use(mpl_style)\n", "import gala.dynamics as gd\n", "import gala.integrate as gi\n", "import gala.potential as gp\n", "from gala.units import galactic\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction\n", "\n", "`gala` provides a simple and easy way to access and integrate orbits in an\n", "approximate mass model for the Milky Way. The parameters of the mass model are\n", "determined by least-squares fitting the enclosed mass profile of a pre-defined\n", "potential form to recent measurements compiled from the literature. These\n", "measurements are provided with the documentation of `gala` and are shown below.\n", "The radius units are kpc, and mass units are solar masses:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "tbl = ascii.read('data/MW_mass_enclosed.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "tbl" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's now plot the above data and uncertainties:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "fig, ax = plt.subplots(1, 1, figsize=(4,4))\n", "\n", "ax.errorbar(tbl['r'], tbl['Menc'], yerr=(tbl['Menc_err_neg'], tbl['Menc_err_pos']), \n", " marker='o', markersize=2, color='k', alpha=1., ecolor='#aaaaaa', \n", " capthick=0, linestyle='none', elinewidth=1.)\n", "\n", "ax.set_xlim(1E-3, 10**2.6)\n", "ax.set_ylim(7E6, 10**12.25)\n", "\n", "ax.set_xlabel('$r$ [kpc]')\n", "ax.set_ylabel('$M(