Skip to content

Commit

Permalink
Merge pull request #107 from pastas/dev
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
dbrakenhoff authored Dec 4, 2023
2 parents bb34669 + 07a0eb2 commit 60b6569
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 83 deletions.
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sys

sys.path.insert(0, os.path.abspath("."))
from pastastore import __version__
from pastastore import __version__ # noqa: E402

# -- Project information -----------------------------------------------------

Expand Down Expand Up @@ -125,7 +125,6 @@
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
Expand Down
4 changes: 0 additions & 4 deletions examples/notebooks/ex02_pastastore_plots_and_maps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import os\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"import pastastore as pst\n",
"import pastas as ps\n",
Expand Down
8 changes: 4 additions & 4 deletions examples/notebooks/ex03_pastastore_yaml_interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pastastore.datasets import example_pastastore"
"from pastastore.datasets import example_pastastore # noqa: E402"
]
},
{
Expand Down Expand Up @@ -364,7 +364,7 @@
],
"source": [
"ml.solve(report=False)\n",
"ml.plots.results();"
"ml.plots.results()"
]
},
{
Expand Down Expand Up @@ -802,7 +802,7 @@
],
"source": [
"ml.solve(report=False)\n",
"ml.plots.results();"
"ml.plots.results()"
]
},
{
Expand Down Expand Up @@ -910,7 +910,7 @@
],
"source": [
"ml.solve(report=False)\n",
"ml.plots.results();"
"ml.plots.results()"
]
},
{
Expand Down
9 changes: 5 additions & 4 deletions pastastore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from . import connectors, util
from .connectors import (
# ruff: noqa: F401
from pastastore import connectors, util
from pastastore.connectors import (
ArcticConnector,
ArcticDBConnector,
DictConnector,
PasConnector,
PystoreConnector,
)
from .store import PastaStore
from .version import __version__
from pastastore.store import PastaStore
from pastastore.version import __version__
31 changes: 21 additions & 10 deletions pastastore/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from numpy import isin
from packaging.version import parse as parse_version
from pastas.io.pas import PastasEncoder
from tqdm import tqdm
from tqdm.auto import tqdm

from .util import ItemInLibraryException, _custom_warning, validate_names
from .version import PASTAS_LEQ_022
from pastastore.util import ItemInLibraryException, _custom_warning, validate_names
from pastastore.version import PASTAS_LEQ_022

FrameorSeriesUnion = Union[pd.DataFrame, pd.Series]
warnings.showwarning = _custom_warning
Expand Down Expand Up @@ -934,13 +934,24 @@ def empty_library(
)
if ui.lower() != "y":
return
names = self._parse_names(None, libname)
for name in (
tqdm(names, desc=f"Deleting items from {libname}") if progressbar else names
):
self._del_item(libname, name)
self._clear_cache(libname)
print(f"Emptied library {libname} in {self.name}: " f"{self.__class__}")

if libname == "models":
# also delete linked modelnames linked to oseries
libs = ["models", "oseries_models"]
else:
libs = [libname]

# delete items and clear caches
for libname in libs:
names = self._parse_names(None, libname)
for name in (
tqdm(names, desc=f"Deleting items from {libname}")
if progressbar
else names
):
self._del_item(libname, name)
self._clear_cache(libname)
print(f"Emptied library {libname} in {self.name}: " f"{self.__class__}")

def _iter_series(self, libname: str, names: Optional[List[str]] = None):
"""Internal method iterate over time series in library.
Expand Down
4 changes: 2 additions & 2 deletions pastastore/connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import pandas as pd
from pastas.io.pas import PastasEncoder, pastas_hook

from .base import BaseConnector, ConnectorUtil, ModelAccessor
from .util import _custom_warning
from pastastore.base import BaseConnector, ConnectorUtil, ModelAccessor
from pastastore.util import _custom_warning

FrameorSeriesUnion = Union[pd.DataFrame, pd.Series]
warnings.showwarning = _custom_warning
Expand Down
33 changes: 21 additions & 12 deletions pastastore/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
ax = pstore.maps.oseries()
pstore.maps.add_background_map(ax) # for adding a background map
"""

from collections.abc import Iterable

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -96,15 +93,11 @@ def _timeseries(

if ax is None:
if split:
fig, axes = plt.subplots(len(names), 1, sharex=True, figsize=figsize)
_, axes = plt.subplots(len(names), 1, sharex=True, figsize=figsize)
else:
fig, axes = plt.subplots(1, 1, figsize=figsize)
_, axes = plt.subplots(1, 1, figsize=figsize)
else:
axes = ax
if isinstance(axes, Iterable):
fig = axes[0].figure
else:
fig = axes.figure

tsdict = self.pstore.conn._get_series(
libname, names, progressbar=progressbar, squeeze=False
Expand Down Expand Up @@ -397,20 +390,31 @@ def _data_availability(
linewidth=0,
rasterized=True,
)

# make a colorbar in an ax on the
# right side, then set the current axes to ax again
cb = fig.colorbar(pc, ax=ax, cax=cax, extend="both")
cb.set_ticks(bounds)
cb.ax.set_yticklabels(labels)
cb.ax.minorticks_off()

if set_yticks:
ax.set_yticks(np.arange(0.5, len(series) + 0.5))
ax.set_yticks(np.arange(0.5, len(series) + 0.5), minor=False)
ax.set_yticks(np.arange(0, len(series) + 1), minor=True)
if names is None:
names = [s.name for s in series]
ax.set_yticklabels(names)

for tick in ax.yaxis.get_major_ticks(): # don't show major ytick marker
tick.tick1line.set_visible(False)

ax.grid(True, which="minor", axis="y")
ax.grid(True, which="major", axis="x")

else:
ax.set_ylabel("Timeseries (-)")
ax.grid(True)
ax.grid(True, which="both")
ax.grid(True, which="both")

return ax

Expand Down Expand Up @@ -712,6 +716,7 @@ def models(
def modelstat(
self,
statistic,
modelnames=None,
label=True,
adjust=False,
cmap="viridis",
Expand All @@ -728,6 +733,8 @@ def modelstat(
----------
statistic: str
name of the statistic, e.g. "evp" or "aic"
modelnames : list of str, optional
list of modelnames to include
label: bool, optional
label points, by default True
adjust: bool, optional
Expand Down Expand Up @@ -757,7 +764,9 @@ def modelstat(
--------
self.add_background_map
"""
statsdf = self.pstore.get_statistics([statistic], progressbar=False).to_frame()
statsdf = self.pstore.get_statistics(
[statistic], modelnames=modelnames, progressbar=False
).to_frame()

statsdf["oseries"] = [
self.pstore.get_models(m, return_dict=True)["oseries"]["name"]
Expand Down
Loading

0 comments on commit 60b6569

Please sign in to comment.