[yt-svn] commit/yt: jzuhone: Merged in xarthisius/yt (pull request #1632)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sun Jul 12 07:11:19 PDT 2015
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/f474f54a4124/
Changeset: f474f54a4124
Branch: yt
User: jzuhone
Date: 2015-07-12 14:11:09+00:00
Summary: Merged in xarthisius/yt (pull request #1632)
[opt] use scipy special function to compute voigt profile if it is available (order of mag faster)
Affected #: 2 files
diff -r b34ec79bbd55d2aa56e047de9dc67d0f4256699c -r f474f54a41241eb9cccd7a8f1c61bd629b9eb66d yt/analysis_modules/absorption_spectrum/absorption_line.py
--- a/yt/analysis_modules/absorption_spectrum/absorption_line.py
+++ b/yt/analysis_modules/absorption_spectrum/absorption_line.py
@@ -18,8 +18,16 @@
charge_proton_cgs, \
mass_electron_cgs, \
speed_of_light_cgs
+from yt.utilities.on_demand_imports import _scipy, NotAModule
-def voigt(a,u):
+special = _scipy.special
+
+def voigt_scipy(a, u):
+ x = np.asarray(u).astype(np.float64)
+ y = np.asarray(a).astype(np.float64)
+ return special.wofz(x + 1j * y).real
+
+def voigt_old(a, u):
"""
NAME:
VOIGT
@@ -209,3 +217,8 @@
tauphi = (tau0 * phi).in_units("") # profile scaled with tau0
return (lambda_bins, tauphi)
+
+if isinstance(special, NotAModule):
+ voigt = voigt_old
+else:
+ voigt = voigt_scipy
diff -r b34ec79bbd55d2aa56e047de9dc67d0f4256699c -r f474f54a41241eb9cccd7a8f1c61bd629b9eb66d yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py
--- a/yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py
+++ b/yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py
@@ -10,8 +10,11 @@
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
-import yt
-from yt.testing import *
+import numpy as np
+from yt.testing import \
+ assert_allclose, requires_file, requires_module
+from yt.analysis_modules.absorption_spectrum.absorption_line import \
+ voigt_old, voigt_scipy
from yt.analysis_modules.absorption_spectrum.api import AbsorptionSpectrum
from yt.analysis_modules.cosmological_observation.api import LightRay
import tempfile
@@ -20,6 +23,7 @@
COSMO_PLUS = "enzo_cosmology_plus/AMRCosmology.enzo"
+
@requires_file(COSMO_PLUS)
def test_absorption_spectrum():
"""
@@ -44,22 +48,24 @@
my_label = 'HI Lya'
field = 'H_number_density'
- wavelength = 1215.6700 # Angstromss
+ wavelength = 1215.6700 # Angstromss
f_value = 4.164E-01
gamma = 6.265e+08
mass = 1.00794
- sp.add_line(my_label, field, wavelength, f_value, gamma, mass, label_threshold=1.e10)
+ sp.add_line(my_label, field, wavelength, f_value,
+ gamma, mass, label_threshold=1.e10)
my_label = 'HI Lya'
field = 'H_number_density'
- wavelength = 912.323660 # Angstroms
+ wavelength = 912.323660 # Angstroms
normalization = 1.6e17
index = 3.0
sp.add_continuum(my_label, field, wavelength, normalization, index)
- wavelength, flux = sp.make_spectrum('lightray.h5', output_file='spectrum.txt',
+ wavelength, flux = sp.make_spectrum('lightray.h5',
+ output_file='spectrum.txt',
line_list_file='lines.txt',
use_peculiar_velocity=True)
@@ -93,25 +99,34 @@
my_label = 'HI Lya'
field = 'H_number_density'
- wavelength = 1215.6700 # Angstromss
+ wavelength = 1215.6700 # Angstromss
f_value = 4.164E-01
gamma = 6.265e+08
mass = 1.00794
- sp.add_line(my_label, field, wavelength, f_value, gamma, mass, label_threshold=1.e10)
+ sp.add_line(my_label, field, wavelength, f_value,
+ gamma, mass, label_threshold=1.e10)
my_label = 'HI Lya'
field = 'H_number_density'
- wavelength = 912.323660 # Angstroms
+ wavelength = 912.323660 # Angstroms
normalization = 1.6e17
index = 3.0
sp.add_continuum(my_label, field, wavelength, normalization, index)
- wavelength, flux = sp.make_spectrum('lightray.h5', output_file='spectrum.fits',
+ wavelength, flux = sp.make_spectrum('lightray.h5',
+ output_file='spectrum.fits',
line_list_file='lines.txt',
use_peculiar_velocity=True)
# clean up
os.chdir(curdir)
shutil.rmtree(tmpdir)
+
+
+ at requires_module("scipy")
+def test_voigt_profiles():
+ a = 1.7e-4
+ x = np.linspace(5.0, -3.6, 60)
+ yield assert_allclose, voigt_old(a, x), voigt_scipy(a, x), 1e-8
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list