Skip to content

nirwals.physics.bandpass

Functions related to throughput calculations.

atmospheric_transmission(zenith_distance)

Return the atmospheric transmission curve for a given zenith distance.

Parameters:

Name Type Description Default
zenith_distance deg

Zenith distance.

required

Returns:

Type Description
SpectralElement

The transmission curve.

Source code in nirwals/physics/bandpass.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@u.quantity_input
def atmospheric_transmission(zenith_distance: u.deg) -> SpectralElement:
    """
    Return the atmospheric transmission curve for a given zenith distance.
    Parameters
    ----------
    zenith_distance: Angle
        Zenith distance.

    Returns
    -------
    SpectralElement
        The transmission curve.
    """
    # Get the extinction coefficients.
    path = pathlib.Path(get_file_base_dir() / "atmospheric_extinction_coefficients.npz")
    with open(path, "rb") as f:
        wavelengths, kappa_values = read_from_file(f)

    # Calculate the transmission values.
    sec_z = 1 / math.cos(zenith_distance.to(u.rad).value)
    transmissions = np.power(10, -0.4 * kappa_values * sec_z)

    # Return the extinction.
    return SpectralElement(Empirical1D, points=wavelengths, lookup_table=transmissions)

detector_quantum_efficiency()

Return the quantum efficiency of the detector.

Returns:

Type Description
SpectralElement

The quantum efficiency.

Source code in nirwals/physics/bandpass.py
50
51
52
53
54
55
56
57
58
59
60
61
62
def detector_quantum_efficiency() -> SpectralElement:
    """
    Return the quantum efficiency of the detector.

    Returns
    -------
    SpectralElement
        The quantum efficiency.
    """
    path = pathlib.Path(get_file_base_dir() / "detector_quantum_efficiency.npz")
    with open(path, "rb") as f:
        wavelengths, efficiencies = read_from_file(f)
    return SpectralElement(Empirical1D, points=wavelengths, lookup_table=efficiencies)

fibre_throughput(seeing, source_extension, zenith_distance)

Return the fibre throughput.

For a point source the throughput is the fraction of the flux in the seeing disk which is covered by the fibre, assuming the source is located at the centre of the fibre. The seeing disk includes atmospheric and telescope seeing.

For a diffuse source the throughput is 1, as losses and gains due to seeing cancel.

Parameters:

Name Type Description Default
seeing arcsec

The full width half maximum of the seeing disk for a zenith distance of 0.

required
source_extension SourceExtension

The source extension ("Point" or "Diffuse"O).

required
zenith_distance deg

The zenith distance of the source.

required

Returns:

Type Description
SpectralElement

The fibre throughput.

Source code in nirwals/physics/bandpass.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
@u.quantity_input
def fibre_throughput(
    seeing: u.arcsec, source_extension: SourceExtension, zenith_distance: u.deg
) -> SpectralElement:
    """
    Return the fibre throughput.

    For a point source the throughput is the fraction of the flux in the seeing disk
    which is covered by the fibre, assuming the source is located at the centre of the
    fibre. The seeing disk includes atmospheric and telescope seeing.

    For a diffuse source the throughput is 1, as losses and gains due to seeing cancel.

    Parameters
    ----------
    seeing: Angle
        The full width half maximum of the seeing disk for a zenith distance of 0.
    source_extension: SourceExtension
        The source extension ("Point" or "Diffuse"O).
    zenith_distance: Angle
        The zenith distance of the source.

    Returns
    -------
    SpectralElement
        The fibre throughput.
    """
    # Sanity check
    if source_extension not in get_args(SourceExtension):
        raise ValueError(f"Unsupported source extension {source_extension}")

    # There is no throughput loss for diffuse sources.
    if source_extension == "Diffuse":
        return SpectralElement(ConstFlux1D, amplitude=1)

    # Get the standard deviation for atmospheric seeing.
    sec_z = 1 / math.cos(zenith_distance.to(u.rad).value)
    sigma_atm = seeing * sec_z ** (3 / 5) / (2 * math.sqrt(2 * math.log(2)))

    # Get the standard deviation for the telescope seeing.
    sigma_tel = TELESCOPE_SEEING / (2 * math.sqrt(2 * math.log(2)))

    # Get the square of the total standard deviation for the seeing disk
    sigma_squared = sigma_atm**2 + sigma_tel**2

    # Calculate the fraction of the seeing disk flux covered by the fibre.
    covered_fraction = 1 - math.exp(-(FIBRE_RADIUS**2) / (2 * sigma_squared))

    # Return the throughput.
    return SpectralElement(ConstFlux1D, amplitude=covered_fraction)

