Skip to content

Commit

Permalink
Merge pull request #179 from ArtesiaWater/dev
Browse files Browse the repository at this point in the history
New Major release 0.10.0
  • Loading branch information
OnnoEbbens authored Jan 11, 2024
2 parents 3faeab1 + 337db2a commit 4dfd27d
Show file tree
Hide file tree
Showing 12 changed files with 1,052 additions and 129 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 O.E. Ebbens, D.A. Brakenhoff, R. Calje
Copyright (c) 2020 O.N. Ebbens, D.A. Brakenhoff, R. Calje

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions hydropandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
read_fews,
read_imod,
read_knmi,
read_lizard,
read_menyanthes,
read_modflow,
read_pastastore,
Expand Down
14 changes: 8 additions & 6 deletions hydropandas/extensions/gwobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,21 @@ def get_zvec(x, y, gwf=None, ds=None):

cid = nlmod.dims.xy_to_icell2d((x, y), ds)
sel = ds.sel(icell2d=cid)
zvec = np.concatenate(([sel["top"].data], sel["botm"].data))
zvec = np.concatenate(([sel["top"].values], sel["botm"].values))
mask = np.isnan(zvec)
idx = np.where(~mask, np.arange(mask.size), 0)
np.maximum.accumulate(idx, axis=0, out=idx)
zvec[mask] = zvec[idx[mask]]
else:
sel = ds.sel(x=x, y=y, method="nearest")
first_notna = np.nonzero(np.isfinite(np.atleast_1d(sel["top"].data)))[0][0]
if sel["top"].data.shape == tuple():
top = np.atleast_1d(sel["top"].data)
first_notna = np.nonzero(np.isfinite(np.atleast_1d(sel["top"].values)))[0][
0
]
if sel["top"].values.shape == tuple():
top = np.atleast_1d(sel["top"].values)
else:
top = np.atleast_1d(sel["top"].data[[first_notna]])
zvec = np.concatenate([top, sel["botm"].data])
top = np.atleast_1d(sel["top"].values[[first_notna]])
zvec = np.concatenate([top, sel["botm"].values])
mask = np.isnan(zvec)
idx = np.where(~mask, np.arange(mask.size), 0)
np.maximum.accumulate(idx, axis=0, out=idx)
Expand Down
55 changes: 55 additions & 0 deletions hydropandas/extensions/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.gridspec import GridSpec
from tqdm.auto import tqdm

from ..observation import GroundwaterObs
from . import accessor

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -644,6 +646,59 @@ def section_plot(

return fig, axes

def series_per_group(self, plot_column, by=None, savefig=True, outputdir="."):
"""Plot time series per group.
The default groupby is based on identical x, y coordinates, so plots unique
time series per location.
Parameters
----------
plot_column : str
name of column containing time series data
by : (list of) str or (list of) array-like
groupby parameters, default is None which sets groupby to
columns ["x", "y"].
savefig : bool, optional
save figures, by default True
outputdir : str, optional
path to output directory, by default the current directory (".")
"""
if by is None:
by = ["x", "y"]
gr = self._obj.groupby(by=by)
for _, group in tqdm(gr, desc="Plotting series per group", total=len(gr)):
f, ax = plt.subplots(1, 1, figsize=(10, 3))
for name, row in group.iterrows():
if isinstance(row.obs, GroundwaterObs):
lbl = (
f"{name} (NAP{row['screen_top']:+.1f}"
f"-{row['screen_bottom']:+.1f}m)"
)
else:
lbl = f"{name}"
ax.plot(
row.obs.index,
row.obs[plot_column],
label=lbl,
)
ax.legend(
loc=(0, 1),
frameon=False,
ncol=min(group.index.size, 3),
fontsize="x-small",
)
ax.set_ylabel(row["unit"])
ax.grid(True)
f.tight_layout()
if savefig:
if isinstance(row.obs, GroundwaterObs):
name = name.split("-")[0]
f.savefig(
os.path.join(outputdir, f"{name}.png"), bbox_inches="tight", dpi=150
)
plt.close(f)


@accessor.register_obs_accessor("plots")
class ObsPlots:
Expand Down
10 changes: 6 additions & 4 deletions hydropandas/io/fews.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,13 @@ class of the observations, e.g. GroundwaterObs or WaterlvlObs
[d + " " + t for d, t in zip(date, time)], errors="coerce"
)
ts = pd.DataFrame(events, index=index)
ts.loc[:, "value"] = ts.loc[:, "value"].astype(float)

if remove_nan and (not ts.empty):
ts.dropna(subset=["value"], inplace=True)
header["unit"] = "m NAP"
if not ts.empty:
ts["value"] = ts["value"].astype(float)

if remove_nan:
ts.dropna(subset=["value"], inplace=True)
header["unit"] = "m NAP"

o, header = _obs_from_meta(ts, header, translate_dic, ObsClass)
if locationIds is not None:
Expand Down
Loading

0 comments on commit 4dfd27d

Please sign in to comment.