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

Issue 570 processed var warning #681

Merged
merged 5 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

## Bug fixes

- Add warning if `ProcessedVariable` is called outisde its interpolation range ([#681](https://github.com/pybamm-team/PyBaMM/pull/681))
- Improve the way `ProcessedVariable` objects are created in higher dimensions ([#581](https://github.com/pybamm-team/PyBaMM/pull/581))

# [v0.1.0](https://github.com/pybamm-team/PyBaMM/tree/v0.1.0) - 2019-10-08
Expand Down
2 changes: 1 addition & 1 deletion pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _load_version_int():
__version_int__ = _load_version_int()
__version__ = ".".join([str(x) for x in __version_int__])
if sys.version_info[0] < 3:
del (x) # Before Python3, list comprehension iterators leaked
del x # Before Python3, list comprehension iterators leaked

#
# Expose PyBaMM version
Expand Down
9 changes: 6 additions & 3 deletions pybamm/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#
import logging


def set_logging_level(level):
logger.setLevel(level)


format = (
"%(asctime)s - [%(levelname)s] %(module)s.%(funcName)s(%(lineno)d): "
+ "%(message)s"
Expand All @@ -12,7 +17,5 @@

# Create a custom logger
logger = logging.getLogger(__name__)
set_logging_level("WARNING")
Copy link
Contributor

@rtimms rtimms Oct 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the test_logger test needs updating as the default logger level has changed



def set_logging_level(level):
logger.setLevel(level)
15 changes: 10 additions & 5 deletions pybamm/processed_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,24 @@ def initialise_3D_scikit_fem(self):
fill_value=np.nan,
)

def __call__(self, t=None, x=None, r=None, y=None, z=None):
def __call__(self, t=None, x=None, r=None, y=None, z=None, warn=True):
"""
Evaluate the variable at arbitrary t (and x, r, y and/or z), using interpolation
"""
if self.dimensions == 1:
return self._interpolation_function(t)
out = self._interpolation_function(t)
elif self.dimensions == 2:
if t is None:
return self._interpolation_function(y, z)
out = self._interpolation_function(y, z)
else:
return self.call_2D(t, x, r, z)
out = self.call_2D(t, x, r, z)
elif self.dimensions == 3:
return self.call_3D(t, x, r, y, z)
out = self.call_3D(t, x, r, y, z)
if warn is True and np.isnan(out).any():
pybamm.logger.warning(
"Calling variable outside interpolation range (returns 'nan')"
)
return out

def call_2D(self, t, x, r, z):
"Evaluate a 2D variable"
Expand Down
10 changes: 7 additions & 3 deletions pybamm/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ def plot(self, t):
spatial_scale = self.spatial_scales[spatial_var_name]
self.plots[key][i][j], = ax.plot(
spatial_var_value * spatial_scale,
variable(t, **{spatial_var_name: spatial_var_value}),
variable(
t, **{spatial_var_name: spatial_var_value}, warn=False
),
lw=2,
color=colors[i],
linestyle=linestyles[j],
Expand All @@ -333,7 +335,7 @@ def plot(self, t):
full_t = self.ts[i]
self.plots[key][i][j], = ax.plot(
full_t * self.time_scale,
variable(full_t),
variable(full_t, warn=False),
lw=2,
color=colors[i],
linestyle=linestyles[j],
Expand Down Expand Up @@ -394,7 +396,9 @@ def update(self, val):
for j, variable in enumerate(variable_lists):
plot[i][j].set_ydata(
variable(
t_dimensionless, **{spatial_var_name: spatial_var_value}
t_dimensionless,
**{spatial_var_name: spatial_var_value},
warn=False
)
)
else:
Expand Down