Created
August 1, 2019 13:59
-
-
Save mwcraig/2ca84a5a29e61d5aa871b059505dd28a to your computer and use it in GitHub Desktop.
Quick try at blinking/cycling through images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import ipywidgets as widgets\n", | |
"from astrowidgets import ImageWidget\n", | |
"from astropy.nddata import CCDData" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"WARNING: FITSFixedWarning: RADECSYS= 'FK5 ' / Equatorial coordinate system \n", | |
"the RADECSYS keyword is deprecated, use RADESYSa. [astropy.wcs.wcs]\n" | |
] | |
} | |
], | |
"source": [ | |
"f1 = '/Users/mcraig/Documents/Research/find-file-links-ccd-redu-phot/ccd-reduction-and-photometry-guide/notebooks/example-thermo-electric/kelt-16-b-S001-R001-C084-r.fit'\n", | |
"ccd1 = CCDData.read(f1)\n", | |
"f2 = '/Users/mcraig/Documents/Research/find-file-links-ccd-redu-phot/ccd-reduction-and-photometry-guide/notebooks/example-thermo-electric/kelt-16-b-S001-R001-C125-r.fit'\n", | |
"ccd2 = CCDData.read(f2) " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "f1b49c6c4bd64f62bc764de3f7748a62", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"VBox(children=(ToggleButton(value=False, description='Blink'), ImageWidget(children=(Image(value=b'', format='…" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"iw = ImageWidget()\n", | |
"blinker = widgets.ToggleButton(description='Blink')\n", | |
"\n", | |
"vb = widgets.VBox(children=[blinker, iw])\n", | |
"vb" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/Users/mcraig/conda-main/envs/awid-dev/lib/python3.6/site-packages/ginga/AstroImage.py:183: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.\n", | |
" data = self.get_mddata()[view]\n", | |
"WARNING: FITSFixedWarning: RADECSYS= 'FK5 ' \n", | |
"the RADECSYS keyword is deprecated, use RADESYSa. [astropy.wcs.wcs]\n" | |
] | |
} | |
], | |
"source": [ | |
"iw.load_fits(f1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def handle_blink_file(change):\n", | |
" if change['new']:\n", | |
" iw.load_fits(f2)\n", | |
" else:\n", | |
" iw.load_fits(f1)\n", | |
" \n", | |
"blinker.observe(handle_blink_file, names='value')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"WARNING: Some non-standard WCS keywords were excluded: A_ORDER, A_0_2, A_1_1, A_2_0, B_ORDER, B_0_2, B_1_1, B_2_0, AP_ORDER, AP_0_0, AP_0_1, AP_0_2, AP_1_0, AP_1_1, AP_2_0, BP_ORDER, BP_0_0, BP_0_1, BP_0_2, BP_1_0, BP_1_1, BP_2_0 Use the ``relax`` kwarg to control this. [astropy.wcs.wcs]\n" | |
] | |
} | |
], | |
"source": [ | |
"iw.load_nddata(ccd1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def handle_blink_memory(change):\n", | |
" if change['new']:\n", | |
" iw.load_nddata(ccd2)\n", | |
" else:\n", | |
" iw.load_nddata(ccd1)\n", | |
" \n", | |
"blinker.observe(handle_blink_memory, names='value')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from skimage.filters import median" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/Users/mcraig/conda-main/envs/awid-dev/lib/python3.6/site-packages/skimage/filters/rank/generic.py:104: UserWarning: Bad rank filter performance is expected due to a large number of bins (65536), equivalent to an approximate bitdepth of 16.0.\n", | |
" \"bitdepth of {:.1f}.\".format(n_bins, np.log2(n_bins)))\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[1405, 1163, 1184, ..., 1111, 1111, 1144],\n", | |
" [1389, 1163, 1175, ..., 1111, 1111, 1144],\n", | |
" [1389, 1173, 1173, ..., 1120, 1112, 1144],\n", | |
" ...,\n", | |
" [1362, 1136, 1137, ..., 1106, 1101, 1144],\n", | |
" [1362, 1136, 1136, ..., 1113, 1101, 1144],\n", | |
" [1362, 1136, 1136, ..., 1135, 1135, 1144]], dtype=uint16)" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"median(ccd1.data)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "99ef6dddd54d431f9555f11130b4b0eb", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"Play(value=0)" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"player = widgets.Play()\n", | |
"player" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"images = [\n", | |
" '/Users/mcraig/Downloads/2018-08-22/wasp-10-b-S001-R001-C006-r.fit',\n", | |
" '/Users/mcraig/Downloads/2018-08-22/wasp-10-b-S001-R001-C014-r.fit',\n", | |
" '/Users/mcraig/Downloads/2018-08-22/wasp-10-b-S001-R001-C028-r.fit',\n", | |
" '/Users/mcraig/Downloads/2018-08-22/wasp-10-b-S001-R001-C040-r.fit',\n", | |
" '/Users/mcraig/Downloads/2018-08-22/wasp-10-b-S001-R001-C053-r.fit'\n", | |
"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/Users/mcraig/conda-main/envs/awid-dev/lib/python3.6/site-packages/ginga/AstroImage.py:183: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.\n", | |
" data = self.get_mddata()[view]\n", | |
"WARNING: FITSFixedWarning: RADECSYS= 'FK5 ' \n", | |
"the RADECSYS keyword is deprecated, use RADESYSa. [astropy.wcs.wcs]\n" | |
] | |
}, | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "0ff57f05665e4a238324b947ff8f5760", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"VBox(children=(ToggleButtons(options=(0, 1, 2, 3, 4), style=ToggleButtonsStyle(button_width='10px'), value=0),…" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"toggles = widgets.ToggleButtons(options=range(len(images)),\n", | |
" style=widgets.ToggleButtonsStyle(button_width='10px'))\n", | |
"\n", | |
"iw2 = ImageWidget()\n", | |
"iw2.load_fits(images[0])\n", | |
"\n", | |
"def update_displayed_image(change):\n", | |
" zoom = iw2.zoom_level\n", | |
" center = iw2._viewer.get_pan()\n", | |
" iw2.load_fits(images[change['new']])\n", | |
" iw2.zoom_level = zoom\n", | |
" iw2.center_on(center)\n", | |
" \n", | |
"toggles.observe(update_displayed_image, names='value')\n", | |
"\n", | |
"moops = widgets.VBox(children=[toggles, iw2])\n", | |
"moops" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.12171372930866602" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"iw2.zoom_level" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"gv = iw2._viewer" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(2054.5, 2048.0)" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"gv.get_pan()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "TypeError", | |
"evalue": "load_fits() missing 1 required positional argument: 'filepath'", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-16-60d0d4f8d91c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mgv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload_fits\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m: load_fits() missing 1 required positional argument: 'filepath'" | |
] | |
} | |
], | |
"source": [ | |
"gv.load_fits()" | |
] | |
} | |
], | |
"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": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment