Skip to content

Implement irradiance.complete_irradiance with component sum equations #1567

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

Merged
merged 40 commits into from
Nov 1, 2022

Conversation

kperrynrel
Copy link
Member

@kperrynrel kperrynrel commented Oct 5, 2022

Added the function component_sum_irradiance() to independently calculate the irradiance ghi, dhi, and dni fields from the modelchains module.

@kandersolar kandersolar added this to the 0.9.4 milestone Oct 5, 2022
@cwhanse
Copy link
Member

cwhanse commented Oct 5, 2022

Not a review, rather, thoughts for discussion:

  • I have a preference for irradiance.complete_irradiance because that's the ModelChain method that has done a similar operation.
  • Would the user experience be improved if the function returned a DataFrame with 'ghi', 'dni' and 'dhi' columns? That's closer to what the rest of pvlib would expect, and it would simplify the parameter names here which I suspect is the reason for the 'ghi_series', etc., input parameter names.

'clearsky_dni' should be described as optional.

@kperrynrel
Copy link
Member Author

@cwhanse on the second point, modelchains definitely prefers the dataframe with the dni, ghi, and dhi fields, but I worry about the use of a dataframe not in the context of modelchains. I set it up as separate fields for situations where the dataframe has uniquely named ghi, dni, and dhi columns. Open to either way, but that's what motivated the initial choice to make the ghi, dni, and dhi fields as separate parameters.

@cwhanse
Copy link
Member

cwhanse commented Oct 5, 2022

Is there an aversion to having e.g. 'ghi' be both an input and output parameter name?

@kperrynrel
Copy link
Member Author

I don't have an aversion to it if we change the name of the pvlib.irradiance.dni() function. I originally had the fields ghi, dhi, and dni as passed parameters, but it was erroring since we also have a dni() method (got confused between parameter and method). What do you think about renaming the method?

@kandersolar
Copy link
Member

I think @cwhanse is suggesting keeping the input parameters as separate series but returning the outputs together in a single dataframe, which I agree is more consistent with other functions in pvlib.irradiance that return multiple irradiance variables. Sorry @kperrynrel I wasn't clear when we were talking before; I meant that dataframes are to be avoided as inputs to functions, but sometimes it makes sense to use them for outputs.

Something related to this if you're up for it: with this kind of function, we try to write it such that it will work equally well for scalar, numpy, and pandas inputs, and return outputs of similar type (scalar in -> scalar out, numpy in -> numpy out, pandas in -> pandas out). In this case for scalar inputs we'd return a dictionary instead of a dataframe. pvlib.irradiance.campbell_norman is a good example to follow here. One complication is that the dni function apparently doesn't follow this style and won't work as-is with scalars -- it might need a bit of rewrite to allow that if we want the new function to work with all input types. If not, ok with me to just assume pandas for now and do a follow-up PR later to add support for other types.

Regarding the dni name collision: I suggest naming the input parameter dni for consistency with the rest of pvlib and calling the dni function via pvlib.irradiance.dni(...) (this will require an import pvlib at the top of the file). It's not really ideal, but it avoids a breaking change and/or inconsistent parameter names.

@kperrynrel
Copy link
Member Author

Ok, @kanderso-nrel that makes more sense. Thank you guys both for the suggestions @kanderso-nrel and @cwhanse ! I'll see what I can do to adapt the code to make it fit better with the pvlib framework.

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.

Here's a partial review

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.

Getting close! Sorry I'm so nitpicky about everything...

@@ -1904,7 +1904,7 @@ def test_complete_irradiance(sapm_dc_snl_ac_system, location):

mc.complete_irradiance(i[['dhi', 'ghi']])
assert_series_equal(mc.results.weather['dni'],
pd.Series([49.756966, 62.153947],
pd.Series([49.63565561689957, 62.10624908037814],
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I guess this is an artifact of switching to apparent_zenith. Maybe we shouldn't actually make that change, or if we do then it needs to be mentioned in the changelog. Let's keep this as "to discuss" also.

Copy link
Member

Choose a reason for hiding this comment

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

On technical merit, apparent_zenith would be better. But the practical difference is small and not worth annoying someone trying to reproduce archived results. I could go either way: change to apparent_zenith, or name the parameter solar_zenith and give a generic description.

Copy link
Member

Choose a reason for hiding this comment

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

Any other input on this change? We have two votes neither opposed but neither in strong favor. If that's the roll call, I'd say keep it as zenith.

Co-authored-by: Kevin Anderson <[email protected]>
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.

@pvlib/pvlib-core, any thoughts regarding the apparent zenith question (#1567 (comment) and #1567 (comment))?

A few other minor things below, otherwise LGTM

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.

Pending zenith vs. apparent_zenith, I'm approving.

@@ -1904,7 +1904,7 @@ def test_complete_irradiance(sapm_dc_snl_ac_system, location):

mc.complete_irradiance(i[['dhi', 'ghi']])
assert_series_equal(mc.results.weather['dni'],
pd.Series([49.756966, 62.153947],
pd.Series([49.63565561689957, 62.10624908037814],
Copy link
Member

Choose a reason for hiding this comment

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

On technical merit, apparent_zenith would be better. But the practical difference is small and not worth annoying someone trying to reproduce archived results. I could go either way: change to apparent_zenith, or name the parameter solar_zenith and give a generic description.

@@ -1904,7 +1904,7 @@ def test_complete_irradiance(sapm_dc_snl_ac_system, location):

mc.complete_irradiance(i[['dhi', 'ghi']])
assert_series_equal(mc.results.weather['dni'],
pd.Series([49.756966, 62.153947],
pd.Series([49.63565561689957, 62.10624908037814],
Copy link
Member

Choose a reason for hiding this comment

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

Any other input on this change? We have two votes neither opposed but neither in strong favor. If that's the roll call, I'd say keep it as zenith.

Copy link
Member

@wholmgren wholmgren left a comment

Choose a reason for hiding this comment

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

A few minor comments that I'd prefer to see addressed but won't object to ignoring.

Can we change the PR name (and thus the default commit) to something like "Implement irradiance.complete_irradiance with component sum equations"? The current title makes me think of the pvanalytics QC function.

@kperrynrel kperrynrel changed the title Implement Component sum equations Implement irradiance.complete_irradiance with component sum equations Oct 31, 2022
@kperrynrel
Copy link
Member Author

@wholmgren thank you for the review! I went ahead and worked on addressing all of your comments, and changed the PR name to the suggested name. Let me know if there's anything else I can do before merging!

@wholmgren
Copy link
Member

thanks @kperrynrel! @kanderso-nrel can you merge if you're happy with it too?

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.

Going back to zenith meant the associated ModelChain test changes needed to be undone as well, but LGTM now. Thanks @kperrynrel!

@kandersolar kandersolar merged commit e50def0 into pvlib:master Nov 1, 2022
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.

Add in component sum equations for GHI, DHI, and DNI into the pvlib.irradiance module.
4 participants