Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ src/hydrodiy/gis/tests/*.cpg
src/hydrodiy/gis/tests/*.dbf
src/hydrodiy/gis/tests/*.shp
src/hydrodiy/gis/tests/*.shx
src/hydrodiy/plot/tests/images/
src/hydrodiy/stat/tests/__pycache__/
src/hydrodiy/io/tests/script_test*
src/hydrodiy/gis/tests/grid_test.bil
src/hydrodiy/data/c_hydrodiy_data.c
Expand Down
9 changes: 5 additions & 4 deletions src/hydrodiy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
if sys.version_info > (3, 0):
PYVERSION = 3


def has_c_module(name, raise_error=True):
name = f"c_hydrodiy_{name}"
out = importlib.util.find_spec(name)

if not out is None:
if out is not None:
return True
else:
if raise_error:
raise ImportError(f"C module {name} is "+\
"not available, please run python setup.py build")
raise ImportError(f"C module {name} is "
+ "not available, please "
+ "run python setup.py build")
else:
return False

7 changes: 7 additions & 0 deletions src/hydrodiy/io/hyruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ def from_cartesian_product(self, **kwargs):
+ f" an int or a string, got {type(v)}."
raise TypeError(errmsg)

# convert numpy to list
try:
v2 = v2.tolist()
except AttributeError:
pass

# Store options
sk = str(k)
self.options[sk] = v2

Expand Down
6 changes: 3 additions & 3 deletions src/hydrodiy/io/iutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ def __init__(self, logger,
self.tab_length = tab_length

def get_separator(self, nsep, sep):
return sep*nsep
return sep * nsep

def add_tab(self, msg, ntab):
if ntab == 0:
return msg

tab_space = " "*self.tab_length*ntab
return tab_space+msg
tab_space = " " * self.tab_length * ntab
return tab_space + msg

def error(self, msg, ntab=0, *args, **kwargs):
msg = self.add_tab(msg, ntab)
Expand Down
3 changes: 2 additions & 1 deletion src/hydrodiy/io/tests/test_hyio_hyruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ def test_option_dict():

def test_option_file():
opm = hyruns.OptionManager(bidule="test")
opm.from_cartesian_product(v1=["a", "b"], v2=[1, 2, 3])
opm.from_cartesian_product(v1=pd.Series(["a", "b"]),
v2=np.arange(1, 4))

f = TESTS_DIR / "opm.json"
if f.exists():
Expand Down
33 changes: 23 additions & 10 deletions src/hydrodiy/plot/putils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np
import pandas as pd

from hydrodiy.data.dutils import get_value_from_kwargs
from hydrodiy.stat import sutils

HAS_CYCLER = False
Expand Down Expand Up @@ -571,6 +572,7 @@ def scattercat(ax, x, y, z, ncats=5, cuts=None, cmap="PiYG",
fmt="0.2f",
eps=1e-5,
show_extremes_in_legend=True,
show_counts_in_legend=False,
*args, **kwargs):
""" Draw a scatter plot using different colors or markersize depending
on categories defined by z. Be careful when z has a lot of zeros,
Expand Down Expand Up @@ -611,7 +613,9 @@ def scattercat(ax, x, y, z, ncats=5, cuts=None, cmap="PiYG",
Number format to be used in labels
show_extremes_in_legend : bool
Show lowest and highest bounds in legend. If False, report <b or b> in
legend.
legend. Can be abbreviated as 'sel'.
show_counts_in_legend : bool
Show count of categoriges in legend. Can be abbreviated as 'scl'.
eps : float
Tolerance on min and max value if using cuts.
args, kwargs
Expand All @@ -633,18 +637,24 @@ def scattercat(ax, x, y, z, ncats=5, cuts=None, cmap="PiYG",
Series containing the category number for each item
"""
# Check inputs
if "m" in kwargs:
markers = kwargs["m"]
kwargs.pop("m")
markers = get_value_from_kwargs(kwargs, "markers", "m",
markers)

if "ms" in kwargs:
markersizes = kwargs["ms"]
kwargs.pop("ms")
markersizes = get_value_from_kwargs(kwargs, "markersizes",
"ms", markersizes)

if "ec" in kwargs:
edgecolors = kwargs["ec"]
kwargs.pop("ec")
edgecolors = get_value_from_kwargs(kwargs, "edgecolors",
"ec", edgecolors)

show_extremes_in_legend = get_value_from_kwargs(kwargs,
"show_extremes_in_legend",
"sel",
show_extremes_in_legend)

show_counts_in_legend = get_value_from_kwargs(kwargs,
"show_counts_in_legend",
"scl",
show_counts_in_legend)
if not len(x) == len(y):
errmess = "Expected x and y of same length, got "\
+ f"len(x)={len(x)}, len(y)={len(y)}"
Expand Down Expand Up @@ -771,6 +781,9 @@ def notlist(x):
continue

label = labels[icat]
if show_counts_in_legend:
label = f"{label} ({idx.sum()})"

marker = markers[icat]
markersize = markersizes[icat]
col = colors[icat]
Expand Down
11 changes: 11 additions & 0 deletions src/hydrodiy/plot/tests/test_hyplot_putils.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ def test_scattercat():
fig.savefig(fp)


def test_scattercat_counts():
x, y, z = np.random.uniform(0, 1, size=(100, 3)).T
fig, ax = plt.subplots()
plotted, cats = putils.scattercat(ax, x, y, z, 5, \
markersizes=np.linspace(30, 70, 5), \
alphas=0.6, scl=True)
ax.legend(loc=2, title="categories")
fp = FIMG / "scattercat_counts.png"
fig.savefig(fp)


def test_scattercat_nocmap():
""" Test categorical scatter plot with no cmap"""
x, y, z = np.random.uniform(0, 1, size=(100, 3)).T
Expand Down
1 change: 0 additions & 1 deletion src/hydrodiy/plot/violinplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
import pandas as pd
from scipy.stats import gaussian_kde
from numpy.polynomial import Chebyshev

import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
Expand Down