Skip to content

Commit

Permalink
Merge pull request #68 from Adnan-Ali-Ahmad/vaytet_osyris
Browse files Browse the repository at this point in the history
Custom user normalization & verbose flag for LICs
  • Loading branch information
nvaytet committed Feb 10, 2022
2 parents 1551d79 + ba48971 commit aedab72
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 15 additions & 4 deletions src/osyris/plot/parser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2022 Osyris contributors (https://github.com/nvaytet/osyris)

from matplotlib.colors import LogNorm, Normalize
from matplotlib.colors import LogNorm, Normalize, SymLogNorm


def get_norm(norm=None, vmin=None, vmax=None):
if norm == "log":
return LogNorm(vmin=vmin, vmax=vmax)
else:
if norm is None:
return Normalize(vmin=vmin, vmax=vmax)
if isinstance(norm, str):
norm_lowercase = norm.lower()
if norm_lowercase == "log":
return LogNorm(vmin=vmin, vmax=vmax)
elif norm_lowercase == "symlog":
return SymLogNorm(linthresh=1e-2, vmin=vmin, vmax=vmax, base=10)
elif norm_lowercase == "linear":
return Normalize(vmin=vmin, vmax=vmax)
else:
raise RuntimeError("Unknown norm keyword '{}'.\nAvailable keywords"
" are 'log', 'symlog' and 'linear'.".format(norm))
else:
return norm


def parse_layer(layer,
Expand Down
6 changes: 4 additions & 2 deletions src/osyris/plot/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .. import config
from ..core import Array
from contextlib import redirect_stderr
from contextlib import redirect_stderr, nullcontext
import io
import matplotlib.pyplot as plt
from matplotlib.cm import ScalarMappable
Expand Down Expand Up @@ -189,6 +189,7 @@ def line_integral_convolution(ax,
cblabel=None,
length=None,
color=None,
verbose=False,
**kwargs):
"""
Wrapper that plots a line integral convolution of a vector field.
Expand All @@ -199,7 +200,8 @@ def line_integral_convolution(ax,
# Compute line integral convolution
if length is None:
length = int(max(z.shape[:-1]) * 15 / 128)
with redirect_stderr(io.StringIO()) as _:
cm = nullcontext() if verbose else redirect_stderr(io.StringIO())
with cm:
lic_res = lic(z[..., 1], z[..., 0], length=length)

if color is not None:
Expand Down

0 comments on commit aedab72

Please sign in to comment.