Skip to content

Instantly share code, notes, and snippets.

@eteq
Created February 15, 2019 01:55
Show Gist options
  • Save eteq/96b6b3159d9b73d0bbb94d22a4e72682 to your computer and use it in GitHub Desktop.
Save eteq/96b6b3159d9b73d0bbb94d22a4e72682 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"from astropy import units as u\n",
"from astropy.coordinates import SkyCoord, CartesianRepresentation,SphericalRepresentation\n",
"from astropy.table import Table\n",
"from astropy.io import fits\n",
"\n",
"first = lambda x:next(iter(x))\n",
"\n",
"%matplotlib inline\n",
"from matplotlib import style, pyplot as plt\n",
"from mpl_toolkits.mplot3d import Axes3D"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"m33 = SkyCoord.from_name('M33')\n",
"m33 = SkyCoord(m33, distance=700*u.kpc)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"n = 100000\n",
"rad = 161*u.kpc # assume halo radius is ~161 kpc\n",
"xyz = (np.random.rand(3, n)*2-1)*rad\n",
"rep = CartesianRepresentation(xyz).represent_as(SphericalRepresentation)\n",
"rep = rep[rep.distance<rad]\n",
"halo = SkyCoord(rep + m33.data)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def fraction_of_halo_in_field(field_center):\n",
" n_in_field = np.sum(halo.separation(field_center) < 90*u.arcmin)\n",
" return n_in_field/len(halo)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.01732772245177752"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fraction_of_halo_in_field(SkyCoord(m33.ra, 25*u.deg))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.019212826322904965"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fraction_of_halo_in_field(SkyCoord(m33.ra, 29*u.deg))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment