|
7 | 7 | from collections.abc import Sequence |
8 | 8 |
|
9 | 9 | import numpy as np |
| 10 | +from matplotlib import pyplot as plt |
| 11 | + |
10 | 12 | from astropy import units as u |
11 | 13 | from astropy.table import Table |
12 | 14 | from synphot import SpectralElement, Empirical1D |
@@ -253,20 +255,52 @@ def all_effects(self) -> list[efs.Effect]: |
253 | 255 | """Get all effects in all optical elements.""" |
254 | 256 | return [eff for opt_eff in self.optical_elements for eff in opt_eff] |
255 | 257 |
|
256 | | - @property |
257 | | - def system_transmission(self): |
| 258 | + def system_transmission(self, plot=False): |
| 259 | + """Compute system transmission |
| 260 | +
|
| 261 | + The method computes the total system transmission and returns it as a |
| 262 | + ``synphot.spectrum.SpectralElement``. |
| 263 | +
|
| 264 | + When ``plot`` is ``True``, it creates a plot of the transmission |
| 265 | + curves of the indivdual elements in the system as well as the system |
| 266 | + transmission. |
| 267 | + """ |
258 | 268 | wave_unit = u.Unit(from_currsys("!SIM.spectral.wave_unit", self.cmds)) |
259 | 269 | dwave = from_currsys("!SIM.spectral.spectral_bin_width", self.cmds) |
260 | 270 | wave_min = from_currsys("!SIM.spectral.wave_min", self.cmds) |
261 | 271 | wave_max = from_currsys("!SIM.spectral.wave_max", self.cmds) |
262 | 272 | wave = np.arange(wave_min, wave_max, dwave) |
263 | | - trans = np.ones_like(wave) |
264 | 273 | sys_trans = SpectralElement(Empirical1D, points=wave*u.Unit(wave_unit), |
265 | | - lookup_table=trans) |
| 274 | + lookup_table=np.ones_like(wave)) |
266 | 275 |
|
267 | 276 | for effect in self.get_z_order_effects(100): |
268 | 277 | sys_trans *= effect.throughput |
269 | 278 |
|
| 279 | + if plot: |
| 280 | + # only plot range where sys_trans is larger than zero |
| 281 | + wave <<= wave_unit |
| 282 | + transval = sys_trans(wave).value |
| 283 | + wmin = np.min(wave[transval > 0.01]) |
| 284 | + wmax = np.max(wave[transval > 0.01]) |
| 285 | + wmin = wmin - 0.1 * (wmax - wmin) |
| 286 | + wmax = wmax + 0.1 * (wmax - wmin) |
| 287 | + wave = wave[(wave > wmin) * (wave < wmax)] |
| 288 | + |
| 289 | + _, ax = plt.subplots() |
| 290 | + for effect in self.get_z_order_effects(100): |
| 291 | + lw, alpha = 2, 1 |
| 292 | + if isinstance(effect, efs.SkycalcTERCurve): |
| 293 | + lw, alpha = 1, 0.5 |
| 294 | + ax.plot(wave, effect.throughput(wave), lw=lw, alpha=alpha, |
| 295 | + label=effect.display_name) |
| 296 | + ax.plot(wave, sys_trans(wave), lw=2, color="black", |
| 297 | + label="System transmission") |
| 298 | + ax.legend(bbox_to_anchor=(0.5, 1.02), fancybox=True, |
| 299 | + loc="lower center", ncol=2) |
| 300 | + ax.set_xlabel("Wavelength [um]") |
| 301 | + ax.set_ylabel("Transmission") |
| 302 | + plt.show() |
| 303 | + |
270 | 304 | return sys_trans |
271 | 305 |
|
272 | 306 | @property |
|
0 commit comments