Skip to content

Commit 88d2ea2

Browse files
authored
correct misspelling in meta setter (#172)
1 parent b16380d commit 88d2ea2

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Smoke tests for SourceSpectra
3+
"""
4+
import numpy as np
5+
import pytest
6+
7+
import astropy.units as u
8+
9+
from sunkit_instruments.response import SourceSpectra
10+
11+
12+
@pytest.mark.parametrize(('density', 'meta'), [
13+
(None, None),
14+
(1e15*u.K/u.cm**3, None),
15+
(None, {'abundance_model': 'test'}),
16+
(1e15*u.K/u.cm**3, {'abundance_model': 'test'}),
17+
])
18+
def test_create_source_spectra(density, meta):
19+
temperature = np.logspace(4, 9, 100) * u.K
20+
wavelength = np.linspace(1, 1000, 50) * u.Angstrom
21+
if density is not None:
22+
density = density / temperature
23+
data_shape = temperature.shape + wavelength.shape
24+
data = np.random.rand(*data_shape) * u.Unit("photon cm3 s-1 sr-1 Angstrom-1")
25+
spec = SourceSpectra(
26+
temperature,
27+
wavelength,
28+
data,
29+
density=density,
30+
meta=meta,
31+
)
32+
assert isinstance(spec.meta, dict)
33+
assert isinstance(spec.data, u.Quantity)
34+
assert isinstance(spec.wavelength, u.Quantity)
35+
assert isinstance(spec.temperature, u.Quantity)
36+
if density is not None:
37+
assert isinstance(spec.density, u.Quantity)
38+
else:
39+
with pytest.raises(ValueError, match="No density data available."):
40+
spec.density

sunkit_instruments/response/thermal.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def meta(self, x):
108108
if x is None:
109109
self._meta = {}
110110
elif isinstance(x, dict):
111-
self._mata = x
111+
self._meta = x
112112
else:
113113
raise TypeError(f'Unsupported metadata type {type(x)}')
114114

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

125+
@property
126+
@u.quantity_input
127+
def density(self) -> u.cm**(-3):
128+
if "density" in self._da.coords:
129+
return u.Quantity(self._da.density.data, self._da.density.attrs["unit"])
130+
else:
131+
raise ValueError("No density data available.")
132+
125133
@property
126134
@u.quantity_input
127135
def data(self) -> u.photon * u.cm**3 / (u.s * u.Angstrom * u.steradian):

0 commit comments

Comments
 (0)