Skip to content

Instantly share code, notes, and snippets.

@mwcraig
Created October 4, 2017 13:23
Show Gist options
  • Save mwcraig/ac20da8ad3037f5ef1a0e08d9d907db1 to your computer and use it in GitHub Desktop.
Save mwcraig/ac20da8ad3037f5ef1a0e08d9d907db1 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": {
"collapsed": true
},
"outputs": [],
"source": [
"from astropy import units as u\n",
"from astropy.coordinates import SkyCoord\n",
"from astroquery.vizier import Vizier"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"center = SkyCoord(135.563301393, 49.76324262, unit=('deg','deg'))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"viz_gaia = Vizier(catalog='I/337/gaia')\n",
"viz_gaia.ROW_LIMIT=-1\n",
"gaia = viz_gaia.query_region(coordinates=center, radius='30 arcmin', catalog='I/337/gaia')[0]"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"from ccdproc import CCDData\n",
"from photutils import DAOStarFinder\n",
"from astropy.stats import mad_std\n",
"ccd = CCDData.read('ey-uma-022R.fit')\n",
"bkg_sigma = mad_std(ccd.data)\n",
"daofind = DAOStarFinder(fwhm=3.0, threshold=5. * bkg_sigma)\n",
"sources = daofind(ccd.data)\n",
"bright = sources[sources['mag'].argsort()[:30]]"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [],
"source": [
"gaia.sort('__Gmag_')"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from ccdproc import astrometry as astrom\n",
"x, y = bright['xcentroid'], bright['ycentroid']\n",
"x, y = astrom.remove_duplicates(x, y, tolerance=10)"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
"from astropy.modeling import models, fitting\n",
"r, d = gaia['RA_ICRS'], gaia['DE_ICRS']\n",
"matches = astrom.match_by_triangle(\n",
" x, y, r, d, n_limit=30, tolerance=0.02,\n",
" clean_limit=5, match_tolerance=0.02, m_init=models.Polynomial2D(1),\n",
" fitter = fitting.LinearLSQFitter())\n",
"i1, i2 = matches"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(2, 10, 16)"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"i2"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<Column name='xcentroid' dtype='float64' length=26>\n",
"<table>\n",
"<tr><td>886.857049833</td></tr>\n",
"<tr><td>903.58616164</td></tr>\n",
"<tr><td>123.534804185</td></tr>\n",
"<tr><td>2305.38021102</td></tr>\n",
"<tr><td>574.005540121</td></tr>\n",
"<tr><td>1169.05912492</td></tr>\n",
"<tr><td>1005.20433163</td></tr>\n",
"<tr><td>2037.73662435</td></tr>\n",
"<tr><td>996.203242244</td></tr>\n",
"<tr><td>2016.56040245</td></tr>\n",
"<tr><td>0.238950932001</td></tr>\n",
"<tr><td>1395.02148639</td></tr>\n",
"<tr><td>...</td></tr>\n",
"<tr><td>0.358481237615</td></tr>\n",
"<tr><td>0.145549608648</td></tr>\n",
"<tr><td>0.268287794025</td></tr>\n",
"<tr><td>2978.13928298</td></tr>\n",
"<tr><td>0.292174177587</td></tr>\n",
"<tr><td>2533.26954325</td></tr>\n",
"<tr><td>981.142357235</td></tr>\n",
"<tr><td>0.40720295707</td></tr>\n",
"<tr><td>2590.99390345</td></tr>\n",
"<tr><td>0.270443917744</td></tr>\n",
"<tr><td>0.191384343996</td></tr>\n",
"<tr><td>0.305400718284</td></tr>\n",
"</table>"
],
"text/plain": [
"<Column name='xcentroid' dtype='float64' length=26>\n",
" 886.857049833\n",
" 903.58616164\n",
" 123.534804185\n",
" 2305.38021102\n",
" 574.005540121\n",
" 1169.05912492\n",
" 1005.20433163\n",
" 2037.73662435\n",
" 996.203242244\n",
" 2016.56040245\n",
"0.238950932001\n",
" 1395.02148639\n",
" ...\n",
"0.358481237615\n",
"0.145549608648\n",
"0.268287794025\n",
" 2978.13928298\n",
"0.292174177587\n",
" 2533.26954325\n",
" 981.142357235\n",
" 0.40720295707\n",
" 2590.99390345\n",
"0.270443917744\n",
"0.191384343996\n",
"0.305400718284"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"idp, idx = astrom.match_by_fit(\n",
" x, y, r, d, i1, i2, tolerance=0.00138889)"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 2, 3])"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"idp"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"WCS Keywords\n",
"\n",
"Number of WCS axes: 2\n",
"CTYPE : 'RA---TAN' 'DEC--TAN' \n",
"CRVAL : 135.19683274323401 49.692117170561744 \n",
"CRPIX : 1543.0 1024.5 \n",
"CD1_1 CD1_2 : -0.00016587864604585486 -0.0001488163963875111 \n",
"CD2_1 CD2_2 : -0.00022838515568534252 0.00026324797457884919 \n",
"NAXIS : 0 0"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wcs = astrom.create_wcs_from_fit(x, y, r.data, d.data, idp, idx, xref=1543.0, yref=1024.5)\n",
"wcs"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"WCS Keywords\n",
"\n",
"Number of WCS axes: 2\n",
"CTYPE : 'RA---TAN-SIP' 'DEC--TAN-SIP' \n",
"CRVAL : 135.56330139299999 49.76324262 \n",
"CRPIX : 1543.0 1024.5 \n",
"CD1_1 CD1_2 : 0.00015466617567099999 8.0679635065000002e-06 \n",
"CD2_1 CD2_2 : -8.1372895240600001e-06 0.000154600989856 \n",
"NAXIS : 3073 2048"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ccd.wcs"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[array([ 444.82033693]), array([ 557.0450302])]"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wcs.all_world2pix([135.586500], [49.819250], 0)"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[array([ 1619.74502698]), array([ 1390.01159188])]"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ccd.wcs.all_world2pix([135.586500], [49.819250], 0)"
]
},
{
"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.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment