Comments (7)
Thanks, Birk.
I'm not sure how to best construct the API for this. I removed the kwargs
, and thus NumPoints
, from the from the singlediode
function in the 0.2 API refactor. One approach is to use two different functions, one for labelled points and one for arbitrary points. What are you returning from the function? A dataframe and, optionally, a series? You could just embed the whole function in a comment using triple ticks and the python declaration.
Also, I think that i_from_v
will work with vector inputs, and this will be a lot faster than iterating over each point.
What do others think?
from pvlib-python.
Here's my code to make IV curves. I'm still not sure if any of this should be included in pvlib or not. I think we should at least add something similar to this to the documentation. Maybe someone else has a better way to do this.
def fivepoints_to_frame(pnt):
"""
Converts a 1 dimensional, dict-like singlediode or sapm result
to a 5 row DataFrame with columns current and voltage.
Users can iterate over the rows of a multidimensional
singlediode or sapm result, if necessary.
"""
ivframe = {'i_sc': (pnt['i_sc'], 0),
'p_mp': (pnt['i_mp'], pnt['v_mp']),
'i_x': (pnt['i_x'], 0.5*pnt['v_oc']),
'i_xx': (pnt['i_xx'], 0.5*(pnt['v_oc']+pnt['v_mp'])),
'v_oc': (0, pnt['v_oc'])}
ivframe = pd.DataFrame(ivframe, index=['current', 'voltage']).T
ivframe = ivframe.sort_values(by='voltage')
return ivframe
resistance_shunt = 16
resistance_series = 0.094
nNsVth = 0.473
saturation_current = 1.943e-09
photocurrent = 7
module_parameters = pvsystem.retrieve_sam('cecmod')['Example_Module']
v_oc = pvsystem.v_from_i(resistance_shunt, resistance_series, nNsVth, 0, saturation_current, photocurrent)
voltage = np.linspace(0, v_oc, 100)
current = pvsystem.i_from_v(resistance_shunt, resistance_series, nNsVth, voltage, saturation_current, photocurrent)
fivepnts = pvsystem.singlediode(
module_parameters, photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)
ivframe = fivepoints_to_frame(fivepnts)
fig, ax = plt.subplots()
ax.plot(voltage, current)
ax.scatter(ivframe['voltage'], ivframe['current'], c='k', s=36, zorder=10)
ax.set_xlim(0, None)
ax.set_ylim(0, None)
ax.set_ylabel('current (A)')
ax.set_xlabel('voltage (V)')
The fivepoints_to_frame
function takes this input
fivepnts
{'i_mp': 6.104597093609919,
'i_sc': 6.9584938427061607,
'i_x': 6.6367680322891767,
'i_xx': 4.4589886731292712,
'p_mp': 51.257040864030472,
'v_mp': 8.3964658237125214,
'v_oc': 10.362416515927016}
and creates this output
print(ivframe)
current voltage
i_sc 6.958494 0.000000
i_x 6.636768 5.181208
p_mp 6.104597 8.396466
i_xx 4.458989 9.379441
v_oc 0.000000 10.362417
requires #190.
from pvlib-python.
Will,
I’d include the code, but I’d also have the function return a second dataframe with all 100 computed points.
Cliff
from pvlib-python.
Another option is to reproduce the pvl_singlediode.m Matlab API by switching our singlediode's output from a DataFrame a simple dictionary. The dictionary values would be scalars or arrays as determined by the numpy broadcasting rules.
Here's another try at the multiple function approach. We'd have the existing singlediode
that works with either scalar or time series inputs, and these functions that handle IV curve stuff for scalar inputs.
I don't know if one approach is better than the other.
def singlediode_points_to_frame(pnt):
"""
Converts a dict of scalars describing the 5 points of
a single diode curve to a 5 row DataFrame with
columns current and voltage.
Useful for plotting.
Parameters
----------
pnt: dict
Typically the output of the singlediode function.
Must have keys i_sc, p_mp, i_x, i_xx, v_oc.
Returns
-------
fivepnts: DataFrame
Columns labeled voltage, current.
Rows labeled i_sc, p_mp, i_x, i_xx, v_oc.
"""
fivepnts = {'i_sc': (pnt['i_sc'], 0),
'p_mp': (pnt['i_mp'], pnt['v_mp']),
'i_x': (pnt['i_x'], 0.5*pnt['v_oc']),
'i_xx': (pnt['i_xx'], 0.5*(pnt['v_oc']+pnt['v_mp'])),
'v_oc': (0, pnt['v_oc'])}
fivepnts = pd.DataFrame(fivepnts, index=['current', 'voltage']).T
fivepnts = fivepnts.sort_values(by='voltage')
return fivepnts
def singlediode_ivcurve(module_parameters, photocurrent, saturation_current,
resistance_series, resistance_shunt, nNsVth, v_oc=None, num=50):
"""
Creates a single diode IV curve with uniformly spaced points.
Parameters
----------
See singlediode
v_oc: None or float
Will be calculated if None.
num: int
Number of IV curve samples.
Returns
-------
ivcurve: DataFrame
Columns labeled voltage, current.
Rows labeled by point number.
"""
if v_oc is None:
v_oc = pvsystem.v_from_i(
resistance_shunt, resistance_series, nNsVth, 0, saturation_current, photocurrent)
voltage = np.linspace(0, v_oc, num)
current = pvsystem.i_from_v(
resistance_shunt, resistance_series, nNsVth, voltage, saturation_current, photocurrent)
ivcurve = pd.DataFrame(np.array([voltage, current]).T, columns=['voltage', 'current'])
return ivcurve
def singlediode_points_ivcurve(module_parameters, photocurrent, saturation_current,
resistance_series, resistance_shunt, nNsVth,
num=50):
"""
Solves the single diode model for scalar inputs and returns an IV curve
and the 5 IV curve characterization points.
Parameters
----------
see singlediode
Returns
-------
fivepnts: DataFrame
Columns labeled voltage, current.
Rows labeled i_sc, p_mp, i_x, i_xx, v_oc.
ivcurve: DataFrame
Columns labeled voltage, current.
Rows labeled by point number.
"""
fivepnts = pvsystem.singlediode(
module_parameters, photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)
fivepnts = singlediode_points_to_frame(fivepnts)
ivcurve = singlediode_ivcurve(
module_parameters, photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth,
v_oc=fivepnts.ix['v_oc', 'voltage'])
return fivepnts, ivcurve
resistance_shunt = 16
resistance_series = 0.094
nNsVth = 0.473
saturation_current = 1.943e-09
photocurrent = 7
fivepnts, ivcurve = singlediode_points_ivcurve(
module_parameters, photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)
fig, ax = plt.subplots()
ax.plot(ivcurve['voltage'], ivcurve['current'])
ax.scatter(fivepnts['voltage'], fivepnts['current'], c='k', s=36, zorder=10)
ax.set_xlim(0, None)
ax.set_ylim(0, None)
ax.set_ylabel('current (A)')
ax.set_xlabel('voltage (V)')
# as shown above
from pvlib-python.
I would prefer the dict output rather than the dataframe for IV curves. We won’t use the pandas time series functionality for IV curves so the extra overhead doesn’t make sense to me.
from pvlib-python.
People do use the singlediode function for time series analysis, though, so I don't want to take that away from them (or at least me). I think everyone can be happy, and very little code should break, if I amend my previous comment to say:
The dictionary values would be scalars, arrays, or series as determined by the input type.
See below for a couple of API proposals. Option 1 can be implemented immediately. Option 2 would break existing code.
Option 3 (not shown), would use option 1 and create a separate "tuplizer" function. The tuples are nice for plotting.
def singlediode(module, photocurrent, saturation_current,
resistance_series, resistance_shunt, nNsVth,
ivcurve_pnts=None):
"""
Parameters
----------
...
ivcurve_pnts: None or int
The number of points with which to simulate an IV curve.
If None or 0, an IV curve will not be generated.
Returns option 1
-------
output: dict
A dict with the following keys:
* i_sc - short circuit current in amperes.
* v_oc - open circuit voltage in volts.
* i_mp - current at maximum power point in amperes.
* v_mp - voltage at maximum power point in volts.
* p_mp - power at maximum power point in watts.
* i_x - current, in amperes, at ``v = 0.5*v_oc``.
* i_xx - current, in amperes, at ``V = 0.5*(v_oc+v_mp)``.
* i - None or iv curve current. I'd also consider an empty array or missing key instead of None.
* v - None or iv curve voltage. I'd also consider an empty array or missing key instead of None.
Returns option 2
-------
output: dict
A dict with the following keys and (voltage, current, power) values:
* i_sc - (0, i_sc, 0)
* v_oc - (v_oc, 0, 0)
* p_mp - (v_mp, i_mp, p_mp)
* i_x - (v_x, i_x, p_x) at ``v_x = 0.5*v_oc``
* i_xx - (v_xx, i_xx, p_xx) at ``v_xx = 0.5*(v_oc+v_mp)``
* ivcurve - None or (voltage, current, power) tuple. I'd also consider a tuple of empty arrays or a missing key instead of None.
"""
from pvlib-python.
What I meant, and perhaps didn’t say clearly, is that a dataframe (time series object) doesn’t seem a natural fit to contain a single IV curve. A time series of a point on IV curves (e.g., Isc) makes a lot of sense.
Option 1 is better than 2, I think.
from pvlib-python.
Related Issues (20)
- Discontinuous Diffuse Sky Irradiance from Perez Model HOT 1
- Dynamic Snow Loss Model HOT 7
- NREL mismatch losses model due to non-uniform irradiance of cells HOT 2
- Photosynthetically active radiation decomposition model HOT 9
- Allow arbitrary IAM function in pvlib.iam.marion_diffuse HOT 3
- Provide major version lower and upper bounds on all dependencies HOT 10
- Losses usage unclear in PVSystem and ModelChain User Guide
- Clearsky functions handling tz-aware datetimes as tz-naive, contrary to user guide HOT 5
- Support for HJT modules HOT 2
- pvlib users group meeting - 2024-05-09
- Shading model that takes into account the bypass diodes and layout of modules
- GSoC participation roadmap of Echedey HOT 2
- Google Summer of Code project summary: Implementing new spectral corrections in pvlib HOT 4
- Evaluate opportunities to ease the experience of new contributors HOT 1
- Google Summer of Code: Floating PV HOT 1
- Direct and diffuse shading factors - spatial approach (for Photosynthetically Active Radiation)
- Upcoming whatsnews can't be tested on RTD CI HOT 3
- Failed unit test for nrel 2008 solar position algorithm HOT 5
- GSoC feedback on the pvlib contribution process HOT 2
- pvlib.ivtools.sdm.fit_cec_sam() causes import error due to uppercase letters in import statement HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pvlib-python.