Skip to content

Commit 5a7c541

Browse files
authored
Use scipy.constants (#1617)
* use scipy.constants rather than hard-coded values * update requirements to scipy>=1.4.0 * setup.py * whatsnew" * update scipy in asv
1 parent f82fd68 commit 5a7c541

File tree

10 files changed

+26
-22
lines changed

10 files changed

+26
-22
lines changed

benchmarks/asv.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"build": "",
118118
"numpy": "1.16.0",
119119
"pandas": "0.25.0",
120-
"scipy": "1.2.0",
120+
"scipy": "1.4.0",
121121
// Note: these don't have a minimum in setup.py
122122
"h5py": "2.10.0",
123123
"ephem": "3.7.6.0",

ci/requirements-py3.10.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- python=3.10
2424
- pytz
2525
- requests
26-
- scipy >= 1.2.0
26+
- scipy >= 1.4.0
2727
- shapely # pvfactors dependency
2828
# - siphon # conda-forge
2929
- statsmodels

ci/requirements-py3.7-min.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
- h5py==3.1.0
1818
- numpy==1.16.0
1919
- pandas==0.25.0
20-
- scipy==1.2.0
20+
- scipy==1.4.0
2121
- pytest-rerunfailures # conda version is >3.6
2222
- pytest-remotedata # conda package is 0.3.0, needs > 0.3.1
2323
- requests-mock

ci/requirements-py3.7.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- python=3.7
2424
- pytz
2525
- requests
26-
- scipy >= 1.2.0
26+
- scipy >= 1.4.0
2727
- shapely # pvfactors dependency
2828
- siphon # conda-forge
2929
- statsmodels

ci/requirements-py3.8.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- python=3.8
2424
- pytz
2525
- requests
26-
- scipy >= 1.2.0
26+
- scipy >= 1.4.0
2727
- shapely # pvfactors dependency
2828
- siphon # conda-forge
2929
- statsmodels

ci/requirements-py3.9.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- python=3.9
2424
- pytz
2525
- requests
26-
- scipy >= 1.2.0
26+
- scipy >= 1.4.0
2727
- shapely # pvfactors dependency
2828
# - siphon # conda-forge
2929
- statsmodels

docs/sphinx/source/whatsnew/v0.9.4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Benchmarking
7373

7474
Requirements
7575
~~~~~~~~~~~~
76-
76+
* Minimum version of scipy advanced from 1.2.0 to 1.4.0 (:issue:`483`, :pull:`1617`)
7777

7878
Contributors
7979
~~~~~~~~~~~~

pvlib/ivtools/sdm.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import numpy as np
1010

11-
import scipy.constants
11+
from scipy import constants
1212
from scipy import optimize
1313
from scipy.special import lambertw
1414
from scipy.misc import derivative
@@ -20,6 +20,9 @@
2020
from pvlib.ivtools.sde import _fit_sandia_cocontent
2121

2222

23+
CONSTANTS = {'E0': 1000.0, 'T0': 25.0, 'k': constants.k, 'q': constants.e}
24+
25+
2326
def fit_cec_sam(celltype, v_mp, i_mp, v_oc, i_sc, alpha_sc, beta_voc,
2427
gamma_pmp, cells_in_series, temp_ref=25):
2528
"""
@@ -204,7 +207,7 @@ def fit_desoto(v_mp, i_mp, v_oc, i_sc, alpha_sc, beta_voc, cells_in_series,
204207
"""
205208

206209
# Constants
207-
k = scipy.constants.value('Boltzmann constant in eV/K')
210+
k = constants.value('Boltzmann constant in eV/K') # in eV/K
208211
Tref = temp_ref + 273.15 # [K]
209212

210213
# initial guesses of variables for computing convergence:
@@ -340,9 +343,9 @@ def fit_pvsyst_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
340343
T0 : float
341344
cell temperature at STC, default 25 [C]
342345
k : float
343-
1.38066E-23 J/K (Boltzmann's constant)
346+
Boltzmann's constant [J/K]
344347
q : float
345-
1.60218E-19 Coulomb (elementary charge)
348+
elementary charge [Coulomb]
346349
347350
maxiter : int, default 5
348351
input that sets the maximum number of iterations for the parameter
@@ -417,7 +420,7 @@ def fit_pvsyst_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
417420
"""
418421

419422
if const is None:
420-
const = {'E0': 1000.0, 'T0': 25.0, 'k': 1.38066e-23, 'q': 1.60218e-19}
423+
const = CONSTANTS
421424

422425
ee = ivcurves['ee']
423426
tc = ivcurves['tc']
@@ -520,9 +523,9 @@ def fit_desoto_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
520523
T0 : float
521524
cell temperature at STC, default 25 [C]
522525
k : float
523-
1.38066E-23 J/K (Boltzmann's constant)
526+
Boltzmann's constant [J/K]
524527
q : float
525-
1.60218E-19 Coulomb (elementary charge)
528+
elementary charge [Coulomb]
526529
527530
maxiter : int, default 5
528531
input that sets the maximum number of iterations for the parameter
@@ -579,7 +582,7 @@ def fit_desoto_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
579582
"""
580583

581584
if const is None:
582-
const = {'E0': 1000.0, 'T0': 25.0, 'k': 1.38066e-23, 'q': 1.60218e-19}
585+
const = CONSTANTS
583586

584587
ee = ivcurves['ee']
585588
tc = ivcurves['tc']

pvlib/pvsystem.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
from urllib.request import urlopen
1212
import numpy as np
13+
from scipy import constants
1314
import pandas as pd
1415
from dataclasses import dataclass
1516
from abc import ABC, abstractmethod
@@ -2043,8 +2044,8 @@ def calcparams_desoto(effective_irradiance, temp_cell,
20432044
Source: [4]
20442045
'''
20452046

2046-
# Boltzmann constant in eV/K
2047-
k = 8.617332478e-05
2047+
# Boltzmann constant in eV/K, 8.617332478e-05
2048+
k = constants.value('Boltzmann constant in eV/K')
20482049

20492050
# reference temperature
20502051
Tref_K = temp_ref + 273.15
@@ -2301,10 +2302,10 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,
23012302
'''
23022303

23032304
# Boltzmann constant in J/K
2304-
k = 1.38064852e-23
2305+
k = constants.k
23052306

23062307
# elementary charge in coulomb
2307-
q = 1.6021766e-19
2308+
q = constants.e
23082309

23092310
# reference temperature
23102311
Tref_K = temp_ref + 273.15
@@ -2576,8 +2577,8 @@ def sapm(effective_irradiance, temp_cell, module):
25762577
temp_ref = 25
25772578
irrad_ref = 1000
25782579

2579-
q = 1.60218e-19 # Elementary charge in units of coulombs
2580-
kb = 1.38066e-23 # Boltzmann's constant in units of J/K
2580+
q = constants.e # Elementary charge in units of coulombs
2581+
kb = constants.k # Boltzmann's constant in units of J/K
25812582

25822583
# avoid problem with integer input
25832584
Ee = np.array(effective_irradiance, dtype='float64') / irrad_ref

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
'pandas >= 0.25.0',
3939
'pytz',
4040
'requests',
41-
'scipy >= 1.2.0',
41+
'scipy >= 1.4.0',
4242
'h5py',
4343
'importlib-metadata; python_version < "3.8"']
4444

0 commit comments

Comments
 (0)