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.quadrature in the TestLineShapes #457

Merged
Merged
Changes from 3 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
17 changes: 7 additions & 10 deletions cherab/core/tests/test_lineshapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import numpy as np
from scipy.special import erf, hyp2f1
from scipy.integrate import quadrature
from scipy.integrate import quad

from raysect.core import Point3D, Vector3D
from raysect.core.math.function.float import Arg1D, Constant1D
Expand Down Expand Up @@ -296,7 +296,7 @@ def test_stark_broadened_line(self):
line = Line(deuterium, 0, (6, 2)) # D-delta line
target_species = self.plasma.composition.get(line.element, line.charge)
wavelength = 656.104
integrator = GaussianQuadrature(relative_tolerance=1.e-5)
integrator = GaussianQuadrature(relative_tolerance=1.e-8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.e-8 is used in the quad calls too, please consider using a variable instead (e.g. relative_tolerance), if the values are supposed to be equal here and below. It could save some trouble in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @Mateasek. I added the relative_tolerance variable. Also, in this case it is better to check for relative error rather than absolute error, so I changed that too.

stark_line = StarkBroadenedLine(line, wavelength, target_species, self.plasma, self.atomic_data, integrator=integrator)

# spectrum parameters
Expand Down Expand Up @@ -373,14 +373,11 @@ def stark_lineshape_sigma_minus(x):
lorentz_weight = np.exp(np.poly1d(weight_poly_coeff[::-1])(np.log(fwhm_lorentz / fwhm_full)))

for i in range(bins):
lorentz_bin = 0.5 * sin_sqr * quadrature(stark_lineshape_pi, wavelengths[i], wavelengths[i + 1],
rtol=integrator.relative_tolerance)[0] / delta
lorentz_bin += (0.25 * sin_sqr + 0.5 * cos_sqr) * quadrature(stark_lineshape_sigma_plus, wavelengths[i], wavelengths[i + 1],
rtol=integrator.relative_tolerance)[0] / delta
lorentz_bin += (0.25 * sin_sqr + 0.5 * cos_sqr) * quadrature(stark_lineshape_sigma_minus, wavelengths[i], wavelengths[i + 1],
rtol=integrator.relative_tolerance)[0] / delta
ref_value = lorentz_bin * lorentz_weight + gaussian[i] * (1. - lorentz_weight)
self.assertAlmostEqual(ref_value, spectrum.samples[i], delta=1e-9,
lorentz_bin = 0.5 * sin_sqr * quad(stark_lineshape_pi, wavelengths[i], wavelengths[i + 1], epsrel=1.e-8)[0]
lorentz_bin += (0.25 * sin_sqr + 0.5 * cos_sqr) * quad(stark_lineshape_sigma_plus, wavelengths[i], wavelengths[i + 1], epsrel=1.e-8)[0]
lorentz_bin += (0.25 * sin_sqr + 0.5 * cos_sqr) * quad(stark_lineshape_sigma_minus, wavelengths[i], wavelengths[i + 1], epsrel=1.e-8)[0]
ref_value = lorentz_bin / delta * lorentz_weight + gaussian[i] * (1. - lorentz_weight)
self.assertAlmostEqual(ref_value, spectrum.samples[i], delta=1e-8,
msg='StarkBroadenedLine.add_line() method gives a wrong value at {} nm.'.format(wavelengths[i]))

def test_beam_emission_multiplet(self):
Expand Down
Loading