Commit 2e96a710 authored by Médéric Boquien's avatar Médéric Boquien

It turns out that elevating 10 to some power is very slow. Because the...

It turns out that elevating 10 to some power is very slow. Because the attenuation curve will not change between two calls, we save its shape for the young and old ages rather than recomputing it every single time. This leads to a massive speedup.
parent 1962d770
......@@ -19,6 +19,7 @@
- The estimation of the physical properties is made a bit faster when all the models are valid. (Médéric Boquien)
- The access to the SED and module caches has been made faster and simpler. This results in a speedup of ~6% in the computation of the models. (Médéric Boquien)
- The models counter was a bottleneck when using many cores as updating it could stall other parallel processes. Now the internal counter is updated much less frequently. The speedup goes from between negligible (few cores) up to a factor of a few (many cores). The downside is the the updates on the screen may be a bit irregular. (Médéric Boquien)
- It turns out that elevating an array to some power is an especially slow operation in python. The `dustatt_calzleit` module has been optimised leading to a massive speed improvement. This speedup is especially large for models that do not include dust emission. (Médéric Boquien)
## 0.12.1 (2018-02-27)
### Fixed
......@@ -252,7 +252,7 @@ class CalzLeit(SedModule):
# We cannot compute the attenuation until we know the wavelengths. Yet,
# we reserve the object.
self.sel_attenuation = None
self.curve = {}
def process(self, sed):
"""Add the CCM dust attenuation to the SED.
......@@ -268,12 +268,12 @@ class CalzLeit(SedModule):
flux_noatt = {filt: sed.compute_fnu(filt) for filt in self.filter_list}
# Compute attenuation curve
if self.sel_attenuation is None:
self.sel_attenuation = a_vs_ebv(wavelength,
if len(self.curve) == 0:
sel_att = a_vs_ebv(wavelength, self.uv_bump_wavelength,
self.uv_bump_width, self.uv_bump_amplitude,
for age in ['young', 'old']:
self.curve[age] = 10 ** (-.4 * self.ebvs[age] * sel_att)
attenuation_total = 0.
contribs = [contrib for contrib in sed.contribution_names if
......@@ -281,9 +281,7 @@ class CalzLeit(SedModule):
for contrib in contribs:
age = contrib.split('.')[-1].split('_')[-1]
luminosity = sed.get_lumin_contribution(contrib)
attenuated_luminosity = (luminosity * 10. ** (self.ebvs[age] *
self.sel_attenuation / -2.5))
attenuation_spectrum = attenuated_luminosity - luminosity
attenuation_spectrum = luminosity * (self.curve[age] - 1.)
# We integrate the amount of luminosity attenuated (-1 because the
# spectrum is negative).
attenuation = -1. * np.trapz(attenuation_spectrum, wavelength)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment