Skip to content

nirwals.physics.spectrum

Functions for generating the source and sky background spectra.

normalize(spectrum, magnitude)

Normalize a source spectrum to have given Johnson J magnitude.

The waveset property must be defined for the given source spectrum.

Parameters:

Name Type Description Default
spectrum SourceSpectrum

The source spectrum to normalize.

required
magnitude float

The magnitude the normalized spectrum should have.

required

Returns:

Type Description
SourceSpectrum

The normalized spectrum.

Source code in nirwals/physics/spectrum.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def normalize(spectrum: SourceSpectrum, magnitude: float) -> SourceSpectrum:
    """
    Normalize a source spectrum to have given Johnson J magnitude.

    The `waveset` property must be defined for the given source spectrum.

    Parameters
    ----------
    spectrum : SourceSpectrum
        The source spectrum to normalize.
    magnitude : float
        The magnitude the normalized spectrum should have.

    Returns
    -------
    SourceSpectrum
        The normalized spectrum.
    """
    # Get the total non-normalised flux in the J band.
    J = SpectralElement.from_filter("johnson_j")
    F = (J * spectrum).integrate(flux_unit=units.FLAM)

    # Get the total (normalised) flux for the given magnitude.
    F_m = 10 ** (-0.4 * magnitude) * ZERO_MAGNITUDE_FLUX

    # Normalise the spectrum.
    normalisation_factor = float(F_m / F)
    return normalisation_factor * spectrum

sky_spectrum()

Return the sky background.

The background is assumed to include any atmospheric extinction already, i.e, it is the flux received at the telescope.

Returns:

Type Description
SourceSpectrum

The sky background, as received at the telescope.

Source code in nirwals/physics/spectrum.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
def sky_spectrum() -> SourceSpectrum:
    """
    Return the sky background.

    The background is assumed to include any atmospheric extinction already, i.e, it is
    the flux received at the telescope.

    Returns
    -------
    SourceSpectrum
        The sky background, as received at the telescope.
    """
    path = pathlib.Path(get_file_base_dir() / "nirsky.npz")
    with open(path, "rb") as f:
        wavelengths, fluxes = read_from_file(f, units.PHOTLAM)

    return SourceSpectrum(Empirical1D, points=wavelengths, lookup_table=fluxes)

source_spectrum(configuration)

Return the source spectrum for a given configuration.

Parameters:

Name Type Description Default
configuration Configuration

The configuration.

required

Returns:

Type Description
SourceSpectrum

The source spectrum.

Source code in nirwals/physics/spectrum.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def source_spectrum(configuration: Configuration) -> SourceSpectrum:
    """
    Return the source spectrum for a given configuration.

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

    Returns
    -------
    SourceSpectrum
        The source spectrum.
    """
    if configuration.source is None:
        raise ValueError("Source missing in configuration")

    summed_spectrum = SourceSpectrum(ConstFlux1D, amplitude=0 * units.PHOTLAM)
    for s in configuration.source.spectrum:
        summed_spectrum += _spectrum(s)

    return summed_spectrum