Skip to content

Instantly share code, notes, and snippets.

@nstarman
Created May 2, 2021 20:09
Show Gist options
  • Save nstarman/5a7a1a17ff1759c12d2448846e9a1a9f to your computer and use it in GitHub Desktop.
Save nstarman/5a7a1a17ff1759c12d2448846e9a1a9f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "employed-vehicle",
"metadata": {},
"source": [
"<br><br>\n",
"\n",
"- - - \n",
"\n",
"## Prepare\n"
]
},
{
"cell_type": "markdown",
"id": "stuck-copying",
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"source": [
"### Imports"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "geological-patrick",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/nathanielstarkman/local/galpy/galpy/util/bovy_conversion.py:6: FutureWarning: galpy.util.bovy_conversion is being deprecated in favor of galpy.util.conversion; all functions in there are the same; please switch to the new import, because the old import will be removed in v1.9\n",
" warnings.warn('galpy.util.bovy_conversion is being deprecated in favor of galpy.util.conversion; all functions in there are the same; please switch to the new import, because the old import will be removed in v1.9',FutureWarning)\n",
"\n",
"/Users/nathanielstarkman/local/galpy/galpy/util/bovy_coords.py:6: FutureWarning: galpy.util.bovy_coords is being deprecated in favor of galpy.util.coords; all functions in there are the same; please switch to the new import, because the old import will be removed in v1.9\n",
" warnings.warn('galpy.util.bovy_coords is being deprecated in favor of galpy.util.coords; all functions in there are the same; please switch to the new import, because the old import will be removed in v1.9',FutureWarning)\n",
"\n"
]
}
],
"source": [
"# THIRD PARTY\n",
"import astropy.units as u\n",
"import astropy.coordinates as coord\n",
"from astropy.table import QTable\n",
"from astropy.tests.helper import catch_warnings\n",
"from astropy.utils.misc import NumpyRNGContext\n",
"\n",
"from galpy import potential\n",
"from galpy.orbit import Orbit\n",
"from galpy.df import streamdf\n",
"from galpy.actionAngle import actionAngleIsochroneApprox\n",
"from galpy.util import conversion\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import numpy as np\n",
"\n",
"import streamtools\n",
"from streamtools.df import streamspraydf"
]
},
{
"cell_type": "markdown",
"id": "affected-printing",
"metadata": {},
"source": [
"Setting up an orbit and potential"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "decent-destiny",
"metadata": {
"collapsed": false,
"inputHidden": false,
"jupyter": {
"outputs_hidden": false
},
"outputHidden": false
},
"outputs": [],
"source": [
"# potential\n",
"lp = potential.LogarithmicHaloPotential(normalize=1.,q=0.9)\n",
"lp.turn_physical_on()\n",
"\n",
"# progenitor properties\n",
"o = Orbit(coord.SkyCoord(coord.ICRS(\n",
" ra=229.022 * u.deg, dec=-0.112 * u.deg, distance=23.2 * u.kpc,\n",
" pm_ra_cosdec=-2.736 * u.mas / u.yr, pm_dec=-2.646 * u.mas / u.yr, radial_velocity=-58.60 * u.km / u.s,)))\n",
"\n",
"mass = 2*10.**4.*u.Msun\n",
"tdisrupt = 5*u.Gyr"
]
},
{
"cell_type": "markdown",
"id": "exceptional-passenger",
"metadata": {},
"source": [
"<br><br>\n",
"\n",
"- - - \n",
"\n",
"## With Units"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "confident-vacuum",
"metadata": {},
"outputs": [],
"source": [
"# leading\n",
"spdf_l = streamspraydf(\n",
" progenitor_mass=mass,\n",
" progenitor=o,\n",
" pot=lp,\n",
" tdisrupt=tdisrupt,\n",
" leading=True,\n",
" ro=8*u.kpc, vo=220*u.km/u.s,\n",
")\n",
"\n",
"# trailing\n",
"spdf_t = streamspraydf(\n",
" progenitor_mass=mass,\n",
" progenitor=o,\n",
" pot=lp,\n",
" tdisrupt=tdisrupt,\n",
" leading=False,\n",
" ro=8*u.kpc, vo=220*u.km/u.s,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "massive-brooklyn",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 3.07 s, sys: 35.7 ms, total: 3.11 s\n",
"Wall time: 3.17 s\n"
]
}
],
"source": [
"%%time\n",
"with NumpyRNGContext(4):\n",
"\n",
" RvR_l, dt = spdf_l.sample(n=300, returndt=True, integrate=True)\n",
" RvR_t, dt = spdf_t.sample(n=300, returndt=True, integrate=True)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "nearby-wisdom",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$[10.058216,~7.7699016,~8.2472834,~\\dots,~7.903767,~7.7573701,~8.1571772] \\; \\mathrm{kpc}$"
],
"text/plain": [
"<Quantity [10.05821571, 7.76990165, 8.24728344, 8.23608889, 8.26252376,\n",
" 7.82733284, 7.8227129 , 8.14844061, 7.74947341, 7.7378447 ,\n",
" 9.20494365, 7.77693193, 8.71895659, 7.772061 , 7.83052182,\n",
" 8.24765065, 8.13871235, 7.71145364, 7.95918784, 8.98432985,\n",
" 7.75250956, 8.79465749, 8.91524536, 9.15514276, 7.92866238,\n",
" 7.98460295, 7.90484663, 7.86939359, 8.70831761, 7.71844585,\n",
" 7.96288743, 7.88934062, 7.77759182, 7.77703826, 7.8173244 ,\n",
" 7.7678472 , 7.92641618, 8.20699556, 7.72013942, 8.8541468 ,\n",
" 7.73502358, 7.82482812, 7.81099252, 7.68782249, 7.8188413 ,\n",
" 7.75087997, 8.57462689, 7.71318035, 7.99866913, 8.08934693,\n",
" 10.62808427, 8.21794309, 7.79804249, 7.81987087, 8.07497761,\n",
" 7.77956484, 7.86859957, 7.72347883, 8.64024617, 7.73050265,\n",
" 8.05842208, 7.75169419, 7.8378724 , 8.04175157, 8.57496489,\n",
" 7.71351094, 7.805019 , 7.97664236, 7.71909337, 7.94968243,\n",
" 7.78900347, 8.98102181, 7.92310261, 7.77921562, 8.10962382,\n",
" 8.33374308, 7.8488487 , 7.99263278, 7.80321479, 9.18051979,\n",
" 8.25294539, 7.89050409, 7.8274379 , 7.96239181, 7.73979467,\n",
" 7.98220892, 7.80509019, 8.16017687, 8.13172512, 9.19922895,\n",
" 8.12057006, 7.77217225, 7.80189225, 8.36771952, 7.74842218,\n",
" 7.8678845 , 7.98780188, 7.70090985, 8.1907516 , 7.74905378,\n",
" 7.77533147, 7.86733 , 7.85675183, 8.87862717, 9.36638765,\n",
" 7.79271711, 7.95326751, 8.11083273, 7.67460999, 7.98971968,\n",
" 7.69945491, 7.95808178, 8.00920142, 7.88545771, 8.80216123,\n",
" 8.57015222, 7.71800452, 9.4623962 , 7.73461608, 8.56116253,\n",
" 7.71880245, 9.28340154, 8.87955142, 7.89726908, 8.93172953,\n",
" 7.95698925, 8.10653457, 7.82646923, 8.02018996, 8.83771146,\n",
" 7.96360739, 7.69330104, 7.82276113, 7.78795578, 7.91904994,\n",
" 8.02052373, 8.13406738, 7.97569659, 7.92828875, 7.7911819 ,\n",
" 7.71685242, 8.35725192, 7.74341305, 8.34126493, 8.41549077,\n",
" 8.62798329, 7.78256108, 7.71948614, 8.29126911, 12.46972439,\n",
" 7.92607971, 7.81414442, 8.53870644, 10.69085747, 7.98081183,\n",
" 8.09541586, 8.07553749, 8.1103042 , 7.71564792, 7.77838497,\n",
" 7.73243522, 8.80727361, 7.73367515, 7.75612301, 7.86601032,\n",
" 8.5020847 , 9.86558514, 8.88675202, 7.98129336, 7.97697686,\n",
" 7.74320279, 11.19425429, 9.27062113, 8.6092653 , 7.87048299,\n",
" 7.95283166, 7.80107219, 7.7884748 , 7.68439351, 7.72539591,\n",
" 7.873075 , 7.705681 , 8.05698434, 7.77185927, 7.89013089,\n",
" 8.10407746, 8.10089159, 7.90698804, 8.35008248, 10.02980644,\n",
" 9.2154808 , 7.70863482, 7.84714214, 7.72404181, 7.76655187,\n",
" 8.36159424, 7.71589741, 8.4455664 , 8.8669957 , 7.79351539,\n",
" 7.78724779, 8.02946628, 8.37141382, 7.75160467, 8.00642294,\n",
" 7.75547102, 7.8838222 , 7.73543166, 7.8308416 , 7.76803922,\n",
" 7.76786479, 7.84222658, 8.60544368, 7.7191551 , 9.15550085,\n",
" 7.96570259, 7.96231404, 7.89832045, 8.93539369, 7.82187155,\n",
" 8.05134281, 8.03001108, 9.68508337, 8.11994612, 7.65982398,\n",
" 7.71246492, 7.69751696, 7.8915111 , 7.79075908, 7.73555136,\n",
" 7.71123818, 8.79994065, 7.72763513, 7.81218432, 7.87321608,\n",
" 7.80100719, 7.85237886, 7.89171276, 7.94466275, 7.78404047,\n",
" 7.72754988, 8.12244814, 8.97688797, 7.82000931, 8.02316653,\n",
" 7.84921165, 10.23583725, 7.94873997, 7.80953535, 10.15701122,\n",
" 8.03372876, 8.10918264, 7.89939039, 7.71064242, 7.72721278,\n",
" 7.73909729, 7.77661308, 8.01794196, 7.99294092, 7.98411857,\n",
" 7.80324562, 7.86754849, 7.7543682 , 8.09030138, 7.77120248,\n",
" 7.74660259, 8.50774656, 7.7691352 , 7.81197869, 8.27920685,\n",
" 7.92467086, 7.72201697, 8.074955 , 8.07506459, 7.7031963 ,\n",
" 7.70127592, 7.76243115, 7.93622314, 7.96381544, 8.86641513,\n",
" 7.7848882 , 7.89993581, 7.99258314, 7.72346123, 7.73380497,\n",
" 7.94660147, 7.80906088, 8.17126069, 7.837105 , 9.76172289,\n",
" 9.50876353, 7.74841309, 7.82318968, 8.14460514, 7.81126302,\n",
" 7.71667894, 7.93550828, 7.90376697, 7.7573701 , 8.15717719] kpc>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"RvR_l[0]"
]
},
{
"cell_type": "markdown",
"id": "addressed-wright",
"metadata": {},
"source": [
"<br><br>\n",
"\n",
"- - - \n",
"\n",
"## Without Units"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "english-screw",
"metadata": {},
"outputs": [],
"source": [
"# leading\n",
"spdf_l = streamspraydf(\n",
" progenitor_mass=mass,\n",
" progenitor=o,\n",
" pot=lp,\n",
" tdisrupt=tdisrupt,\n",
" leading=True,\n",
"# ro=8*u.kpc, vo=220*u.km/u.s,\n",
")\n",
"\n",
"# trailing\n",
"spdf_t = streamspraydf(\n",
" progenitor_mass=mass,\n",
" progenitor=o,\n",
" pot=lp,\n",
" tdisrupt=tdisrupt,\n",
" leading=False,\n",
"# ro=8*u.kpc, vo=220*u.km/u.s,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "polar-irrigation",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 3.44 s, sys: 36 ms, total: 3.47 s\n",
"Wall time: 3.53 s\n"
]
}
],
"source": [
"%%time\n",
"with NumpyRNGContext(4):\n",
"\n",
" RvR_l2, dt2 = spdf_l.sample(n=300, returndt=True, integrate=True)\n",
" RvR_t2, dt2 = spdf_t.sample(n=300, returndt=True, integrate=True)"
]
},
{
"cell_type": "markdown",
"id": "cellular-redhead",
"metadata": {},
"source": [
"- - -\n",
"Compare"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "square-denver",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"all good\n"
]
}
],
"source": [
"assert np.allclose(RvR_l[0].value, RvR_l2[0] * spdf_l._ro)\n",
"assert np.allclose(RvR_l[1].value, RvR_l2[1] * spdf_l._vo)\n",
"assert np.allclose(RvR_l[2].value, RvR_l2[2] * spdf_l._vo)\n",
"assert np.allclose(RvR_l[3].value, RvR_l2[3] * spdf_l._ro)\n",
"assert np.allclose(RvR_l[4].value, RvR_l2[4] * spdf_l._vo)\n",
"assert np.allclose(RvR_l[5].value, RvR_l2[5])\n",
"\n",
"print(\"all good\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "earlier-immigration",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "dev",
"language": "python",
"name": "dev"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment