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

Behavior of calcparams and singlediode function could be improved #1626

Closed
5 tasks
cwhanse opened this issue Dec 22, 2022 · 8 comments
Closed
5 tasks

Behavior of calcparams and singlediode function could be improved #1626

cwhanse opened this issue Dec 22, 2022 · 8 comments
Milestone

Comments

@cwhanse
Copy link
Member

cwhanse commented Dec 22, 2022

The type and shape of output from calcparams and singlediode functions have some oddities that make the output somewhat annoying and may pose a risk of code breaking if pandas/numpy broadcasting and/or typecasting change.

Observations:

  • When pvsystem.calcparams_ functions have float inputs, some of the outputs are arrays.
  • When pvsystem.calcparams_ functions have Series input, not all output are Series, and some of the output Series inherits a name from the input Series.
  • When pvsystem.singlediode has length 1 irradiance and temperature, and ivcurve_pnts=N is specified, the returned arrays are shape (1, N), and so must be transposed to plot the I-V curve.
  • When ivcurve_pnts=None (default) pvsystem.singlediode returns a DataFrame. When ivcurve_pnts is specified, pvsystem.singlediodereturns an OrderedDict.
  • When multiple IV curves are to be calculated with IV curve points, the IV curves are row-by-row, so must be transposed to be plotted.

To Reproduce
gist here

Expected behavior

  • calcparams functions return floats when all inputs are floats
  • when Series are returned, don't inherit name from input (e.g. 'temp_cell' for the saturation current)
  • IV curve points should be transposed for convenient plotting
  • Consider always returning a DataFrame from singlediode.

Versions:

  • pvlib.__version__: 0.9.4
  • pandas.__version__: 1.2.4
@wholmgren
Copy link
Member

Nice gist.

When pvsystem.calcparams_ functions have Series input, not all output are Series,

Do you propose casting resistance_series to a series of same length as the input?

and some of the output Series inherits a name from the input Series.

This problem is not unique to these functions. A couple of functions have code like this, but I would hate to see this in every function:

try:
aoi_value.name = 'aoi'
except AttributeError:
pass

A wrapper function for input/output types could solve this among other problems. Also item 1.

When ivcurve_pnts=None (default) pvsystem.singlediode returns a DataFrame. When ivcurve_pnts is specified, pvsystem.singlediodereturns an OrderedDict.

Related discussion in #418. I still think ivcurve_pnts should be removed from singlediode. That could be a good path to solving items 3-5.

@cwhanse
Copy link
Member Author

cwhanse commented Dec 22, 2022

My primary aims would be to 1) have these functions return consistent output for single vs. array-like input, and 2) avoid .T when making plots.

Yes, I think resistance_series should be returned from calcparams in the same type as other outputs.

I'd be OK if singlediode (and i_from_v, v_from_i) always returned DataFrame.

I'm willing to agree to removing ivcurves_pnts because we have pvsystem.i_from_v and .v_from_i functions (and methods).

@cwhanse
Copy link
Member Author

cwhanse commented Dec 24, 2022

Here's another corner case that we missed with tests. The vectorized newton solver doesn't work if parameters are Series of length one.


import pandas as pd
import pvlib


args = (0.001, 1.5, 6., 5e-9, 1000., 0.5)
params = pvlib.pvsystem.calcparams_desoto(1000., 25, *args)
params_series = pvlib.pvsystem.calcparams_desoto(pd.Series(data=[1000.]),
                                                 pd.Series([25.]), *args)
params_series2 = pvlib.pvsystem.calcparams_desoto(pd.Series(data=[1000., 1000.]),
                                                  pd.Series([25., 25.]), *args)
# works with each input as float
result = pvlib.pvsystem.singlediode(*params, method='newton')

# works with Series if length > 1
result_series2 = pvlib.pvsystem.singlediode(*params_series2, method='newton')

# errors with Series if length is 1
result_series = pvlib.pvsystem.singlediode(*params_series, method='newton')

@adriesse
Copy link
Member

Good ideas and initiatives. Regarding the transposition for convenient graphing, I have the impression I have to do this from time to time with results from numpy or scipy too. Most important thing is that the output shapes broadcast appropriately to downstream vectorized calculations.

@kandersolar
Copy link
Member

@cwhanse @reepoi with #1700 and #1743 both merged, should this issue be closed?

@reepoi
Copy link
Contributor

reepoi commented Jun 27, 2023

Those two pull requests completed the checkmarks in the opening comment of this issue, so I think it can be closed.
They did not address the bug brought up in this comment, which is an issue with pvlib.singlediode.bishop88_v_from_i. I think a new issue should be created for that.

@cwhanse
Copy link
Member Author

cwhanse commented Jun 27, 2023

Agree, we can close. I made #1787 for #1626 (comment)

@cwhanse
Copy link
Member Author

cwhanse commented Jun 27, 2023

Closed via #1700 and #1743

@cwhanse cwhanse closed this as completed Jun 27, 2023
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

No branches or pull requests

5 participants