def test_clearness_index(): ghi = np.array([-1, 0, 1, 1000]) solar_zenith = np.array([180, 90, 89.999, 0]) ghi, solar_zenith = np.meshgrid(ghi, solar_zenith) # default min_cos_zenith out = irradiance.clearness_index(ghi, solar_zenith, 1370) # np.set_printoptions(precision=3, floatmode='maxprec', suppress=True) expected = np.array( [[0. , 0. , 0.011, 2. ], [0. , 0. , 0.011, 2. ], [0. , 0. , 0.011, 2. ], [0. , 0. , 0.001, 0.73 ]]) assert_allclose(out, expected, atol=0.001) # specify min_cos_zenith with np.errstate(invalid='ignore', divide='ignore'): out = irradiance.clearness_index(ghi, solar_zenith, 1400, min_cos_zenith=0) expected = np.array( [[0. , nan, 2. , 2. ], [0. , 0. , 2. , 2. ], [0. , 0. , 2. , 2. ], [0. , 0. , 0.001, 0.714]]) assert_allclose(out, expected, atol=0.001) # specify max_clearness_index out = irradiance.clearness_index(ghi, solar_zenith, 1370, max_clearness_index=0.82) expected = np.array( [[ 0. , 0. , 0.011, 0.82 ], [ 0. , 0. , 0.011, 0.82 ], [ 0. , 0. , 0.011, 0.82 ], [ 0. , 0. , 0.001, 0.73 ]]) assert_allclose(out, expected, atol=0.001) # specify min_cos_zenith and max_clearness_index with np.errstate(invalid='ignore', divide='ignore'): out = irradiance.clearness_index(ghi, solar_zenith, 1400, min_cos_zenith=0, max_clearness_index=0.82) expected = np.array( [[ 0. , nan, 0.82 , 0.82 ], [ 0. , 0. , 0.82 , 0.82 ], [ 0. , 0. , 0.82 , 0.82 ], [ 0. , 0. , 0.001, 0.714]]) assert_allclose(out, expected, atol=0.001) # scalars out = irradiance.clearness_index(1000, 10, 1400) expected = 0.725 assert_allclose(out, expected, atol=0.001) # series times = pd.DatetimeIndex(start='20180601', periods=2, freq='12H') ghi = pd.Series([0, 1000], index=times) solar_zenith = pd.Series([90, 0], index=times) extra_radiation = pd.Series([1360, 1400], index=times) out = irradiance.clearness_index(ghi, solar_zenith, extra_radiation) expected = pd.Series([0, 0.714285714286], index=times) assert_series_equal(out, expected)
def test_clearness_index(): ghi = np.array([-1, 0, 1, 1000]) solar_zenith = np.array([180, 90, 89.999, 0]) ghi, solar_zenith = np.meshgrid(ghi, solar_zenith) # default min_cos_zenith out = irradiance.clearness_index(ghi, solar_zenith, 1370) # np.set_printoptions(precision=3, floatmode='maxprec', suppress=True) expected = np.array( [[0. , 0. , 0.011, 2. ], [0. , 0. , 0.011, 2. ], [0. , 0. , 0.011, 2. ], [0. , 0. , 0.001, 0.73 ]]) assert_allclose(out, expected, atol=0.001) # specify min_cos_zenith with np.errstate(invalid='ignore', divide='ignore'): out = irradiance.clearness_index(ghi, solar_zenith, 1400, min_cos_zenith=0) expected = np.array( [[0. , nan, 2. , 2. ], [0. , 0. , 2. , 2. ], [0. , 0. , 2. , 2. ], [0. , 0. , 0.001, 0.714]]) assert_allclose(out, expected, atol=0.001) # specify max_clearness_index out = irradiance.clearness_index(ghi, solar_zenith, 1370, max_clearness_index=0.82) expected = np.array( [[ 0. , 0. , 0.011, 0.82 ], [ 0. , 0. , 0.011, 0.82 ], [ 0. , 0. , 0.011, 0.82 ], [ 0. , 0. , 0.001, 0.73 ]]) assert_allclose(out, expected, atol=0.001) # specify min_cos_zenith and max_clearness_index with np.errstate(invalid='ignore', divide='ignore'): out = irradiance.clearness_index(ghi, solar_zenith, 1400, min_cos_zenith=0, max_clearness_index=0.82) expected = np.array( [[ 0. , nan, 0.82 , 0.82 ], [ 0. , 0. , 0.82 , 0.82 ], [ 0. , 0. , 0.82 , 0.82 ], [ 0. , 0. , 0.001, 0.714]]) assert_allclose(out, expected, atol=0.001) # scalars out = irradiance.clearness_index(1000, 10, 1400) expected = 0.725 assert_allclose(out, expected, atol=0.001) # series times = pd.DatetimeIndex(start='20180601', periods=2, freq='12H') ghi = pd.Series([0, 1000], index=times) solar_zenith = pd.Series([90, 0], index=times) extra_radiation = pd.Series([1360, 1400], index=times) out = irradiance.clearness_index(ghi, solar_zenith, extra_radiation) expected = pd.Series([0, 0.714285714286], index=times) assert_series_equal(out, expected)