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 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
27 changes: 16 additions & 11 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,8 @@ 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)
relative_tolerance = 1.e-8
integrator = GaussianQuadrature(relative_tolerance=relative_tolerance)
stark_line = StarkBroadenedLine(line, wavelength, target_species, self.plasma, self.atomic_data, integrator=integrator)

# spectrum parameters
Expand Down Expand Up @@ -373,15 +374,19 @@ 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,
msg='StarkBroadenedLine.add_line() method gives a wrong value at {} nm.'.format(wavelengths[i]))
lorentz_bin = 0.5 * sin_sqr * quad(stark_lineshape_pi, wavelengths[i], wavelengths[i + 1],
epsrel=relative_tolerance)[0]
lorentz_bin += (0.25 * sin_sqr + 0.5 * cos_sqr) * quad(stark_lineshape_sigma_plus, wavelengths[i], wavelengths[i + 1],
epsrel=relative_tolerance)[0]
lorentz_bin += (0.25 * sin_sqr + 0.5 * cos_sqr) * quad(stark_lineshape_sigma_minus, wavelengths[i], wavelengths[i + 1],
epsrel=relative_tolerance)[0]
ref_value = lorentz_bin / delta * lorentz_weight + gaussian[i] * (1. - lorentz_weight)
if ref_value:
self.assertAlmostEqual(spectrum.samples[i] / ref_value, 1., delta=relative_tolerance,
msg='StarkBroadenedLine.add_line() method gives a wrong value at {} nm.'.format(wavelengths[i]))
else:
self.assertAlmostEqual(ref_value, spectrum.samples[i], delta=relative_tolerance,
msg='StarkBroadenedLine.add_line() method gives a wrong value at {} nm.'.format(wavelengths[i]))

def test_beam_emission_multiplet(self):
# Test MSE line shape
Expand Down
Loading