Skip to content

Instantly share code, notes, and snippets.

@HajimeKawahara
Created October 27, 2022 12:19
Show Gist options
  • Save HajimeKawahara/56ea38b18107586a91f1b838de7aa21d to your computer and use it in GitHub Desktop.
Save HajimeKawahara/56ea38b18107586a91f1b838de7aa21d 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,
"id": "df9eed7e",
"metadata": {},
"outputs": [],
"source": [
"from astropy.io import fits\n",
"from astropy.wcs import WCS\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fe29b0fc",
"metadata": {},
"outputs": [],
"source": [
"filename = \"/home/kawahara/hst/color_hst_12182_46_wfc3_ir_f139m_f127m_sci.fits\"\n",
"hdu = fits.open(filename)\n",
"dbname = \"/home/kawahara/hst/db/gns_catalog.csv\"\n",
"db = pd.read_csv(dbname)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5907813a",
"metadata": {},
"outputs": [],
"source": [
"#Ohsawa code\n",
"__keywords_naxis3 = (\n",
" 'NAXIS3', 'CTYPE3', 'CRPIX3', 'CRVAL3', 'CUNIT3',\n",
" 'CD1_3', 'CD2_3', 'CD3_3', 'CD3_2', 'CD3_1',\n",
")\n",
"\n",
"def drop_naxis3_keywords(header):\n",
" header.set('NAXIS', 2)\n",
" for key in __keywords_naxis3: header.remove(key, ignore_missing=True)\n",
" return header\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0e7fd8c8",
"metadata": {},
"outputs": [],
"source": [
"img = hdu[0].data\n",
"new_header= drop_naxis3_keywords(hdu[0].header)\n",
"wcs = WCS(new_header)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "64831c4c",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "138f03a6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"53660 53660\n"
]
}
],
"source": [
"ra = db[\"ra\"].values\n",
"dec = db[\"dec\"].values\n",
"jmag = db[\"Jmag\"].values\n",
"hmag = db[\"Hmag\"].values\n",
"hwmag = 0.8*jmag + 0.2*hmag\n",
"mask = hwmag < 16.5 \n",
"print(len(ra[mask]),len(dec[mask]))\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "9233fcb6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using matplotlib backend: Qt5Agg\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_3882/2356762234.py:7: RuntimeWarning: invalid value encountered in log10\n",
" a=plt.imshow(np.log10(img[j,:,:]), origin='lower')\n"
]
}
],
"source": [
"%matplotlib \n",
"\n",
"j=0\n",
"fig = plt.figure(figsize=(20,20))\n",
"ax = plt.subplot(projection=wcs)\n",
"#ax.set_autoscale_on(False)\n",
"a=plt.imshow(np.log10(img[j,:,:]), origin='lower')\n",
"plt.scatter(ra[mask],dec[mask],marker=\"+\",alpha=0.5,color=\"C3\",transform=ax.get_transform('fk5'))\n",
"plt.colorbar(a)\n",
"plt.savefig(\"tmp.png\")\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c19838b2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.8 ('base')",
"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.8.8"
},
"vscode": {
"interpreter": {
"hash": "72bc7f8b1808a6f5ada3c6a20601509b8b1843160436d276d47f2ba819b3753b"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment