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

TST: test_streamplot_2D faster #4221

Merged
Merged
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
35 changes: 15 additions & 20 deletions testsuite/MDAnalysisTests/visualization/test_streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ def membrane_xtc(tmpdir_factory, univ):
z_delta += 0.02
return str(tmp_xtc)

def test_streamplot_2D(membrane_xtc, univ, tmpdir):
# simple roundtrip test to ensure that
# a plot is generated by the 2D streamplot
# code
def test_streamplot_2D(membrane_xtc, univ):
# regression test the data structures
# generated by the 2D streamplot code
u1, v1, avg, std = streamlines.generate_streamlines(topology_file_path=Martini_membrane_gro,
trajectory_file_path=membrane_xtc,
grid_spacing=20,
Expand All @@ -67,22 +66,18 @@ 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_allclose(u1, np.array([[0.79999924, 0.79999924, 0.80000687, 0.79999542, 0.79998779],
[0.80000019, 0.79999542, 0.79999924, 0.79999542, 0.80001068],
[0.8000021, 0.79999924, 0.80001068, 0.80000305, 0.79999542],
[0.80000019, 0.79999542, 0.80001068, 0.80000305, 0.80000305],
[0.79999828, 0.80000305, 0.80000305, 0.80000305, 0.79999542]]))
assert_allclose(v1, np.array([[0.53999901, 0.53999996, 0.53999996, 0.53999996, 0.54000092],
[0.5399971, 0.54000092, 0.54000092, 0.54000092, 0.5399971 ],
[0.54000473, 0.54000473, 0.54000092, 0.5399971, 0.54000473],
[0.54000092, 0.53999329, 0.53999329, 0.53999329, 0.54000092],
[0.54000092, 0.53999329, 0.53999329, 0.54000092, 0.53999329]]))
assert avg == pytest.approx(0.965194167)
assert std == pytest.approx(4.444808820e-06)


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