-
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a helper class PlotW7 for comparison plots.
- Loading branch information
Karan Desai
committed
May 24, 2016
1 parent
e743801
commit 4be6db9
Showing
2 changed files
with
44 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
class PlotW7: | ||
""" | ||
A helper class to TestW7 for creating comparison plots. | ||
""" | ||
|
||
def __init__(self, obtained, reference): | ||
self.obtained = obtained | ||
self.reference = reference | ||
|
||
def plot_luminosity_density_lambda(self, passed): | ||
spectrum_fig = plt.figure() | ||
spectrum_fig.suptitle("Deviation in spectrum quantities", fontweight="bold") | ||
|
||
# `ldl_` prefixed variables associated with `luminosity_density_lambda`. | ||
ldl_axes = spectrum_fig.add_subplot(111) | ||
ldl_axes.set_title("Deviation in luminosity_density_lambda") | ||
ldl_axes.set_xlabel("N-th packet") | ||
ldl_axes.set_ylabel("Relative error (1 - obtained / baseline)") | ||
deviation = 1 - ( | ||
self.obtained.spectrum.luminosity_density_lambda.value / | ||
self.reference['luminosity_density_lambda'].value) | ||
|
||
if passed: | ||
ldl_axes.text(0.9, 0.9, 'PASSED', transform=ldl_axes.transAxes, | ||
bbox={'facecolor': 'green', 'alpha': 0.5, 'pad': 10}) | ||
ldl_axes.plot(deviation, "g+") | ||
else: | ||
ldl_axes.set_yscale("log") | ||
ldl_axes.text(0.9, 0.9, 'FAILED', transform=ldl_axes.transAxes, | ||
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 10}) | ||
ldl_axes.plot(deviation, "rx") | ||
|
||
# Figure is saved in `tmp` directory of slow tests baseline data. | ||
plt.savefig(os.path.join("/tmp", "spectrum_plot.png")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters