Skip to content

Commit

Permalink
Cosmetic improvements in plot_spectrum method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Desai committed May 24, 2016
1 parent fa303e6 commit 39fc5f4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tardis/tests/tests_slow/test_w7.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from numpy.testing import assert_allclose
from astropy.tests.helper import assert_quantity_allclose

import tardis
from tardis.atomic import AtomData
from tardis.simulation.base import Simulation
from tardis.model import Radial1DModel
Expand Down Expand Up @@ -128,12 +127,12 @@ def test_spectrum(self):
self.reference['luminosity_density_lambda'],
self.result.spectrum.luminosity_density_lambda)

self.plot_spectrum(passed=True)
self.plot_spectrum(has_passed=True)
except Exception as e:
self.plot_spectrum(passed=False)
self.plot_spectrum(has_passed=False)
raise e

def plot_spectrum(self, passed):
def plot_spectrum(self, has_passed):
plt.suptitle("Deviation in spectrum_quantities", fontweight="bold")

# `ldl_` prefixed variables associated with `luminosity_density_lambda`.
Expand All @@ -142,19 +141,21 @@ def plot_spectrum(self, passed):
ldl_ax = plt.subplot(111)
ldl_ax.set_title("Deviation in luminosity_density_lambda")
ldl_ax.set_xlabel("Wavelength")
ldl_ax.set_ylabel("Relative error (1 - obtained / baseline)")
ldl_ax.set_ylabel("Relative error (1 - result / reference)")
deviation = 1 - (
self.result.spectrum.luminosity_density_lambda.value /
self.reference['luminosity_density_lambda'].value)

if passed:
if has_passed:
ldl_ax.text(0.8, 0.8, 'passed', transform=ldl_ax.transAxes,
bbox={'facecolor': 'green', 'alpha': 0.5, 'pad': 10})
ldl_ax.plot(self.reference['wavelength'], deviation, "g+")
ldl_ax.plot(self.reference['wavelength'], deviation,
color="green", marker=".")
else:
ldl_ax.text(0.8, 0.8, 'failed', transform=ldl_ax.transAxes,
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 10})
ldl_ax.plot(self.reference['wavelength'], deviation, "rx")
ldl_ax.plot(self.reference['wavelength'], deviation,
color="red", marker=".")

# Figure is saved in `tmp` directory right now, till a suitable way of
# saving them is decided.
Expand Down

0 comments on commit 39fc5f4

Please sign in to comment.