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

Version 0.2.1 release #930

Merged
merged 7 commits into from
Mar 31, 2020
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM)
# [v0.2.1](https://github.com/pybamm-team/PyBaMM/tree/v0.2.1) - 2020-03-31

New expression tree node types, models, parameter sets and solvers, as well as general bug fixes and new examples.

## Features

Expand Down Expand Up @@ -26,6 +28,7 @@

## Bug fixes

- Fixed tight layout for QuickPlot in jupyter notebooks ([#930](https://github.com/pybamm-team/PyBaMM/pull/930))
- Fixed bug raised if function returns a scalar ([#919](https://github.com/pybamm-team/PyBaMM/pull/919))
- Fixed event handling in `ScipySolver` ([#905](https://github.com/pybamm-team/PyBaMM/pull/905))
- Made input handling clearer in solvers ([#905](https://github.com/pybamm-team/PyBaMM/pull/905))
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# The short X.Y version
version = "0.2"
# The full version, including alpha/beta/rc tags
release = "0.2.0"
release = "0.2.1"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def version(formatted=False):
# other
#
from .processed_variable import ProcessedVariable
from .quick_plot import QuickPlot, ax_min, ax_max
from .quick_plot import QuickPlot, dynamic_plot, ax_min, ax_max

from .simulation import Simulation, load_sim, is_notebook

Expand Down
29 changes: 22 additions & 7 deletions pybamm/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
import numpy as np
import pybamm
import warnings
from collections import defaultdict


Expand Down Expand Up @@ -45,6 +44,24 @@ def split_long_string(title, max_words=4):
return first_line + "\n" + second_line


def dynamic_plot(*args, **kwargs):
"""
Creates a :class:`pybamm.QuickPlot` object (with arguments 'args' and keyword
arguments 'kwargs') and then calls :meth:`pybamm.QuickPlot.dynamic_plot`.
The key-word argument 'testing' is passed to the 'dynamic_plot' method, not the
`QuickPlot' class.

Returns
-------
plot : :class:`pybamm.QuickPlot`
The 'QuickPlot' object that was created
"""
kwargs_for_class = {k: v for k, v in kwargs.items() if k != "testing"}
plot = pybamm.QuickPlot(*args, **kwargs_for_class)
plot.dynamic_plot(kwargs.get("testing", False))
return plot


class QuickPlot(object):
"""
Generates a quick plot of a subset of key outputs of the model so that the model
Expand Down Expand Up @@ -615,6 +632,10 @@ def plot(self, t):
if len(solution_handles) > 0:
self.fig.legend(solution_handles, self.labels, loc="lower right")

# Fix layout
bottom = 0.05 + 0.03 * max((len(self.labels) - 2), 0)
self.gridspec.tight_layout(self.fig, rect=[0, bottom, 1, 1])

def dynamic_plot(self, testing=False, step=None):
"""
Generate a dynamic plot with a slider to control the time.
Expand Down Expand Up @@ -651,12 +672,6 @@ def dynamic_plot(self, testing=False, step=None):
)
self.slider.on_changed(self.slider_update)

# ignore the warning about tight layout
warnings.simplefilter("ignore")
bottom = 0.05 + 0.03 * max((len(self.labels) - 2), 0)
self.gridspec.tight_layout(self.fig, rect=[0, bottom, 1, 1])
warnings.simplefilter("always")

if not testing: # pragma: no cover
plt.show()

Expand Down
13 changes: 6 additions & 7 deletions pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ class Simulation:
----------
model : :class:`pybamm.BaseModel`
The model to be simulated
experiment : : class:`pybamm.Experiment` (optional)
experiment : :class:`pybamm.Experiment` (optional)
The experimental conditions under which to solve the model
geometry: :class:`pybamm.Geometry` (optional)
The geometry upon which to solve the model
parameter_values: dict (optional)
A dictionary of parameters and their corresponding numerical
values
parameter_values: :class:`pybamm.ParameterValues` (optional)
Parameters and their corresponding numerical values.
submesh_types: dict (optional)
A dictionary of the types of submesh to use on each subdomain
var_pts: dict (optional)
Expand Down Expand Up @@ -533,9 +532,9 @@ def plot(self, quick_plot_vars=None, testing=False):
if quick_plot_vars is None:
quick_plot_vars = self.quick_plot_vars

plot = pybamm.QuickPlot(self._solution, output_variables=quick_plot_vars)

plot.dynamic_plot(testing=testing)
self.quick_plot = pybamm.dynamic_plot(
self._solution, output_variables=quick_plot_vars, testing=testing
)

@property
def model(self):
Expand Down
6 changes: 3 additions & 3 deletions pybamm/solvers/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ def save_data(self, filename, variables=None, to_format="pickle"):
savemat(filename, data)
elif to_format == "csv":
for name, var in data.items():
if var.ndim == 2:
if var.ndim >= 2:
raise ValueError(
"only 1D variables can be saved to csv, but '{}' is 2D".format(
name
"only 0D variables can be saved to csv, but '{}' is {}D".format(
name, var.ndim - 1
)
)
df = pd.DataFrame(data)
Expand Down
2 changes: 1 addition & 1 deletion pybamm/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0, 2, 0
0, 2, 1
2 changes: 1 addition & 1 deletion tests/unit/test_solvers/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_save(self):

# to csv
with self.assertRaisesRegex(
ValueError, "only 1D variables can be saved to csv"
ValueError, "only 0D variables can be saved to csv"
):
solution.save_data("test.csv", to_format="csv")
# only save "c" and "2c"
Expand Down