diff --git a/docs/user-guide/remapping.ipynb b/docs/user-guide/remapping.ipynb index 76e16a802..423af41c3 100644 --- a/docs/user-guide/remapping.ipynb +++ b/docs/user-guide/remapping.ipynb @@ -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", ")" ] }, @@ -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\")" ] }, { @@ -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)" ] @@ -258,11 +285,22 @@ "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", @@ -270,6 +308,7 @@ " **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)" @@ -319,11 +358,22 @@ "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", @@ -331,6 +381,7 @@ " **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)" @@ -415,11 +466,22 @@ "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", @@ -427,6 +489,7 @@ " **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)" @@ -468,13 +531,22 @@ "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", @@ -482,6 +554,7 @@ " **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)" @@ -527,7 +600,11 @@ "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", @@ -535,6 +612,7 @@ " **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)" @@ -572,7 +650,11 @@ "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", @@ -580,6 +662,7 @@ " **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)" @@ -612,7 +695,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.4" } }, "nbformat": 4, diff --git a/uxarray/__init__.py b/uxarray/__init__.py index d15b38075..f00f06099 100644 --- a/uxarray/__init__.py +++ b/uxarray/__init__.py @@ -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 @@ -47,6 +47,10 @@ def disable_fma(): "INT_DTYPE", "INT_FILL_VALUE", "Grid", + "sequential", + "diverging", + "sequential_blue", + "sequential_green", "enable_fma", "disable_fma", ) diff --git a/uxarray/cmaps.py b/uxarray/cmaps.py new file mode 100644 index 000000000..3ab9217d7 --- /dev/null +++ b/uxarray/cmaps.py @@ -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)), + ), +)