|
94 | 94 | "outputs": [], |
95 | 95 | "source": [ |
96 | 96 | "import matplotlib.pyplot as plt\n", |
| 97 | + "import matplotlib.image as mpimg\n", |
| 98 | + "\n", |
97 | 99 | "import math\n", |
98 | 100 | "import numpy as np\n", |
99 | 101 | "\n", |
|
354 | 356 | "\n", |
355 | 357 | " figsize = (figsize_per_plot[0] * n_cols,\n", |
356 | 358 | " 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", |
357 | 370 | "\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", |
360 | 373 | "\n", |
| 374 | + " for ax in axes[n_subplots:]:\n", |
| 375 | + " ax.remove()\n", |
| 376 | + "\n", |
| 377 | + " \n", |
361 | 378 | " return fig, axes[:n_subplots]" |
362 | 379 | ] |
363 | 380 | }, |
|
707 | 724 | "source": [ |
708 | 725 | "## 3. Bulk image cutouts\n", |
709 | 726 | "\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)." |
711 | 728 | ] |
712 | 729 | }, |
713 | 730 | { |
714 | 731 | "cell_type": "code", |
715 | 732 | "execution_count": null, |
716 | | - "id": "52fec53e-9f55-4c06-ac54-08005285878b", |
| 733 | + "id": "7bf8ad75-a0ef-4546-9020-8fb6cde2c4d5", |
717 | 734 | "metadata": {}, |
718 | 735 | "outputs": [], |
719 | 736 | "source": [ |
720 | 737 | "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", |
722 | 754 | "\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", |
724 | 777 | "for i, ax in enumerate(axes):\n", |
725 | 778 | "\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", |
728 | 788 | "\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", |
731 | 791 | "\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", |
738 | 798 | "\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", |
741 | 801 | "\n", |
742 | 802 | " #figname = os.path.join(tempdir, 'cutout_' + str(i) + '.png')\n", |
743 | 803 | " #if os.path.isfile(figname):\n", |
|
759 | 819 | { |
760 | 820 | "cell_type": "code", |
761 | 821 | "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", |
774 | 823 | "metadata": {}, |
775 | 824 | "outputs": [], |
776 | 825 | "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()))" |
801 | 829 | ] |
802 | 830 | }, |
803 | 831 | { |
|
831 | 859 | "start with an ra/dec and date range where you already know. don't even need to refer to the other notebook\n" |
832 | 860 | ] |
833 | 861 | }, |
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 | | - }, |
846 | 862 | { |
847 | 863 | "cell_type": "markdown", |
848 | 864 | "id": "1c07a8b1-f24a-4c03-a56b-515a381cfa42", |
|
0 commit comments