Skip to content

Commit

Permalink
Merge pull request #54 from mikofski/futurize
Browse files Browse the repository at this point in the history
Futurize
  • Loading branch information
chetan201 authored Jan 18, 2018
2 parents 40d7eb4 + 60ab2ac commit 6abcafe
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ide
.spyderproject
.spyproject
.project
.pydevproject
.settings/
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: python
python:
- "2.7"
- "3.6"
cache: pip
sudo: required
before_install:
Expand Down
54 changes: 27 additions & 27 deletions pvmismatch/contrib/gen_coeffs/tests/test_two_diode.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ def test_didv_dpdv_frsh():
'rsh': RSH_2, 'ic': IC, 'vc': VC, 'vt': VT}
fdidv_test, jdidv_test = fdidv(**test_data)
expected_data = {
'isat1': ISAT1_2, 'isat2': ISAT2_2, 'rs': RS_2, 'rsh': RSH_2,
'ic(vc)': IC, 'vc': VC, 'vd': VD_2, 'vt': VT
isat1: ISAT1_2, isat2: ISAT2_2, rs: RS_2, rsh: RSH_2,
ic: IC, vc: VC, 'vd': VD_2, vt: VT
}
didv_simple = didv.subs('vc + ic(vc) * rs', 'vd')
didv_simple = didv.subs(vc + ic * rs, 'vd')
fdidv_expected = np.float(didv_simple.evalf(subs=expected_data))
LOGGER.debug('fdidv test: %g, expected: %g', fdidv_test, fdidv_expected)
assert np.isclose(fdidv_test, fdidv_expected)
# jacobian
d_didv_isat1 = didv.diff(isat1).subs('vc + ic(vc) * rs', 'vd')
d_didv_isat2 = didv.diff(isat2).subs('vc + ic(vc) * rs', 'vd')
d_didv_rs = didv.diff(rs).subs('vc + ic(vc) * rs', 'vd')
d_didv_rsh = didv.diff(rsh).subs('vc + ic(vc) * rs', 'vd')
d_didv_ic = didv.diff(ic).subs('vc + ic(vc) * rs', 'vd')
d_didv_vc = didv.diff(vc).subs('vc + ic(vc) * rs', 'vd')
d_didv_isat1 = didv.diff(isat1).subs(vc + ic * rs, 'vd')
d_didv_isat2 = didv.diff(isat2).subs(vc + ic * rs, 'vd')
d_didv_rs = didv.diff(rs).subs(vc + ic * rs, 'vd')
d_didv_rsh = didv.diff(rsh).subs(vc + ic * rs, 'vd')
d_didv_ic = didv.diff(ic).subs(vc + ic * rs, 'vd')
d_didv_vc = didv.diff(vc).subs(vc + ic * rs, 'vd')
# update expected test data with calculated derivative
expected_data['Derivative(ic(vc), vc)'] = fdidv_expected
expected_data[di_dv] = fdidv_expected
jdidv_expected = np.array([
d_didv_isat1.evalf(subs=expected_data),
d_didv_isat2.evalf(subs=expected_data),
Expand All @@ -88,17 +88,17 @@ def test_didv_dpdv_frsh():
dpdv = didv * vc + ic
# test fdpdv
fdpdv_test, jdpdv_test = fdpdv(**test_data)
dpdv_simple = dpdv.subs('vc + ic(vc) * rs', 'vd')
dpdv_simple = dpdv.subs(vc + ic * rs, 'vd')
fdpdv_expected = np.float(dpdv_simple.evalf(subs=expected_data))
LOGGER.debug('fdpdv test: %g, expected: %g', fdpdv_test, fdpdv_expected)
assert np.isclose(fdpdv_test, fdpdv_expected)
# jacobian
d_dpdv_isat1 = dpdv.diff(isat1).subs('vc + ic(vc) * rs', 'vd')
d_dpdv_isat2 = dpdv.diff(isat2).subs('vc + ic(vc) * rs', 'vd')
d_dpdv_rs = dpdv.diff(rs).subs('vc + ic(vc) * rs', 'vd')
d_dpdv_rsh = dpdv.diff(rsh).subs('vc + ic(vc) * rs', 'vd')
d_dpdv_ic = dpdv.diff(ic).subs('vc + ic(vc) * rs', 'vd')
d_dpdv_vc = dpdv.diff(vc).subs('vc + ic(vc) * rs', 'vd')
d_dpdv_isat1 = dpdv.diff(isat1).subs(vc + ic * rs, 'vd')
d_dpdv_isat2 = dpdv.diff(isat2).subs(vc + ic * rs, 'vd')
d_dpdv_rs = dpdv.diff(rs).subs(vc + ic * rs, 'vd')
d_dpdv_rsh = dpdv.diff(rsh).subs(vc + ic * rs, 'vd')
d_dpdv_ic = dpdv.diff(ic).subs(vc + ic * rs, 'vd')
d_dpdv_vc = dpdv.diff(vc).subs(vc + ic * rs, 'vd')
jdpdv_expected = np.array([
d_dpdv_isat1.evalf(subs=expected_data),
d_dpdv_isat2.evalf(subs=expected_data),
Expand All @@ -117,23 +117,23 @@ def test_didv_dpdv_frsh():
del test_data['ic'], test_data['vc'] # remove Ic, Vc
test_data['isc'] = ISC0 # add Isc
frsh_test, jfrsh_test = fjrsh(**test_data)
frsh_simple = frsh.subs('vc + ic(vc) * rs', 'vd')
frsh_simple = frsh.subs(vc + ic * rs, 'vd')
# update expected test data with calculated derivative
expected_data['ic(vc)'] = ISC0
expected_data['vc'] = 0
expected_data[ic] = ISC0
expected_data[vc] = 0
expected_data['vd'] = ISC0 * RS_2
didv_isc = np.float(didv_simple.evalf(subs=expected_data))
expected_data['Derivative(ic(vc), vc)'] = didv_isc
expected_data[di_dv] = didv_isc
frsh_expected = np.float(frsh_simple.evalf(subs=expected_data))
LOGGER.debug('frsh test: %r, expected: %r', frsh_test, frsh_expected)
assert np.isclose(frsh_test, frsh_expected)
# jacobian
dfrsh_isat1 = frsh.diff(isat1).subs('vc + ic(vc) * rs', 'vd')
dfrsh_isat2 = frsh.diff(isat2).subs('vc + ic(vc) * rs', 'vd')
dfrsh_rs = frsh.diff(rs).subs('vc + ic(vc) * rs', 'vd')
dfrsh_rsh = frsh.diff(rsh).subs('vc + ic(vc) * rs', 'vd')
dfrsh_ic = frsh.diff(ic).subs('vc + ic(vc) * rs', 'vd')
dfrsh_vc = frsh.diff(vc).subs('vc + ic(vc) * rs', 'vd')
dfrsh_isat1 = frsh.diff(isat1).subs(vc + ic * rs, 'vd')
dfrsh_isat2 = frsh.diff(isat2).subs(vc + ic * rs, 'vd')
dfrsh_rs = frsh.diff(rs).subs(vc + ic * rs, 'vd')
dfrsh_rsh = frsh.diff(rsh).subs(vc + ic * rs, 'vd')
dfrsh_ic = frsh.diff(ic).subs(vc + ic * rs, 'vd')
dfrsh_vc = frsh.diff(vc).subs(vc + ic * rs, 'vd')
jfrsh_expected = np.array([
dfrsh_isat1.evalf(subs=expected_data),
dfrsh_isat2.evalf(subs=expected_data),
Expand Down
4 changes: 3 additions & 1 deletion pvmismatch/pvmismatch_lib/pvcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
object which is used by modules, strings and systems.
"""

from __future__ import absolute_import
from future.utils import iteritems
from pvmismatch.pvmismatch_lib.pvconstants import PVconstants
import numpy as np
from matplotlib import pyplot as plt
Expand Down Expand Up @@ -95,7 +97,7 @@ def update(self, **kwargs):
"""
# TODO: use __dict__.update(), check for floats and update IV curve
# self.__dict__.update(kwargs)
for k, v in kwargs.iteritems():
for k, v in iteritems(kwargs):
setattr(self, k, v)

@property
Expand Down
8 changes: 6 additions & 2 deletions pvmismatch/pvmismatch_lib/pvmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
This module defines the :class:`~pvmismatch.pvmismatch_lib.pvmodule.PVmodule`.
"""

from __future__ import absolute_import
from past.builtins import xrange, range
from builtins import zip
from six import itervalues
import numpy as np
from copy import copy
from matplotlib import pyplot as plt
Expand Down Expand Up @@ -244,7 +248,7 @@ def setSuns(self, Ee, cells=None):
else:
new_pvcells[cell_id] = old_pvcells[pvcell]
self.pvcells = new_pvcells
pvcell_set = old_pvcells.itervalues()
pvcell_set = itervalues(old_pvcells)
for pvc in pvcell_set:
pvc.Ee = Ee
elif np.size(Ee) == self.numberCells:
Expand Down Expand Up @@ -314,7 +318,7 @@ def setTemps(self, Tc, cells=None):
else:
new_pvcells[cell_id] = old_pvcells[pvcell]
self.pvcells = new_pvcells
pvcell_set = old_pvcells.itervalues()
pvcell_set = itervalues(old_pvcells)
for pvc in pvcell_set:
pvc.Tcell = Tc
elif np.size(Tc) == self.numberCells:
Expand Down
7 changes: 5 additions & 2 deletions pvmismatch/pvmismatch_lib/pvstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
class.
"""

from __future__ import absolute_import
from past.builtins import range
from future.utils import iteritems
import numpy as np
from copy import copy
from matplotlib import pyplot as plt
Expand Down Expand Up @@ -101,7 +104,7 @@ def setSuns(self, Ee):
else:
self.pvmods = copy(self.pvmods) # copy list first
try:
for pvmod, cell_Ee in Ee.iteritems():
for pvmod, cell_Ee in iteritems(Ee):
pvmod = int(pvmod)
self.pvmods[pvmod] = copy(self.pvmods[pvmod])
if hasattr(cell_Ee, 'keys'):
Expand Down Expand Up @@ -164,7 +167,7 @@ def setTemps(self, Tc):
else:
self.pvmods = copy(self.pvmods) # copy list first
try:
for pvmod, cell_Tc in Tc.iteritems():
for pvmod, cell_Tc in iteritems(Tc):
pvmod = int(pvmod)
self.pvmods[pvmod] = copy(self.pvmods[pvmod])
if hasattr(cell_Tc, 'keys'):
Expand Down
30 changes: 13 additions & 17 deletions pvmismatch/pvmismatch_lib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
class.
"""

from __future__ import absolute_import
from past.builtins import basestring
from future.utils import iteritems
import numpy as np
from copy import copy
from matplotlib import pyplot as plt
Expand Down Expand Up @@ -117,7 +120,7 @@ def setSuns(self, Ee):
for pvstr in self.pvstrs:
pvstr.setSuns(Ee)
else:
for pvstr, pvmod_Ee in Ee.iteritems():
for pvstr, pvmod_Ee in iteritems(Ee):
pvstr = int(pvstr)
self.pvstrs[pvstr] = copy(self.pvstrs[pvstr])
self.pvstrs[pvstr].setSuns(pvmod_Ee)
Expand Down Expand Up @@ -155,7 +158,7 @@ def setTemps(self, Tc):
for pvstr in self.pvstrs:
pvstr.setTemps(Tc)
else:
for pvstr, pvmod_Tc in Tc.iteritems():
for pvstr, pvmod_Tc in iteritems(Tc):
pvstr = int(pvstr)
self.pvstrs[pvstr] = copy(self.pvstrs[pvstr])
self.pvstrs[pvstr].setTemps(pvmod_Tc)
Expand All @@ -166,23 +169,16 @@ def setTemps(self, Tc):
def plotSys(self, sysPlot=None):
"""
Plot system I-V curves.
Arguments sysPlot : matplotlib.figure.Figure
Returns sysPlot : matplotlib.figure.Figure
:param sysPlot: integer, string, or existing figure
:returns: new figure
"""
# create new figure if sysPlot is None
# or make the specified sysPlot current and clear it
if not sysPlot:
sysPlot = plt.figure()
elif isinstance(sysPlot, (int, basestring)):
# create new figure if sysPlot or make the specified sysPlot current
# and clear it
try:
sysPlot.clear()
except (AttributeError, SyntaxError):
sysPlot = plt.figure(sysPlot)
else:
try:
sysPlot = plt.figure(sysPlot.number)
except TypeError as e:
print '%s is not a figure.' % sysPlot
print 'Sorry, "plotSys" takes a "int", "str" or "Figure".'
raise e
sysPlot.clear()
plt.subplot(2, 1, 1)
plt.plot(self.Vsys, self.Isys)
plt.xlim(0, self.Voc * 1.1)
Expand Down
3 changes: 1 addition & 2 deletions pvmismatch/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
from nose.tools import ok_

def test_parallel_cals_is_gone():
from pvmismatch import *

from pvmismatch import pvconstants, pvcell, pvmodule, pvstring, pvsystem
20 changes: 11 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
nose
numpy
scipy
matplotlib
sphinx
dulwich
sympy
pvlib
pytest
nose==1.3.7
numpy==1.13.3
scipy==1.0.0
matplotlib==2.1.0
Sphinx==1.6.3
dulwich==0.18.6
sympy==1.1.1
pvlib==0.5.1
pytest==3.2.1
future==0.16.0
six==1.11.0
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
72 changes: 53 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,56 @@
except IOError:
pass

setup(name=__name__,
version=__version__,
description='PV Mismatch Calculator',
long_description=README,
author=__author__,
author_email=__email__,
url=__url__,
license='BSD 3-clause',
packages=['pvmismatch', 'pvmismatch.pvmismatch_lib',
'pvmismatch.pvmismatch_tk', 'pvmismatch.contrib',
'pvmismatch.contrib.gen_coeffs'],
requires=['numpy (>=1.8)', 'matplotlib (>=1.3)', 'scipy (>=0.12.0)'],
scripts=['pv_tk.py'],
package_data={'pvmismatch':
['pvmismatch_json/messagetext.English.json',
'pvmismatch_json/validationConstants.json',
'res/logo.png', 'res/logo_invert.png',
'res/logo_bg.png', 'docs/conf.py', 'docs/*.rst',
'docs/Makefile', 'docs/make.bat']})
INSTALL_REQUIRES = [
'numpy>=1.13.3', 'matplotlib>=2.1.0', 'scipy>=1.0.0', 'future>=0.16.0',
'six>=1.11.0'
]

TESTS_REQUIRES = [
'nose>=1.3.7', 'pytest>=3.2.1', 'sympy>=1.1.1', 'pvlib>=0.5.1'
]

CLASSIFIERS = [
'Development Status :: 4 - Beta',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Intended Audience :: Science/Research',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Scientific/Engineering',
]

setup(
name=__name__,
version=__version__,
description='PV Mismatch Calculator',
long_description=README,
author=__author__,
author_email=__email__,
url=__url__,
license='BSD 3-clause',
packages=[
'pvmismatch', 'pvmismatch.pvmismatch_lib',
'pvmismatch.pvmismatch_tk', 'pvmismatch.contrib',
'pvmismatch.contrib.gen_coeffs'
],
install_requires=INSTALL_REQUIRES,
tests_require=TESTS_REQUIRES,
scripts=['pv_tk.py'],
package_data={
'pvmismatch': [
'pvmismatch_json/messagetext.English.json',
'pvmismatch_json/validationConstants.json',
'res/logo.png', 'res/logo_invert.png',
'res/logo_bg.png', 'docs/conf.py', 'docs/*.rst',
'docs/Makefile', 'docs/make.bat'
]
},
classifiers=CLASSIFIERS
)

0 comments on commit 6abcafe

Please sign in to comment.