Skip to content

Commit 8b2b7ca

Browse files
committed
complete tests
1 parent 82598ec commit 8b2b7ca

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

tests/spectrum/test_mismatch.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,66 @@ def test_spectral_factor_polo(module_type, expected):
324324
out = spectrum.spectral_factor_polo(
325325
pws, ams, aods, aois, pressure, module_type=module_type, albedo=alb)
326326
np.testing.assert_allclose(out, expected, atol=1e-6)
327+
328+
329+
@pytest.fixture
330+
def polo_inputs():
331+
return {'precipitable_water': 0.96,
332+
'airmass_absolute': 1.34,
333+
'aod500': 0.085,
334+
'aoi': 76,
335+
'pressure': 101400,
336+
'albedo': 0.2}
337+
338+
339+
def test_spectral_factor_polo_coefficients(polo_inputs):
340+
# test that supplying custom coefficients works as expected
341+
coefficients = (
342+
(0.0027, 10.34, 9.48, 0.31, 0.00077, 0.006) # base Si coeffs
343+
+ (0, -0.003, 1.0) # Si albedo correction coeffs
344+
)
345+
out = spectrum.spectral_factor_polo(**polo_inputs,
346+
coefficients=coefficients)
347+
np.testing.assert_allclose(out, 0.969588, atol=1e-6)
348+
349+
350+
def test_spectral_factor_polo_errors(polo_inputs):
351+
with pytest.raises(ValueError, match='Must provide either'):
352+
spectrum.spectral_factor_polo(**polo_inputs)
353+
with pytest.raises(ValueError, match='Only one of'):
354+
spectrum.spectral_factor_polo(**polo_inputs, module_type='CdTe',
355+
coefficients=(1, 1, 1, 1, 1, 1))
356+
357+
358+
def test_spectral_factor_polo_types(polo_inputs):
359+
# float:
360+
out = spectrum.spectral_factor_polo(**polo_inputs, module_type='monosi')
361+
assert isinstance(out, float)
362+
np.testing.assert_allclose(out, 0.969588, atol=1e-6)
363+
364+
# array:
365+
arrays = {k: np.array([v, v]) for k, v in polo_inputs.items()}
366+
out = spectrum.spectral_factor_polo(**arrays, module_type='monosi')
367+
assert isinstance(out, np.ndarray)
368+
np.testing.assert_allclose(out, [0.969588]*2, atol=1e-6)
369+
370+
# series:
371+
series = {k: pd.Series(v) for k, v in arrays.items()}
372+
out = spectrum.spectral_factor_polo(**series, module_type='monosi')
373+
assert isinstance(out, pd.Series)
374+
pd.testing.assert_series_equal(out, pd.Series([0.969588]*2), atol=1e-6)
375+
376+
377+
def test_spectral_factor_polo_NaN(polo_inputs):
378+
# nan in -> nan out
379+
for key in polo_inputs:
380+
inputs = polo_inputs.copy()
381+
inputs[key] = np.nan
382+
out = spectrum.spectral_factor_polo(**inputs, module_type='monosi')
383+
assert np.isnan(out)
384+
385+
386+
def test_spectral_factor_polo_aoi_gt_90(polo_inputs):
387+
polo_inputs['aoi'] = 95
388+
out = spectrum.spectral_factor_polo(**polo_inputs, module_type='monosi')
389+
assert np.isnan(out)

0 commit comments

Comments
 (0)