Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed distance parameter not producing accurate SDEC plots #1442

Merged
merged 4 commits into from
Feb 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions tardis/widgets/sdec_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down Expand Up @@ -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

jaladh-singhal marked this conversation as resolved.
Show resolved Hide resolved
# Calculate luminosities to be shown in plot
(
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
jaladh-singhal marked this conversation as resolved.
Show resolved Hide resolved
else: # Set y-axis label for luminosity
self.ax.set_ylabel(r"$L_{\lambda}$ [erg/s/$\AA$]", fontsize=12)
Expand Down Expand Up @@ -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
Expand Down