Skip to content
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

replace deprecated scipy.integrate.simps with scipy.integrate.simpson #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions xopto/diffusion/srr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
################################# End license ##################################

import numpy as np
from scipy.integrate import simps
from scipy.integrate import simpson

def fresnel_s_polarized(theta:float, n1: float, n2: float) -> float:
'''
Expand Down Expand Up @@ -127,8 +127,8 @@ def _fresnel_j(theta: float, nmedium: float, noutside: float) -> float:
def r_eff(nmedium: float, noutside: float, steps: int = 10000) -> float:
theta = np.linspace(0, np.pi/2.0, steps)

r_phi = simps(_fresnel_phi(theta, nmedium, noutside), dx=theta[1] - theta[0])
r_j = simps(_fresnel_j(theta, nmedium, noutside), dx=theta[1] - theta[0])
r_phi = simpson(_fresnel_phi(theta, nmedium, noutside), dx=theta[1] - theta[0])
r_j = simpson(_fresnel_j(theta, nmedium, noutside), dx=theta[1] - theta[0])

return (r_phi + r_j)/(2.0 - r_phi + r_j)

Expand Down Expand Up @@ -159,13 +159,13 @@ def __init__(self, nmedium: float, noutside: float,
1.0 - fresnel_unpolarized(theta, nmedium, noutside))*\
np.cos(theta)*np.sin(theta)

self._back_hemi_coeff1 = simps(back_hemi_coeff1, dx=theta[1]-theta[0])
self._back_hemi_coeff1 = simpson(back_hemi_coeff1, dx=theta[1]-theta[0])

back_hemi_coeff2 = 1.5*(
1.0 - fresnel_unpolarized(theta, nmedium, noutside))*\
np.cos(theta)**2*np.sin(theta)

self._back_hemi_coeff2 = simps(back_hemi_coeff2, dx=theta[1] - theta[0])
self._back_hemi_coeff2 = simpson(back_hemi_coeff2, dx=theta[1] - theta[0])

self._R_eff = r_eff(nmedium, noutside, steps)

Expand Down
6 changes: 3 additions & 3 deletions xopto/mcbase/mcrmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
################################# End license ##################################

import numpy as np
from scipy.integrate import simps
from scipy.integrate import simpson

from xopto.diffusion.srr import SRDA

Expand Down Expand Up @@ -120,12 +120,12 @@ def __call__(self, mua: float, musr: float) -> float:

def _r_total(self) -> float:
r = np.linspace(0, self.R_MAX, self.STEPS)
return simps(
return simpson(
2.0*np.pi*self._da(r, self._mua, self._musr)*r, dx=r[1] - r[0])

def _residual(self, i) -> float:
r = np.linspace(self._rmin + (i - 1)*self._dr, self.R_MAX, self.STEPS)
return simps(
return simpson(
2.0*np.pi*self._da(r, self._mua, self._musr)*r, dx=r[1] - r[0])

def _find_rmax(self) -> float:
Expand Down
4 changes: 2 additions & 2 deletions xopto/mcbase/mcutil/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ def __init__(self, start: float=0.0, stop: float=1.0, n: int=1,
The spacing of points in the RadialAxis is uneven even if logscale is
set to False, since correction of the bin centers depends on the
absolute position of the bin.
If using data from RadialAxis with the simpson integration method make
If using data from RadialAxis with the Simpson integration method make
sure to use a version that does not require a fixed step (specify x
instead of dx in a call to scipy.integrate.simps).
instead of dx in a call to scipy.integrate.simpson).
If using the :py:meth:`xopto.util.hankel.discrete_simpson` method make
sure to set the value of the uneven parameter to True.
'''
Expand Down
7 changes: 3 additions & 4 deletions xopto/mcbase/mcutil/fourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import numpy as np

# Import the Symmetric Fourier Transform class
from scipy.interpolate import interp1d
from scipy.integrate import quad, simps
from scipy.integrate import simpson

