- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.1k
 
          Allow delta_t to be array in SPA functions
          #2190
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
745eb0f
              4ae9c48
              a26e83f
              57755ac
              d5e1026
              cc4a8af
              3d14954
              56646a6
              1044ec7
              bcb70d9
              36d705d
              6ee8a7c
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -139,7 +139,7 @@ | |
| assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) | ||
| 
     | 
||
| 
     | 
||
| @pytest.mark.parametrize('delta_t', [65.0, None]) | ||
| @pytest.mark.parametrize('delta_t', [65.0, None, np.array([65, 65])]) | ||
| def test_sun_rise_set_transit_spa(expected_rise_set_spa, golden, delta_t): | ||
| # solution from NREL SAP web calculator | ||
| south = Location(-35.0, 0.0, tz='UTC') | ||
| 
          
            
          
           | 
    @@ -478,14 +478,14 @@ | |
| 
     | 
||
| 
     | 
||
| @pytest.mark.parametrize("delta_t, method", [ | ||
| (None, 'nrel_numpy'), | ||
| pytest.param( | ||
| None, 'nrel_numba', | ||
| marks=[pytest.mark.xfail( | ||
| reason='spa.calculate_deltat not implemented for numba yet')]), | ||
| (None, 'nrel_numba'), | ||
| (67.0, 'nrel_numba'), | ||
| (np.array([67.0, 67.0]), 'nrel_numba'), | ||
| # minimize reloads, with numpy being last | ||
| (None, 'nrel_numpy'), | ||
| (67.0, 'nrel_numpy'), | ||
| ]) | ||
| (np.array([67.0, 67.0]), 'nrel_numpy'), | ||
| ]) | ||
| def test_get_solarposition_deltat(delta_t, method, expected_solpos_multi, | ||
| golden): | ||
| times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), | ||
| 
          
            
          
           | 
    @@ -530,7 +530,7 @@ | |
| assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) | ||
| 
     | 
||
| 
     | 
||
| @pytest.mark.parametrize('delta_t', [64.0, None]) | ||
| @pytest.mark.parametrize('delta_t', [64.0, None, np.array([64, 64])]) | ||
| def test_nrel_earthsun_distance(delta_t): | ||
| times = pd.DatetimeIndex([datetime.datetime(2015, 1, 2), | ||
| datetime.datetime(2015, 8, 2)] | ||
| 
        
          
        
         | 
    @@ -540,11 +540,12 @@ | |
| index=times) | ||
| assert_series_equal(expected, result) | ||
| 
     | 
||
| times = datetime.datetime(2015, 1, 2) | ||
| result = solarposition.nrel_earthsun_distance(times, delta_t=delta_t) | ||
| expected = pd.Series(np.array([0.983289204601]), | ||
| index=pd.DatetimeIndex([times, ])) | ||
| assert_series_equal(expected, result) | ||
| if np.size(delta_t) == 1: # skip the array delta_t | ||
| times = datetime.datetime(2015, 1, 2) | ||
| result = solarposition.nrel_earthsun_distance(times, delta_t=delta_t) | ||
| expected = pd.Series(np.array([0.983289204601]), | ||
| index=pd.DatetimeIndex([times, ])) | ||
| assert_series_equal(expected, result) | ||
| 
     | 
||
| 
     | 
||
| def test_equation_of_time(): | ||
| 
          
            
          
           | 
    @@ -770,14 +771,14 @@ | |
| 
     | 
||
| 
     | 
||
| @requires_pandas_2_0 | ||
| @pytest.mark.parametrize('tz', [None, 'utc', 'US/Eastern']) | ||
| @pytest.mark.parametrize('method', [ | ||
| 'nrel_numpy', | ||
| 'ephemeris', | ||
| pytest.param('pyephem', marks=requires_ephem), | ||
| pytest.param('nrel_numba', marks=requires_numba), | ||
| pytest.param('nrel_c', marks=requires_spa_c), | ||
| ]) | ||
| @pytest.mark.parametrize('tz', [None, 'utc', 'US/Eastern']) | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This order change was so that all the numba tests run in sequence; the previous ordering interleaved numpy & numba calls, causing unnecessary reloading of   | 
||
| def test_get_solarposition_microsecond_index(method, tz): | ||
| # https://github.com/pvlib/pvlib-python/issues/1932 | ||
| 
     | 
||
| 
        
          
        
         | 
    @@ -786,8 +787,12 @@ | |
| index_ns = pd.date_range(unit='ns', **kwargs) | ||
| index_us = pd.date_range(unit='us', **kwargs) | ||
| 
     | 
||
| sp_ns = solarposition.get_solarposition(index_ns, 40, -80, method=method) | ||
| sp_us = solarposition.get_solarposition(index_us, 40, -80, method=method) | ||
| with warnings.catch_warnings(): | ||
| # don't warn on method reload | ||
| warnings.simplefilter("ignore") | ||
| 
         
      Comment on lines
    
      -790
     to 
      +807
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is not directly related; just a tweak to suppress nuisance reloading warnings  | 
||
| 
     | 
||
| sp_ns = solarposition.get_solarposition(index_ns, 40, -80, method=method) | ||
| sp_us = solarposition.get_solarposition(index_us, 40, -80, method=method) | ||
| 
     | 
||
| assert_frame_equal(sp_ns, sp_us, check_index_type=False) | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whereas
delta_tused to be a scalar that could live inloc_args, now it is a time-varying value (same length asunixtime) and thus requires a separate array input. So a new parameter is needed, andloc_argsshrinks by one.