filter_transmission(filter_name)

Return the transmission curve for a given filter.

Parameters:

Name Type Description Default
filter_name Filter

Filter name.

required

Returns:

Type Description
SpectralElement

The filter transmission curve.

Source code in nirwals/physics/bandpass.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def filter_transmission(filter_name: Filter) -> SpectralElement:
    """
    Return the transmission curve for a given filter.
    Parameters
    ----------
    filter_name: Filter
        Filter name.

    Returns
    -------
    SpectralElement
        The filter transmission curve.
    """
    # Sanity check
    match filter_name:
        case "clear-filter":
            filename = "clear_filter_transmission.npz"
        case "lwbf":
            filename = "lwbf_transmission.npz"
        case _:
            raise ValueError(f"Unsupported filter: {filter_name}")

    # Get the filter transmission.
    path = pathlib.Path(get_file_base_dir() / "filters" / filename)
    with open(path, "rb") as f:
        wavelengths, transmissions = read_from_file(f)
    return SpectralElement(Empirical1D, points=wavelengths, lookup_table=transmissions)

grating_efficiency(grating_angle, grating_name)

Returns the grating efficiency for a given grating angle.

The grating angle is the angle between the incoming light rays and the grating normal.

Parameters:

Name Type Description Default
grating_angle deg

Grating angle.

required
grating_name GratingName

Grating name. This is equal to the grating frequency, i.e. grooves per mm.

required

Returns:

Type Description
SpectralElement

The grating efficiency.

Source code in nirwals/physics/bandpass.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
@u.quantity_input
def grating_efficiency(
    grating_angle: u.deg, grating_name: GratingName
) -> SpectralElement:
    """
    Returns the grating efficiency for a given grating angle.

    The grating angle is the angle between the incoming light rays and the grating
    normal.

    Parameters
    ----------
    grating_angle: Angle
        Grating angle.
    grating_name: GratingName
        Grating name. This is equal to the grating frequency, i.e. grooves per mm.

    Returns
    -------
    SpectralElement
        The grating efficiency.

    """

    import numpy as np

    # Grating angles for which a grating efficiency file exists and the wavelengths for
    # the maxima of the corresponding grating efficiency curves.
    grating_parameters = [
        (30 * u.deg, 10795.6 * u.AA),
        (35 * u.deg, 12081.6 * u.AA),
        (40 * u.deg, 13400.4 * u.AA),
        (45 * u.deg, 14700.0 * u.AA),
        (50 * u.deg, 15907.2 * u.AA),
    ]
    angles = [gp[0] for gp in grating_parameters]
    maxima = {gp[0]: gp[1] for gp in grating_parameters}

    # Avoid rounding issues.
    eps = 0.000001
    if angles[0] - eps * u.deg < grating_angle < angles[0] + eps * u.deg:
        grating_angle = angles[0] + eps * u.deg
    if angles[-1] - eps * u.deg < grating_angle < angles[-1] + eps * u.deg:
        grating_angle = angles[-1] - eps * u.deg

    # Find the smallest interval [alpha1, alpha2] in angles with
    # alpha1 <= alpha <= alpha2.
    if angles[0] > grating_angle or grating_angle > angles[-1]:
        raise ValueError(
            f"Only grating angles between {angles[0]} and {angles[1]} are "
            f"supported."
        )
    alpha1 = max([a for a in angles if a <= grating_angle])
    alpha2 = min([a for a in angles if grating_angle < a])

    # Figure out whether to shift the efficiency curve for alpha1 to the right or the
    # curve for alpha2 to the left.
    if grating_angle <= (alpha1 + alpha2) / 2:
        angle = alpha1
        shift_to_right = True
    else:
        angle = alpha2
        shift_to_right = False

    # Get the efficiency curve to shift.
    angle_value = round(angle.to(u.deg).value)
    path = pathlib.Path(
        get_file_base_dir()
        / "gratings"
        / grating_name
        / f"grating_{grating_name}_{angle_value}deg.npz"
    )
    with open(path, "rb") as f:
        wavelengths_, efficiencies_ = read_from_file(f)
    efficiency = SpectralElement(
        Empirical1D, points=wavelengths_, lookup_table=efficiencies_
    )

    # Perform the shift
    lmax1 = maxima[alpha1]
    lmax2 = maxima[alpha2]
    if shift_to_right:
        shift = -((grating_angle - alpha1) / (alpha2 - alpha1)) * (lmax2 - lmax1)
    else:
        shift = ((alpha2 - grating_angle) / (alpha2 - alpha1)) * (lmax2 - lmax1)
    wavelengths = np.arange(4000, 22000, 0.2) * u.AA
    shifted_wavelengths = wavelengths + shift
    shifted_efficiencies = efficiency(shifted_wavelengths)

    # Return the grating efficiency.
    return SpectralElement(
        Empirical1D, points=wavelengths, lookup_table=shifted_efficiencies
    )

