Skip to content

Commit

Permalink
small fixes (#11)
Browse files Browse the repository at this point in the history
- use isinstance instead of type
- check shape of array in concentration heatmap image
- removed unused imports
- increase tolerance of minimize test
  • Loading branch information
lkeegan authored Aug 25, 2021
1 parent df22b9c commit 5cc546d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 0 additions & 1 deletion sme_contrib/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from matplotlib import pyplot as plt
from matplotlib.colors import LinearSegmentedColormap as lscmap
from matplotlib import animation
import sme


def colormap(color, name="my colormap"):
Expand Down
14 changes: 7 additions & 7 deletions sme_contrib/tests/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def test_minimize() -> None:
iterations=20,
ps_options={"c1": 2.025, "c2": 2.025, "w": 0.5},
)
assert np.abs(res[0] - 0.375) < 0.100
assert np.abs(res[1] + 0.900) < 0.100
assert np.abs(res[0] - 0.375) < 0.200
assert np.abs(res[1] + 0.900) < 0.200


def test_rescale() -> None:
Expand Down Expand Up @@ -97,21 +97,21 @@ def test_steady_state() -> None:

# just check plots have correct titles for now
ax = ss.plot_target_concentration()
assert type(ax) == matplotlib.axes._subplots.Subplot
assert isinstance(ax, matplotlib.axes._subplots.Subplot)
assert ax.get_title() == "Target Concentration"

ax = ss.plot_model_concentration()
assert type(ax) == matplotlib.axes._subplots.Subplot
assert isinstance(ax, matplotlib.axes._subplots.Subplot)
assert ax.get_title() == "Model Concentration"

ax = ss.plot_cost_history()
assert type(ax) == matplotlib.axes._subplots.Subplot
assert isinstance(ax, matplotlib.axes._subplots.Subplot)
assert ax.get_title() == "Best cost history"

ax = ss.plot_cost_history_pbest()
assert type(ax) == matplotlib.axes._subplots.Subplot
assert isinstance(ax, matplotlib.axes._subplots.Subplot)
assert ax.get_title() == "Mean particle best cost history"

ax = ss.plot_timeseries(1, 1)
assert type(ax) == matplotlib.axes._subplots.Subplot
assert isinstance(ax, matplotlib.axes._subplots.Subplot)
assert ax.get_title() == "Concentration time series"
7 changes: 6 additions & 1 deletion sme_contrib/tests/test_plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sme_contrib.plot as smeplot
import numpy as np
import sme
import os.path

Expand Down Expand Up @@ -32,15 +31,21 @@ def test_concentration_heatmap() -> None:
# single species
ax, im = smeplot.concentration_heatmap(results[-1], ["A_nucl"])
assert ax.title.get_text() == "Concentration of A_nucl at time 10.0"
assert im.get_array().shape == (100, 100)
assert im.get_array()[0, 0] == 0.0
# two species
ax, im = smeplot.concentration_heatmap(results[-1], ["A_nucl", "A_cell"])
assert ax.title.get_text() == "Concentration of A_nucl, A_cell at time 10.0"
assert im.get_array().shape == (100, 100)
assert im.get_array()[0, 0] == 0.0
# specify title, existing plot axis & colormap
colormap = smeplot.colormap((1, 0, 0), "red1")
ax, im = smeplot.concentration_heatmap(
results[-1], ["A_nucl", "A_cell"], "my Title", ax, colormap
)
assert ax.title.get_text() == "my Title"
assert im.get_array().shape == (100, 100)
assert im.get_array()[0, 0] == 0.0


def test_concentration_heatmap_animation() -> None:
Expand Down

0 comments on commit 5cc546d

Please sign in to comment.