Skip to content

Commit 322caf5

Browse files
authored
Merge pull request #4 from AssessingSolar/add-mad-error-metric
Add mean absolute difference error metric
2 parents 476bb0c + f4ad0d8 commit 322caf5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/solposx/tools.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Collection of utility functions."""
22

33
import pvlib
4+
import numpy as np
45

56

67
def _pandas_to_utc(pd_object):
@@ -39,7 +40,7 @@ def _fractional_hour(times):
3940
4041
Returns
4142
-------
42-
fraction of hour
43+
fraction_of_hour : pd.Index
4344
"""
4445
hour = (times.hour + (
4546
times.minute + (times.second + times.microsecond*1e-6)/60)/60)
@@ -48,39 +49,44 @@ def _fractional_hour(times):
4849

4950
def calc_error(zenith_1, azimuth_1, zenith_2, azimuth_2):
5051
"""
51-
Calculate angular difference metrics between two solar positions.
52+
Calculate angular difference metrics between two sets of solar positions.
5253
5354
Parameters
5455
----------
5556
zenith_1, zenith_2 : array-like
56-
Zenith angles for the two solar positions. [degrees]
57+
Zenith angles for the two sets of solar positions. [degrees]
5758
azimuth_1, azimuth_2 : array-like
58-
Azimuth angles for the two solar positions. [degrees]
59+
Azimuth angles for the two sets of solar position. [degrees]
5960
6061
Returns
6162
-------
6263
out : dict
6364
Dict with keys:
6465
6566
* zenith_bias, azimuth_bias: average (signed) difference in zenith/azimuth
67+
* zenith_mad, azimuth_mad: mean absolute difference in zenith/azimuth
6668
* zenith_rmsd, azimuth_rmsd: root-mean-squared difference in zenith/azimuth
6769
* combined_rmse: total angular root-mean-squared difference in position
6870
"""
6971
zenith_diff = zenith_1 - zenith_2
7072
zenith_bias = zenith_diff.mean()
73+
zenith_mad = np.abs(zenith_diff).mean()
7174
zenith_rmsd = (zenith_diff**2).mean()**0.5
7275

7376
azimuth_diff = (azimuth_1 - azimuth_2 + 180) % 360 - 180 # handle 0/360 correctly
7477
azimuth_bias = azimuth_diff.mean()
78+
azimuth_mad = np.abs(azimuth_diff).mean()
7579
azimuth_rmsd = (azimuth_diff**2).mean()**0.5
7680

7781
aoi = pvlib.irradiance.aoi(zenith_1, azimuth_1, zenith_2, azimuth_2)
7882
combined_rmsd = (aoi**2).mean()**0.5
7983

8084
out = {
8185
'zenith_bias': zenith_bias,
86+
'zenith_mad': zenith_mad,
8287
'zenith_rmsd': zenith_rmsd,
8388
'azimuth_bias': azimuth_bias,
89+
'azimuth_mad': azimuth_mad,
8490
'azimuth_rmsd': azimuth_rmsd,
8591
'combined_rmsd': combined_rmsd,
8692
}

tests/test_tools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ def expected_calc_error():
3939
N = 10
4040
out = {
4141
'zenith_bias': np.zeros(N),
42+
'zenith_mad': np.zeros(N),
4243
'zenith_rmsd': np.zeros(N),
4344
'azimuth_bias': np.zeros(N),
45+
'azimuth_mad': np.zeros(N),
4446
'azimuth_rmsd': np.zeros(N),
4547
'combined_rmsd': np.zeros(N),
4648
}
@@ -52,3 +54,4 @@ def test_calc_error(expected_calc_error):
5254
result = calc_error(zeros, zeros, zeros, zeros)
5355
for k in expected_calc_error.keys():
5456
np.testing.assert_equal(result[k], expected_calc_error[k])
57+
assert len(result.keys()) == len(expected_calc_error.keys())

0 commit comments

Comments
 (0)