telescope_throughput()

Return the telescope throughput.

The telescope throughput includes the mirror efficiency and the throughput of the telescope optics, but excludes the filter transmission, grating efficiency and detector efficiency.

Returns:

Type Description
SpectralElement

The telescope throughput.

Source code in nirwals/physics/bandpass.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
def telescope_throughput() -> SpectralElement:
    """
    Return the telescope throughput.

    The telescope throughput includes the mirror efficiency and the throughput of the
    telescope optics, but excludes the filter transmission, grating efficiency and
    detector efficiency.

    Returns
    -------
    SpectralElement
        The telescope throughput.
    """
    path = pathlib.Path(get_file_base_dir() / "telescope_throughput.npz")
    with open(path, "rb") as f:
        wavelengths, throughputs = read_from_file(f)
    # Apply a throughput fudge factor, as suggested in
    # Encarni's email from 14 June 2024
    # The throughput fudge factor has beed update as per meeting held on the 8th May 2025 to be 0.75
    # see meeting minutes for more details
    throughputs *= 0.75
    return SpectralElement(Empirical1D, points=wavelengths, lookup_table=throughputs)

throughput(configuration)

Calculate the throughput for a given configuration.

The throughput includes the following:

  • The atmospheric transmission
  • The mirror efficiency
  • The fibre throughput
  • The filter transmission
  • The grating efficiency
  • The detector quantum efficiency

Parameters:

Name Type Description Default
configuration Configuration

The configuration.

required

Returns:

Type Description
SpectralElement

The throughput.

Source code in nirwals/physics/bandpass.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
def throughput(configuration: Configuration) -> SpectralElement:
    """
    Calculate the throughput for a given configuration.

    The throughput includes the following:

    - The atmospheric transmission
    - The mirror efficiency
    - The fibre throughput
    - The filter transmission
    - The grating efficiency
    - The detector quantum efficiency

    Parameters
    ----------
    configuration: Configuration
        The configuration.

    Returns
    -------
    SpectralElement
        The throughput.
    """
    grating = cast(Grating, configuration.telescope.grating)
    configuration_source = cast(Source, configuration.source)
    bandpass = (
        atmospheric_transmission(zenith_distance=configuration.zenith_distance)
        * telescope_throughput()
        * fibre_throughput(
            seeing=configuration.seeing,
            source_extension=configuration_source.extension,
            zenith_distance=configuration.zenith_distance,
        )
        * filter_transmission(filter_name=cast(Filter, configuration.telescope.filter))
        * grating_efficiency(
            grating_angle=grating.grating_angle,
            grating_name=grating.name,
        )
        * detector_quantum_efficiency()
    )

    return bandpass