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

Perform dayofyear-based calculations according to UTC, not local time #2055

Open
wants to merge 55 commits into
base: main
Choose a base branch
from

Conversation

yhkee0404
Copy link

@yhkee0404 yhkee0404 commented May 19, 2024

A similar solution as #333

@yhkee0404 yhkee0404 marked this pull request as ready for review May 19, 2024 22:33
@yhkee0404 yhkee0404 changed the title Clearsky timezone Fix tz-naive linke_turbidity and dni_extra to be tz-aware May 19, 2024
@yhkee0404 yhkee0404 closed this May 26, 2024
@yhkee0404 yhkee0404 deleted the clearsky-timezone branch May 26, 2024 02:53
@yhkee0404 yhkee0404 restored the clearsky-timezone branch May 26, 2024 03:17
pvlib/clearsky.py Outdated Show resolved Hide resolved
pvlib/irradiance.py Outdated Show resolved Hide resolved
docs/sphinx/source/whatsnew/v0.11.0.rst Outdated Show resolved Hide resolved
pvlib/tests/test_irradiance.py Outdated Show resolved Hide resolved
pvlib/tests/test_irradiance.py Outdated Show resolved Hide resolved
pvlib/tools.py Show resolved Hide resolved
pvlib/tools.py Show resolved Hide resolved
pvlib/tools.py Outdated Show resolved Hide resolved
Co-authored-by: Cliff Hansen <[email protected]>
@yhkee0404 yhkee0404 closed this Jun 5, 2024
@cwhanse
Copy link
Member

cwhanse commented Jun 5, 2024

@yhkee0404 did you close this intentionally? If you aren't able to complete the PR, let us know and one of us could take it from here.

@yhkee0404
Copy link
Author

yhkee0404 commented Jun 5, 2024

@cwhanse Oh, sorry for confusion. I was in the midst of my struggle with the problem and was going to reopen it after several hours. Thank you for your suggestions! Now I think it is better to keep it open. Any help would be welcome!

Copy link
Member

@cwhanse cwhanse left a comment

Choose a reason for hiding this comment

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

Unless objections are stated, I intend to merge this on 9/6

@kandersolar
Copy link
Member

I am taking a look at this PR now. Apologies for the delay @yhkee0404!

Copy link
Member

@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.

Thanks @yhkee0404 for this thorough PR! I have a few questions below that I hope you can help me understand.

I also think the title of this PR should be edited to reflect the broader scope of the changes.

benchmarks/benchmarks/solarposition.py Outdated Show resolved Hide resolved
pvlib/iotools/solrad.py Outdated Show resolved Hide resolved
Comment on lines +1385 to -1391
# times must be localized
if not times.tz:
raise ValueError('times must be localized')

# hours - timezone = (times - normalized_times) - (naive_times - times)
if times.tz is None:
times = times.tz_localize('utc')
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I agree with this change. The docstring says the input timestamps "must be localized to the timezone for the longitude", which is inconsistent with the previous behavior (localize to UTC if not already localized), so I can see some change being needed here. But why is this the correct change?

Copy link
Author

@yhkee0404 yhkee0404 Sep 6, 2024

Choose a reason for hiding this comment

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

It was added in accordance with sun_rise_set_transit_spa and sun_rise_set_transit_ephem as well as the docstring. I agree with the previous convention of raising a ValueError since it prevents users from unwittingly calling the functions naively without assuming any timezones and ignoring the fact that an hour angle is counted up from zero at noon in a predefined local timezone. Please refer to the followings:

# times must be localized
if times.tz:
tzinfo = times.tz
else:
raise ValueError('times must be localized')

# times must be localized
if times.tz:
tzinfo = times.tz
else:
raise ValueError('times must be localized')

pvlib/tests/test_solarposition.py Show resolved Hide resolved
@yhkee0404
Copy link
Author

yhkee0404 commented Sep 6, 2024

Many thanks to @cwhanse for leading this PR into the right way, and @kandersolar for taking time for a further reconciliation from other aspects! Please feel free to fix or revert any including the title or whatsnew with your excellent ideas.

@cwhanse
Copy link
Member

cwhanse commented Sep 11, 2024

@yhkee0404 we should add a few tests to improve coverage. Let me know if you would like my help with that.

@yhkee0404
Copy link
Author

yhkee0404 commented Sep 12, 2024

@cwhanse I have just made some patchs to improve coverage but I am not sure they would work. I would really appreciate if you could please help me. This is my first time to work with Codecov. Is there a way to see the difference locally on my own, or should I just wait for your manual approval for codecov workflow?

@cwhanse
Copy link
Member

cwhanse commented Sep 12, 2024

@yhkee0404 the additional tests are good enough. I don't see why codecov is flagging that one line. Like you I don't know how to run codecov locally, and just let the CI do it for me.

@yhkee0404
Copy link
Author

yhkee0404 commented Sep 13, 2024

Great! It seems calling solarposition.spa_c in test_spa_c_physical and test_spa_c_physical_dst on pvlib/tests/test_solarposition.py both fail on Codecov because of lack of spa_c_files which makes these lines fail accordingly: from pvlib.spa_c_files.spa_py import spa_calc, has_spa_c and requires_spa_c. It is different from the case of other libraries like ephem and numba since both has_ephem and has_numba are True on Codecov while has_spa_c() is evaluated as False: https://app.codecov.io/gh/pvlib/pvlib-python/pull/1944/blob/pvlib/tests/conftest.py#L136 In another word, to test spa_c which is not imported, we should install it on Codecov somehow like this direction: https://pvlib-python.readthedocs.io/en/stable/user_guide/installation.html?highlight=spa_c_files#nrel-spa-algorithm

Copy link
Member

@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.

I believe I have finally understood this PR. It it looks correct to me. I have only a couple revisions to the what's new text to fully communicate the changes.

In another word, to test spa_c which is not imported, we should install it on Codecov somehow like this direction

Unfortunately, licensing reasons prevent us from testing the spa_c code in CI. Any coverage issues related to spa_c should be ignored :)

docs/sphinx/source/whatsnew/v0.11.1.rst Outdated Show resolved Hide resolved
docs/sphinx/source/whatsnew/v0.11.1.rst Outdated Show resolved Hide resolved
@kandersolar kandersolar changed the title Fix tz-naive linke_turbidity and dni_extra to be tz-aware Perform dayofyear-based calculations according to UTC, not local time Sep 17, 2024
@yhkee0404
Copy link
Author

Thank you for your thorough review and suggestion that clarifies this PR in more datail👍!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clearsky functions handling tz-aware datetimes as tz-naive, contrary to user guide
4 participants