diff --git a/tardis/widgets/sdec_plot.py b/tardis/widgets/sdec_plot.py index f806f1d0303..5dc75e56ca8 100644 --- a/tardis/widgets/sdec_plot.py +++ b/tardis/widgets/sdec_plot.py @@ -441,7 +441,7 @@ def _calculate_plotting_data( [lower_lambda, upper_lambda] * u.AA distance : astropy.Quantity Distance used to calculate flux instead of luminosities in the plot. - Preferrably having units of cm. + It should have a length unit like m, Mpc, etc. Notes ----- @@ -502,7 +502,14 @@ def _calculate_plotting_data( if distance is None: self.lum_to_flux = 1 # so that this term will have no effect else: - self.lum_to_flux = 4.0 * np.pi * (distance.to("cm")) ** 2 + if distance <= 0: + raise ValueError( + "distance passed must be greater than 0. If you intended " + "to plot luminosities instead of flux, set distance=None " + "or don't specify distance parameter in the function call." + ) + else: + self.lum_to_flux = 4.0 * np.pi * (distance.to("cm")) ** 2 # Calculate luminosities to be shown in plot ( @@ -660,6 +667,7 @@ def _calculate_emission_luminosities(self, packets_mode, packet_wvl_range): group["nus"], bins=self.plot_frequency_bins, weights=group["energies"] + / self.lum_to_flux / self.data[packets_mode].time_of_simulation, ) @@ -736,6 +744,7 @@ def _calculate_absorption_luminosities( group["last_line_interaction_in_nu"], bins=self.plot_frequency_bins, weights=group["energies"] + / self.lum_to_flux / self.data[packets_mode].time_of_simulation, ) @@ -805,7 +814,7 @@ def generate_plot_mpl( [lower_lambda, upper_lambda] * u.AA. Default value is None distance : astropy.Quantity or None, optional Distance used to calculate flux instead of luminosities in the plot. - Preferrably having units of cm. Default value is None + It should have a length unit like m, Mpc, etc. Default value is None show_modeled_spectrum : bool, optional Whether to show modeled spectrum in SDEC Plot. Default value is True @@ -867,7 +876,7 @@ def generate_plot_mpl( self.ax.set_xlabel(r"Wavelength $[\AA]$", fontsize=12) if distance: # Set y-axis label for flux self.ax.set_ylabel( - r"$F_{\lambda}$ [erg/s/$\AA/cm^{2}$]", fontsize=12 + r"$F_{\lambda}$ [erg/s/cm^{2}/$\AA$]", fontsize=12 ) else: # Set y-axis label for luminosity self.ax.set_ylabel(r"$L_{\lambda}$ [erg/s/$\AA$]", fontsize=12) @@ -994,7 +1003,7 @@ def generate_plot_ply( [lower_lambda, upper_lambda] * u.AA. Default value is None distance : astropy.Quantity or None, optional Distance used to calculate flux instead of luminosities in the plot. - Preferrably having units of cm. Default value is None + It should have a length unit like m, Mpc, etc. Default value is None show_modeled_spectrum : bool, optional Whether to show modeled spectrum in SDEC Plot. Default value is True