From ea9e659455558e2c763e651129dd520841d8b27a Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Mon, 22 Nov 2021 22:28:47 +0100 Subject: [PATCH 1/2] fix quality of LIC figures by decreasing resolution in docs --- docs/plotting.ipynb | 60 +++++++++++++++++++++---------------- src/osyris/plot/wrappers.py | 9 ++++-- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/docs/plotting.ipynb b/docs/plotting.ipynb index c113575d..1c80da7f 100644 --- a/docs/plotting.ipynb +++ b/docs/plotting.ipynb @@ -63,7 +63,8 @@ "osyris.histogram2d(\n", " data[\"hydro\"][\"density\"], data[\"hydro\"][\"B_field\"],\n", " {\"data\": data[\"hydro\"][\"mass\"], \"norm\": \"log\"}, # layer 1\n", - " {\"data\": data[\"amr\"][\"level\"], \"operation\": \"mean\", \"mode\": \"contour\", \"colors\": \"k\"}, # layer 2\n", + " {\"data\": data[\"amr\"][\"level\"], \"operation\": \"mean\",\n", + " \"mode\": \"contour\", \"colors\": \"k\"}, # layer 2\n", " loglog=True)" ] }, @@ -215,10 +216,7 @@ "outputs": [], "source": [ "# Create figure\n", - "fig = plt.figure(figsize=(10, 3.5))\n", - "ax1 = fig.add_subplot(121)\n", - "ax2 = fig.add_subplot(122)\n", - "plt.subplots_adjust(wspace=0.5)\n", + "fig, ax = plt.subplots(1, 2, figsize=(12, 4.5))\n", "\n", "# Define region to plot\n", "dx = 2000.0 * osyris.units(\"au\")\n", @@ -235,16 +233,13 @@ " \"linestyles\": [\"solid\",\"dashed\",\"solid\"],\n", " \"cmap\": None,\n", " \"labels\": False},\n", - " dx=dx,\n", - " origin=center,\n", - " direction=\"z\", ax=ax1)\n", + " dx=dx, origin=center, direction=\"z\", ax=ax[0])\n", "\n", "osyris.plane({\"data\": data[\"hydro\"][\"temperature\"], \"norm\": \"log\", \"mode\": \"contourf\",\n", - " \"levels\": np.logspace(0.9, 2, 21), \"cmap\": \"hot\"},\n", - " {\"data\": data[\"amr\"][\"level\"], \"mode\": \"contour\", \"colors\": \"w\", \"levels\": [6, 7, 8]},\n", - " dx=dx,\n", - " origin=center,\n", - " direction=\"z\", ax=ax2)" + " \"levels\": np.logspace(0.9, 2, 11), \"cmap\": \"hot\"},\n", + " {\"data\": data[\"amr\"][\"level\"], \"mode\": \"contour\", \"colors\": \"w\",\n", + " \"levels\": [6, 7, 8]},\n", + " dx=dx, origin=center, direction=\"z\", ax=ax[1])" ] }, { @@ -506,7 +501,9 @@ "source": [ "## Line integral convolution vector field visualizations\n", "\n", - "Osyris now supports line integral convolution (LIC) visualizations of vector fields. This visualization method, although computationally intensive, offers an excellent representation of the vector field (especially near discontinuities) provided we have enough resolution.\n", + "Osyris now supports line integral convolution (LIC) visualizations of vector fields.\n", + "This visualization method, although computationally intensive,\n", + "offers an excellent representation of the vector field (especially near discontinuities).\n", "\n", "**Note:** This feature requires the [lic](https://pypi.org/project/lic/) package to be installed.\n", "\n", @@ -520,16 +517,20 @@ "outputs": [], "source": [ "osyris.plane({\"data\": data[\"hydro\"][\"velocity\"], \"mode\": \"lic\"},\n", - " dx=2000 * osyris.units(\"au\"),\n", - " origin=center,\n", - " direction=\"z\", resolution=1000)" + " dx=2000 * osyris.units(\"au\"), direction=\"z\",\n", + " origin=center, cmap=\"binary\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The LIC can be colored by a scalar field using the `color` keyword, and the length of the lines of the LIC can also be modified using the `length` keyword (whose default value is 30):" + "The LIC can be colored by a scalar field using the `color` keyword,\n", + "and the length of the lines of the LIC can also be modified using the `length` keyword.\n", + "\n", + "In the following example,\n", + "we use the colors to show the gas density overlayed onto the velocity flow structure on the left,\n", + "while on the right we use the colors to recover some information on the magnitude of the velocities." ] }, { @@ -538,19 +539,26 @@ "metadata": {}, "outputs": [], "source": [ + "fig, ax = plt.subplots(1, 2, figsize=(12, 4))\n", + "\n", + "dx = 2000 * osyris.units(\"au\")\n", + "\n", "osyris.plane({\"data\": data[\"hydro\"][\"velocity\"], \"mode\": \"lic\",\n", - " \"color\": data[\"hydro\"][\"density\"], \"norm\": \"log\", \"length\":30},\n", - " dx=2000 * osyris.units(\"au\"),\n", - " origin=center,\n", - " direction=\"z\", resolution=1000)" + " \"color\": data[\"hydro\"][\"density\"], \"norm\": \"log\",\n", + " \"length\":60}, ax=ax[0],\n", + " dx=dx, origin=center, direction=\"z\")\n", + "osyris.plane({\"data\": data[\"hydro\"][\"velocity\"], \"mode\": \"lic\",\n", + " \"color\": data[\"hydro\"][\"velocity\"], \"norm\": \"linear\",\n", + " \"length\":60, \"cmap\": \"plasma\"}, ax=ax[1],\n", + " dx=dx, origin=center, direction=\"z\")" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, - "source": [ - "Overlaying this plot with velocity arrows allows us to retrieve some information on the magnitude of the vector field." - ] + "outputs": [], + "source": [] } ], "metadata": { diff --git a/src/osyris/plot/wrappers.py b/src/osyris/plot/wrappers.py index 3cc9ba4d..234ad2e4 100644 --- a/src/osyris/plot/wrappers.py +++ b/src/osyris/plot/wrappers.py @@ -2,6 +2,8 @@ # Copyright (c) 2021 Osyris contributors (https://github.com/nvaytet/osyris) from .. import config from ..core import Array +from contextlib import redirect_stderr +import io import matplotlib.pyplot as plt from matplotlib.cm import ScalarMappable from matplotlib.collections import PatchCollection @@ -175,7 +177,7 @@ def line_integral_convolution(ax, z, cbar=False, cblabel=None, - length=30, + length=None, color=None, **kwargs): """ @@ -185,7 +187,10 @@ def line_integral_convolution(ax, from lic import lic # Compute line integral convolution - lic_res = lic(z[..., 1], z[..., 0], length=length) + if length is None: + length = int(max(z.shape[:-1]) * 15 / 128) + with redirect_stderr(io.StringIO()) as _: + lic_res = lic(z[..., 1], z[..., 0], length=length) if color is not None: plot_args = {**kwargs} From 76ede3ad1b1d356ba994faf73b37b0c3433214a6 Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Mon, 22 Nov 2021 22:29:12 +0100 Subject: [PATCH 2/2] bump version --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 9925f828..b3a9b5a6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = osyris -version = 2.3.1 +version = 2.3.2 author = Neil Vaytet author_email = neil.vaytet@esss.se description = A package to visualize AMR data from the RAMSES code