Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 23 additions & 2 deletions pvlib/clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def ineichen(apparent_zenith, airmass_absolute, linke_turbidity,
report on clear sky models found the Ineichen/Perez model to have
excellent performance with a minimal input data set [3]_.

Default values for monthly Linke turbidity provided by SoDa [4]_, [5]_.
Default monthly Linke turbidity values are available via
:py:func:`pvlib.clearsky.lookup_linke_turbidity`, which uses data
provided by SoDa [4]_, [5]_. Users must supply Linke turbidity values
explicitly unless providing their own turbidity data.


Parameters
-----------
Expand Down Expand Up @@ -147,9 +151,13 @@ def ineichen(apparent_zenith, airmass_absolute, linke_turbidity,
def lookup_linke_turbidity(time, latitude, longitude, filepath=None,
interp_turbidity=True):
"""
Look up the Linke Turibidity from the ``LinkeTurbidities.h5``
Look up the Linke turbidity from the ``LinkeTurbidities.h5`
data file supplied with pvlib.

The Linke turbidity climatology used by this function is sourced from
SoDa (Solar Radiation Data) and corresponds to the references cited in
:py:func:`pvlib.clearsky.ineichen`.

Parameters
----------
time : pandas.DatetimeIndex
Expand All @@ -175,6 +183,19 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None,
The returned value for each time is either the monthly value or an
interpolated value to smooth the transition between months.
Interpolation is done on the day of year as determined by UTC.

Examples
--------
>>> from pvlib.clearsky import lookup_linke_turbidity, ineichen
>>> from pvlib.location import Location
>>> import pandas as pd
>>>
>>> times = pd.date_range('2024-06-01', freq='1H', periods=24, tz='UTC')
>>> loc = Location(35, -110)
>>>
>>> tl = lookup_linke_turbidity(times, loc.latitude, loc.longitude)
>>> cs = ineichen(times, loc.latitude, loc.longitude,
... linke_turbidity=tl)
"""

# The .h5 file 'LinkeTurbidities.h5' contains a single 2160 x 4320 x 12
Expand Down
7 changes: 3 additions & 4 deletions pvlib/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ def simple_efficiency(
input_power : numeric
The real AC power input to the transformer. [W]

no_load_loss : numeric
no_load_loss : float
The constant losses experienced by a transformer, even
when the transformer is not under load. Fraction of transformer rating,
value from 0 to 1. [unitless]
when the transformer is not under load. Fraction of transformer rating, value from 0 to 1. [unitless]

load_loss: numeric
load_loss: float
The load dependent losses experienced by the transformer.
Fraction of transformer rating, value from 0 to 1. [unitless]

Expand Down
44 changes: 40 additions & 4 deletions tests/test_transformer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pandas as pd
import numpy as np
import pytest

from numpy.testing import assert_allclose

from pvlib.transformer import simple_efficiency
from pvlib import transformer


Expand Down Expand Up @@ -48,13 +50,47 @@ def test_simple_efficiency_known_values():

# verify correct behavior at no-load condition
assert_allclose(
transformer.simple_efficiency(no_load_loss*rating, *args),
transformer.simple_efficiency(no_load_loss * rating, *args),
0.0
)

# verify correct behavior at rated condition
assert_allclose(
transformer.simple_efficiency(rating*(1 + no_load_loss + load_loss),
*args),
transformer.simple_efficiency(
rating * (1 + no_load_loss + load_loss),
*args
),
rating,
)


# =========================
# NEW TESTS (Issue #2649)
# =========================

def test_simple_efficiency_numpy_input_power():
input_power = np.array([500, 1000, 1500])
no_load_loss = 0.01
load_loss = 0.02
transformer_rating = 2000

output = simple_efficiency(
input_power, no_load_loss, load_loss, transformer_rating
)

assert isinstance(output, np.ndarray)
assert output.shape == input_power.shape


def test_simple_efficiency_zero_load_loss():
input_power = np.array([500, 1000])
no_load_loss = 0.01
load_loss = 0.0
transformer_rating = 2000

with pytest.warns(RuntimeWarning):
output = simple_efficiency(
input_power, no_load_loss, load_loss, transformer_rating
)

assert np.all(np.isnan(output))