From aca7d56f0767d1d5f87629551349cfb704fe3912 Mon Sep 17 00:00:00 2001 From: Atharva Arya Date: Thu, 29 Jul 2021 19:06:23 +0530 Subject: [PATCH] Observed Spectrum option for the matplotlib plot --- tardis/visualization/tools/sdec_plot.py | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tardis/visualization/tools/sdec_plot.py b/tardis/visualization/tools/sdec_plot.py index 6c9d1dc5868..d14b3bb71a8 100644 --- a/tardis/visualization/tools/sdec_plot.py +++ b/tardis/visualization/tools/sdec_plot.py @@ -1082,6 +1082,7 @@ def generate_plot_mpl( packets_mode="virtual", packet_wvl_range=None, distance=None, + observed_spectrum=None, show_modeled_spectrum=True, ax=None, figsize=(12, 7), @@ -1105,6 +1106,8 @@ def generate_plot_mpl( distance : astropy.Quantity or None, optional Distance used to calculate flux instead of luminosity in the plot. It should have a length unit like m, Mpc, etc. Default value is None + observed_spectrum : tuple or list of two astropy quantities, optional + Option to plot the observed spectrum. show_modeled_spectrum : bool, optional Whether to show modeled spectrum in SDEC Plot. Default value is True @@ -1178,6 +1181,33 @@ def generate_plot_mpl( linewidth=1, ) + # Plot observed spectrum + if observed_spectrum: + observed_spectrum_wavelength = None + observed_spectrum_luminosity = None + + if ( + type(observed_spectrum[0]) is u.quantity.Quantity + and type(observed_spectrum[1]) is u.quantity.Quantity + ): + # If the observed spectrum is a list of quantities, then convert to wavelength and luminosity units + observed_spectrum_wavelength = observed_spectrum[0].to(u.AA) + observed_spectrum_luminosity = observed_spectrum[1].to( + u.erg / (u.s) + ) + + else: + raise ValueError( + "Both wavelength and luminosity should be astropy quantities." + ) + self.ax.plot( + observed_spectrum_wavelength, + observed_spectrum_luminosity, + linestyle="--", + label="Observed Spectrum", + linewidth=1, + ) + # Plot photosphere self.ax.plot( self.plot_wavelength,