Coverage for pyrc \ core \ wall.py: 61%

36 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-13 16:59 +0200

1# ------------------------------------------------------------------------------- 

2# Copyright (C) 2026 Joel Kimmich, Tim Jourdan 

3# ------------------------------------------------------------------------------ 

4# License 

5# This file is part of PyRC, distributed under GPL-3.0-or-later. 

6# ------------------------------------------------------------------------------ 

7 

8from copy import copy 

9 

10import numpy as np 

11import pandas as pd 

12from pvlib import solarposition 

13 

14 

15class Wall: 

16 def __init__(self, azimuth_deg=180, location: tuple = (53.0123, 7.0123), tilt_deg=90, sight_factor_sky=None): 

17 """ 

18 

19 Parameters 

20 ---------- 

21 azimuth_deg : float 

22 Wall azimuth angle in degrees (0 = north, 90 = east, 180 = south, ...). 

23 location : tuple 

24 Latitude and longitude of the location in degrees. 

25 tilt_deg : float 

26 Tilt angle of the wall from horizontal in degrees (90 = vertical, 0 = flat). 

27 sight_factor_sky : float, optional 

28 The sight factor to the atmosphere (sky). 

29 If None, it is calculated. 

30 """ 

31 self.azimuth = np.radians(azimuth_deg) 

32 self.location = location 

33 self.tilt = np.radians(tilt_deg) 

34 

35 if sight_factor_sky is None: 

36 sight_factor_sky = 0.5 * (1 + np.cos(self.tilt)) 

37 self.sight_factor_sky = sight_factor_sky 

38 

39 def calculate_sight_factor_sky(self): 

40 self.sight_factor_sky = 0.5 * (1 + np.cos(self.tilt)) 

41 

42 def __copy__(self): 

43 return Wall( 

44 azimuth_deg=np.degrees(self.azimuth), 

45 location=copy(self.location), 

46 tilt_deg=np.degrees(self.tilt), 

47 sight_factor_sky=self.sight_factor_sky, 

48 ) 

49 

50 def __deepcopy__(self): 

51 return self.__copy__() 

52 

53 @property 

54 def latitude(self): 

55 return self.location[0] 

56 

57 @property 

58 def longitude(self): 

59 return self.location[1] 

60 

61 def apply_direct_radiation(self, values: np.ndarray, dates: np.ndarray) -> np.ndarray: 

62 """ 

63 Changes horizontal values to actual values. 

64 

65 Parameters 

66 ---------- 

67 values : np.ndarray 

68 The values of the direct solar radiation measures on a horizontal plane. 

69 dates : np.ndarray 

70 The date times of the values. 

71 

72 Returns 

73 ------- 

74 np.ndarray : 

75 The values of the direct solar radiation measures on the wall. 

76 """ 

77 times = pd.DatetimeIndex(dates) 

78 solpos = solarposition.get_solarposition(times, self.latitude, self.longitude) 

79 

80 zenith = np.radians(solpos["zenith"].values) 

81 azimuth = np.radians(solpos["azimuth"].values) 

82 

83 cos_theta = np.cos(zenith) * np.cos(self.tilt) + np.sin(zenith) * np.sin(self.tilt) * np.cos( 

84 azimuth - self.azimuth 

85 ) 

86 cos_theta = np.maximum(0, cos_theta) 

87 

88 return values * cos_theta 

89 

90 def apply_sky_radiation(self, values: np.ndarray) -> np.ndarray: 

91 """ 

92 Like apply_direct_radiation but applies radiation to the sky. 

93 

94 Parameters 

95 ---------- 

96 values : np.ndarray 

97 The values of the diffuse solar radiation measures on a horizontal plane. 

98 dates : np.ndarray 

99 The date times of the values. 

100 

101 Returns 

102 ------- 

103 np.ndarray : 

104 The values of the diffuse solar radiation measures on the wall reduced by the sight factor of the wall. 

105 """ 

106 return self.sight_factor_sky * values 

107 

108 def apply_ground_radiation(self, values: np.ndarray) -> np.ndarray: 

109 """ 

110 Like apply_direct_radiation but applies radiation to the ground. 

111 

112 Parameters 

113 ---------- 

114 values : np.ndarray 

115 The values of the diffuse solar radiation measures on a horizontal plane. 

116 dates : np.ndarray 

117 The date times of the values. 

118 

119 Returns 

120 ------- 

121 np.ndarray : 

122 The values of the diffuse solar radiation measures on the wall reduced by the sight factor of the wall. 

123 """ 

124 return (1 - self.sight_factor_sky) * values