Skip to content
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

Allow delta_t to be array in SPA functions #2190

Merged
merged 12 commits into from
Sep 26, 2024

Conversation

kandersolar
Copy link
Member

@kandersolar kandersolar commented Aug 28, 2024

See #2189. Additional tests are needed before this is ready for detailed review.

@kandersolar kandersolar mentioned this pull request Sep 24, 2024
11 tasks
@kandersolar kandersolar added this to the v0.11.1 milestone Sep 24, 2024
@kandersolar kandersolar marked this pull request as ready for review September 24, 2024 19:28
Copy link
Member Author

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for review. The coverage complaints are the usual numba issue; they can be ignored.

A brief explanation: the complexity here is to accommodate numba. With the numpy calculations, duck typing means both scalar and array delta_t are fine. But with numba, we have to pick a single dtype. This PR makes delta_t always an array (forcing scalars to arrays if needed) so that the numba code can deal with arrays only.

Technically this change will increase memory use, but my informal benchmarking found no noticeable slowdown. Considering what a computational beast the SPA is, I'm not surprised that one extra array doesn't make any measurable difference.

def solar_position_loop(unixtime, loc_args, out):
@jcompile('void(float64[:], float64[:], float64[:], float64[:,:])',
nopython=True, nogil=True)
def solar_position_loop(unixtime, delta_t, loc_args, out):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whereas delta_t used to be a scalar that could live in loc_args, now it is a time-varying value (same length as unixtime) and thus requires a separate array input. So a new parameter is needed, and loc_args shrinks by one.

@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'])
Copy link
Member Author

Choose a reason for hiding this comment

The 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 pvlib.spa.

Comment on lines -790 to +792
sp_us = solarposition.get_solarposition(index_us, 40, -80, method=method)
with warnings.catch_warnings():
# don't warn on method reload
warnings.simplefilter("ignore")
Copy link
Member Author

Choose a reason for hiding this comment

The 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

pvlib/spa.py Outdated Show resolved Hide resolved
@AdamRJensen
Copy link
Member

A better test instead of [65, 65] would be to have an array input with different values, e.g., [65, 66].

@AdamRJensen
Copy link
Member

@kandersolar Thanks for the test update. I'll merge this tomorrow before the next release unless I hear any objections.

@AdamRJensen AdamRJensen merged commit 5803ce3 into pvlib:main Sep 26, 2024
28 of 30 checks passed
@kandersolar kandersolar deleted the spa-scalars branch September 26, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

solarposition.spa_python does not accept arrays for delta_t parameter
2 participants