-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
f4d42e8
to
6d1ab57
Compare
Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
@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. |
@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! |
28a94d5
to
fe5b5c1
Compare
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.
Unless objections are stated, I intend to merge this on 9/6
I am taking a look at this PR now. Apologies for the delay @yhkee0404! |
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.
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.
# 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') |
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.
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?
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.
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:
pvlib-python/pvlib/solarposition.py
Lines 448 to 452 in 524fa55
# times must be localized | |
if times.tz: | |
tzinfo = times.tz | |
else: | |
raise ValueError('times must be localized') |
pvlib-python/pvlib/solarposition.py
Lines 560 to 564 in 524fa55
# times must be localized | |
if times.tz: | |
tzinfo = times.tz | |
else: | |
raise ValueError('times must be localized') |
Co-authored-by: Kevin Anderson <kevin.anderso@gmail.com>
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. |
@yhkee0404 we should add a few tests to improve coverage. Let me know if you would like my help with that. |
@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? |
@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. |
Great! It seems calling |
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.
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 :)
Thank you for your thorough review and suggestion that clarifies this PR in more datail👍! |
Thanks again @yhkee0404 for finding, investigating, and fixing this complex issue! |
docs/sphinx/source/reference
for API changes.docs/sphinx/source/whatsnew
for all changes. Includes link to the GitHub Issue with:issue:`num`
or this Pull Request with:pull:`num`
. Includes contributor name and/or GitHub username (link with:ghuser:`user`
).remote-data
) and Milestone are assigned to the Pull Request and linked Issue.A similar solution as #333