Skip to content

Commit a809e72

Browse files
authored
Plot system transmission components (#894)
2 parents 4d3ce4c + 34431dd commit a809e72

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

scopesim/optics/optics_manager.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from collections.abc import Sequence
88

99
import numpy as np
10+
from matplotlib import pyplot as plt
11+
1012
from astropy import units as u
1113
from astropy.table import Table
1214
from synphot import SpectralElement, Empirical1D
@@ -253,20 +255,52 @@ def all_effects(self) -> list[efs.Effect]:
253255
"""Get all effects in all optical elements."""
254256
return [eff for opt_eff in self.optical_elements for eff in opt_eff]
255257

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+
"""
258268
wave_unit = u.Unit(from_currsys("!SIM.spectral.wave_unit", self.cmds))
259269
dwave = from_currsys("!SIM.spectral.spectral_bin_width", self.cmds)
260270
wave_min = from_currsys("!SIM.spectral.wave_min", self.cmds)
261271
wave_max = from_currsys("!SIM.spectral.wave_max", self.cmds)
262272
wave = np.arange(wave_min, wave_max, dwave)
263-
trans = np.ones_like(wave)
264273
sys_trans = SpectralElement(Empirical1D, points=wave*u.Unit(wave_unit),
265-
lookup_table=trans)
274+
lookup_table=np.ones_like(wave))
266275

267276
for effect in self.get_z_order_effects(100):
268277
sys_trans *= effect.throughput
269278

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+
270304
return sys_trans
271305

272306
@property

0 commit comments

Comments
 (0)