Skip to content

Commit efe6b3b

Browse files
committed
fix some tests
1 parent 93716bb commit efe6b3b

File tree

4 files changed

+57
-39
lines changed

4 files changed

+57
-39
lines changed

pvlib/pvsystem.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,10 @@ def fuentes_celltemp(self, poa_global, temp_air, wind_speed,
760760
The Fuentes thermal model uses the module surface tilt for convection
761761
modeling. The SAM implementation of PVWatts hardcodes the surface tilt
762762
value at 30 degrees, ignoring whatever value is used for irradiance
763-
transposition. If you want to match the PVWatts behavior, specify a
764-
``surface_tilt`` value in the Array's ``temperature_model_parameters``.
763+
transposition. If you want to match the PVWatts behavior you can
764+
either leave ``surface_tilt`` unspecified to use the PVWatts default
765+
of 30, or specify a ``surface_tilt`` value in the Array's
766+
``temperature_model_parameters``.
765767
766768
The `temp_air`, `wind_speed`, and `surface_tilt` parameters may be
767769
passed as tuples

pvlib/tests/test_modelchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def test_run_model_with_weather_fuentes_temp(sapm_dc_snl_ac_system, location,
697697
weather['wind_speed'] = 5
698698
weather['temp_air'] = 10
699699
sapm_dc_snl_ac_system.temperature_model_parameters = {
700-
'noct_installed': 45
700+
'noct_installed': 45, 'surface_tilt': 30,
701701
}
702702
mc = ModelChain(sapm_dc_snl_ac_system, location)
703703
mc.temperature_model = 'fuentes'

pvlib/tests/test_pvsystem.py

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,13 @@ def test_PVSystem_multi_array_celltemp_functions(celltemp, two_array_system):
566566
irrad_two = pd.Series(500, index=times)
567567
temp_air = pd.Series(25, index=times)
568568
wind_speed = pd.Series(1, index=times)
569+
kwargs = {}
570+
if celltemp == pvsystem.PVSystem.fuentes_celltemp:
571+
kwargs['surface_tilt'] = 30
572+
569573
temp_one, temp_two = celltemp(
570-
two_array_system, (irrad_one, irrad_two), temp_air, wind_speed)
574+
two_array_system, (irrad_one, irrad_two), temp_air, wind_speed,
575+
**kwargs)
571576
assert (temp_one != temp_two).all()
572577

573578

@@ -583,18 +588,24 @@ def test_PVSystem_multi_array_celltemp_multi_temp(celltemp, two_array_system):
583588
temp_air_one = pd.Series(25, index=times)
584589
temp_air_two = pd.Series(5, index=times)
585590
wind_speed = pd.Series(1, index=times)
591+
kwargs = {}
592+
if celltemp == pvsystem.PVSystem.fuentes_celltemp:
593+
kwargs['surface_tilt'] = 30
594+
586595
temp_one, temp_two = celltemp(
587596
two_array_system,
588597
(irrad, irrad),
589598
(temp_air_one, temp_air_two),
590-
wind_speed
599+
wind_speed,
600+
**kwargs
591601
)
592602
assert (temp_one != temp_two).all()
593603
temp_one_swtich, temp_two_switch = celltemp(
594604
two_array_system,
595605
(irrad, irrad),
596606
(temp_air_two, temp_air_one),
597-
wind_speed
607+
wind_speed,
608+
**kwargs
598609
)
599610
assert_series_equal(temp_one, temp_two_switch)
600611
assert_series_equal(temp_two, temp_one_swtich)
@@ -612,18 +623,24 @@ def test_PVSystem_multi_array_celltemp_multi_wind(celltemp, two_array_system):
612623
temp_air = pd.Series(25, index=times)
613624
wind_speed_one = pd.Series(1, index=times)
614625
wind_speed_two = pd.Series(5, index=times)
626+
kwargs = {}
627+
if celltemp == pvsystem.PVSystem.fuentes_celltemp:
628+
kwargs['surface_tilt'] = 30
629+
615630
temp_one, temp_two = celltemp(
616631
two_array_system,
617632
(irrad, irrad),
618633
temp_air,
619-
(wind_speed_one, wind_speed_two)
634+
(wind_speed_one, wind_speed_two),
635+
**kwargs
620636
)
621637
assert (temp_one != temp_two).all()
622638
temp_one_swtich, temp_two_switch = celltemp(
623639
two_array_system,
624640
(irrad, irrad),
625641
temp_air,
626-
(wind_speed_two, wind_speed_one)
642+
(wind_speed_two, wind_speed_one),
643+
**kwargs
627644
)
628645
assert_series_equal(temp_one, temp_two_switch)
629646
assert_series_equal(temp_two, temp_one_swtich)
@@ -703,18 +720,21 @@ def test_PVSystem_fuentes_celltemp(mocker):
703720
temps = pd.Series(25, index)
704721
irrads = pd.Series(1000, index)
705722
winds = pd.Series(1, index)
706-
out = system.fuentes_celltemp(irrads, temps, winds)
723+
724+
out = system.fuentes_celltemp(irrads, temps, winds, surface_tilt=0)
707725
assert_series_equal(spy.call_args[0][0], irrads)
708726
assert_series_equal(spy.call_args[0][1], temps)
709727
assert_series_equal(spy.call_args[0][2], winds)
728+
assert spy.call_args[1]['surface_tilt'] == 0
710729
assert spy.call_args[1]['noct_installed'] == noct_installed
711730
assert_series_equal(out, pd.Series([52.85, 55.85, 55.85], index,
712731
name='tmod'))
713732

714733

715734
def test_PVSystem_fuentes_celltemp_override(mocker):
716735
# test that the surface_tilt value in the cell temp calculation can be
717-
# overridden but defaults to the surface_tilt attribute of the PVSystem
736+
# overridden but defaults to the surface_tilt value in
737+
# array.temperature_model_parameters
718738
spy = mocker.spy(temperature, 'fuentes')
719739

720740
noct_installed = 45
@@ -724,38 +744,33 @@ def test_PVSystem_fuentes_celltemp_override(mocker):
724744
winds = pd.Series(1, index)
725745

726746
# uses default value
727-
temp_model_params = {'noct_installed': noct_installed}
728-
system = pvsystem.PVSystem(temperature_model_parameters=temp_model_params,
729-
surface_tilt=20)
747+
temp_model_params = {'noct_installed': noct_installed, 'surface_tilt': 20}
748+
system = pvsystem.PVSystem(temperature_model_parameters=temp_model_params)
730749
system.fuentes_celltemp(irrads, temps, winds)
731750
assert spy.call_args[1]['surface_tilt'] == 20
732751

733-
# can be overridden
734-
temp_model_params = {'noct_installed': noct_installed, 'surface_tilt': 30}
735-
system = pvsystem.PVSystem(temperature_model_parameters=temp_model_params,
736-
surface_tilt=20)
737-
system.fuentes_celltemp(irrads, temps, winds)
738-
assert spy.call_args[1]['surface_tilt'] == 30
752+
# if no default, uses the user-specified values
753+
temp_model_params = {'noct_installed': noct_installed}
754+
system = pvsystem.PVSystem(temperature_model_parameters=temp_model_params)
755+
system.fuentes_celltemp(irrads, temps, winds, surface_tilt=40)
756+
assert spy.call_args[1]['surface_tilt'] == 40
739757

740758

741759
def test_Array__infer_temperature_model_params():
742-
array = pvsystem.Array(mount=pvsystem.FixedMount(0, 180),
760+
array = pvsystem.Array(mount=pvsystem.FixedMount(0, 180, racking_model='open_rack'),
743761
module_parameters={},
744-
racking_model='open_rack',
745762
module_type='glass_polymer')
746763
expected = temperature.TEMPERATURE_MODEL_PARAMETERS[
747764
'sapm']['open_rack_glass_polymer']
748765
assert expected == array._infer_temperature_model_params()
749-
array = pvsystem.Array(mount=pvsystem.FixedMount(0, 180),
766+
array = pvsystem.Array(mount=pvsystem.FixedMount(0, 180, racking_model='freestanding'),
750767
module_parameters={},
751-
racking_model='freestanding',
752768
module_type='glass_polymer')
753769
expected = temperature.TEMPERATURE_MODEL_PARAMETERS[
754770
'pvsyst']['freestanding']
755771
assert expected == array._infer_temperature_model_params()
756-
array = pvsystem.Array(mount=pvsystem.FixedMount(0, 180),
772+
array = pvsystem.Array(mount=pvsystem.FixedMount(0, 180, racking_model='insulated'),
757773
module_parameters={},
758-
racking_model='insulated',
759774
module_type=None)
760775
expected = temperature.TEMPERATURE_MODEL_PARAMETERS[
761776
'pvsyst']['insulated']
@@ -1881,10 +1896,9 @@ def test_PVSystem___repr__():
18811896
name: pv ftw
18821897
Array:
18831898
name: None
1884-
mount: FixedMount(surface_tilt=0, surface_azimuth=180)
1899+
mount: FixedMount(surface_tilt=0, surface_azimuth=180, racking_model=None, module_height=None)
18851900
module: blah
18861901
albedo: 0.25
1887-
racking_model: None
18881902
module_type: None
18891903
temperature_model_parameters: {'a': -3.56}
18901904
strings: 1
@@ -1906,49 +1920,46 @@ def test_PVSystem_multi_array___repr__():
19061920
name: None
19071921
Array:
19081922
name: None
1909-
mount: FixedMount(surface_tilt=30, surface_azimuth=100)
1923+
mount: FixedMount(surface_tilt=30, surface_azimuth=100, racking_model=None, module_height=None)
19101924
module: None
19111925
albedo: 0.25
1912-
racking_model: None
19131926
module_type: None
19141927
temperature_model_parameters: {}
19151928
strings: 1
19161929
modules_per_string: 1
19171930
Array:
19181931
name: foo
1919-
mount: FixedMount(surface_tilt=20, surface_azimuth=220)
1932+
mount: FixedMount(surface_tilt=20, surface_azimuth=220, racking_model=None, module_height=None)
19201933
module: None
19211934
albedo: 0.25
1922-
racking_model: None
19231935
module_type: None
19241936
temperature_model_parameters: {}
19251937
strings: 1
19261938
modules_per_string: 1
1927-
inverter: blarg"""
1939+
inverter: blarg""" # noqa: E501
19281940
assert expected == system.__repr__()
19291941

19301942

19311943
def test_Array___repr__():
19321944
array = pvsystem.Array(
1933-
mount=pvsystem.FixedMount(surface_tilt=10, surface_azimuth=100),
1945+
mount=pvsystem.FixedMount(surface_tilt=10, surface_azimuth=100,
1946+
racking_model='close_mount'),
19341947
albedo=0.15, module_type='glass_glass',
19351948
temperature_model_parameters={'a': -3.56},
1936-
racking_model='close_mount',
19371949
module_parameters={'foo': 'bar'},
19381950
modules_per_string=100,
19391951
strings=10, module='baz',
19401952
name='biz'
19411953
)
19421954
expected = """Array:
19431955
name: biz
1944-
mount: FixedMount(surface_tilt=10, surface_azimuth=100)
1956+
mount: FixedMount(surface_tilt=10, surface_azimuth=100, racking_model='close_mount', module_height=None)
19451957
module: baz
19461958
albedo: 0.15
1947-
racking_model: close_mount
19481959
module_type: glass_glass
19491960
temperature_model_parameters: {'a': -3.56}
19501961
strings: 10
1951-
modules_per_string: 100"""
1962+
modules_per_string: 100""" # noqa: E501
19521963
assert array.__repr__() == expected
19531964

19541965

pvlib/tracking.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pandas as pd
33

44
from pvlib.tools import cosd, sind, tand
5+
from pvlib.tools import _build_kwargs
56
from pvlib.pvsystem import (
67
PVSystem, Array, SingleAxisTrackerMount, _unwrap_single_value
78
)
@@ -78,15 +79,19 @@ class SingleAxisTracker(PVSystem):
7879
def __init__(self, axis_tilt=0, axis_azimuth=0, max_angle=90,
7980
backtrack=True, gcr=2.0/7.0, cross_axis_tilt=0.0, **kwargs):
8081

82+
mount_kwargs = {
83+
k: kwargs.pop(k) for k in ['racking_model', 'module_height']
84+
if k in kwargs
85+
}
8186
mount = SingleAxisTrackerMount(axis_tilt, axis_azimuth, max_angle,
82-
backtrack, gcr, cross_axis_tilt)
87+
backtrack, gcr, cross_axis_tilt,
88+
**mount_kwargs)
8389

8490
array_defaults = {
8591
'albedo': None, 'surface_type': None, 'module': None,
8692
'module_type': None, 'module_parameters': None,
8793
'temperature_model_parameters': None,
8894
'modules_per_string': 1,
89-
'racking_model': None,
9095
}
9196
array_kwargs = {
9297
key: kwargs.get(key, array_defaults[key]) for key in array_defaults

0 commit comments

Comments
 (0)