Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skill groupby attrs #351

Merged
merged 34 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fea7e0a
optionally include attrs in to_dataframe and _attrs_keys_in_by
jsmariegaard Dec 19, 2023
a46b24c
rename to group and prepare for x, y
jsmariegaard Dec 19, 2023
22cb543
temporary disable astype(category)
jsmariegaard Dec 19, 2023
a42b5a0
only if str
jsmariegaard Dec 19, 2023
c464769
reintroduce astype("category") and remove resulting empty groups 🤔
jsmariegaard Dec 19, 2023
b093f96
type: ignore
jsmariegaard Dec 19, 2023
3b874ad
Add option to include observeed categories
ecomodeller Dec 21, 2023
fec47bf
boolean logic backwards
ecomodeller Dec 21, 2023
37c47f7
Ignore ruff
ecomodeller Dec 21, 2023
11bc69a
Merge branch 'skill-grouby-attrs' of https://github.com/DHI/modelskil…
jsmariegaard Dec 21, 2023
568943d
Merge branch 'main' into skill-grouby-attrs
jsmariegaard Dec 21, 2023
ee3e029
reverse observed
jsmariegaard Dec 21, 2023
f154cb8
Merge branch 'main' into skill-grouby-attrs
jsmariegaard Jan 3, 2024
a2c8b4d
Merge branch 'main' into skill-grouby-attrs
jsmariegaard Jan 3, 2024
581690d
test_skill_by_attrs_gtype and test_skill_by_attrs_gtype_and_mod
jsmariegaard Jan 3, 2024
ee1fff1
docstring
jsmariegaard Jan 3, 2024
1411245
test_skill_by_attrs_int, test_skill_by_attrs_observed
jsmariegaard Jan 3, 2024
af27dbe
TODO on sort=False
jsmariegaard Jan 3, 2024
00376b2
Merge branch 'main' into skill-grouby-attrs
jsmariegaard Jan 4, 2024
da3669b
observed=False
jsmariegaard Jan 4, 2024
354a52e
mod_idx
jsmariegaard Jan 4, 2024
e93bba1
docstrings and variable naming
jsmariegaard Jan 4, 2024
3506819
improved docstrings including consistent kwargs
jsmariegaard Jan 4, 2024
bd960fb
move deprecated methods to the bottom, and other clean-up
jsmariegaard Jan 4, 2024
9fbf00a
idx instead of id
jsmariegaard Jan 4, 2024
959023a
better docstrings
jsmariegaard Jan 4, 2024
43209c4
move load/save and deprecated functionality to bottom of file
jsmariegaard Jan 4, 2024
597b2fa
rename residual to _residual (for now)
jsmariegaard Jan 4, 2024
5c3afff
IdOrNameTypes renamed to IdxOrNameTypes
jsmariegaard Jan 4, 2024
d16ea04
Improved docstrings, correct return types, lists in arguments
jsmariegaard Jan 4, 2024
56c7cd4
rename to_dataframe to _to_long_dataframe
jsmariegaard Jan 4, 2024
5afaa51
to_dataframe removed, use cmp.data.to_dataframe instead
jsmariegaard Jan 4, 2024
a235c92
rename
jsmariegaard Jan 4, 2024
256a344
cmp.to_dataframe removed
jsmariegaard Jan 4, 2024
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
562 changes: 309 additions & 253 deletions modelskill/comparison/_collection.py

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions modelskill/comparison/_collection_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def scatter(
by default False
ax : matplotlib axes, optional
axes to plot on, by default None
**kwargs :
**kwargs
other keyword arguments to matplotlib.pyplot.scatter()

Examples
Expand Down Expand Up @@ -196,7 +196,7 @@ def _scatter_one_model(
if cc_sel_mod.n_points == 0:
raise ValueError("No data found in selection")

df = cc_sel_mod.to_dataframe()
df = cc_sel_mod._to_long_dataframe()
x = df.obs_val.values
y = df.mod_val.values

Expand Down Expand Up @@ -287,7 +287,7 @@ def kde(self, *, ax=None, figsize=None, title=None, **kwargs) -> Axes:
"""
_, ax = _get_fig_ax(ax, figsize)

df = self.cc.to_dataframe()
df = self.cc._to_long_dataframe()
ax = df.obs_val.plot.kde(
ax=ax, linestyle="dashed", label="Observation", **kwargs
)
Expand Down Expand Up @@ -351,7 +351,8 @@ def hist(
axes to plot on, by default None
figsize : tuple, optional
width and height of the figure, by default None
kwargs : other keyword arguments to df.hist()
**kwargs
other keyword arguments to df.hist()

Returns
-------
Expand Down Expand Up @@ -413,17 +414,17 @@ def _hist_one_model(
assert (
mod_name in self.cc.mod_names
), f"Model {mod_name} not found in collection"
mod_id = _get_idx(mod_name, self.cc.mod_names)
mod_idx = _get_idx(mod_name, self.cc.mod_names)

title = (
_default_univarate_title("Histogram", self.cc) if title is None else title
)

cmp = self.cc
df = cmp.to_dataframe()
df = cmp._to_long_dataframe()
kwargs["alpha"] = alpha
kwargs["density"] = density
df.mod_val.hist(bins=bins, color=MOD_COLORS[mod_id], ax=ax, **kwargs)
df.mod_val.hist(bins=bins, color=MOD_COLORS[mod_idx], ax=ax, **kwargs)
df.obs_val.hist(
bins=bins,
color=self.cc[0].data["Observation"].attrs["color"],
Expand Down
35 changes: 22 additions & 13 deletions modelskill/comparison/_comparer_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def timeseries(
figsize : (float, float), optional
figure size, by default None
backend : str, optional
use "plotly" (interactive) or "matplotlib" backend, by default "matplotlib"backend:
use "plotly" (interactive) or "matplotlib" backend,
by default "matplotlib"
**kwargs
other keyword arguments to fig.update_layout (plotly backend)

Returns
-------
Expand Down Expand Up @@ -165,7 +168,8 @@ def hist(
If True, draw and return a probability density
alpha : float, optional
alpha transparency fraction, by default 0.5
kwargs : other keyword arguments to df.plot.hist()
**kwargs
other keyword arguments to df.plot.hist()

Returns
-------
Expand Down Expand Up @@ -220,7 +224,7 @@ def _hist_one_model(

cmp = self.comparer
assert mod_name in cmp.mod_names, f"Model {mod_name} not found in comparer"
mod_id = _get_idx(mod_name, cmp.mod_names)
mod_idx = _get_idx(mod_name, cmp.mod_names)

title = f"{mod_name} vs {cmp.name}" if title is None else title

Expand All @@ -233,7 +237,7 @@ def _hist_one_model(
ax = (
cmp.data[mod_name]
.to_series()
.hist(bins=bins, color=MOD_COLORS[mod_id], **kwargs)
.hist(bins=bins, color=MOD_COLORS[mod_idx], **kwargs)
)

cmp.data[cmp._obs_name].to_series().hist(
Expand Down Expand Up @@ -265,7 +269,8 @@ def kde(self, ax=None, title=None, figsize=None, **kwargs) -> matplotlib.axes.Ax
plot title, default: "KDE plot for [observation name]"
figsize : tuple, optional
figure size, by default None
kwargs : other keyword arguments to df.plot.kde()
**kwargs
other keyword arguments to df.plot.kde()

Returns
-------
Expand Down Expand Up @@ -339,7 +344,8 @@ def qq(
axes to plot on, by default None
figsize : tuple, optional
figure size, by default None
kwargs : other keyword arguments to plt.plot()
**kwargs
other keyword arguments to plt.plot()

Returns
-------
Expand Down Expand Up @@ -414,7 +420,8 @@ def box(self, *, ax=None, title=None, figsize=None, **kwargs):
plot title, default: [observation name]
figsize : tuple, optional
figure size, by default None
kwargs : other keyword arguments to df.boxplot()
**kwargs
other keyword arguments to df.boxplot()

Returns
-------
Expand Down Expand Up @@ -531,7 +538,8 @@ def scatter(
right of the scatter plot, by default False
ax : matplotlib.axes.Axes, optional
axes to plot on, by default None
**kwargs: other keyword arguments to plt.scatter()
**kwargs
other keyword arguments to plt.scatter()

Examples
------
Expand Down Expand Up @@ -715,11 +723,11 @@ def taylor(
mtr.cc,
]

s = cmp.skill(metrics=metrics)
sk = cmp.skill(metrics=metrics)

if s is None: # TODO
if sk is None: # TODO
return
df = s.to_dataframe()
df = sk.to_dataframe()
ref_std = 1.0 if normalize_std else df.iloc[0]["_std_obs"]

df = df[["_std_obs", "_std_mod", "cc"]].copy()
Expand Down Expand Up @@ -758,7 +766,8 @@ def residual_hist(
figure size, by default None
ax : matplotlib.axes.Axes, optional
axes to plot on, by default None
kwargs : other keyword arguments to plt.hist()
**kwargs
other keyword arguments to plt.hist()

Returns
-------
Expand All @@ -769,7 +778,7 @@ def residual_hist(
default_color = "#8B8D8E"
color = default_color if color is None else color
title = f"Residuals, {self.comparer.name}" if title is None else title
ax.hist(self.comparer.residual, bins=bins, color=color, **kwargs)
ax.hist(self.comparer._residual, bins=bins, color=color, **kwargs)
ax.set_title(title)
ax.set_xlabel(f"Residuals of {self.comparer._unit_text}")

Expand Down
Loading