Skip to content

Commit f720feb

Browse files
authored
Merge pull request #43 from nvaytet/lic_tweaks
Lic tweaks
2 parents ac892c2 + 76ede3a commit f720feb

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

docs/plotting.ipynb

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"osyris.histogram2d(\n",
6464
" data[\"hydro\"][\"density\"], data[\"hydro\"][\"B_field\"],\n",
6565
" {\"data\": data[\"hydro\"][\"mass\"], \"norm\": \"log\"}, # layer 1\n",
66-
" {\"data\": data[\"amr\"][\"level\"], \"operation\": \"mean\", \"mode\": \"contour\", \"colors\": \"k\"}, # layer 2\n",
66+
" {\"data\": data[\"amr\"][\"level\"], \"operation\": \"mean\",\n",
67+
" \"mode\": \"contour\", \"colors\": \"k\"}, # layer 2\n",
6768
" loglog=True)"
6869
]
6970
},
@@ -215,10 +216,7 @@
215216
"outputs": [],
216217
"source": [
217218
"# Create figure\n",
218-
"fig = plt.figure(figsize=(10, 3.5))\n",
219-
"ax1 = fig.add_subplot(121)\n",
220-
"ax2 = fig.add_subplot(122)\n",
221-
"plt.subplots_adjust(wspace=0.5)\n",
219+
"fig, ax = plt.subplots(1, 2, figsize=(12, 4.5))\n",
222220
"\n",
223221
"# Define region to plot\n",
224222
"dx = 2000.0 * osyris.units(\"au\")\n",
@@ -235,16 +233,13 @@
235233
" \"linestyles\": [\"solid\",\"dashed\",\"solid\"],\n",
236234
" \"cmap\": None,\n",
237235
" \"labels\": False},\n",
238-
" dx=dx,\n",
239-
" origin=center,\n",
240-
" direction=\"z\", ax=ax1)\n",
236+
" dx=dx, origin=center, direction=\"z\", ax=ax[0])\n",
241237
"\n",
242238
"osyris.plane({\"data\": data[\"hydro\"][\"temperature\"], \"norm\": \"log\", \"mode\": \"contourf\",\n",
243-
" \"levels\": np.logspace(0.9, 2, 21), \"cmap\": \"hot\"},\n",
244-
" {\"data\": data[\"amr\"][\"level\"], \"mode\": \"contour\", \"colors\": \"w\", \"levels\": [6, 7, 8]},\n",
245-
" dx=dx,\n",
246-
" origin=center,\n",
247-
" direction=\"z\", ax=ax2)"
239+
" \"levels\": np.logspace(0.9, 2, 11), \"cmap\": \"hot\"},\n",
240+
" {\"data\": data[\"amr\"][\"level\"], \"mode\": \"contour\", \"colors\": \"w\",\n",
241+
" \"levels\": [6, 7, 8]},\n",
242+
" dx=dx, origin=center, direction=\"z\", ax=ax[1])"
248243
]
249244
},
250245
{
@@ -506,7 +501,9 @@
506501
"source": [
507502
"## Line integral convolution vector field visualizations\n",
508503
"\n",
509-
"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",
504+
"Osyris now supports line integral convolution (LIC) visualizations of vector fields.\n",
505+
"This visualization method, although computationally intensive,\n",
506+
"offers an excellent representation of the vector field (especially near discontinuities).\n",
510507
"\n",
511508
"**Note:** This feature requires the [lic](https://pypi.org/project/lic/) package to be installed.\n",
512509
"\n",
@@ -520,16 +517,20 @@
520517
"outputs": [],
521518
"source": [
522519
"osyris.plane({\"data\": data[\"hydro\"][\"velocity\"], \"mode\": \"lic\"},\n",
523-
" dx=2000 * osyris.units(\"au\"),\n",
524-
" origin=center,\n",
525-
" direction=\"z\", resolution=1000)"
520+
" dx=2000 * osyris.units(\"au\"), direction=\"z\",\n",
521+
" origin=center, cmap=\"binary\")"
526522
]
527523
},
528524
{
529525
"cell_type": "markdown",
530526
"metadata": {},
531527
"source": [
532-
"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):"
528+
"The LIC can be colored by a scalar field using the `color` keyword,\n",
529+
"and the length of the lines of the LIC can also be modified using the `length` keyword.\n",
530+
"\n",
531+
"In the following example,\n",
532+
"we use the colors to show the gas density overlayed onto the velocity flow structure on the left,\n",
533+
"while on the right we use the colors to recover some information on the magnitude of the velocities."
533534
]
534535
},
535536
{
@@ -538,19 +539,26 @@
538539
"metadata": {},
539540
"outputs": [],
540541
"source": [
542+
"fig, ax = plt.subplots(1, 2, figsize=(12, 4))\n",
543+
"\n",
544+
"dx = 2000 * osyris.units(\"au\")\n",
545+
"\n",
541546
"osyris.plane({\"data\": data[\"hydro\"][\"velocity\"], \"mode\": \"lic\",\n",
542-
" \"color\": data[\"hydro\"][\"density\"], \"norm\": \"log\", \"length\":30},\n",
543-
" dx=2000 * osyris.units(\"au\"),\n",
544-
" origin=center,\n",
545-
" direction=\"z\", resolution=1000)"
547+
" \"color\": data[\"hydro\"][\"density\"], \"norm\": \"log\",\n",
548+
" \"length\":60}, ax=ax[0],\n",
549+
" dx=dx, origin=center, direction=\"z\")\n",
550+
"osyris.plane({\"data\": data[\"hydro\"][\"velocity\"], \"mode\": \"lic\",\n",
551+
" \"color\": data[\"hydro\"][\"velocity\"], \"norm\": \"linear\",\n",
552+
" \"length\":60, \"cmap\": \"plasma\"}, ax=ax[1],\n",
553+
" dx=dx, origin=center, direction=\"z\")"
546554
]
547555
},
548556
{
549-
"cell_type": "markdown",
557+
"cell_type": "code",
558+
"execution_count": null,
550559
"metadata": {},
551-
"source": [
552-
"Overlaying this plot with velocity arrows allows us to retrieve some information on the magnitude of the vector field."
553-
]
560+
"outputs": [],
561+
"source": []
554562
}
555563
],
556564
"metadata": {

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = osyris
3-
version = 2.3.1
3+
version = 2.3.2
44
author = Neil Vaytet
55
author_email = [email protected]
66
description = A package to visualize AMR data from the RAMSES code

src/osyris/plot/wrappers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Copyright (c) 2021 Osyris contributors (https://github.com/nvaytet/osyris)
33
from .. import config
44
from ..core import Array
5+
from contextlib import redirect_stderr
6+
import io
57
import matplotlib.pyplot as plt
68
from matplotlib.cm import ScalarMappable
79
from matplotlib.collections import PatchCollection
@@ -175,7 +177,7 @@ def line_integral_convolution(ax,
175177
z,
176178
cbar=False,
177179
cblabel=None,
178-
length=30,
180+
length=None,
179181
color=None,
180182
**kwargs):
181183
"""
@@ -185,7 +187,10 @@ def line_integral_convolution(ax,
185187
from lic import lic
186188

187189
# Compute line integral convolution
188-
lic_res = lic(z[..., 1], z[..., 0], length=length)
190+
if length is None:
191+
length = int(max(z.shape[:-1]) * 15 / 128)
192+
with redirect_stderr(io.StringIO()) as _:
193+
lic_res = lic(z[..., 1], z[..., 0], length=length)
189194

190195
if color is not None:
191196
plot_args = {**kwargs}

0 commit comments

Comments
 (0)