Skip to content

Commit

Permalink
STY: Precommit notebook.
Browse files Browse the repository at this point in the history
  • Loading branch information
zssherman committed Jan 22, 2025
1 parent c615639 commit 727ad78
Showing 1 changed file with 28 additions and 66 deletions.
94 changes: 28 additions & 66 deletions docs/source/blog_posts/2024/2024_colormaps_cvd_lens.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -120,65 +120,43 @@
"# Plot reflectivity using pyart for NWS Ref\n",
"display = pyart.graph.RadarMapDisplay(radar)\n",
"display.plot_ppi_map(\n",
" 'reflectivity',\n",
" vmin=-10,\n",
" title_flag=False,\n",
" vmax=60,\n",
" ax=ax,\n",
" cmap='pyart_NWSRef'\n",
" 'reflectivity', vmin=-10, title_flag=False, vmax=60, ax=ax, cmap='pyart_NWSRef'\n",
")\n",
"ax.axis('off')\n",
"fig.canvas.draw() # draw the canvas, cache the renderer\n",
"fig.canvas.draw() # draw the canvas, cache the renderer\n",
"\n",
"# Create an image from the plot.\n",
"image_from_plot_nws = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)\n",
"image_from_plot_nws = image_from_plot_nws.reshape(fig.canvas.get_width_height()[::-1] + (3,))\n",
"image_from_plot_nws = image_from_plot_nws / 255.\n",
"image_from_plot_nws = image_from_plot_nws / 255.0\n",
"\n",
"# Sample image for non-CVD RGB for ChaseSpectral\n",
"fig = plt.figure()\n",
"ax = fig.gca()\n",
"# Plot reflectivity using pyart for ChaseSpectral\n",
"display = pyart.graph.RadarMapDisplay(radar)\n",
"display.plot_ppi_map(\n",
" 'reflectivity',\n",
" vmin=-10,\n",
" title_flag=False,\n",
" vmax=60,\n",
" ax=ax,\n",
" cmap='pyart_ChaseSpectral'\n",
" 'reflectivity', vmin=-10, title_flag=False, vmax=60, ax=ax, cmap='pyart_ChaseSpectral'\n",
")\n",
"ax.axis('off')\n",
"fig.canvas.draw() # draw the canvas, cache the renderer\n",
"fig.canvas.draw() # draw the canvas, cache the renderer\n",
"\n",
"# Create an image from the plot.\n",
"image_from_plot_chase = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)\n",
"image_from_plot_chase = image_from_plot_chase.reshape(fig.canvas.get_width_height()[::-1] + (3,))\n",
"image_from_plot_chase = image_from_plot_chase / 255.\n",
"image_from_plot_chase = image_from_plot_chase / 255.0\n",
"\n",
"# Convert both NWS Ref and ChaseSpectral images to Deuteranopia\n",
"cvd_space_d = {\n",
" \"name\": \"sRGB1+CVD\",\n",
" \"cvd_type\": \"deuteranomaly\",\n",
" \"severity\": 100\n",
"}\n",
"cvd_space_d = {\"name\": \"sRGB1+CVD\", \"cvd_type\": \"deuteranomaly\", \"severity\": 100}\n",
"img_d_nws = cspace_convert(image_from_plot_nws, cvd_space_d, \"sRGB1\")\n",
"img_d_chase = cspace_convert(image_from_plot_chase, cvd_space_d, \"sRGB1\")\n",
"\n",
"# Convert both NWS Ref and ChaseSpectral images to Protanopia\n",
"cvd_space_p = {\n",
" \"name\": \"sRGB1+CVD\",\n",
" \"cvd_type\": \"protanomaly\",\n",
" \"severity\": 100\n",
"}\n",
"cvd_space_p = {\"name\": \"sRGB1+CVD\", \"cvd_type\": \"protanomaly\", \"severity\": 100}\n",
"img_p_nws = cspace_convert(image_from_plot_nws, cvd_space_p, \"sRGB1\")\n",
"\n",
"# Protanopia\n",
"cvd_space = {\n",
" \"name\": \"sRGB1+CVD\",\n",
" \"cvd_type\": \"protanomaly\",\n",
" \"severity\": 100\n",
"}\n",
"cvd_space = {\"name\": \"sRGB1+CVD\", \"cvd_type\": \"protanomaly\", \"severity\": 100}\n",
"img_p_chase = cspace_convert(image_from_plot_chase, cvd_space_p, \"sRGB1\")"
]
},
Expand Down Expand Up @@ -214,39 +192,34 @@
"source": [
"# Overall Figure with both original plots as well as the deuteranopia and protanopia images\n",
"fig, axes = plt.subplot_mosaic(\n",
" [\n",
" ['ref', 'chase'],\n",
" ['d_nws', 'd_chase'],\n",
" ['p_nws', 'p_chase']\n",
" ],\n",
" figsize=(10, 10)\n",
" [['ref', 'chase'], ['d_nws', 'd_chase'], ['p_nws', 'p_chase']], figsize=(10, 10)\n",
")\n",
"\n",
"axes['ref'].imshow(image_from_plot_nws)\n",
"axes['ref'].axis('off')\n",
"axes['ref'].set_title(\"NWS Ref\", pad=-.5)\n",
"axes['ref'].set_title(\"NWS Ref\", pad=-0.5)\n",
"\n",
"axes['chase'].imshow(image_from_plot_chase)\n",
"axes['chase'].axis('off')\n",
"axes['chase'].set_title(\"Chase Spectral\", pad=-.5)\n",
"axes['chase'].set_title(\"Chase Spectral\", pad=-0.5)\n",
"\n",
"axes['d_nws'].imshow(img_d_nws)\n",
"axes['d_nws'].axis('off')\n",
"axes['d_nws'].set_title(\"Deuteranopia NWS\", pad=-.5)\n",
"axes['d_nws'].set_title(\"Deuteranopia NWS\", pad=-0.5)\n",
"\n",
"# Plot ChaseSpectral for deuteranopia\n",
"axes['d_chase'].imshow(img_d_chase)\n",
"axes['d_chase'].axis('off')\n",
"axes['d_chase'].set_title(\"Deuteranopia Chase Spectral\", pad=-.5)\n",
"axes['d_chase'].set_title(\"Deuteranopia Chase Spectral\", pad=-0.5)\n",
"\n",
"# Plot ChaseSpectral for deuteranopia\n",
"axes['p_nws'].imshow(img_p_nws)\n",
"axes['p_nws'].axis('off')\n",
"axes['p_nws'].set_title(\"Protanopia NWS\", pad=-.5)\n",
"axes['p_nws'].set_title(\"Protanopia NWS\", pad=-0.5)\n",
"\n",
"axes['p_chase'].imshow(img_p_chase)\n",
"axes['p_chase'].axis('off')\n",
"axes['p_chase'].set_title(\"Protanopia Chase Spectral\", pad=-.5)\n",
"axes['p_chase'].set_title(\"Protanopia Chase Spectral\", pad=-0.5)\n",
"\n",
"plt.tight_layout()\n",
"plt.show()"
Expand Down Expand Up @@ -317,15 +290,15 @@
" vmax=nyq,\n",
" ax=ax,\n",
" cmap='pyart_NWSVel',\n",
" colorbar_label=r'velocity m s$_{-1}$'\n",
" colorbar_label=r'velocity m s$_{-1}$',\n",
")\n",
"ax.axis('off')\n",
"fig.canvas.draw() # draw the canvas, cache the renderer\n",
"fig.canvas.draw() # draw the canvas, cache the renderer\n",
"\n",
"# Create an image from the plot.\n",
"image_from_plot_nws = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)\n",
"image_from_plot_nws = image_from_plot_nws.reshape(fig.canvas.get_width_height()[::-1] + (3,))\n",
"image_from_plot_nws = image_from_plot_nws / 255.\n",
"image_from_plot_nws = image_from_plot_nws / 255.0\n",
"\n",
"# Sample image for non-CVD RGB for cmocean balance\n",
"fig = plt.figure()\n",
Expand All @@ -341,31 +314,25 @@
" title_flag=False,\n",
" ax=ax,\n",
" cmap='pyart_balance',\n",
" colorbar_label=r'velocity m s$_{-1}$'\n",
" colorbar_label=r'velocity m s$_{-1}$',\n",
")\n",
"ax.axis('off')\n",
"fig.canvas.draw() # draw the canvas, cache the renderer\n",
"fig.canvas.draw() # draw the canvas, cache the renderer\n",
"\n",
"# Create an image from the plot.\n",
"image_from_plot_cmocean = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)\n",
"image_from_plot_cmocean = image_from_plot_cmocean.reshape(fig.canvas.get_width_height()[::-1] + (3,))\n",
"image_from_plot_cmocean = image_from_plot_cmocean / 255.\n",
"image_from_plot_cmocean = image_from_plot_cmocean.reshape(\n",
" fig.canvas.get_width_height()[::-1] + (3,)\n",
")\n",
"image_from_plot_cmocean = image_from_plot_cmocean / 255.0\n",
"\n",
"# Convert both NWS Vel and cmocean balance images to deuteranopia\n",
"cvd_space_d = {\n",
" \"name\": \"sRGB1+CVD\",\n",
" \"cvd_type\": \"deuteranomaly\",\n",
" \"severity\": 100\n",
"}\n",
"cvd_space_d = {\"name\": \"sRGB1+CVD\", \"cvd_type\": \"deuteranomaly\", \"severity\": 100}\n",
"img_d_nws = cspace_convert(image_from_plot_nws, cvd_space_d, \"sRGB1\")\n",
"img_d_cmocean = cspace_convert(image_from_plot_cmocean, cvd_space_d, \"sRGB1\")\n",
"\n",
"# Convert both NWS Vel and cmocean balance images to protanopia\n",
"cvd_space_p = {\n",
" \"name\": \"sRGB1+CVD\",\n",
" \"cvd_type\": \"protanomaly\",\n",
" \"severity\": 100\n",
"}\n",
"cvd_space_p = {\"name\": \"sRGB1+CVD\", \"cvd_type\": \"protanomaly\", \"severity\": 100}\n",
"img_p_nws = cspace_convert(image_from_plot_nws, cvd_space_p, \"sRGB1\")\n",
"img_p_cmocean = cspace_convert(image_from_plot_cmocean, cvd_space_p, \"sRGB1\")"
]
Expand Down Expand Up @@ -402,12 +369,7 @@
"source": [
"# Overall Figure\n",
"fig, axes = plt.subplot_mosaic(\n",
" [\n",
" ['vel', 'cmocean'],\n",
" ['d_nws', 'd_cmocean'],\n",
" ['p_nws', 'p_cmocean']\n",
" ],\n",
" figsize=(10, 10)\n",
" [['vel', 'cmocean'], ['d_nws', 'd_cmocean'], ['p_nws', 'p_cmocean']], figsize=(10, 10)\n",
")\n",
"\n",
"\n",
Expand Down

0 comments on commit 727ad78

Please sign in to comment.