-
Notifications
You must be signed in to change notification settings - Fork 1.1k
BUG: ENH: update spa_files to patch timezone bug #576
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
BUG: ENH: update spa_files to patch timezone bug #576
Conversation
* closes pvlib#168 * get source and header in setup.py * replace "timezone" with "timezone" to fix the bug * also update readme * also remove a lot of extra whitespace and tabs Signed-off-by: Mark Mikofski <[email protected]>
pvlib/spa_c_files/README.md
Outdated
** Due to licensing issues, the [SPA C files](http://www.nrel.gov/midc/spa) can | ||
_not_ be included in the pvlib-python distribution. The SPA C files will be | ||
downloaded when you build the Python extension. By using this module you agree | ||
to the NREL license in SPA_NOTICE. ** |
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 concerned about adding this feature. Can we really say this and wash our hands of the license issue? I would be surprised. I'd believe we're in the clear if we pulled the license text, printed it, and waited for the user to input y
.
Also not clear to me how this is supposed to work (or not work) with the spa related code in the root setup.py
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.
(by this feature I mean the auto-download capability)
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 concerned about adding this feature. Can we really say this and wash our hands of the license issue? I would be surprised.
but the LICENSED code is not being distributed with pvlib, so I don't see the concern?
I'd believe we're in the clear if we pulled the license text, printed it, and waited for the user to input
y
.
I guess we can do that
Also not clear to me how this is supposed to work (or not work) with the spa related code in the root
setup.py
AFAIK there's no difference, everything is exactly the same way it was before. The user has to follow the instructions in the README. If they want to use the SPA C-files, then they need to somehow enter this folder and run
python setup.py build_ext --inplace
it's the only way to build it, and by doing this act, then implicitly agree to the license. If they don't want to use the SPA C-files they do nothing. AFAIK the rest of pvlib still works exactly the way it always did, what's different?
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.
but the LICENSED code is not being distributed with pvlib, so I don't see the concern?
Maybe. But I don't want NREL to think "Holmgren, Mikofski, and the rest of those ^&*( pvlib-ers snaked their way around our license."
If we support automatic download, I'd also want a user to be required to input the form information rather than it being supplied as "pvlib-python" etc. NREL is presumably asking for this information from each user in order to justify funding to DOE. Putting a placeholder there doesn't seem right, regardless of whether we agree with NREL's strategy here or not.
AFAIK there's no difference, everything is exactly the same way it was before.
The root setup.py compiles the extension if the files were detected during a pip install .
or python setup.py
. Or at least it used to -- it's been years since I tried. Perhaps it's best to remove the capability of the root setup.py to do anything with this extension.
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.
great idea, okay, it now asks for users name, and sends that, if no name, then it fails with some ugly message which contains the contents of spa.c which says something like:
Name must be atleast 2 valid characters.
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 looks like the root setup.py
checks if the files are present so I think it will run okay.
It looks like the CI's had no problems building it either.
Also I just checked it on my PC, and it also works as expected:
- if no
spa.c
orspa.h
then you get this:WARNING: spa_c files not detected. See installation instructions for more information.
- if yes
spa.c
orspa.h
then it builds the extension.
* add enumeration for function type, it was reading garbage, so you never new exacton which calculations SPA was doing, and you would get garbage values for incidence, sunrise, transit, and sunset times * set function SPA_ALL, and pass extra args in as optional keyword args for slope, delta_ut1, azm_rotation, and atmos_refract * add example file that user can run to test build
pvlib/spa_c_files/README.md
Outdated
|
||
Download the ``spa.c`` and ``spa.h`` files from NREL, | ||
and copy them into the ``pvlib/spa_c_files`` directory. | ||
** Due to licensing issues, the [SPA C files](http://www.nrel.gov/midc/spa) can |
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.
http://www.nrel.gov/midc/spa forwards to https://midcdmz.nrel.gov/
looks like https://midcdmz.nrel.gov/spa/ is now the correct url
okay, the user is forced to see the license and push a key to install now, here's what they see:
Then they have to press a key to continue. ok? |
I'm not comfortable with the auto-download, I would be more comfortable with if we sought and received NREL's agreement that the auto-download satisfies their request for registration. I don't think we should merge until we have their approval. I suspect they will not be pleased with the I'd be happy to contact NREL about this. I appreciate and agree with the motivation to make the build convenient for users, especially with the |
@cwhanse sounds good , FYI: I changed it so the user has to enter their name now |
Thanks @mikofski. Can we do something similar for all of the fields? print('Enter the following to accept the NREL LICENSE:')
VALUES['name'] = input('Name: ')
VALUES['country'] = input('Country: ')
VALUES['company'] = input('Company: ')
VALUES['software'] = input('Software (enter pvlib-python if not bundling with another application): ') |
@wholmgren I responded to some of your comments that are hidden as outdata above I guess you saw them? |
@mikofski confused about your comment above about the CI building it -- I don't think it is. In any case, it didn't work for me:
|
no I didn't mean it's building the spa-c files, I meant it is building pvlib-python without the spa-c files, which I think is what we would expect, right? and it is consistently building pvlib-python everytime AFAICT
weird, same for me on linux, but seems to work on windows? is this a red herring? grrrrr |
@cwhanse @mikofski I support asking NREL if the latest interface meets their requirements. Here's what it looked like after I pulled @mikofski's latest changes that require the user to enter all information:
|
Great. Let's not add this to the CI. No clue about the platform/test issues. Sorry. |
It's "time_zone" now, not "timezone"! pdb to the rescue! |
pvlib/spa_c_files/setup.py
Outdated
REQ = request.Request(SPA_C_URL, DATA) | ||
with request.urlopen(REQ) as response: | ||
SPA_C = response.read() | ||
SPA_C = SPA_C.replace(b'timezone', b'time_zone') |
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.
you might consider a comment here about why you're doing this and also reference the github issue.
OK, works now in linux too, thanks for catching that! I
I thought this would be the minimum API change, assuming that no one ever calls
|
See this explanation from the cython users google group - evidently , only a windows issue, and only since Python-3.5, |
…r args and returns
I confirm that the tests pass on my mac on commit 162e712 Probably want to add I think the proposed API is fine. |
I should probably leave, so I slightly revert the changes, and added spa_py.c back in after accidently deleting it, you might have you check your tests again, but make sure to purge your build folders, I had to on linux, it passes for me. I just thought it was better to have a consistent in/out api for spa_calc, even tho timezone isn't used that much. |
Tests still pass. This seems sub-optimal but not a must fix:
|
I'm not a fan either, if rather drop the generated Cython, I can't think of a case where any user would use it |
I think that's only showing up on your machine after you build inplace and replace that |
My objection is when I build the package it modifies a file that git tracks, so now I have a file that shows up under "not staged for commit" in my local repo. If I used this regularly it would be a problem for me because I use |
Sorry, I misunderstood, yes the same annoying thing happens to me too. I vote to git remove it and then git ignore as you suggest. |
What do you think of the LGTM alerts? No big deal for this? |
* git rm spa_py.c to remove it from repo * add cython to option extra requires * use full paths in spa_c_files for sources * add line to bug fixes addressing pvlib#168
I thought about this, it's only a concern for Python-2, b/c in Python-3,
If we wanted we could just use python-future: or if we can't have six or future as requirements, then try something like this: # see if raw_input is defined
try:
raw_input():
except NameError:
# this is Python-3
raw_input = input six also renames, raw_input to input to be compatible with Python-3, which I don't know if it will satisfy LGTM. |
Anyway, if you get approval from NREL, I think this ready. Any need for a lot of what's new updates? thanks! |
@mikofski @wholmgren am trading emails with NREL will let you know if/when they approve. |
@mikofski thanks for detailed explanation of the input checks. I agree we should leave it as If you want to factor out the code that downloads the files from NREL then we can go ahead and merge. I don't view the iteration on the auto-download code as a waste of time because I think it's important that we can present to NREL a clear idea of how it would work. This PR is one part bug fix and another part new feature, so no problem splitting it up from that perspective. Or we can give it some time (hours/days/weeks/months/years?) to see what they say. Up to you. @cwhanse thanks for contacting NREL. |
OK, I agree, I'll factor out the download code. And BTW, it works fine in Python-2 Also FYI: the timezone Python bug is already being tracked here: Python bugs issue: 24643 |
I agree with the factoring at this point. |
BTW: refactoring out the autodownload removes the Anyway, OK now? |
Here's the old code for a future PR, with the |
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.
Looks good. I confirmed it works as expected. I needed to already have the spa.c
file manually downloaded from the website (no more auto-download). And the annoying git pollution is gone -- thanks Mark!
@cwhanse go ahead and merge if you approve.
pvlib/solarposition.py
Outdated
@@ -206,7 +206,7 @@ def spa_c(time, latitude, longitude, pressure=101325, altitude=0, | |||
spa_df = pd.DataFrame(spa_out, index=time) | |||
|
|||
if raw_spa_output: | |||
return spa_df | |||
return spa_df.rename(columns={'time_zone': 'timezone'}) |
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.
Add a comment explaining why this is done
pvlib/spa_c_files/setup.py
Outdated
# patch spa.c | ||
with open(os.path.join(DIRNAME, 'spa.c'), 'rb') as f: | ||
SPA_C = f.read() | ||
# replace timezone with time_zone to avoid a nameclash the function |
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.
with the function
Ready to go, except that I think a few inline comments would be wise to remind us why we change |
* explain that timezone is replaced with time_zone in spa_c docstring to avoid nameclash due to Python bug 24643 * explain why time_zone column renamed to timezone to match caller API
* that explains that we replace timezone with time_zone at build
pvlib/solarposition.py
Outdated
NREL SPA reference: http://rredc.nrel.gov/solar/codesandalgorithms/spa/ | ||
NREL SPA C files: https://midcdmz.nrel.gov/spa/ | ||
|
||
Note: The ``timezone`` field in the SPA C files is replaced with ``time_zone`` |
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.
E501 line too long (82 > 79 characters)
pvlib/solarposition.py
Outdated
|
||
Note: The ``timezone`` field in the SPA C files is replaced with ``time_zone`` | ||
to avoid a nameclash with the function ``__timezone`` that is redefined by | ||
Python>=3.5. This issue is `Python bug 24643 <https://bugs.python.org/issue24643>`_. |
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.
E501 line too long (88 > 79 characters)
@wholmgren AFAIK I think this is ready whenever, just waiting for approval from @cwhanse |
Closes #168 |
setup.py
Signed-off-by: Mark Mikofski [email protected]