From 95b6ac47cecf53015e69197a7f6389a8cad5ba73 Mon Sep 17 00:00:00 2001 From: Natsuhiko Mizutani Date: Fri, 5 Jul 2024 23:01:36 +0900 Subject: [PATCH] `scipy>=1.14.0` has moved from `scipy.integrate.trapz` to `scipy.integrate.trapezoid`. import statement updated using try / except --- PyMieScatt/Inverse.py | 5 ++++- PyMieScatt/Mie.py | 5 ++++- docs/examples.rst | 5 ++++- docs/forward.rst | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/PyMieScatt/Inverse.py b/PyMieScatt/Inverse.py index 66c8e8d..182a278 100644 --- a/PyMieScatt/Inverse.py +++ b/PyMieScatt/Inverse.py @@ -6,7 +6,10 @@ from matplotlib.contour import QuadContourSet from matplotlib.collections import LineCollection from scipy.ndimage import zoom -from scipy.integrate import trapz +try: + from scipy.integrate import trapz +except ImportError: + from scipy.integrate import trapezoid as trapz from shapely import geometry def coerceDType(d): diff --git a/PyMieScatt/Mie.py b/PyMieScatt/Mie.py index 958245a..526c158 100644 --- a/PyMieScatt/Mie.py +++ b/PyMieScatt/Mie.py @@ -2,7 +2,10 @@ # http://pymiescatt.readthedocs.io/en/latest/forward.html import numpy as np from scipy.special import jv, yv -from scipy.integrate import trapz +try: + from scipy.integrate import trapz +except ImportError: + from scipy.integrate import trapezoid as trapz import warnings def coerceDType(d): diff --git a/docs/examples.rst b/docs/examples.rst index 967a01e..7833e57 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -189,7 +189,10 @@ Recently, a colleague needed to know how much light a distribution of salt aeros import PyMieScatt as ps # import PyMieScatt and abbreviate as ps import matplotlib.pyplot as plt # import standard plotting library and abbreviate as plt import numpy as np # import numpy and abbreviate as np - from scipy.integrate import trapz # import a single function for integration using trapezoidal rule + try: + from scipy.integrate import trapz # import a single function for integration using trapezoidal rule + except ImportError: + from scipy.integrate import trapezoid as trapz # for scipy>=1.14.0 m = 1.536 # refractive index of NaCl wavelength = 405 # replace with the laser wavelength (nm) diff --git a/docs/forward.rst b/docs/forward.rst index 4436a26..23face3 100644 --- a/docs/forward.rst +++ b/docs/forward.rst @@ -368,7 +368,7 @@ There is an important distinction in how the size distribution is reported from .. py:Function:: Mie_SD(m, wavelength, sizeDistributionDiameterBins, sizeDistribution[, nMedium=1.0, SMPS=True, asDict=False]) - Returns Mie coefficients β\ :sub:`ext`, β\ :sub:`sca`, β\ :sub:`abs`, G, β\ :sub:`pr`, β\ :sub:`back`, β\ :sub:`ratio`. Uses `scipy.integrate.trapz `_ to compute the integral, which can introduce errors if your distribution is too sparse. Best used with a continuous, compactly-supported distribution. + Returns Mie coefficients β\ :sub:`ext`, β\ :sub:`sca`, β\ :sub:`abs`, G, β\ :sub:`pr`, β\ :sub:`back`, β\ :sub:`ratio`. Uses `scipy.integrate.trapz `_ (or `scipy.integrate.trapezoid `_ )to compute the integral, which can introduce errors if your distribution is too sparse. Best used with a continuous, compactly-supported distribution. **Parameters** @@ -398,7 +398,7 @@ There is an important distinction in how the size distribution is reported from .. py:Function:: Mie_Lognormal(m, wavelength, geoStdDev, geoMean, numberOfParticles[, nMedium=1.0, numberOfBins=1000, lower=1, upper=1000, gamma=[1], returnDistribution=False, decomposeMultimodal=False, asDict=False]) - Returns Mie coefficients :math:`\beta_{ext}`, :math:`\beta_{sca}`, :math:`\beta_{abs}`, :math:`G`, :math:`\beta_{pr}`, :math:`\beta_{back}`, and :math:`\beta_{ratio}`, integrated over a mathematically-generated k-modal lognormal particle number distribution. Uses `scipy.integrate.trapz `_ to compute the integral. + Returns Mie coefficients :math:`\beta_{ext}`, :math:`\beta_{sca}`, :math:`\beta_{abs}`, :math:`G`, :math:`\beta_{pr}`, :math:`\beta_{back}`, and :math:`\beta_{ratio}`, integrated over a mathematically-generated k-modal lognormal particle number distribution. Uses `scipy.integrate.trapz `_ (or `scipy.integrate.trapezoid `_) to compute the integral. The general form of a k-modal lognormal distribution is given by: