Skip to content

Commit

Permalink
UXarray Themed Colormaps (#873)
Browse files Browse the repository at this point in the history
* Added color maps

* Updated colors

* Updated cmaps.py

* Updated __init__.py

* Update Remapping Notebook

* Update __init__.py

* Updated and added colormaps

* Updated colors

* Update cmaps.py

* Update remapping.ipynb

* Update remapping.ipynb

* Added plot names and edges

---------

Co-authored-by: Philip Chmielowiec <[email protected]>
  • Loading branch information
aaronzedwick and philipc2 authored Aug 23, 2024
1 parent 1c07b70 commit 38ae001
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 21 deletions.
123 changes: 103 additions & 20 deletions docs/user-guide/remapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,21 @@
"grid = ux.open_grid(destination_grid)\n",
"uxds = ux.open_dataset(grid_path, data_path)\n",
"(\n",
" uxds[\"t2m\"].plot(fig_size=150, colorbar=False, cmap=\"inferno\", backend=\"matplotlib\")\n",
" + grid.plot(fig_size=150, colorbar=False, cmap=\"inferno\", backend=\"matplotlib\")\n",
" uxds[\"t2m\"].plot(\n",
" fig_size=150,\n",
" colorbar=False,\n",
" cmap=ux.cmaps.sequential_green_blue,\n",
" backend=\"matplotlib\",\n",
" title=\"Mesh with Data\",\n",
" )\n",
" * uxds.uxgrid.plot.mesh(backend=\"matplotlib\", color=\"black\")\n",
" + grid.plot(\n",
" fig_size=150,\n",
" colorbar=False,\n",
" cmap=ux.cmaps.sequential_green_blue,\n",
" backend=\"matplotlib\",\n",
" title=\"Mesh without Data\",\n",
" )\n",
")"
]
},
Expand All @@ -102,7 +115,13 @@
"metadata": {},
"outputs": [],
"source": [
"remapped_grid.plot(fig_size=150, colorbar=False, cmap=\"inferno\", backend=\"matplotlib\")"
"remapped_grid.plot(\n",
" fig_size=150,\n",
" colorbar=True,\n",
" cmap=ux.cmaps.sequential_green_blue,\n",
" backend=\"matplotlib\",\n",
" title=\"Mesh With Remapped Data\",\n",
") * remapped_grid.uxgrid.plot.mesh(backend=\"matplotlib\", color=\"black\")"
]
},
{
Expand Down Expand Up @@ -170,9 +189,17 @@
"outputs": [],
"source": [
"(\n",
" uxds_480[\"bottomDepth\"].plot(title=\"Bottom Depth (480km)\", backend=\"matplotlib\")\n",
" uxds_480[\"bottomDepth\"].plot(\n",
" title=\"Bottom Depth (480km)\",\n",
" backend=\"matplotlib\",\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + uxds_120[\"bottomDepth\"].plot(title=\"Bottom Depth (120km)\", backend=\"matplotlib\")\n",
" + uxds_120[\"bottomDepth\"].plot(\n",
" title=\"Bottom Depth (120km)\",\n",
" backend=\"matplotlib\",\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
").opts(fig_size=300).cols(1)"
]
Expand Down Expand Up @@ -258,18 +285,30 @@
"outputs": [],
"source": [
"(\n",
" uxds_480[\"bottomDepth\"].plot(title=\"Bottom Depth (480km)\", **plot_kwargs) * features\n",
" + upsampling.plot(title=\"Remapped Bottom Depth (480km to 120km)\", **plot_kwargs)\n",
" uxds_480[\"bottomDepth\"].plot(\n",
" title=\"Bottom Depth (480km)\", **plot_kwargs, cmap=ux.cmaps.sequential_blue\n",
" )\n",
" * features\n",
" + upsampling.plot(\n",
" title=\"Remapped Bottom Depth (480km to 120km)\",\n",
" **plot_kwargs,\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + uxds_480[\"bottomDepth\"].plot(\n",
" title=\"Zoomed (480km)\", **plot_kwargs, xlim=(-10, 10), ylim=(-5, 5)\n",
" title=\"Zoomed (480km)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + upsampling.plot(\n",
" title=\"Zoomed Remap (480km to 120km)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
").opts(fig_size=300).cols(1)"
Expand Down Expand Up @@ -319,18 +358,30 @@
"outputs": [],
"source": [
"(\n",
" uxds_120[\"bottomDepth\"].plot(title=\"Bottom Depth (120km)\", **plot_kwargs) * features\n",
" + downsampling.plot(title=\"Remapped Bottom Depth (120km to 480km)\", **plot_kwargs)\n",
" uxds_120[\"bottomDepth\"].plot(\n",
" title=\"Bottom Depth (120km)\", **plot_kwargs, cmap=ux.cmaps.sequential_blue\n",
" )\n",
" * features\n",
" + downsampling.plot(\n",
" title=\"Remapped Bottom Depth (120km to 480km)\",\n",
" **plot_kwargs,\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + uxds_120[\"bottomDepth\"].plot(\n",
" title=\"Zoomed (120km)\", **plot_kwargs, xlim=(-10, 10), ylim=(-5, 5)\n",
" title=\"Zoomed (120km)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + downsampling.plot(\n",
" title=\"Zoomed Remap (120km to 480km)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
").opts(fig_size=300).cols(1)"
Expand Down Expand Up @@ -415,18 +466,30 @@
"outputs": [],
"source": [
"(\n",
" uxds_480[\"bottomDepth\"].plot(title=\"Bottom Depth (480km)\", **plot_kwargs) * features\n",
" + upsampling_idw.plot(title=\"Remapped Bottom Depth (480km to 120km)\", **plot_kwargs)\n",
" uxds_480[\"bottomDepth\"].plot(\n",
" title=\"Bottom Depth (480km)\", **plot_kwargs, cmap=ux.cmaps.sequential_blue\n",
" )\n",
" * features\n",
" + upsampling_idw.plot(\n",
" title=\"Remapped Bottom Depth (480km to 120km)\",\n",
" **plot_kwargs,\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + uxds_480[\"bottomDepth\"].plot(\n",
" title=\"Zoomed (480km)\", **plot_kwargs, xlim=(-10, 10), ylim=(-5, 5)\n",
" title=\"Zoomed (480km)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + upsampling_idw.plot(\n",
" title=\"Zoomed Remap (480km to 120km)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
").opts(fig_size=300).cols(1)"
Expand Down Expand Up @@ -468,20 +531,30 @@
"outputs": [],
"source": [
"(\n",
" uxds_120[\"bottomDepth\"].plot(title=\"Bottom Depth (120km)\", **plot_kwargs) * features\n",
" uxds_120[\"bottomDepth\"].plot(\n",
" title=\"Bottom Depth (120km)\", **plot_kwargs, cmap=ux.cmaps.sequential_blue\n",
" )\n",
" * features\n",
" + downsampling_idw.plot(\n",
" title=\"Remapped Bottom Depth (120km to 480km)\", **plot_kwargs\n",
" title=\"Remapped Bottom Depth (120km to 480km)\",\n",
" **plot_kwargs,\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + uxds_120[\"bottomDepth\"].plot(\n",
" title=\"Zoomed (120km)\", **plot_kwargs, xlim=(-10, 10), ylim=(-5, 5)\n",
" title=\"Zoomed (120km)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + downsampling_idw.plot(\n",
" title=\"Zoomed Remap (120km to 480km)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
").opts(fig_size=300).cols(1)"
Expand Down Expand Up @@ -527,14 +600,19 @@
"source": [
"(\n",
" downsampling_idw_low.plot(\n",
" title=\"Zoomed 480km (power=1, k=2)\", **plot_kwargs, xlim=(-10, 10), ylim=(-5, 5)\n",
" title=\"Zoomed 480km (power=1, k=2)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + downsampling_idw_high.plot(\n",
" title=\"Zoomed 480km (power=5, k=128)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
").opts(fig_size=300).cols(1)"
Expand Down Expand Up @@ -572,14 +650,19 @@
"source": [
"(\n",
" upsampling_idw_low.plot(\n",
" title=\"Zoomed 120km (power=1, k=2)\", **plot_kwargs, xlim=(-10, 10), ylim=(-5, 5)\n",
" title=\"Zoomed 120km (power=1, k=2)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
" + upsampling_idw_high.plot(\n",
" title=\"Zoomed 120km (power=5, k=128)\",\n",
" **plot_kwargs,\n",
" xlim=(-10, 10),\n",
" ylim=(-5, 5),\n",
" cmap=ux.cmaps.sequential_blue,\n",
" )\n",
" * features\n",
").opts(fig_size=300).cols(1)"
Expand Down Expand Up @@ -612,7 +695,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
6 changes: 5 additions & 1 deletion uxarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .grid import Grid

from .constants import INT_DTYPE, INT_FILL_VALUE

from .cmaps import sequential, diverging, sequential_blue, sequential_green

try:
from importlib.metadata import version as _version
Expand Down Expand Up @@ -47,6 +47,10 @@ def disable_fma():
"INT_DTYPE",
"INT_FILL_VALUE",
"Grid",
"sequential",
"diverging",
"sequential_blue",
"sequential_green",
"enable_fma",
"disable_fma",
)
33 changes: 33 additions & 0 deletions uxarray/cmaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from matplotlib.colors import LinearSegmentedColormap


diverging = LinearSegmentedColormap.from_list(
"diverging",
(
(0.000, (0.016, 0.576, 0.565)),
(0.500, (1.000, 1.000, 1.000)),
(1.000, (0.004, 0.400, 0.569)),
),
)

# UXarray themed sequential color map
sequential = LinearSegmentedColormap.from_list(
"sequential", ((0.000, (0.004, 0.400, 0.569)), (1.000, (0.016, 0.576, 0.565)))
)

sequential_blue = LinearSegmentedColormap.from_list(
"sequential_blue", ((0.000, (1.000, 1.000, 1.000)), (1.000, (0.004, 0.400, 0.569)))
)

sequential_green = LinearSegmentedColormap.from_list(
"sequential_green", ((0.000, (1.000, 1.000, 1.000)), (1.000, (0.016, 0.576, 0.565)))
)

sequential_green_blue = LinearSegmentedColormap.from_list(
"sequential_green_blue",
(
(0.000, (1.000, 1.000, 1.000)),
(0.500, (0.016, 0.576, 0.565)),
(1.000, (0.004, 0.400, 0.569)),
),
)

0 comments on commit 38ae001

Please sign in to comment.