8000 Accept albedo in weather input to ModelChain.run_model method by cwhanse · Pull Request #1469 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Accept albedo in weather input to ModelChain.run_model method #1469

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 16 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
shh stickler, docstrings
  • Loading branch information
cwhanse committed Jun 13, 2022
commit cdf853e4e6a3aeb003a9cffc7f4458d0794bdd56
35 changes: 28 additions & 7 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,9 +1473,11 @@ def prepare_inputs(self, weather):
----------
weather : DataFrame, or tuple or list of DataFrame
Required column names include ``'dni'``, ``'ghi'``, ``'dhi'``.
Optional column names are ``'wind_speed'``, ``'temp_air'``; if not
Optional column names are ``'wind_speed'``, ``'temp_air'``, ``'albedo'``.

If optional columns ``'wind_speed'``, ``'temp_air'`` are not
provided, air temperature of 20 C and wind speed
of 0 m/s will be added to the DataFrame.
of 0 m/s will be added to the `weather` DataFrame.

If `weather` is a tuple or list, it must be of the same length and
order as the Arrays of the ModelChain's PVSystem.
Expand All @@ -1490,6 +1492,9 @@ def prepare_inputs(self, weather):
ValueError
If `weather` is a tuple or list with a different length than the
number of Arrays in the system.
ValueError
If ``'albedo'`` is a column in `weather` and is also an attribute
of the ModelChain's PVSystem.Arrays.

Notes
-----
Expand Down Expand Up @@ -1742,16 +1747,32 @@ def run_model(self, weather):
Parameters
----------
weather : DataFrame, or tuple or list of DataFrame
Irradiance column names must include ``'dni'``, ``'ghi'``, and
``'dhi'``. If optional columns ``'temp_air'`` and ``'wind_speed'``
Column names must include:

- ``'dni'``
- ``'ghi'``
- ``'dhi'``

Optional columns are:

- ``'temp_air'``
- ``'cell_temperature'``
- ``'module_temperature'``
- ``'wind_speed'``
- ``'albedo'``

If optional columns ``'temp_air'`` and ``'wind_speed'``
are not provided, air temperature of 20 C and wind speed of 0 m/s
are added to the DataFrame. If optional column
``'cell_temperature'`` is provided, these values are used instead
of `temperature_model`. If optional column `module_temperature`
of `temperature_model`. If optional column ``'module_temperature'``
is provided, `temperature_model` must be ``'sapm'``.

If list or tuple, must be of the same length and order as the
Arrays of the ModelChain's PVSystem.
If optional column ``'albedo'`` is provided, ``'albedo'`` may not
be present on the ModelChain's PVSystem or PVSystem.Arrays.

If weather is a list or tuple, it must be of the same length and
order as the Arrays of the ModelChain's PVSystem.

Returns
-------
Expand Down
10 changes: 6 additions & 4 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class PVSystem:
a single array is created from the other parameters (e.g.
`surface_tilt`, `surface_azimuth`). Must contain at least one Array,
if length of arrays is 0 a ValueError is raised. If `arrays` is
specified the following parameters are ignored:
specified the following PVSystem parameters are ignored:

- `surface_tilt`
- `surface_azimuth`
Expand All @@ -156,11 +156,13 @@ class PVSystem:
Azimuth angle of the module surface.
North=0, East=90, South=180, West=270.

albedo : None or numeric, default None
albedo : None or float, default None
Ground surface albedo. If ``None``, then ``surface_type`` is used
to look up a value in ``irradiance.SURFACE_ALBEDOS``.
If ``surface_type`` is also None then a ground surface albedo
of 0.25 is used.
of 0.25 is used. For time-dependent albedos, add ``'albedo'`` to
the input ``'weather'`` DataFrame for
:py:class:`pvlib.modelchain.ModelChain` methods.

surface_type : None or string, default None
The ground surface type. Required if ``albedo`` is None.
Expand Down Expand Up @@ -1258,7 +1260,7 @@ class Array:
single axis tracker. Mounting is used to determine module orientation.
If not provided, a FixedMount with zero tilt is used.

albedo : None or numeric, default None
albedo : None or float, default None
Ground surface albedo. If ``None``, then ``surface_type`` is used
to look up a value in ``irradiance.SURFACE_ALBEDOS``.
If ``surface_type`` is also None then a ground surface albedo
Expand Down
3 changes: 0 additions & 3 deletions pvlib/tests/test_clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,3 @@ def test_bird():
testdata2[['Direct Beam', 'Direct Hz', 'Global Hz', 'Dif Hz']].iloc[11],
rtol=1e-3)
return pd.DataFrame({'Eb': Eb, 'Ebh': Ebh, 'Gh': Gh, 'Dh': Dh}, index=times)


test_bird()
2 changes: 1 addition & 1 deletion pvlib/tests/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_get_ground_diffuse_albedo_0(irrad_data):
def test_get_ground_diffuse_albedo_series(times):
albedo = pd.Series(0.2, index=times)
ground_irrad = irradiance.get_ground_diffuse(
45, pd.Series(1000, index=times), albedo)
45, pd.Series(1000, index=times), albedo)
expected = albedo * 0.5 * (1 - np.sqrt(2) / 2.) * 1000
expected.name = 'diffuse_ground'
assert_series_equal(ground_irrad, expected)
Expand Down
4 changes: 2 additions & 2 deletions pvlib/tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,14 @@ def test_prepare_inputs_transfer_albedo(
del a.albedo
mc = ModelChain(pvsystem, location)
mc = mc.prepare_inputs(weather)
assert (mc.system.arrays[0].albedo.values==0.5).all()
assert (mc.system.arrays[0].albedo.values == 0.5).all()
# again with weather as a tuple
for a in pvsystem.arrays:
del a.albedo
mc = ModelChain(pvsystem, location)
mc = mc.prepare_inputs(input_type((weather, weather)))
for a in mc.system.arrays:
assert (a.albedo.values==0.5).all()
assert (a.albedo.values == 0.5).all()


def test_prepare_inputs_no_irradiance(sapm_dc_snl_ac_system, location):
Expand Down
0