From d1df273bddff014542a682c062986310dc4d8e4b Mon Sep 17 00:00:00 2001 From: briannapt Date: Tue, 23 Jan 2018 11:54:02 -0800 Subject: [PATCH] Add files via upload Crossmatching --- HW2-Pt4_Thomas.ipynb | 263 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 HW2-Pt4_Thomas.ipynb diff --git a/HW2-Pt4_Thomas.ipynb b/HW2-Pt4_Thomas.ipynb new file mode 100644 index 0000000..9bed369 --- /dev/null +++ b/HW2-Pt4_Thomas.ipynb @@ -0,0 +1,263 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from astropy.table import Table, Column, vstack\n", + "import collections\n", + "%matplotlib inline\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Read HLC and NSC Tables" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#--------------HLC-----------------------#\n", + "\n", + "hlc1=Table.read('HLC.RA_00_to_01.fits.gz')\n", + "hlc2=Table.read('HLC.RA_01_to_02.fits.gz')\n", + "hlc3=Table.read('HLC.RA_02_to_03.fits.gz')\n", + "hlc4=Table.read('HLC.RA_03_to_04.fits.gz')\n", + "hlc5=Table.read('HLC.RA_20_to_21.fits.gz')\n", + "hlc6=Table.read('HLC.RA_21_to_22.fits.gz')\n", + "hlc7=Table.read('HLC.RA_22_to_23.fits.gz')\n", + "hlc8=Table.read('HLC.RA_23_to_24.fits.gz')\n", + "\n", + "hlc=vstack(hlc1,hlc2,hlc3,hlc4,hlc5,hlc6,hlc7,hlc8)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#--------------NSC----------------------#\n", + "\n", + "nsc1=Table.read('stripe82_315_ra_45_-1_3_dec_0.txt', format='ascii.basic')\n", + "nsc2=Table.read('stripe82_315_ra_45_0_dec_1_3.txt', format='ascii.basic')\n", + "\n", + "nsc=vstack(nsc1,nsc2)\n", + "\n", + "print('Done')" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "idx=Table.read('manxmatch_hlc_nsc_idx.txt', format='ascii.no_header')\n", + "dist=Table.read('manxmatch_hlc_nsc_d2d.txt', format='ascii.no_header')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Crossmatching" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#-----------Read matched indices and distances tables--------------#\n", + "\n", + "idx=Table.read('manxmatch_hlc_nsc_idx.txt', format='ascii.no_header')\n", + "dist=Table.read('manxmatch_hlc_nsc_d2d.txt', format='ascii.no_header')\n", + "\n", + "#print(len(idx), len(dist))\n", + "#dist['col1']\n", + "\n", + "#----------Make list of duplicates--------------------#\n", + "\n", + "# Count duplicates\n", + "count=collections.Counter(idx['col1'])\n", + "# Turn list into array\n", + "count=np.array(count.items())\n", + "# Make mask of multiple matches\n", + "multimatch=count[:,1]>1\n", + "\n", + "#-------------Match Multiples in Indices array----------------#\n", + "\n", + "# Here, I'm going to create a massive list of the indices of matches I want to throw away.\n", + "\n", + "match=[]\n", + "b=[]\n", + "\n", + "for indice in count[multimatch][:,0]:\n", + " #Create mask to find multiple indicies\n", + " a=np.where(idx['col1']==indice)[0]\n", + " #Append matches to list\n", + " match.append([a,idx['col1'][a],dist['col1'][a]])\n", + " #Create mask to find the minimum distance within the matches\n", + " b.append(dist['col1'][a]==min(d for d in dist['col1'][a]))\n", + "\n", + "\n", + "# Apply the mask to this weird \"match\" list and make a new list of the wrong \n", + "# indice matches using the '~'.\n", + "\n", + "wrong=[]\n", + "\n", + "for i in range(len(match)):\n", + " wrong.append(match[i][0][~b[i]])\n", + "\n", + "# Concatenate list of indicies into \"badmatch\"\n", + "badmatch=np.concatenate(wrong, axis=0)\n", + "\n", + "#---------Check list of the right indice matches--------------#\n", + "\n", + "#right=[]\n", + "\n", + "#for i in range(len(match)):\n", + " #right.append(match[i][0][b[i]])\n", + "\n", + "#---------------------Final list of matches---------------------#\n", + "idxnew=np.delete(idx['col1'],badmatch)\n", + "\n", + "#-------------Apply indicies to nsc table-------------#\n", + "nsc[idxnew]\n", + "\n", + "#-------------Split nsc table---------------------------------#\n", + "nsc1=nsc[0:len(hlc1)-1]\n", + "nsc2=nsc[len(hlc1):len(hlc2)-1]\n", + "nsc3=nsc[len(hlc2):len(hlc3)-1]\n", + "nsc4=nsc[len(hlc3):len(hlc4)-1]\n", + "nsc5=nsc[len(hlc4):len(hlc5)-1]\n", + "nsc6=nsc[len(hlc5):len(hlc6)-1]\n", + "nsc7=nsc[len(hlc6):len(hlc7)-1]\n", + "nsc8=nsc[len(hlc7):len(hlc8)-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1527346" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "idxnew=np.delete(idx['col1'],badmatch)\n", + "len(idxnew)" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(1527346, 1527346)" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Proper Motion" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#-----------------dPM----------------------------#\n", + "# HLC proper motions\n", + "HLCpmRA = 1000*hlc['RA_PM']\n", + "HLCpmRAerr = 1000*hlc['RA_PM_ERR']\n", + "HLCpmDec = 1000*hlc['DEC_PM']\n", + "HLCpmDecerr = 1000*hlc['DEC_PM_ERR']\n", + "# NSC proper motions \n", + "NSCpmRA = nsc['pmra']\n", + "NSCpmRAerr = nsc['pmraerr']\n", + "NSCpmDec = nsc['pmdec']\n", + "NSCpmDecerr = nsc['pmdecerr']\n", + "\n", + "dra = 3600*(hlc['RAPM_MEAN'] - nsc['ra']) \n", + "ddec = 3600*(hlc['DEC_MEAN'] - nsc['dec']) \n", + "\n", + "\n", + "dPMra = HLCpmRA - NSCpmRA\n", + "\n", + "N, xedges, yedges = binned_statistic_2d(r, , dPMRA, 'count', bins=150)\n", + "\n", + "plt.xlabel('$r$')\n", + "plt.ylabel('$dpmRA$')\n", + "plt.imshow(np.log10(N.T), origin='lower', extent=[xedges[0], xedges[-1], yedges[0], \n", + " yedges[-1]], aspect='auto', interpolation='nearest', cmap=multicolor)\n", + " \n", + "cb = plt.colorbar(orientation='horizontal')\n", + "cb.set_label('$log(count)$')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.13" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}