1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
# Copyright (c) 2013, 2014, 2015, 2016, 2018 Adam.Dybbroe |
5
|
|
|
|
6
|
|
|
# Author(s): |
7
|
|
|
|
8
|
|
|
# Adam.Dybbroe <[email protected]> |
9
|
|
|
|
10
|
|
|
# This program is free software: you can redistribute it and/or modify |
11
|
|
|
# it under the terms of the GNU General Public License as published by |
12
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
# (at your option) any later version. |
14
|
|
|
|
15
|
|
|
# This program is distributed in the hope that it will be useful, |
16
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
# GNU General Public License for more details. |
19
|
|
|
|
20
|
|
|
# You should have received a copy of the GNU General Public License |
21
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
|
23
|
|
|
"""Unit testing the solar_flux calculations""" |
24
|
|
|
|
25
|
|
|
from pyspectral.solar import (SolarIrradianceSpectrum, |
26
|
|
|
TOTAL_IRRADIANCE_SPECTRUM_2000ASTM) |
27
|
|
|
|
28
|
|
|
import os |
29
|
|
|
import unittest |
30
|
|
|
import numpy as np |
31
|
|
|
|
32
|
|
|
TEST_RSR = {} |
33
|
|
|
TEST_RSR['det-1'] = {} |
34
|
|
|
TEST_RSR['det-1']['wavelength'] = np.array([ |
35
|
|
|
3.6123999, 3.6163599, 3.6264927, 3.6363862, 3.646468, |
36
|
|
|
3.6564937, 3.6664478, 3.6765388, 3.6865413, 3.6964585, |
37
|
|
|
3.7065142, 3.716509, 3.7264658, 3.7364102, 3.7463682, |
38
|
|
|
3.7563652, 3.7664226, 3.7763396, 3.7863384, 3.7964207, |
39
|
|
|
3.8063589, 3.8163606, 3.8264089, 3.8364836, 3.8463381, |
40
|
|
|
3.8563975, 3.8664163, 3.8763755, 3.8864797, 3.8964978, |
41
|
|
|
3.9064275, 3.9164873, 3.9264729, 3.9364026, 3.9465107, |
42
|
|
|
3.9535347], dtype='double') |
43
|
|
|
|
44
|
|
|
TEST_RSR['det-1']['response'] = np.array([ |
45
|
|
|
0.01, 0.0118, 0.01987, 0.03226, 0.05028, 0.0849, |
46
|
|
|
0.16645, 0.33792, 0.59106, 0.81815, 0.96077, 0.92855, |
47
|
|
|
0.86008, 0.8661, 0.87697, 0.85412, 0.88922, 0.9541, |
48
|
|
|
0.95687, 0.91037, 0.91058, 0.94256, 0.94719, 0.94808, |
49
|
|
|
1., 0.92676, 0.67429, 0.44715, 0.27762, 0.14852, |
50
|
|
|
0.07141, 0.04151, 0.02925, 0.02085, 0.01414, 0.01], dtype='double') |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
RESULT_IPOL_WVLS = np.array([0.2, 0.201, 0.202, 0.203, 0.204, 0.205, 0.206, 0.207, 0.208, |
54
|
|
|
0.209, 0.21, 0.211, 0.212, 0.213, 0.214, 0.215, 0.216, 0.217, |
55
|
|
|
0.218, 0.219, 0.22, 0.221, 0.222, 0.223, 0.224, 0.225, 0.226, |
56
|
|
|
0.227, 0.228, 0.229, 0.23, 0.231, 0.232, 0.233, 0.234, 0.235, |
57
|
|
|
0.236, 0.237, 0.238, 0.239, 0.24], dtype='double') |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
class TestSolarflux(unittest.TestCase): |
61
|
|
|
|
62
|
|
|
"""Unit testing the solar flux calculations""" |
63
|
|
|
|
64
|
|
|
def setUp(self): |
65
|
|
|
"""Set up""" |
66
|
|
|
self.solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, |
67
|
|
|
dlambda=0.005) |
68
|
|
|
self.rsr = TEST_RSR |
69
|
|
|
return |
70
|
|
|
|
71
|
|
|
def test_read(self): |
72
|
|
|
"""Test that solar irradiance spctrum""" |
73
|
|
|
self.assertTrue(os.path.exists(self.solar_irr.filename)) |
74
|
|
|
self.assertEqual(self.solar_irr.wavelength.shape[0], 1697) |
75
|
|
|
self.assertEqual(self.solar_irr.irradiance.shape[0], 1697) |
76
|
|
|
|
77
|
|
|
def test_solar_flux(self): |
78
|
|
|
"""Calculate the solar-flux""" |
79
|
|
|
|
80
|
|
|
# rsr function (se above) is given in micronsm therefore the scale |
81
|
|
|
# factor is 1.0 and not 1e+6 (default)! |
82
|
|
|
sflux = self.solar_irr.inband_solarflux(self.rsr, scale=1.0) |
83
|
|
|
self.assertAlmostEqual(sflux, 2.002927627) |
84
|
|
|
# self.assertAlmostEqual(sflux, 2.5) |
85
|
|
|
|
86
|
|
|
def test_interpolate(self): |
87
|
|
|
"""Test the interpolate method""" |
88
|
|
|
self.solar_irr.interpolate(dlambda=0.001, ival_wavelength=(0.200, 0.240)) |
89
|
|
|
self.assertTrue(np.allclose(RESULT_IPOL_WVLS, self.solar_irr.ipol_wavelength)) |
90
|
|
|
|
91
|
|
|
def tearDown(self): |
92
|
|
|
"""Clean up""" |
93
|
|
|
return |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
def suite(): |
97
|
|
|
"""The suite for test_solarflux.""" |
98
|
|
|
loader = unittest.TestLoader() |
99
|
|
|
mysuite = unittest.TestSuite() |
100
|
|
|
mysuite.addTest(loader.loadTestsFromTestCase(TestSolarflux)) |
101
|
|
|
|
102
|
|
|
return mysuite |
103
|
|
|
|