|
| 1 | +import os |
| 2 | +import sys |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import numpy as np |
| 6 | + |
| 7 | +from geophires_x.Model import Model |
| 8 | +from tests.base_test_case import BaseTestCase |
| 9 | + |
| 10 | + |
| 11 | +class SurfacePlantTestCase(BaseTestCase): |
| 12 | + |
| 13 | + def test_integrate_time_series_slice_1_time_step_per_year(self): |
| 14 | + self._workaround_module_initialization_order_dependency() |
| 15 | + from geophires_x.SurfacePlant import SurfacePlant |
| 16 | + |
| 17 | + time_steps_per_year = 1 |
| 18 | + utilization_factor = 0.9 |
| 19 | + |
| 20 | + def _integrate_slice(series: np.ndarray, _i: int) -> np.float64: |
| 21 | + return SurfacePlant.integrate_time_series_slice(series, _i, time_steps_per_year, utilization_factor) |
| 22 | + |
| 23 | + plant_lifetime = 20 |
| 24 | + ElectricityProduced = [ |
| 25 | + 456.1403991563267, |
| 26 | + 456.1403991563267, |
| 27 | + 456.9435504549861, |
| 28 | + 457.36358815671883, |
| 29 | + 457.6422257879382, |
| 30 | + 457.8482065397373, |
| 31 | + 458.01033644148254, |
| 32 | + 458.1433031993208, |
| 33 | + 458.2555647922617, |
| 34 | + 458.35241646970593, |
| 35 | + 458.4373827710431, |
| 36 | + 458.51292228292505, |
| 37 | + 458.58081486894883, |
| 38 | + 458.6423884476247, |
| 39 | + 458.69865878571187, |
| 40 | + 458.7504193786508, |
| 41 | + 458.7983013143066, |
| 42 | + 458.84281435825204, |
| 43 | + 458.8843758887934, |
| 44 | + 458.9233317382275, |
| 45 | + ] |
| 46 | + |
| 47 | + NetElectricityProduced = [ |
| 48 | + 402.39393233698496, |
| 49 | + 402.39393233698496, |
| 50 | + 403.2023017770401, |
| 51 | + 403.6250678276089, |
| 52 | + 403.9055150923539, |
| 53 | + 404.11283347253067, |
| 54 | + 404.2760161602529, |
| 55 | + 404.40984628330665, |
| 56 | + 404.52283676542146, |
| 57 | + 404.6203172528295, |
| 58 | + 404.70583517837395, |
| 59 | + 404.78186509759365, |
| 60 | + 404.8501984341015, |
| 61 | + 404.9121717307827, |
| 62 | + 404.9688073512418, |
| 63 | + 405.020903944086, |
| 64 | + 405.0690966955198, |
| 65 | + 405.11389868149865, |
| 66 | + 405.15572999069246, |
| 67 | + 405.19493870111074, |
| 68 | + ] |
| 69 | + |
| 70 | + TotalkWhProduced = np.zeros(plant_lifetime) |
| 71 | + NetkWhProduced = np.zeros(plant_lifetime) |
| 72 | + for i in range(plant_lifetime): |
| 73 | + TotalkWhProduced[i] = _integrate_slice(ElectricityProduced, i) |
| 74 | + NetkWhProduced[i] = _integrate_slice(NetElectricityProduced, i) |
| 75 | + |
| 76 | + self.assertEqual(TotalkWhProduced[-1], ElectricityProduced[-1]) |
| 77 | + |
| 78 | + def _workaround_module_initialization_order_dependency(self) -> Model: |
| 79 | + stash_cwd = Path.cwd() |
| 80 | + stash_sys_argv = sys.argv |
| 81 | + |
| 82 | + sys.argv = [''] |
| 83 | + |
| 84 | + m = Model(enable_geophires_logging_config=False) |
| 85 | + |
| 86 | + sys.argv = stash_sys_argv |
| 87 | + os.chdir(stash_cwd) |
| 88 | + |
| 89 | + return m |
0 commit comments