def _uneven(array):
tmp = np.diff(array)
Expand Down Expand Up @@ -85,8 +84,8 @@ def discreteSimpson(frequency: list or tuple or np.ndarray,
for index in range(np_freqs.size):
f = fpts*np.exp(-2.0*np.pi*1j*xpts*np_freqs[index])
if out.ndim > 1:
out[:, index] = simps(f, x, dx=dx)
out[:, index] = simpson(f, x, dx=dx)
else:
out[index] = simps(f, x, dx=dx)
out[index] = simpson(f, x, dx=dx)

return out
2 changes: 0 additions & 2 deletions xopto/mcml/test/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import time

import numpy as np
from scipy import io
from scipy.integrate import simps

from xopto.mcbase.mctest import McTest

Expand Down
2 changes: 0 additions & 2 deletions xopto/mcvox/test/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import time

import numpy as np
from scipy import io
from scipy.integrate import simps

from xopto.mcbase.mctest import McTest

Expand Down
2 changes: 0 additions & 2 deletions xopto/pf/miefractal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

from typing import Tuple

import numpy as np

from .pfbase import PfBase
from .miepd import MiePd
from .distribution import Fractal
Expand Down
1 change: 0 additions & 1 deletion xopto/pf/mieml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from typing import List, Tuple

import numpy as np
from scipy.integrate import simps, quad
from scattnlay import scattnlay

from .pfbase import PfBase
Expand Down
7 changes: 2 additions & 5 deletions xopto/pf/miemlfractal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@
# along with PyXOpto. If not, see <https://www.gnu.org/licenses/>.
################################# End license ##################################

from typing import Callable, Tuple

import numpy as np
from scipy.integrate import simps, quad
from typing import Tuple

from .distribution import Fractal
from .miemlpd import MieMlPd, ComplexVector, FloatVector
from .miemlpd import MieMlPd, ComplexVector


class MieMlFractal(MieMlPd):
Expand Down
2 changes: 0 additions & 2 deletions xopto/pf/miemlnormal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# along with PyXOpto. If not, see <https://www.gnu.org/licenses/>.
################################# End license ##################################

import numpy as np

from .distribution import Normal
from .miemlpd import MieMlPd, ComplexVector, FloatVector

Expand Down
10 changes: 5 additions & 5 deletions xopto/pf/miemlpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from typing import Callable, Tuple

import numpy as np
from scipy.integrate import simps, quad
from scipy.integrate import simpson, quad

from .pfbase import PfBase
from .mieml import MieMl, ComplexVector, FloatVector
Expand Down Expand Up @@ -196,9 +196,9 @@ def __init__(self, nlayers: ComplexVector, nmedium: ComplexVector,
Scs_p[i] = mieml.scs()*self._pdpts[i]
Ecs_p[i] = mieml.ecs()*self._pdpts[i]

self._scs = simps(Scs_p, dx=self._dd)
self._ecs = simps(Ecs_p, dx=self._dd)
self._g1 = simps(G1_mieml*Scs_p, dx=self._dd)/self._scs
self._scs = simpson(Scs_p, dx=self._dd)
self._ecs = simpson(Ecs_p, dx=self._dd)
self._g1 = simpson(G1_mieml*Scs_p, dx=self._dd)/self._scs

@staticmethod
def _g1_scs(nlayers, nmedium: ComplexVector, diameters: FloatVector,
Expand Down Expand Up @@ -283,7 +283,7 @@ def acs(self) -> float:

def _mieml_pd(self, Pf):
self._pdpts.shape = (self._D.size, 1)
pf = simps(Pf*self._pdpts, dx=self._dd, axis=0)
pf = simpson(Pf*self._pdpts, dx=self._dd, axis=0)
return pf

def _mieml_quad_pd(self, costheta):
Expand Down
2 changes: 0 additions & 2 deletions xopto/pf/mienormal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

from typing import Callable

import numpy as np

from .pfbase import PfBase
from .miepd import MiePd
from .distribution import Normal
Expand Down
10 changes: 5 additions & 5 deletions xopto/pf/miepd.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from typing import Callable, Tuple

import numpy as np
from scipy.integrate import quad, simps
from scipy.integrate import quad, simpson

from .pfbase import PfBase
from .mie import Mie
Expand Down Expand Up @@ -131,9 +131,9 @@ def __init__(self, nsphere: float or complex, nmedium: float or complex,
Scs_p[i] = mie.scs()*self._pdpts[i]
Ecs_p[i] = mie.ecs()*self._pdpts[i]

self._scs = simps(Scs_p, dx=self._dd)
self._ecs = simps(Ecs_p, dx=self._dd)
self._g1 = simps(G1_mie*Scs_p, dx=self._dd)/self._scs
self._scs = simpson(Scs_p, dx=self._dd)
self._ecs = simpson(Ecs_p, dx=self._dd)
self._g1 = simpson(G1_mie*Scs_p, dx=self._dd)/self._scs

@staticmethod
def _g1_scs(nsphere: float or complex, nmedium: float or complex,
Expand Down Expand Up @@ -215,7 +215,7 @@ def acs(self) -> float:

def _mie_pd(self, Pf: np.ndarray) -> np.ndarray:
self._pdpts.shape = (self._D.size, 1)
pf = simps(Pf*self._pdpts, dx=self._dd, axis=0)
pf = simpson(Pf*self._pdpts, dx=self._dd, axis=0)
return pf

def _mie_pd_quad(self, costheta: np.ndarray) -> np.ndarray:
Expand Down
2 changes: 0 additions & 2 deletions xopto/pf/miepolystyrene.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

from typing import Tuple

import numpy as np

from .mie import Mie
from .miefractal import MieFractal
from .mienormal import MieNormal
Expand Down
16 changes: 8 additions & 8 deletions xopto/pf/pfbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from typing import Tuple

import numpy as np
from scipy.integrate import quad, simps
from scipy.integrate import quad, simpson
from scipy.optimize import minimize
from scipy.interpolate import interp1d

Expand Down Expand Up @@ -56,7 +56,7 @@ def fastg(n: int, pf: np.ndarray, costheta: np.ndarray = None) -> float:
if costheta is None:
costheta = np.linspace(-1.0, 1.0, pf.size)

return simps(pf*np.polynomial.legendre.Legendre.basis(n)(costheta),
return simpson(pf*np.polynomial.legendre.Legendre.basis(n)(costheta),
dx=costheta[1] - costheta[0])

def fastgs(last: int, pf: np.ndarray, costheta: np.ndarray = None,
Expand Down Expand Up @@ -94,8 +94,8 @@ def fastgs(last: int, pf: np.ndarray, costheta: np.ndarray = None,
out = np.zeros([last + 1])

for n in range(last + 1):
out[n] = simps(pf*np.polynomial.legendre.Legendre.basis(n)(costheta),
dx=costheta[1] - costheta[0])
out[n] = simpson(pf*np.polynomial.legendre.Legendre.basis(n)(costheta),
dx=costheta[1] - costheta[0])
return out


Expand Down Expand Up @@ -318,8 +318,8 @@ def fastg(self, n: int, npts: int = 1000, pf: np.ndarray = None,
if pf is None:
pf = self(costheta)

return simps(pf*np.polynomial.legendre.Legendre.basis(n)(costheta),
dx=costheta[1] - costheta[0])
return simpson(pf*np.polynomial.legendre.Legendre.basis(n)(costheta),
dx=costheta[1] - costheta[0])

def fastgs(self, last: int, npts: int = 1000, pf: np.ndarray = None,
costheta: np.ndarray =None) -> np.ndarray:
Expand Down Expand Up @@ -363,8 +363,8 @@ def fastgs(self, last: int, npts: int = 1000, pf: np.ndarray = None,

G = np.zeros([last + 1])
for n in range(last + 1):
G[n] = simps(pf*np.polynomial.legendre.Legendre.basis(n)(costheta),
dx=costheta[1] - costheta[0])
G[n] = simpson(pf*np.polynomial.legendre.Legendre.basis(n)(costheta),
dx=costheta[1] - costheta[0])
return G

def cdf(self, costheta: np.ndarray, meth: str = 'simpson',
Expand Down
16 changes: 8 additions & 8 deletions xopto/util/color/cie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from typing import Tuple

import numpy as np
from scipy.integrate import simps
from scipy.integrate import simpson
from scipy.interpolate import interp1d

from xopto import DATA_PATH
Expand Down Expand Up @@ -431,9 +431,9 @@ def XYZ(self, wavelengths: np.ndarray, spectrum: np.ndarray) \
cmf = self.xyz_cmf(wavelengths)

return \
simps(spectrum*cmf[0], wavelengths), \
simps(spectrum*cmf[1], wavelengths), \
simps(spectrum*cmf[2], wavelengths)
simpson(spectrum*cmf[0], wavelengths), \
simpson(spectrum*cmf[1], wavelengths), \
simpson(spectrum*cmf[2], wavelengths)

def rgb(self, wavelengths: np.ndarray, spectrum: np.ndarray) \
-> Tuple[np.ndarray, np.ndarray, np.ndarray]:
Expand All @@ -456,9 +456,9 @@ def rgb(self, wavelengths: np.ndarray, spectrum: np.ndarray) \
rgb_cmf = self.rgb_cmf(wavelengths)

return \
simps(spectrum*rgb_cmf[0], wavelengths), \
simps(spectrum*rgb_cmf[1], wavelengths), \
simps(spectrum*rgb_cmf[2], wavelengths)
simpson(spectrum*rgb_cmf[0], wavelengths), \
simpson(spectrum*rgb_cmf[1], wavelengths), \
simpson(spectrum*rgb_cmf[2], wavelengths)

def xyY(self, wavelengths: np.ndarray, spectrum: np.ndarray) -> np.ndarray:
'''
Expand Down Expand Up @@ -1020,7 +1020,7 @@ def XYZ(self, observer: str or Observer, normalize: bool or float = False):
raise ValueError('Unknown observer "{}"!'.format(observer))
observer = observer_

XYZ = simps(
XYZ = simpson(
observer.xyz_cmf(STANDARD_WAVELENGTHS)*
self.spd(STANDARD_WAVELENGTHS),
dx=STANDARD_WAVELENGTH_STEP
Expand Down