{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# New visualization function tutorial" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import healpy as hp\n", "from healpy.newvisufunc import projview, newprojplot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = hp.read_map(\n", " \"../healpy/test/data/wmap_band_iqumap_r9_7yr_W_v4_udgraded32_masked_smoothed10deg_fortran.fits\"\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# classic healpy mollweide projections plot\n", "# other matplotlib projections are possible, such as: \"aitoff\",\"hammer\",lambert\"\n", "projview(m, coord=[\"G\"], flip=\"astro\", projection_type=\"mollweide\");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# classic healpy mollweide projections plot with graticule\n", "projview(\n", " m, coord=[\"G\"], graticule=True, graticule_labels=True, projection_type=\"mollweide\"\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# classic healpy mollweide projections plot with graticule and axis labels\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"horizontal\",\n", " projection_type=\"mollweide\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# classic healpy mollweide projections plot with graticule and axis labels and vertical color bar\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " projection_type=\"mollweide\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# classic healpy mollweide projections plot with graticule and axis labels and vertical color bar, when min and max is set\n", "# to be different than the min, max of the data, the colorbar is extended\n", "# with title\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=45,\n", " projection_type=\"mollweide\",\n", " title=\"Mollweide projection, astro convention (default)\",\n", ");\n", "newprojplot(theta=np.radians(50), phi=np.radians(60), marker=\"o\", color=\"r\", markersize=10);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# classic healpy mollweide projections plot with graticule and axis labels and vertical color bar, when min and max is set\n", "# to be different than the min, max of the data, the colorbar is extended\n", "# with title, GEO convention for longitude\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=45,\n", " projection_type=\"mollweide\",\n", " title=\"Mollweide projection, geo convention\",\n", " flip=\"geo\",\n", " phi_convention=\"clockwise\"\n", ");\n", "# newprojplot knows about the flip in plotting longitude\n", "newprojplot(theta=np.radians(50), phi=np.radians(60), marker=\"o\", color=\"r\", markersize=10);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# hammer view plot with graticule and axis labels and vertical color bar, when min and max is set\n", "# to be different than the min, max of the data, the colorbar is extended\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=30,\n", " projection_type=\"hammer\",\n", " title=\"Hammer projection\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# aitoff view plot with graticule and axis labels and vertical color bar, when min and max is set\n", "# to be different than the min, max of the data, the colorbar is extended\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=30,\n", " projection_type=\"aitoff\",\n", " title=\"Aitoff projection\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# equivalent to cartview in classic healpy\n", "projview(m, coord=[\"G\"], projection_type=\"cart\");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# equivalent to cartview\n", "projview(m, coord=[\"G\"], projection_type=\"cart\", xlabel=\"xlabel\", ylabel=\"ylabel\");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# cartview, with labels and graticule\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"horizontal\",\n", " projection_type=\"cart\",\n", " title=\"Cart projection\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# cartview, with labels and graticule\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"horizontal\",\n", " projection_type=\"cart\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# cartview, with labels and graticule, vertical cbar\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " projection_type=\"cart\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 3d view\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " hold=False,\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"horizontal\",\n", " projection_type=\"3d\",\n", " title=\"3D projection\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 3d view, vertical cbar\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " hold=False,\n", " graticule=True,\n", " graticule_labels=True,\n", " projection_type=\"3d\",\n", " unit=\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " cmap=\"viridis\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# polar view\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " cb_orientation=\"horizontal\",\n", " projection_type=\"polar\",\n", " title=\"Polar projection\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# polar view, vertical cbar\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"cbar label\",\n", " cb_orientation=\"vertical\",\n", " projection_type=\"polar\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# polar view, override example\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " hold=False,\n", " graticule=True,\n", " graticule_labels=True,\n", " flip=\"astro\",\n", " projection_type=\"polar\",\n", " unit=\"cbar label\",\n", " cb_orientation=\"horizontal\",\n", " override_plot_properties={\n", " \"cbar_shrink\": 0.5,\n", " \"cbar_pad\": 0.02,\n", " \"cbar_label_pad\": -35,\n", " \"figure_width\": 16,\n", " \"figure_size_ratio\": 0.63,\n", " },\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Hammer projection, changed fontsize example & LaTex font test\n", "# and changed color of the axis ticks and graticule\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=r\"cbar label $\\alpha$\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=30,\n", " projection_type=\"hammer\",\n", " title=\"Hammer projection\",\n", " fontsize={\n", " \"xlabel\": 20,\n", " \"ylabel\": 20,\n", " \"xtick_label\": 20,\n", " \"ytick_label\": 20,\n", " \"title\": 20,\n", " \"cbar_label\": 20,\n", " \"cbar_tick_label\": 20,\n", " },\n", " xtick_label_color=\"r\",\n", " ytick_label_color=\"g\",\n", " graticule_color=\"black\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Hammer projection, no x-axis (phi or longitudinal);; no phi tick label shift\n", "# This shows the true xtick labels\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=r\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=30,\n", " projection_type=\"hammer\",\n", " title=\"Hammer projection\",\n", " phi_convention=\"symmetrical\",\n", ");\n", "\n", "# overlay the plot with another data\n", "s = 500\n", "plt.scatter(np.deg2rad(0), np.deg2rad(0), color=\"r\", marker=\"x\", linewidth=10, s=s);\n", "plt.scatter(np.deg2rad(120), np.deg2rad(0), color=\"r\", marker=\"x\", linewidth=10, s=s);\n", "plt.scatter(np.deg2rad(-120), np.deg2rad(0), color=\"r\", marker=\"x\", linewidth=10, s=s);\n", "plt.scatter(np.deg2rad(0), np.deg2rad(60), color=\"r\", marker=\"x\", linewidth=10, s=s);\n", "plt.scatter(np.deg2rad(0), np.deg2rad(-60), color=\"r\", marker=\"x\", linewidth=10, s=s);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Hammer projection, override axis tick labels\n", "projview(\n", " m,\n", " coord=[\"G\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=r\"cbar label\",\n", " xlabel=\"longitude\",\n", " ylabel=\"latitude\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=30,\n", " projection_type=\"hammer\",\n", " title=\"Hammer projection\",\n", " custom_xtick_labels=[\"A\", \"B\", \"C\", \"D\", \"E\"],\n", " custom_ytick_labels=[\"F\", \"G\", \"H\", \"I\", \"J\"],\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Hammer projection, Equatorial coordinates\n", "projview(\n", " m,\n", " coord=[\"G\", \"C\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=r\"cbar label\",\n", " xlabel=\"RA\",\n", " ylabel=\"DEC\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=30,\n", " projection_type=\"hammer\",\n", " title=\"Hammer projection\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Cartesian projection in Local coordinates (transformed from Galaxy coordinates through Equatorial to local);\n", "# (This is a Galaxy radio emission apex at Pierre Auger Observatory);\n", "# azimuth convention with \"phi_convention='counterclockwise'\" is North:0, East:270, South:180, West:90\n", "local_sidereal_time = 18\n", "altitude = -35.206667\n", "rotAngles = [(180 + (local_sidereal_time * 15)) % 360, -(altitude - 90)]\n", "\n", "projview(\n", " m,\n", " coord=[\"G\", \"C\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=r\"cbar label\",\n", " xlabel=\"azimuth\",\n", " ylabel=\"zenith\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=30,\n", " projection_type=\"cart\",\n", " title=\"Cartesian projection\",\n", " rot=rotAngles,\n", " fontsize={\"xtick_label\": 20},\n", " phi_convention=\"counterclockwise\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Cartesian projection in Local coordinates (transformed from Galaxy coordinates through Equatorial to local);\n", "# (This is the Galaxy radio emission apex at Pierre Auger Observatory);\n", "# azimuth convention with \"phi_convention='clockwise'\" is North:0, East:90, South:180, West:270\n", "\n", "local_sidereal_time = 18\n", "altitude = -35.206667\n", "rotAngles = [(180 + (local_sidereal_time * 15)) % 360, -(altitude - 90)]\n", "\n", "projview(\n", " m,\n", " coord=[\"G\", \"C\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=r\"cbar label\",\n", " xlabel=\"azimuth\",\n", " ylabel=\"zenith\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=30,\n", " projection_type=\"cart\",\n", " title=\"Cartesian projection\",\n", " rot=rotAngles,\n", " fontsize={\"xtick_label\": 20},\n", " phi_convention=\"clockwise\",\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Cartesian projection in Local coordinates (transformed from Galaxy coordinates through Equatorial to local);\n", "# (This is the Galaxy radio emission apex at Pierre Auger Observatory);\n", "# azimuth convention with \"phi_convention='symmetrical'\" is North:0, East:90, South:180, West:-90\n", "\n", "local_sidereal_time = 18\n", "altitude = -35.206667\n", "rotAngles = [(180 + (local_sidereal_time * 15)) % 360, -(altitude - 90)]\n", "\n", "projview(\n", " m,\n", " coord=[\"G\", \"C\"],\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=r\"cbar label\",\n", " xlabel=\"azimuth\",\n", " ylabel=\"zenith\",\n", " cb_orientation=\"vertical\",\n", " min=-0.05,\n", " max=0.05,\n", " latitude_grid_spacing=30,\n", " projection_type=\"cart\",\n", " title=\"Cartesian projection\",\n", " rot=rotAngles,\n", " fontsize={\"xtick_label\": 20},\n", " phi_convention=\"symmetrical\",\n", ")\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# return only data\n", "# [longitude, latitude, grid_map]\n", "# longitude, latitude are 1D arrays to convert them, to 2D arrays for the plot use np.meshgrid(longitude, latitude);;\n", "# longtitude goes from, -pi to pi (-180 to 180 in degs);\n", "# latitude goes from, -pi/2 to pi/2 (-90 to 90 in degs);\n", "\n", "longitude, latitude, grid_map = projview(m, coord=[\"G\"], return_only_data=True)\n", "print(longitude.shape)\n", "print(latitude.shape)\n", "print(grid_map.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This example shows two Planck colormaps.\n", "# The planck_log-colormap is used in combination with\n", "# symlog2 for optimal viewing of frequency maps.\n", "#\n", "# Additional displayed features:\n", "# Subfigures (Work the same way as mollview)\n", "# Serif font\n", "# Show tickmarkers\n", "# tick direction keyword\n", "# dipole/monopole subtraction\n", "\n", "m_scaled = m*3000\n", "projview(\n", " m_scaled,\n", " title=\"Planck colormap\",\n", " cmap=\"planck\",\n", " rlabel=r\"A$_{\\mathsf{ex. 1}}$\",\n", " llabel=r\"$Q$\",\n", " unit=r\"$\\mu$K\",\n", " fontname=\"serif\",\n", " width=10,\n", " show_tickmarkers=True,\n", " cbar_ticks=[-300, 0, 300],\n", " cb_orientation=\"vertical\",\n", " sub=121,\n", " override_plot_properties={\"cbar_tick_direction\": \"in\"},\n", ");\n", "projview(\n", " m_scaled,\n", " title=\"Planck logarithmic colormap\",\n", " cmap=\"planck_log\",\n", " norm=\"symlog2\",\n", " rlabel=r\"A$_{\\mathrm{ex. 3}}$\",\n", " llabel=r\"$I$\",\n", " unit=r\"$\\mu$K\",\n", " min=-1e3,\n", " max=1e7,\n", " cb_orientation=\"vertical\",\n", " sub=122,\n", ");\n", "plt.tight_layout();\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This code shows some of the features listed above,\n", "# in addition to the WMAP colormap.\n", "projview(\n", " m_scaled,\n", " title=\"symlog normalization\",\n", " cmap=\"planck\",\n", " norm=\"symlog\",\n", " rlabel=r\"A$_{\\mathsf{ex. 2}}$\",\n", " llabel=r\"$Q$\",\n", " unit=r\"$\\mu$K\",\n", " cbar_ticks=[-3000, -30, 0, 30, 3000],\n", " remove_mono=True,\n", " show_tickmarkers=True,\n", " sub=121,\n", " override_plot_properties={\"cbar_tick_direction\": \"in\"},\n", " norm_dict={\"linscale\": 0.5},\n", ");\n", "\n", "projview(\n", " m_scaled,\n", " title=\"WMAP colormap\",\n", " cmap=\"wmap\",\n", " rlabel=r\"A$_{\\mathrm{ex. 4}}$\",\n", " llabel=r\"$I$\",\n", " unit=r\"$\\mu$K\",\n", " fontname=\"serif\",\n", " min=-100,\n", " max=100,\n", " sub=122,\n", ");\n", "plt.tight_layout();" ] } ], "metadata": { "interpreter": { "hash": "32233c9ad1b8cc06596fadf6fc9dfa9ff57bec18038c8f5f96d77bc014166f96" }, "kernelspec": { "display_name": "Python 3.8.10 ('local')", "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.11" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }