{ "cells": [ { "cell_type": "code", "execution_count": 45, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from astropy.coordinates import SkyCoord\n", "from astroquery.vizier import Vizier\n", "import astropy.units as u\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 53, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from mpl_toolkits.mplot3d import Axes3D, proj3d\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# set this to get all rows of catalog\n", "Vizier.ROW_LIMIT = -1" ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# retrieve Karachentsev catalog\n", "ktab = Vizier.get_catalogs('J/AJ/145/101/catalog')[0]" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# convert the coordinates in the catalog into something astropy.coords can deal with\n", "# empty arrays\n", "ra = np.zeros((len(ktab))).astype('object')\n", "dec = np.zeros((len(ktab))).astype('object')\n", "\n", "# convert byte strings\n", "for r in range(0,len(ktab)):\n", " ra[r] = ktab['RAJ2000'][r].decode('utf8')\n", " dec[r] = ktab['DEJ2000'][r].decode('utf8')\n", "\n", "# grab the distances\n", "dist = np.array(ktab['Dist'])*u.Mpc " ] }, { "cell_type": "code", "execution_count": 52, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# now create Skycoords\n", "kcoord = SkyCoord(ra,dec,unit=(u.hourangle,u.deg),distance=dist*u.Mpc)\n", "x = kcoord.cartesian.x\n", "y = kcoord.cartesian.y\n", "z = kcoord.cartesian.z" ] }, { "cell_type": "code", "execution_count": 109, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# generate a size for points\n", "# here we use a scaled version of the absolute K-magnitude\n", "# (with a sign flip so that bigger numbers mean a brighter galaxy)\n", "neg_abs_k = 5*np.log10(ktab['Dist']*1e5)-ktab['Kmag']\n", "glx_size = 0.1+3*(neg_abs_k-neg_abs_k.min())" ] }, { "cell_type": "code", "execution_count": 103, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# generate a mask to use for colours \n", "# here we use the TType\n", "early_mask = ktab['TT']<5" ] }, { "cell_type": "code", "execution_count": 138, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def galaxy_xyz(x,y,z,plot_hw,cmask,sz,el=None,az=None):\n", " '''make 3D plot of positions\n", " x,y,z: Cartesian coordinates\n", " plot_hw: plot half width in same units as coordinates\n", " cmask: color mask: if mask is true points are red, if not, blue\n", " sz: size scaling for points\n", " el,az: elevation and azimuth for viewpoint\n", " '''\n", " fig = plt.figure(figsize=(9,9))\n", " ax = fig.add_subplot(111, projection='3d')\n", "# set figure axis limits\n", " ax.set_xlim(-plot_hw,plot_hw)\n", " ax.set_ylim(-plot_hw,plot_hw)\n", " ax.set_zlim(-plot_hw,plot_hw)\n", "# create masks to include only galaxies within plot\n", "# using x.value (etc) here to avoid unit problems\n", " plotmask_red = np.logical_and(np.logical_and(np.abs(x.value)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "galaxy_xyz(x,y,z,5,early_mask,size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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.5.1" } }, "nbformat": 4, "nbformat_minor": 0 }