Skip to content

Commit

Permalink
Merge PR #37 from bmeyers to fix setSuns issue #33
Browse files Browse the repository at this point in the history
* setSuns method at the module level can now take a scalar to set an entire module. Can also still use len-1 list. Fixes #33

* Adding tests for improved setSuns method. Added ducktyping to string-level setting as well.
Relaxed constraint on test_pvcell.test_calc_series to allow for change due to Numpy update.
  • Loading branch information
bmeyers authored and mikofski committed Oct 11, 2016
1 parent d416bbf commit b2e6660
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
18 changes: 13 additions & 5 deletions pvmismatch/pvmismatch_lib/pvstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,19 @@ def setSuns(self, Ee):
for pvmod in iter(self.pvmods):
pvmod.setSuns(Ee)
else:
for pvmod, cell_Ee in Ee.iteritems():
if hasattr(cell_Ee, 'keys'):
self.pvmods[pvmod].setSuns(**cell_Ee)
else:
self.pvmods[pvmod].setSuns(*cell_Ee)
try:
for pvmod, cell_Ee in Ee.iteritems():
if hasattr(cell_Ee, 'keys'):
self.pvmods[pvmod].setSuns(**cell_Ee)
else:
try:
self.pvmods[pvmod].setSuns(*cell_Ee)
except TypeError:
self.pvmods[pvmod].setSuns(cell_Ee)
except AttributeError:
Ee = Ee[0]
for pvmod in iter(self.pvmods):
pvmod.setSuns(Ee)
# update modules
self.Istring, self.Vstring, self.Pstring = self.calcString()

Expand Down
2 changes: 1 addition & 1 deletion pvmismatch/tests/test_pvcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_calc_series():
# noinspection PyTypeChecker
ok_(np.allclose(i, iv[0]))
# noinspection PyTypeChecker
ok_(np.allclose(v, iv[1]))
ok_(np.allclose(v, iv[1], rtol=1e-4))
return i, v


Expand Down
50 changes: 50 additions & 0 deletions pvmismatch/tests/test_setsuns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Test for setSuns method.
Bennet Meyers 10/10/16
"""

import numpy as np
from nose.tools import ok_
from pvmismatch.pvmismatch_lib.pvsystem import PVsystem


def test_basic():
pvsys = PVsystem()
pvsys.setSuns(.75)
ok_(np.isclose(pvsys.Pmp, 23907.936630685774))


def test_dictionary():
pvsys = PVsystem()
Ee = {1: {3: {'cells': np.arange(30), 'Ee': [.25] * 30}}}
pvsys.setSuns(Ee)
ok_(np.isclose(pvsys.Pmp, 31618.1813179655))


def test_set_mod_1():
pvsys = PVsystem()
Ee = {1: {3: [.2], 0: [.1]}}
pvsys.setSuns(Ee)
ok_(np.isclose(pvsys.Pmp, 29566.303088387336))


def test_set_mod_2():
pvsys = PVsystem()
Ee = {1: {3: .2, 0: .1}}
pvsys.setSuns(Ee)
ok_(np.isclose(pvsys.Pmp, 29566.303088387336))


def test_set_str_1():
pvsys = PVsystem()
Ee = {1: [.1]}
pvsys.setSuns(Ee)
ok_(np.isclose(pvsys.Pmp, 29136.544447716446))


def test_set_str_2():
pvsys = PVsystem()
Ee = {1: .1}
pvsys.setSuns(Ee)
ok_(np.isclose(pvsys.Pmp, 29136.544447716446))

0 comments on commit b2e6660

Please sign in to comment.