Skip to content

Use scipy.constants #1617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 20, 2022
Merged
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
2 changes: 1 addition & 1 deletion benchmarks/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"build": "",
"numpy": "1.16.0",
"pandas": "0.25.0",
"scipy": "1.2.0",
"scipy": "1.4.0",
// Note: these don't have a minimum in setup.py
"h5py": "2.10.0",
"ephem": "3.7.6.0",
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
- python=3.10
- pytz
- requests
- scipy >= 1.2.0
- scipy >= 1.4.0
- shapely # pvfactors dependency
# - siphon # conda-forge
- statsmodels
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.7-min.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
- h5py==3.1.0
- numpy==1.16.0
- pandas==0.25.0
- scipy==1.2.0
- scipy==1.4.0
- pytest-rerunfailures # conda version is >3.6
- pytest-remotedata # conda package is 0.3.0, needs > 0.3.1
- requests-mock
2 changes: 1 addition & 1 deletion ci/requirements-py3.7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
- python=3.7
- pytz
- requests
- scipy >= 1.2.0
- scipy >= 1.4.0
- shapely # pvfactors dependency
- siphon # conda-forge
- statsmodels
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
- python=3.8
- pytz
- requests
- scipy >= 1.2.0
- scipy >= 1.4.0
- shapely # pvfactors dependency
- siphon # conda-forge
- statsmodels
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
- python=3.9
- pytz
- requests
- scipy >= 1.2.0
- scipy >= 1.4.0
- shapely # pvfactors dependency
# - siphon # conda-forge
- statsmodels
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/source/whatsnew/v0.9.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Benchmarking

Requirements
~~~~~~~~~~~~

* Minimum version of scipy advanced from 1.2.0 to 1.4.0 (:issue:`483`, :pull:`1617`)

Contributors
~~~~~~~~~~~~
Expand Down
19 changes: 11 additions & 8 deletions pvlib/ivtools/sdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np

import scipy.constants
from scipy import constants
from scipy import optimize
from scipy.special import lambertw
from scipy.misc import derivative
Expand All @@ -20,6 +20,9 @@
from pvlib.ivtools.sde import _fit_sandia_cocontent


CONSTANTS = {'E0': 1000.0, 'T0': 25.0, 'k': constants.k, 'q': constants.e}


def fit_cec_sam(celltype, v_mp, i_mp, v_oc, i_sc, alpha_sc, beta_voc,
gamma_pmp, cells_in_series, temp_ref=25):
"""
Expand Down Expand Up @@ -204,7 +207,7 @@ def fit_desoto(v_mp, i_mp, v_oc, i_sc, alpha_sc, beta_voc, cells_in_series,
"""

# Constants
k = scipy.constants.value('Boltzmann constant in eV/K')
k = constants.value('Boltzmann constant in eV/K') # in eV/K
Tref = temp_ref + 273.15 # [K]

# initial guesses of variables for computing convergence:
Expand Down Expand Up @@ -340,9 +343,9 @@ def fit_pvsyst_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
T0 : float
cell temperature at STC, default 25 [C]
k : float
1.38066E-23 J/K (Boltzmann's constant)
Boltzmann's constant [J/K]
q : float
1.60218E-19 Coulomb (elementary charge)
elementary charge [Coulomb]

maxiter : int, default 5
input that sets the maximum number of iterations for the parameter
Expand Down Expand Up @@ -417,7 +420,7 @@ def fit_pvsyst_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
"""

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

ee = ivcurves['ee']
tc = ivcurves['tc']
Expand Down Expand Up @@ -520,9 +523,9 @@ def fit_desoto_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
T0 : float
cell temperature at STC, default 25 [C]
k : float
1.38066E-23 J/K (Boltzmann's constant)
Boltzmann's constant [J/K]
q : float
1.60218E-19 Coulomb (elementary charge)
elementary charge [Coulomb]

maxiter : int, default 5
input that sets the maximum number of iterations for the parameter
Expand Down Expand Up @@ -579,7 +582,7 @@ def fit_desoto_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
"""

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

ee = ivcurves['ee']
tc = ivcurves['tc']
Expand Down
13 changes: 7 additions & 6 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
from urllib.request import urlopen
import numpy as np
from scipy import constants
import pandas as pd
from dataclasses import dataclass
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -2043,8 +2044,8 @@ def calcparams_desoto(effective_irradiance, temp_cell,
Source: [4]
'''

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

# reference temperature
Tref_K = temp_ref + 273.15
Expand Down Expand Up @@ -2301,10 +2302,10 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,
'''

# Boltzmann constant in J/K
k = 1.38064852e-23
k = constants.k

# elementary charge in coulomb
q = 1.6021766e-19
q = constants.e

# reference temperature
Tref_K = temp_ref + 273.15
Expand Down Expand Up @@ -2576,8 +2577,8 @@ def sapm(effective_irradiance, temp_cell, module):
temp_ref = 25
irrad_ref = 1000

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

# avoid problem with integer input
Ee = np.array(effective_irradiance, dtype='float64') / irrad_ref
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
'pandas >= 0.25.0',
'pytz',
'requests',
'scipy >= 1.2.0',
'scipy >= 1.4.0',
'h5py',
'importlib-metadata; python_version < "3.8"']

Expand Down