Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions sunkit_instruments/response/tests/test_source_spectra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Smoke tests for SourceSpectra
"""
import numpy as np
import pytest

import astropy.units as u

from sunkit_instruments.response import SourceSpectra


@pytest.mark.parametrize(('density', 'meta'), [
(None, None),
(1e15*u.K/u.cm**3, None),
(None, {'abundance_model': 'test'}),
(1e15*u.K/u.cm**3, {'abundance_model': 'test'}),
])
def test_create_source_spectra(density, meta):
temperature = np.logspace(4, 9, 100) * u.K
wavelength = np.linspace(1, 1000, 50) * u.Angstrom
if density is not None:
density = density / temperature
data_shape = temperature.shape + wavelength.shape
data = np.random.rand(*data_shape) * u.Unit("photon cm3 s-1 sr-1 Angstrom-1")
spec = SourceSpectra(
temperature,
wavelength,
data,
density=density,
meta=meta,
)
assert isinstance(spec.meta, dict)
assert isinstance(spec.data, u.Quantity)
assert isinstance(spec.wavelength, u.Quantity)
assert isinstance(spec.temperature, u.Quantity)
if density is not None:
assert isinstance(spec.density, u.Quantity)
else:
with pytest.raises(ValueError, match="No density data available."):
spec.density
10 changes: 9 additions & 1 deletion sunkit_instruments/response/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def meta(self, x):
if x is None:
self._meta = {}
elif isinstance(x, dict):
self._mata = x
self._meta = x
else:
raise TypeError(f'Unsupported metadata type {type(x)}')

Expand All @@ -122,6 +122,14 @@ def temperature(self) -> u.K:
def wavelength(self) -> u.Angstrom:
return u.Quantity(self._da.wavelength.data, self._da.wavelength.attrs["unit"])

@property
@u.quantity_input
def density(self) -> u.cm**(-3):
if "density" in self._da.coords:
return u.Quantity(self._da.density.data, self._da.density.attrs["unit"])
else:
raise ValueError("No density data available.")

@property
@u.quantity_input
def data(self) -> u.photon * u.cm**3 / (u.s * u.Angstrom * u.steradian):
Expand Down