Skip to content

Commit

Permalink
Observed Spectrum option for the matplotlib plot
Browse files Browse the repository at this point in the history
  • Loading branch information
atharva-2001 committed Jul 29, 2021
1 parent 65099eb commit aca7d56
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tardis/visualization/tools/sdec_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit aca7d56

Please sign in to comment.