Skip to content

Commit

Permalink
TST: test_streamplot_2D faster
Browse files Browse the repository at this point in the history
* speed up `test_streamplot_2D()` because it has been
reported to take ~20 seconds on a regular basis
in CI in MDAnalysisgh-4209

* we don't really need to plot the output, which
was taking most of the time, and instead we can
just check the data structures that MDAnalysis
returns (this may be a better test by some definitions
anyway...); I suppose we could also spot check
a few values in the arrays if we wanted as well

* locally, that single test seems to run in 0.39 s
on this branch vs. 4.7 s on `develop`
  • Loading branch information
tylerjereddy committed Aug 1, 2023
1 parent 66a2b21 commit 373e861
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions testsuite/MDAnalysisTests/visualization/test_streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def membrane_xtc(tmpdir_factory, univ):
z_delta += 0.02
return str(tmp_xtc)

def test_streamplot_2D(membrane_xtc, univ, tmpdir):
def test_streamplot_2D(membrane_xtc, univ):
# simple roundtrip test to ensure that
# a plot is generated by the 2D streamplot
# code
Expand All @@ -67,22 +67,10 @@ def test_streamplot_2D(membrane_xtc, univ, tmpdir):
ymax=univ.atoms.positions[...,1].max(),
maximum_delta_magnitude=2.0,
num_cores=1)
x = np.linspace(univ.atoms.positions[...,0].min(),
univ.atoms.positions[...,0].max(),
5)
y = np.linspace(univ.atoms.positions[...,1].min(),
univ.atoms.positions[...,1].max(),
5)
speed = np.sqrt(u1*u1 + v1*v1)
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.streamplot(x, y, u1, v1, density=(10,10), color=speed, linewidth=3*speed/speed.max(),
cmap=plt.cm.viridis)
plot_outpath = os.path.join(str(tmpdir), 'testing_streamline.png')
fig.savefig(plot_outpath, dpi=300)

with open(plot_outpath, 'rb'):
pass
assert u1.shape == (5, 5)
assert v1.shape == (5, 5)
assert_allclose(avg, 0.965194167)
assert_allclose(std, 4.444808820e-06)


def test_streamplot_2D_zero_return(membrane_xtc, univ, tmpdir):
Expand Down

0 comments on commit 373e861

Please sign in to comment.