-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add marion_diffuse_tracking, to be used instead of marion_diffuse for vector surface_tilt inputs
#2824
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
Open
cbcrespo
wants to merge
2
commits into
pvlib:main
Choose a base branch
from
cbcrespo:marion-efficient
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+155
−0
Open
Add marion_diffuse_tracking, to be used instead of marion_diffuse for vector surface_tilt inputs
#2824
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |||||||||||
| import pandas as pd | ||||||||||||
| import functools | ||||||||||||
| from scipy.optimize import minimize | ||||||||||||
| from scipy.interpolate import PchipInterpolator | ||||||||||||
| from pvlib.tools import cosd, sind, acosd | ||||||||||||
|
|
||||||||||||
| # a dict of required parameter names for each IAM model | ||||||||||||
|
|
@@ -644,6 +645,105 @@ def marion_diffuse(model, surface_tilt, **kwargs): | |||||||||||
| return iam | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def marion_diffuse_tracking(model, surface_tilt, resolution=0.5, **kwargs): | ||||||||||||
| """ | ||||||||||||
| Determine diffuse irradiance incidence angle modifiers using Marion's | ||||||||||||
| method of integrating over solid angle. This function is designed for | ||||||||||||
| trackers, where ``surface_tilt`` is a vector, to avoid the computational | ||||||||||||
| burden of calling ``marion_integrate`` for each tilt angle. | ||||||||||||
| Instead, the IAM function is integrated once for a range of tilt angles, | ||||||||||||
| and then interpolated to the requested tilt angles. For fixed-tilt systems, | ||||||||||||
|
Comment on lines
+654
to
+655
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| use :py:func:`marion_diffuse`. | ||||||||||||
|
|
||||||||||||
| Parameters | ||||||||||||
| ---------- | ||||||||||||
| model : str | ||||||||||||
| The IAM function to evaluate across solid angle. Must be one of | ||||||||||||
| `'ashrae', 'physical', 'martin_ruiz', 'sapm', 'schlick'`. | ||||||||||||
|
|
||||||||||||
| surface_tilt : numeric | ||||||||||||
| Surface tilt angles in decimal degrees. | ||||||||||||
| The tilt angle is defined as degrees from horizontal | ||||||||||||
| (e.g. surface facing up = 0, surface facing horizon = 90). | ||||||||||||
|
|
||||||||||||
| resolution : float, default 0.5 | ||||||||||||
| The resolution in degrees of the tilt angle vector used for | ||||||||||||
| the integration. | ||||||||||||
|
|
||||||||||||
| **kwargs | ||||||||||||
| Extra parameters passed to the IAM function. | ||||||||||||
|
|
||||||||||||
| Returns | ||||||||||||
| ------- | ||||||||||||
| iam : dict | ||||||||||||
| IAM values for each type of diffuse irradiance: | ||||||||||||
|
|
||||||||||||
| * 'sky': radiation from the sky dome (zenith <= 90) | ||||||||||||
| * 'horizon': radiation from the region of the sky near the horizon | ||||||||||||
| (89.5 <= zenith <= 90) | ||||||||||||
| * 'ground': radiation reflected from the ground (zenith >= 90) | ||||||||||||
|
|
||||||||||||
| See [1]_ for a detailed description of each class. | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
|
||||||||||||
| See Also | ||||||||||||
| -------- | ||||||||||||
| pvlib.iam.marion_diffuse | ||||||||||||
| pvlib.iam.marion_integrate | ||||||||||||
|
|
||||||||||||
| References | ||||||||||||
| ---------- | ||||||||||||
| .. [1] B. Marion "Numerical method for angle-of-incidence correction | ||||||||||||
| factors for diffuse radiation incident photovoltaic modules", | ||||||||||||
| Solar Energy, Volume 147, Pages 344-348. 2017. | ||||||||||||
| :doi:`10.1016/j.solener.2017.03.027` | ||||||||||||
| """ | ||||||||||||
|
|
||||||||||||
| models = { | ||||||||||||
| 'physical': physical, | ||||||||||||
| 'ashrae': ashrae, | ||||||||||||
| 'sapm': sapm, | ||||||||||||
| 'martin_ruiz': martin_ruiz, | ||||||||||||
| 'schlick': schlick, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| try: | ||||||||||||
| iam_model = models[model] | ||||||||||||
| except KeyError: | ||||||||||||
| raise ValueError('model must be one of: ' + str(list(models.keys()))) | ||||||||||||
|
|
||||||||||||
| full_range = (np.asarray(surface_tilt) > 90).any() | ||||||||||||
|
|
||||||||||||
| iam_function = functools.partial(iam_model, **kwargs) | ||||||||||||
| iam = {} | ||||||||||||
| for region in ['sky', 'horizon', 'ground']: | ||||||||||||
| interpolator = _get_marion_interpolator(iam_function, | ||||||||||||
| region, resolution, full_range) | ||||||||||||
| iam_values = interpolator(surface_tilt) | ||||||||||||
| if isinstance(surface_tilt, pd.Series): | ||||||||||||
| iam_values = pd.Series(iam_values, index=surface_tilt.index) | ||||||||||||
| elif isinstance(surface_tilt, list): | ||||||||||||
| iam_values = iam_values.tolist() | ||||||||||||
| iam[region] = iam_values | ||||||||||||
|
|
||||||||||||
| return iam | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| @functools.cache | ||||||||||||
| def _get_marion_interpolator(iam_function, region, resolution, | ||||||||||||
| full_range=False): | ||||||||||||
| """ | ||||||||||||
| Cached interpolator for the Marion integration of an IAM function over | ||||||||||||
| solid angle. Helper function for :py:func:`marion_efficient` function | ||||||||||||
| to avoid repeated calculations leading to excessive memory use. | ||||||||||||
| """ | ||||||||||||
| if full_range: | ||||||||||||
| tilt = np.arange(0, 180.5, resolution) | ||||||||||||
| else: | ||||||||||||
| tilt = np.arange(0, 90.5, resolution) | ||||||||||||
| iam = marion_integrate(iam_function, tilt, region) | ||||||||||||
| return PchipInterpolator(tilt, iam) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def marion_integrate(function, surface_tilt, region, num=None): | ||||||||||||
| """ | ||||||||||||
| Integrate an incidence angle modifier (IAM) function over solid angle | ||||||||||||
|
|
||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.