Skip to content

Commit

Permalink
updated plot tests, fixed and visually validated all, added for hexbins
Browse files Browse the repository at this point in the history
  • Loading branch information
darianyang committed Nov 10, 2023
1 parent 3975e4f commit fae2616
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 39 deletions.
2 changes: 1 addition & 1 deletion wedap/h5_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __init__(self, X=None, Y=None, Z=None, plot_mode="hist", cmap=None, smoothin
elif self.p_units == "raw_norm":
self.cbar_label = "Normalized Counts"
# if using 3 datasets, put blank name as default cbar
if self.plot_mode == "scatter3d":
if self.plot_mode == "scatter3d" or self.plot_mode == "hexbin3d":
self.cbar_label = ""
# overwrite and apply cbar_label attr if available/specified
if cbar_label:
Expand Down
Binary file modified wedap/tests/data/plot_average_contour_dihedral_2_pcoord.npy
Binary file not shown.
Binary file modified wedap/tests/data/plot_average_contour_pcoord_dihedral_2.npy
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified wedap/tests/data/plot_average_line_dihedral_2.npy
Binary file not shown.
Binary file modified wedap/tests/data/plot_average_line_pcoord.npy
Binary file not shown.
Binary file not shown.
Binary file added wedap/tests/data/plot_evolution_hist_pcoord.npy
Binary file not shown.
Binary file modified wedap/tests/data/plot_instant_contour_dihedral_2_pcoord.npy
Binary file not shown.
Binary file modified wedap/tests/data/plot_instant_contour_pcoord_dihedral_2.npy
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified wedap/tests/data/plot_instant_line_dihedral_2.npy
Binary file not shown.
Binary file modified wedap/tests/data/plot_instant_line_pcoord.npy
Binary file not shown.
47 changes: 15 additions & 32 deletions wedap/tests/make_h5_plot_test_data.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,32 @@
import wedap
#import wedap
#import matplotlib.pyplot as plt
#import numpy as np

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import numpy as np

from wedap.tests.test_h5_plot import plot_data_gen

# def plot_data_gen(h5, data_type, plot_mode, Xname, Yname=None, Zname=None, out=None):
# """
# Make plot and convert to npy binary data file.
# """
# plot = wedap.H5_Plot(h5=h5, data_type=data_type, plot_mode=plot_mode,
# Xname=Xname, Yname=Yname, Zname=Zname)
# plot.plot()
# fig = plot.fig

# #plt.show()
# #import sys; sys.exit(0)

# # If we haven't already shown or saved the plot, then we need to
# # draw the figure first...
# # tight since canvas is large
# fig.tight_layout(pad=0)
# fig.canvas.draw()

# # Now we can save it to a numpy array.
# data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
# data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
# # save as np binary file
# if out:
# np.save(out, data)

h5 = "wedap/data/p53.h5"

# # 1 dataset plots
# for dt in ["evolution", "average", "instant"]:
# for dt in ["evolution"]:
# for pm in ["hist"]:
# for x in ["pcoord", "dihedral_2"]:
# plot_data_gen(h5, dt, pm, x, out=f"wedap/tests/data/plot_{dt}_{pm}_{x}.npy")
#plot_data_gen(h5, dt, pm, x, show=True)
# for dt in ["average", "instant"]:
# for pm in ["line"]:
# for x in ["pcoord", "dihedral_2"]:
# plot_data_gen(h5, dt, pm, x, out=f"wedap/tests/data/data/plot_{dt}_{pm}_{x}.npy")
# plot_data_gen(h5, dt, pm, x, out=f"wedap/tests/data/plot_{dt}_{pm}_{x}.npy")
# #plot_data_gen(h5, dt, pm, x, show=True)

# # 2 dataset plots
# for dt in ["average", "instant"]:
# for pm in ["hist", "contour"]:
# for x, y in [["pcoord", "dihedral_2"], ["dihedral_2", "pcoord"]]:
# plot_data_gen(h5, dt, pm, x, y, out=f"wedap/tests/data/plot_{dt}_{pm}_{x}_{y}.npy")
# #plot_data_gen(h5, dt, pm, x, y, show=True)

# 2 dataset plots with joint plots (TODO)
# for jp in [True, False]:
Expand All @@ -55,8 +37,9 @@

# # 3 dataset plots
# for dt in ["average", "instant"]:
# for pm in ["scatter3d"]:
# for pm in ["scatter3d", "hexbin3d"]:
# for x, y, z in [["pcoord", "dihedral_2", "dihedral_3"],
# ["dihedral_2", "pcoord", "dihedral_3"],
# ["dihedral_2", "dihedral_3", "pcoord"]]:
# plot_data_gen(h5, dt, pm, x, y, z, out=f"wedap/tests/data/plot_{dt}_{pm}_{x}_{y}_{z}.npy")
# plot_data_gen(h5, dt, pm, x, y, z, out=f"wedap/tests/data/plot_{dt}_{pm}_{x}_{y}_{z}.npy")
# #plot_data_gen(h5, dt, pm, x, y, z, show=True)
31 changes: 25 additions & 6 deletions wedap/tests/test_h5_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#@pytest.mark.skip

def plot_data_gen(h5, data_type, plot_mode, Xname, Yname=None, Zname=None,
jointplot=False, out=None):
jointplot=False, out=None, show=False):
"""
Make plot and return or convert to npy binary data file.
"""
Expand All @@ -34,6 +34,10 @@ def plot_data_gen(h5, data_type, plot_mode, Xname, Yname=None, Zname=None,
plot.plot()
fig = plot.fig

if show:
matplotlib.pyplot.show()
return

# draw the figure
# tight since canvas is large
fig.tight_layout(pad=0)
Expand All @@ -47,6 +51,8 @@ def plot_data_gen(h5, data_type, plot_mode, Xname, Yname=None, Zname=None,
if out:
np.save(out, data)

matplotlib.pyplot.close()

return data

class Test_H5_Plot():
Expand All @@ -55,9 +61,21 @@ class Test_H5_Plot():
"""
h5 = "wedap/data/p53.h5"

@pytest.mark.parametrize("data_type", ["evolution", "average", "instant"])
@pytest.mark.parametrize("data_type", ["evolution"])
@pytest.mark.parametrize("Xname", ["pcoord", "dihedral_2"])
def test_1d_evolution_plots(self, data_type, Xname):
# make plot data array
plotdata = plot_data_gen(self.h5, data_type=data_type, plot_mode="hist", Xname=Xname)

# compare to previously generated plot data
data = np.load(f"wedap/tests/data/plot_{data_type}_hist_{Xname}.npy")
#np.testing.assert_allclose(plotdata, data)
# check to see if the amount of mismatches is less than 500 (<1% of 1 million items)
assert data.size - np.count_nonzero(plotdata==data) < 500

@pytest.mark.parametrize("data_type", ["average", "instant"])
@pytest.mark.parametrize("Xname", ["pcoord", "dihedral_2"])
def test_1_dataset_plots(self, data_type, Xname):
def test_1d_avg_inst_plots(self, data_type, Xname):
# make plot data array
plotdata = plot_data_gen(self.h5, data_type=data_type, plot_mode="line", Xname=Xname)

Expand Down Expand Up @@ -85,17 +103,18 @@ def test_2_dataset_plots(self, data_type, plot_mode, Xname, Yname):#, jointplot)
assert data.size - np.count_nonzero(plotdata==data) < 500


@pytest.mark.parametrize("plot_mode", ["scatter3d", "hexbin3d"])
@pytest.mark.parametrize("data_type", ["average", "instant"])
@pytest.mark.parametrize("Xname, Yname, Zname", [["pcoord", "dihedral_2", "dihedral_3"],
["dihedral_2", "pcoord", "dihedral_3"],
["dihedral_2", "dihedral_3", "pcoord"]])
def test_3_dataset_plots(self, data_type, Xname, Yname, Zname):
def test_3_dataset_plots(self, data_type, plot_mode, Xname, Yname, Zname):
# make plot data array
plotdata = plot_data_gen(self.h5, data_type=data_type, plot_mode="scatter3d",
plotdata = plot_data_gen(self.h5, data_type=data_type, plot_mode=plot_mode,
Xname=Xname, Yname=Yname, Zname=Zname)

# compare to previously generated plot data
data = np.load(f"wedap/tests/data/plot_{data_type}_scatter3d_{Xname}_{Yname}_{Zname}.npy")
data = np.load(f"wedap/tests/data/plot_{data_type}_{plot_mode}_{Xname}_{Yname}_{Zname}.npy")
#np.testing.assert_allclose(plotdata, data)
# check to see if the amount of mismatches is less than 500 (<1% of ~1 million items)
assert data.size - np.count_nonzero(plotdata==data) < 500

0 comments on commit fae2616

Please sign in to comment.