8000 polite handling of nan in irradiance.perez by cwhanse · Pull Request #610 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

polite handling of nan in irradiance.perez #610

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

Closed
wants to merge 2 commits into from

Conversation

cwhanse
Copy link
Member
@cwhanse cwhanse commented Oct 23, 2018

pvlib python pull request guidelines

Thank you for your contribution to pvlib python! You may delete all of these instructions except for the list below.

You may submit a pull request with your code at any stage of completion.

The following items must be addressed before the code can be merged. Please don't hesitate to ask for help if you're unsure of how to accomplish any of the items below:

  • [x ] I am familiar with the contributing guidelines.
  • [x ] Fully tested. Added and/or modified tests to ensure correct behavior for all reasonable inputs. Tests (usually) must pass on the TravisCI and Appveyor testing services.
  • Adds description and name entries in the appropriate docs/sphinx/source/whatsnew file for all changes.
  • Code quality and style is sufficient. Passes LGTM and SticklerCI checks.
  • New code is fully documented. Includes sphinx/numpydoc compliant docstrings and comments in the code where necessary.
  • Pull request is nearly complete and ready for detailed review.

Brief description of the problem and proposed solution (if not already fully described in the issue linked to above):


F2 = (F2c[ebin, 0] + F2c[ebin, 1] * delta + F2c[ebin, 2] * z)
F2 = np.maximum(F2, 0)
F2 = np.where(np.isnan(F2), np.nan, np.maximum(F2, 0))
Copy link
Member
@mikofski mikofski Oct 23, 2018

Choose a reason for hiding this comment

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

if this polite handling is going to become a pattern, it might be worth putting it into tools as a dedicated set of functions like

def polite_handling_of_nan(x, f):
    """return nan where x is nan otherwise return f(x)"""
    return np.where(np.isnan(x), np.nan, f(x))

Copy link
Member

Choose a reason for hiding this comment

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

Also isn't another option to turn off NumPy warnings? If that's an alternate, I'm curious if there is any penalty for calling np.where() all the time, instead of just ignoring the warnings.

@cwhanse
Copy link
Member Author
cwhanse commented Oct 23, 2018

Actually that earlier commit did nothing, since np.where evaluates both cases before constructing its output. See the latest commit, adding nanmaximum to pvlib.tools.

Having np.nan in series inputs like dni and airmass should be handled gracefully, where we can.

@wholmgren
Copy link
Member

np.fmax documentation says "See Also... maximum Element-wise maximum of two arrays, propagates NaNs."

It is ridiculous that a function specifically advertised to propagate NaNs would also complain that it was provided a NaN! There's got to be a better way than trying to maintain our own nan-friendly maximum function.

@cwhanse
Copy link
Member Author
cwhanse commented Oct 24, 2018

I agree. We could open an issue for numpy...

@wholmgren
Copy link
Member

I'm working on a comment here.... numpy/numpy#12038

@cwhanse
Copy link
Member Author
cwhanse commented Oct 24, 2018

OK, let's sit on this until numpy makes up its mind. The custom function is messing with the output typing in irradiance.perez

@mikofski
Copy link
Member

Also I'm still concerned about penalty from all these extra np.where calls if we can just turn this warning off as I asked in this comment

@wholmgren
Copy link
Member

Looks like numpy will stop emitting the warnings. I suggest we live with them for now and close this PR.

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

Successfully merging this pull request may close these issues.

3 participants
0