Skip to content

Commit

Permalink
Merge pull request #43 from nvaytet/lic_tweaks
Browse files Browse the repository at this point in the history
Lic tweaks
  • Loading branch information
nvaytet authored Nov 22, 2021
2 parents ac892c2 + 76ede3a commit f720feb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
60 changes: 34 additions & 26 deletions docs/plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
Expand Down Expand Up @@ -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",
Expand All @@ -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])"
]
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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."
]
},
{
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = osyris
version = 2.3.1
version = 2.3.2
author = Neil Vaytet
author_email = [email protected]
description = A package to visualize AMR data from the RAMSES code
Expand Down
9 changes: 7 additions & 2 deletions src/osyris/plot/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -175,7 +177,7 @@ def line_integral_convolution(ax,
z,
cbar=False,
cblabel=None,
length=30,
length=None,
color=None,
**kwargs):
"""
Expand All @@ -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}
Expand Down

0 comments on commit f720feb

Please sign in to comment.