Skip to content

Commit e17a593

Browse files
updating image stamps nb
1 parent 2c3b25e commit e17a593

1 file changed

Lines changed: 82 additions & 66 deletions

File tree

DP1/100_How_to_Use_RSP_Tools/103_Image_access_and_display/103_5_Image_stamps.ipynb

Lines changed: 82 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
"outputs": [],
9595
"source": [
9696
"import matplotlib.pyplot as plt\n",
97+
"import matplotlib.image as mpimg\n",
98+
"\n",
9799
"import math\n",
98100
"import numpy as np\n",
99101
"\n",
@@ -354,10 +356,25 @@
354356
"\n",
355357
" figsize = (figsize_per_plot[0] * n_cols,\n",
356358
" figsize_per_plot[1] * n_rows)\n",
359+
" fig, axes = plt.subplots(\n",
360+
" n_rows,\n",
361+
" n_cols,\n",
362+
" figsize=figsize,\n",
363+
" gridspec_kw={\n",
364+
" \"wspace\": 0,\n",
365+
" \"hspace\": 0})\n",
366+
"\n",
367+
" axes = axes.flatten()\n",
368+
" #fig, axes = plt.subplots(n_rows, n_cols, figsize=figsize)\n",
369+
" #axes = axes.flatten() if n_subplots > 1 else [axes]\n",
357370
"\n",
358-
" fig, axes = plt.subplots(n_rows, n_cols, figsize=figsize)\n",
359-
" axes = axes.flatten() if n_subplots > 1 else [axes]\n",
371+
" for ax in axes:\n",
372+
" ax.axis(\"off\") # ← removes frame, ticks, labels, everything\n",
360373
"\n",
374+
" for ax in axes[n_subplots:]:\n",
375+
" ax.remove()\n",
376+
"\n",
377+
" \n",
361378
" return fig, axes[:n_subplots]"
362379
]
363380
},
@@ -707,37 +724,80 @@
707724
"source": [
708725
"## 3. Bulk image cutouts\n",
709726
"\n",
710-
"Bulk image cutouts will be a key visualization tool for DIA objects. Below, demonstrate how to retrieve (and save), and display many image cutouts."
727+
"Bulk image cutouts will be a key visualization tool for DIA objects. Below, demonstrate how to retrieve many image cutouts (and save as png files)."
711728
]
712729
},
713730
{
714731
"cell_type": "code",
715732
"execution_count": null,
716-
"id": "52fec53e-9f55-4c06-ac54-08005285878b",
733+
"id": "7bf8ad75-a0ef-4546-9020-8fb6cde2c4d5",
717734
"metadata": {},
718735
"outputs": [],
719736
"source": [
720737
"num_visits = len(scitab['t_max'])\n",
721-
"print('number of visits:', num_visits)\n",
738+
"#print('number of visits:', num_visits)\n",
739+
"#for i in range(num_visits):\n",
740+
"# plt.title(f\"MJD {np.round(scitab['t_max'][i], 4)}\")\n",
741+
"\n",
742+
"# dl_result_sci = DatalinkResults.from_result_url(scitab['access_url'][i],\n",
743+
"# session=get_pyvo_auth())\n",
744+
"\n",
745+
"# sci, scihdul = get_cutout(dl_result_sci, ra, dec, get_pyvo_auth(), fov)\n",
746+
"# sci_hdu = scihdul[1]\n",
747+
"# sci_header = scihdul[1].header\n",
748+
"# scidata = scihdul[1].data\n",
749+
"# sciwcs = WCS(scihdul[1].header)\n",
750+
"# reproj_scidata, footprint = reproject_interp((scidata, sciwcs), refwcs)\n",
751+
"\n",
752+
"# plt.imshow(reproj_scidata, origin='lower', vmin=np.nanpercentile(reproj_scidata, 1),\n",
753+
"# vmax=np.nanpercentile(reproj_scidata, 99))\n",
722754
"\n",
723-
"fig, axes = make_subplot_grid(20)\n",
755+
"# figname = os.path.join(tempdir, 'cutout_' + str(i) + '.png')\n",
756+
"# if os.path.isfile(figname):\n",
757+
"# os.remove(figname)\n",
758+
"# plt.savefig(figname)\n"
759+
]
760+
},
761+
{
762+
"cell_type": "markdown",
763+
"id": "357dc241-c5bd-4e58-947c-ce7181c35518",
764+
"metadata": {},
765+
"source": [
766+
"Below, visualize the cutouts that were saved to disk."
767+
]
768+
},
769+
{
770+
"cell_type": "code",
771+
"execution_count": null,
772+
"id": "52fec53e-9f55-4c06-ac54-08005285878b",
773+
"metadata": {},
774+
"outputs": [],
775+
"source": [
776+
"fig, axes = make_subplot_grid(100)\n",
724777
"for i, ax in enumerate(axes):\n",
725778
"\n",
726-
" j = i + 5\n",
727-
" ax.set_title(f\"MJD {np.round(scitab['t_max'][j], 4)}\")\n",
779+
" j = i #+ 5\n",
780+
" figname = os.path.join(tempdir, 'cutout_' + str(j) + '.png')\n",
781+
" img = mpimg.imread(figname)\n",
782+
"\n",
783+
"# 2. Display the image\n",
784+
"# imshow interprets the array as an image\n",
785+
" ax.imshow(img)\n",
786+
"\n",
787+
" #ax.set_title(f\"MJD {np.round(scitab['t_max'][j], 4)}\")\n",
728788
"\n",
729-
" dl_result_sci = DatalinkResults.from_result_url(scitab['access_url'][j],\n",
730-
" session=get_pyvo_auth())\n",
789+
" #dl_result_sci = DatalinkResults.from_result_url(scitab['access_url'][j],\n",
790+
" # session=get_pyvo_auth())\n",
731791
"\n",
732-
" sci, scihdul = get_cutout(dl_result_sci, ra, dec, get_pyvo_auth(), fov)\n",
733-
" sci_hdu = scihdul[1]\n",
734-
" sci_header = scihdul[1].header\n",
735-
" scidata = scihdul[1].data\n",
736-
" sciwcs = WCS(scihdul[1].header)\n",
737-
" reproj_scidata, footprint = reproject_interp((scidata, sciwcs), refwcs)\n",
792+
" #sci, scihdul = get_cutout(dl_result_sci, ra, dec, get_pyvo_auth(), fov)\n",
793+
" #sci_hdu = scihdul[1]\n",
794+
" #sci_header = scihdul[1].header\n",
795+
" #scidata = scihdul[1].data\n",
796+
" #sciwcs = WCS(scihdul[1].header)\n",
797+
" #reproj_scidata, footprint = reproject_interp((scidata, sciwcs), refwcs)\n",
738798
"\n",
739-
" ax.imshow(reproj_scidata, origin='lower', vmin=np.nanpercentile(reproj_scidata, 1),\n",
740-
" vmax=np.nanpercentile(reproj_scidata, 99))\n",
799+
" #ax.imshow(reproj_scidata, origin='lower', vmin=np.nanpercentile(reproj_scidata, 1),\n",
800+
" # vmax=np.nanpercentile(reproj_scidata, 99))\n",
741801
"\n",
742802
" #figname = os.path.join(tempdir, 'cutout_' + str(i) + '.png')\n",
743803
" #if os.path.isfile(figname):\n",
@@ -759,45 +819,13 @@
759819
{
760820
"cell_type": "code",
761821
"execution_count": null,
762-
"id": "96462574-05d0-4827-9c6e-95494307f316",
763-
"metadata": {},
764-
"outputs": [],
765-
"source": [
766-
"import sys\n",
767-
"sys.exit()"
768-
]
769-
},
770-
{
771-
"cell_type": "code",
772-
"execution_count": null,
773-
"id": "7bf8ad75-a0ef-4546-9020-8fb6cde2c4d5",
822+
"id": "0257c6de-2296-4ed2-8173-ac3d74f99e2e",
774823
"metadata": {},
775824
"outputs": [],
776825
"source": [
777-
"for i in range(num_visits):\n",
778-
" j = i #+ 5\n",
779-
" plt.title(f\"MJD {np.round(scitab['t_max'][j], 4)}\")\n",
780-
"\n",
781-
" dl_result_sci = DatalinkResults.from_result_url(scitab['access_url'][j],\n",
782-
" session=get_pyvo_auth())\n",
783-
"\n",
784-
" sci, scihdul = get_cutout(dl_result_sci, ra, dec, get_pyvo_auth(), fov)\n",
785-
" sci_hdu = scihdul[1]\n",
786-
" sci_header = scihdul[1].header\n",
787-
" scidata = scihdul[1].data\n",
788-
" sciwcs = WCS(scihdul[1].header)\n",
789-
" reproj_scidata, footprint = reproject_interp((scidata, sciwcs), refwcs)\n",
790-
"\n",
791-
" plt.imshow(reproj_scidata, origin='lower', vmin=np.nanpercentile(reproj_scidata, 1),\n",
792-
" vmax=np.nanpercentile(reproj_scidata, 99))\n",
793-
"\n",
794-
" figname = os.path.join(tempdir, 'cutout_' + str(i) + '.png')\n",
795-
" if os.path.isfile(figname):\n",
796-
" os.remove(figname)\n",
797-
" plt.savefig(figname)\n",
798-
"\n",
799-
"#plt.tight_layout()\n",
800-
"#plt.show()"
826+
"print(tempdir)\n",
827+
"make_gif(tempdir)\n",
828+
"display(dimg(data=open(tempdir+'/animation.gif', 'rb').read()))"
801829
]
802830
},
803831
{
@@ -831,18 +859,6 @@
831859
"start with an ra/dec and date range where you already know. don't even need to refer to the other notebook\n"
832860
]
833861
},
834-
{
835-
"cell_type": "code",
836-
"execution_count": null,
837-
"id": "0257c6de-2296-4ed2-8173-ac3d74f99e2e",
838-
"metadata": {},
839-
"outputs": [],
840-
"source": [
841-
"print(tempdir)\n",
842-
"make_gif(tempdir)\n",
843-
"display(dimg(data=open(tempdir+'/animation.gif', 'rb').read()))"
844-
]
845-
},
846862
{
847863
"cell_type": "markdown",
848864
"id": "1c07a8b1-f24a-4c03-a56b-515a381cfa42",

0 commit comments

Comments
 (0)