[yt-svn] commit/yt: 6 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Aug 14 06:38:29 PDT 2014
6 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/3e41fdd554da/
Changeset: 3e41fdd554da
Branch: yt
User: jzuhone
Date: 2014-08-13 21:11:50
Summary: We should actually error out if we don't find these files
Affected #: 1 file
diff -r 47d240b30d78885fd9284b85d9d2ee9b82342266 -r 3e41fdd554dad6453d77f0b599b08ff805014aaf yt/analysis_modules/photon_simulator/spectral_models.py
--- a/yt/analysis_modules/photon_simulator/spectral_models.py
+++ b/yt/analysis_modules/photon_simulator/spectral_models.py
@@ -212,11 +212,14 @@
try:
self.line_handle = pyfits.open(self.linefile)
except IOError:
- mylog.error("LINE file %s does not exist" % (self.linefile))
+ mylog.error("LINE file %s does not exist" % self.linefile)
+ raise IOError("LINE file %s does not exist" % self.linefile)
try:
self.coco_handle = pyfits.open(self.cocofile)
except IOError:
- mylog.error("COCO file %s does not exist" % (self.cocofile))
+ mylog.error("COCO file %s does not exist" % self.cocofile)
+ raise IOError("COCO file %s does not exist" % self.cocofile)
+
self.Tvals = self.line_handle[1].data.field("kT")
self.dTvals = np.diff(self.Tvals)
self.minlam = self.wvbins.min()
https://bitbucket.org/yt_analysis/yt/commits/ba7e273c5b82/
Changeset: ba7e273c5b82
Branch: yt
User: jzuhone
Date: 2014-08-13 21:12:19
Summary: Provide a useful error message if we don't have a module installed and try to access something from it
Affected #: 1 file
diff -r 3e41fdd554dad6453d77f0b599b08ff805014aaf -r ba7e273c5b825181b2b470ee3121890c4d1d8f4e yt/utilities/on_demand_imports.py
--- a/yt/utilities/on_demand_imports.py
+++ b/yt/utilities/on_demand_imports.py
@@ -10,6 +10,18 @@
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
+class NotAModule(object):
+ """
+ A class to implement an informative error message that will be outputted if
+ someone tries to use an on-demand import without having the requisite package installed.
+ """
+ def __init__(self, pkg_name):
+ self.pkg_name = pkg_name
+
+ def __getattr__(self, item):
+ raise ImportError("This functionality requires the %s package to be installed."
+ % self.pkg_name)
+
class astropy_imports:
_pyfits = None
@property
@@ -19,7 +31,7 @@
import astropy.io.fits as pyfits
self.log
except ImportError:
- pyfits = None
+ pyfits = NotAModule("astropy")
self._pyfits = pyfits
return self._pyfits
@@ -31,7 +43,7 @@
import astropy.wcs as pywcs
self.log
except ImportError:
- pywcs = None
+ pywcs = NotAModule("astropy")
self._pywcs = pywcs
return self._pywcs
@@ -44,7 +56,7 @@
if log.exception_logging_enabled():
log.disable_exception_logging()
except ImportError:
- log = None
+ log = NotAModule("astropy")
self._log = log
return self._log
https://bitbucket.org/yt_analysis/yt/commits/621bf4a55ef1/
Changeset: 621bf4a55ef1
Branch: yt
User: jzuhone
Date: 2014-08-13 21:36:54
Summary: Add scipy as an on-demand import. Fixing na -> np in absorption_spectrum.
Affected #: 3 files
diff -r ba7e273c5b825181b2b470ee3121890c4d1d8f4e -r 621bf4a55ef1d45f1d81c35ea3d26e030d0c3718 yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
--- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
+++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
@@ -1,8 +1,10 @@
-from scipy import optimize
import numpy as na
import h5py
from yt.analysis_modules.absorption_spectrum.absorption_line \
import voigt
+from yt.utilities.on_demand_imports import _scipy
+
+optimize = _scipy.optimize
def generate_total_fit(x, fluxData, orderFits, speciesDicts,
minError=1E-4, complexLim=.995,
@@ -83,7 +85,7 @@
x0,xRes=x[0],x[1]-x[0]
#Empty fit without any lines
- yFit = na.ones(len(fluxData))
+ yFit = np.ones(len(fluxData))
#Force the first and last flux pixel to be 1 to prevent OOB
fluxData[0]=1
@@ -98,10 +100,10 @@
#Fit all species one at a time in given order from low to high wavelength
for species in orderFits:
speciesDict = speciesDicts[species]
- speciesLines = {'N':na.array([]),
- 'b':na.array([]),
- 'z':na.array([]),
- 'group#':na.array([])}
+ speciesLines = {'N':np.array([]),
+ 'b':np.array([]),
+ 'z':np.array([]),
+ 'group#':np.array([])}
#Set up wavelengths for species
initWl = speciesDict['wavelength'][0]
@@ -131,7 +133,7 @@
yFitBounded,z,speciesDict,
minSize,minError)
- if na.size(newLinesP)> 0:
+ if np.size(newLinesP)> 0:
#Check for EXPLOOOOSIIONNNSSS
newLinesP = _check_numerical_instability(x, newLinesP, speciesDict,b)
@@ -150,12 +152,12 @@
#Add new group to all fitted lines
- if na.size(newLinesP)>0:
- speciesLines['N']=na.append(speciesLines['N'],newLinesP[:,0])
- speciesLines['b']=na.append(speciesLines['b'],newLinesP[:,1])
- speciesLines['z']=na.append(speciesLines['z'],newLinesP[:,2])
- groupNums = b_i*na.ones(na.size(newLinesP[:,0]))
- speciesLines['group#']=na.append(speciesLines['group#'],groupNums)
+ if np.size(newLinesP)>0:
+ speciesLines['N']=np.append(speciesLines['N'],newLinesP[:,0])
+ speciesLines['b']=np.append(speciesLines['b'],newLinesP[:,1])
+ speciesLines['z']=np.append(speciesLines['z'],newLinesP[:,2])
+ groupNums = b_i*np.ones(np.size(newLinesP[:,0]))
+ speciesLines['group#']=np.append(speciesLines['group#'],groupNums)
allSpeciesLines[species]=speciesLines
@@ -226,7 +228,7 @@
initP[0] = speciesDict['init_N']
initP[1] = speciesDict['init_b']
initP[2]=initz
- initP=na.array([initP])
+ initP=np.array([initP])
linesP = initP
@@ -259,7 +261,7 @@
#Set results of optimization
- linesP = na.reshape(fitP,(-1,3))
+ linesP = np.reshape(fitP,(-1,3))
#Generate difference between current best fit and data
yNewFit=_gen_flux_lines(x,linesP,speciesDict)
@@ -288,7 +290,7 @@
break
#If too many lines
- if na.shape(linesP)[0]>8 or na.size(linesP)+3>=len(x):
+ if np.shape(linesP)[0]>8 or np.size(linesP)+3>=len(x):
#If its fitable by flag tools and still bad, use flag tools
if errSq >1E2*errBound and speciesDict['name']=='HI lya':
return [],True
@@ -315,17 +317,17 @@
newP[0] = speciesDict['init_N']
newP[1] = speciesDict['init_b']
newP[2]=(x[dif.argmax()]-wl0)/wl0
- linesP=na.append(linesP,[newP],axis=0)
+ linesP=np.append(linesP,[newP],axis=0)
#Check the parameters of all lines to see if they fall in an
# acceptable range, as given in dict ref
remove=[]
for i,p in enumerate(linesP):
- check=_check_params(na.array([p]),speciesDict,x)
+ check=_check_params(np.array([p]),speciesDict,x)
if check:
remove.append(i)
- linesP = na.delete(linesP,remove,axis=0)
+ linesP = np.delete(linesP,remove,axis=0)
return linesP,flag
@@ -377,7 +379,7 @@
#Iterate through test line guesses
for initLines in lineTests:
if initLines[1,0]==0:
- initLines = na.delete(initLines,1,axis=0)
+ initLines = np.delete(initLines,1,axis=0)
#Do fitting with initLines as first guess
linesP,flag=_complex_fit(x,yDat,yFit,initz,
@@ -421,7 +423,7 @@
"""
#Set up a bunch of empty lines
- testP = na.zeros((10,2,3))
+ testP = np.zeros((10,2,3))
testP[0,0,:]=[1E18,20,initz]
testP[1,0,:]=[1E18,40,initz]
@@ -542,7 +544,7 @@
errBound = 10*errBound*len(yb)
#Generate a fit and find the difference to data
- yFitb=_gen_flux_lines(xb,na.array([p]),speciesDict)
+ yFitb=_gen_flux_lines(xb,np.array([p]),speciesDict)
dif =yb-yFitb
@@ -557,7 +559,7 @@
break
#Remove all bad line fits
- linesP = na.delete(linesP,removeLines,axis=0)
+ linesP = np.delete(linesP,removeLines,axis=0)
return linesP
@@ -755,7 +757,7 @@
if firstLine:
break
- flux = na.exp(-y)
+ flux = np.exp(-y)
return flux
def _gen_tau(t, p, f, Gamma, lambda_unshifted):
@@ -768,7 +770,7 @@
a=7.95774715459E-15*Gamma*lambda_unshifted/b
x=299792.458/b*(lambda_unshifted*(1+z)/t-1)
- H = na.zeros(len(x))
+ H = np.zeros(len(x))
H = voigt(a,x)
tau = tau_o*H
@@ -910,9 +912,9 @@
# Make the final line parameters. Its annoying because
# one or both regions may have fit to nothing
- if na.size(p1)> 0 and na.size(p2)>0:
- p = na.r_[p1,p2]
- elif na.size(p1) > 0:
+ if np.size(p1)> 0 and np.size(p2)>0:
+ p = np.r_[p1,p2]
+ elif np.size(p1) > 0:
p = p1
else:
p = p2
@@ -952,7 +954,7 @@
# max and min to prevent boundary errors
flux = _gen_flux_lines(x,[line],speciesDict,firstLine=True)
- flux = na.r_[flux[:max(b[1]-10,0)], flux[min(b[2]+10,len(x)):]]
+ flux = np.r_[flux[:max(b[1]-10,0)], flux[min(b[2]+10,len(x)):]]
#Find regions that are absorbing outside the region we fit
flux_dif = 1 - flux
@@ -971,7 +973,7 @@
remove_lines.append(i)
if remove_lines:
- p = na.delete(p, remove_lines, axis=0)
+ p = np.delete(p, remove_lines, axis=0)
return p
diff -r ba7e273c5b825181b2b470ee3121890c4d1d8f4e -r 621bf4a55ef1d45f1d81c35ea3d26e030d0c3718 yt/analysis_modules/photon_simulator/spectral_models.py
--- a/yt/analysis_modules/photon_simulator/spectral_models.py
+++ b/yt/analysis_modules/photon_simulator/spectral_models.py
@@ -22,14 +22,10 @@
except ImportError:
pass
-try:
- import xspec
- from scipy.integrate import cumtrapz
- from scipy import stats
-except ImportError:
- pass
-from yt.utilities.on_demand_imports import _astropy
+from yt.utilities.on_demand_imports import _astropy, _scipy
+
pyfits = _astropy.pyfits
+stats = _scipy.stats
from yt.utilities.physical_constants import hcgs, clight, erg_per_keV, amu_cgs
@@ -227,18 +223,18 @@
def _make_spectrum(self, element, tindex):
- tmpspec = np.zeros((self.nchan))
+ tmpspec = np.zeros(self.nchan)
i = np.where((self.line_handle[tindex].data.field('element') == element) &
(self.line_handle[tindex].data.field('lambda') > self.minlam) &
(self.line_handle[tindex].data.field('lambda') < self.maxlam))[0]
- vec = np.zeros((self.nchan))
+ vec = np.zeros(self.nchan)
E0 = hc.value/self.line_handle[tindex].data.field('lambda')[i]
amp = self.line_handle[tindex].data.field('epsilon')[i]
ebins = self.ebins.ndarray_view()
if self.thermal_broad:
- vec = np.zeros((self.nchan))
+ vec = np.zeros(self.nchan)
sigma = E0*np.sqrt(self.Tvals[tindex]*erg_per_keV/(self.A[element]*amu_cgs))/clight.value
for E, sig, a in zip(E0, sigma, amp):
cdf = stats.norm(E,sig).cdf(ebins)
@@ -273,10 +269,10 @@
"""
Get the thermal emission spectrum given a temperature *kT* in keV.
"""
- cspec_l = np.zeros((self.nchan))
- mspec_l = np.zeros((self.nchan))
- cspec_r = np.zeros((self.nchan))
- mspec_r = np.zeros((self.nchan))
+ cspec_l = np.zeros(self.nchan)
+ mspec_l = np.zeros(self.nchan)
+ cspec_r = np.zeros(self.nchan)
+ mspec_r = np.zeros(self.nchan)
tindex = np.searchsorted(self.Tvals, kT)-1
if tindex >= self.Tvals.shape[0]-1 or tindex < 0:
return cspec_l*cm3/units.s, mspec_l*cm3/units.s
diff -r ba7e273c5b825181b2b470ee3121890c4d1d8f4e -r 621bf4a55ef1d45f1d81c35ea3d26e030d0c3718 yt/utilities/on_demand_imports.py
--- a/yt/utilities/on_demand_imports.py
+++ b/yt/utilities/on_demand_imports.py
@@ -23,6 +23,7 @@
% self.pkg_name)
class astropy_imports:
+ _name = "astropy"
_pyfits = None
@property
def pyfits(self):
@@ -31,7 +32,7 @@
import astropy.io.fits as pyfits
self.log
except ImportError:
- pyfits = NotAModule("astropy")
+ pyfits = NotAModule(self._name)
self._pyfits = pyfits
return self._pyfits
@@ -43,7 +44,7 @@
import astropy.wcs as pywcs
self.log
except ImportError:
- pywcs = NotAModule("astropy")
+ pywcs = NotAModule(self._name)
self._pywcs = pywcs
return self._pywcs
@@ -56,7 +57,7 @@
if log.exception_logging_enabled():
log.disable_exception_logging()
except ImportError:
- log = NotAModule("astropy")
+ log = NotAModule(self._name)
self._log = log
return self._log
@@ -67,7 +68,7 @@
try:
from astropy import units
except ImportError:
- units = None
+ units = NotAModule(self._name)
self._units = units
return self._units
@@ -79,8 +80,46 @@
import astropy.convolution as conv
self.log
except ImportError:
- conv = None
+ conv = NotAModule(self._name)
self._conv = conv
return self._conv
-_astropy = astropy_imports()
\ No newline at end of file
+_astropy = astropy_imports()
+
+class scipy_imports:
+ _name = "scipy"
+ _integrate = None
+ @property
+ def integrate(self):
+ if self._integrate is None:
+ try:
+ import scipy.integrate as integrate
+ except ImportError:
+ integrate = NotAModule(self._name)
+ self._integrate = integrate
+ return self._integrate
+
+ _stats = None
+ @property
+ def stats(self):
+ if self._stats is None:
+ try:
+ import scipy.stats as stats
+ except ImportError:
+ stats = NotAModule(self._name)
+ self._stats = stats
+ return self._stats
+
+ _optimize = None
+ @property
+ def optimize(self):
+ if self._optimize is None:
+ try:
+ import scipy.optimize as optimize
+ except ImportError:
+ optimize = NotAModule(self._name)
+ self._optimize = optimize
+ return self._optimize
+
+
+_scipy = scipy_imports()
\ No newline at end of file
https://bitbucket.org/yt_analysis/yt/commits/80c51813eada/
Changeset: 80c51813eada
Branch: yt
User: jzuhone
Date: 2014-08-13 21:42:37
Summary: Forgot the most important line
Affected #: 1 file
diff -r 621bf4a55ef1d45f1d81c35ea3d26e030d0c3718 -r 80c51813eada3af5200e1d10ea37c7210f0fdac6 yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
--- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
+++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
@@ -1,4 +1,4 @@
-import numpy as na
+import numpy as np
import h5py
from yt.analysis_modules.absorption_spectrum.absorption_line \
import voigt
https://bitbucket.org/yt_analysis/yt/commits/1ecb1bbe17b2/
Changeset: 1ecb1bbe17b2
Branch: yt
User: jzuhone
Date: 2014-08-14 03:50:22
Summary: Adding interpolate
Affected #: 1 file
diff -r 80c51813eada3af5200e1d10ea37c7210f0fdac6 -r 1ecb1bbe17b202d4fb05b382ea9cca6c70e7e20b yt/utilities/on_demand_imports.py
--- a/yt/utilities/on_demand_imports.py
+++ b/yt/utilities/on_demand_imports.py
@@ -121,5 +121,15 @@
self._optimize = optimize
return self._optimize
+ _interpolate = None
+ @property
+ def interpolate(self):
+ if self._interpolate is None:
+ try:
+ import scipy.interpolate as interpolate
+ except ImportError:
+ interpolate = NotAModule(self._name)
+ self._interpolate = interpolate
+ return self._interpolate
_scipy = scipy_imports()
\ No newline at end of file
https://bitbucket.org/yt_analysis/yt/commits/d85047922d9e/
Changeset: d85047922d9e
Branch: yt
User: MatthewTurk
Date: 2014-08-14 15:38:22
Summary: Merged in jzuhone/yt-3.x (pull request #1144)
Graceful and informative exits for on-demand imports; adding scipy to the on-demand imports
Affected #: 3 files
diff -r ce08b4644d20723154a7b0811fb1ef483cd1bf23 -r d85047922d9e1cbfc557566e8c00c8ae54d1779e yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
--- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
+++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
@@ -1,8 +1,10 @@
-from scipy import optimize
-import numpy as na
+import numpy as np
import h5py
from yt.analysis_modules.absorption_spectrum.absorption_line \
import voigt
+from yt.utilities.on_demand_imports import _scipy
+
+optimize = _scipy.optimize
def generate_total_fit(x, fluxData, orderFits, speciesDicts,
minError=1E-4, complexLim=.995,
@@ -83,7 +85,7 @@
x0,xRes=x[0],x[1]-x[0]
#Empty fit without any lines
- yFit = na.ones(len(fluxData))
+ yFit = np.ones(len(fluxData))
#Force the first and last flux pixel to be 1 to prevent OOB
fluxData[0]=1
@@ -98,10 +100,10 @@
#Fit all species one at a time in given order from low to high wavelength
for species in orderFits:
speciesDict = speciesDicts[species]
- speciesLines = {'N':na.array([]),
- 'b':na.array([]),
- 'z':na.array([]),
- 'group#':na.array([])}
+ speciesLines = {'N':np.array([]),
+ 'b':np.array([]),
+ 'z':np.array([]),
+ 'group#':np.array([])}
#Set up wavelengths for species
initWl = speciesDict['wavelength'][0]
@@ -131,7 +133,7 @@
yFitBounded,z,speciesDict,
minSize,minError)
- if na.size(newLinesP)> 0:
+ if np.size(newLinesP)> 0:
#Check for EXPLOOOOSIIONNNSSS
newLinesP = _check_numerical_instability(x, newLinesP, speciesDict,b)
@@ -150,12 +152,12 @@
#Add new group to all fitted lines
- if na.size(newLinesP)>0:
- speciesLines['N']=na.append(speciesLines['N'],newLinesP[:,0])
- speciesLines['b']=na.append(speciesLines['b'],newLinesP[:,1])
- speciesLines['z']=na.append(speciesLines['z'],newLinesP[:,2])
- groupNums = b_i*na.ones(na.size(newLinesP[:,0]))
- speciesLines['group#']=na.append(speciesLines['group#'],groupNums)
+ if np.size(newLinesP)>0:
+ speciesLines['N']=np.append(speciesLines['N'],newLinesP[:,0])
+ speciesLines['b']=np.append(speciesLines['b'],newLinesP[:,1])
+ speciesLines['z']=np.append(speciesLines['z'],newLinesP[:,2])
+ groupNums = b_i*np.ones(np.size(newLinesP[:,0]))
+ speciesLines['group#']=np.append(speciesLines['group#'],groupNums)
allSpeciesLines[species]=speciesLines
@@ -226,7 +228,7 @@
initP[0] = speciesDict['init_N']
initP[1] = speciesDict['init_b']
initP[2]=initz
- initP=na.array([initP])
+ initP=np.array([initP])
linesP = initP
@@ -259,7 +261,7 @@
#Set results of optimization
- linesP = na.reshape(fitP,(-1,3))
+ linesP = np.reshape(fitP,(-1,3))
#Generate difference between current best fit and data
yNewFit=_gen_flux_lines(x,linesP,speciesDict)
@@ -288,7 +290,7 @@
break
#If too many lines
- if na.shape(linesP)[0]>8 or na.size(linesP)+3>=len(x):
+ if np.shape(linesP)[0]>8 or np.size(linesP)+3>=len(x):
#If its fitable by flag tools and still bad, use flag tools
if errSq >1E2*errBound and speciesDict['name']=='HI lya':
return [],True
@@ -315,17 +317,17 @@
newP[0] = speciesDict['init_N']
newP[1] = speciesDict['init_b']
newP[2]=(x[dif.argmax()]-wl0)/wl0
- linesP=na.append(linesP,[newP],axis=0)
+ linesP=np.append(linesP,[newP],axis=0)
#Check the parameters of all lines to see if they fall in an
# acceptable range, as given in dict ref
remove=[]
for i,p in enumerate(linesP):
- check=_check_params(na.array([p]),speciesDict,x)
+ check=_check_params(np.array([p]),speciesDict,x)
if check:
remove.append(i)
- linesP = na.delete(linesP,remove,axis=0)
+ linesP = np.delete(linesP,remove,axis=0)
return linesP,flag
@@ -377,7 +379,7 @@
#Iterate through test line guesses
for initLines in lineTests:
if initLines[1,0]==0:
- initLines = na.delete(initLines,1,axis=0)
+ initLines = np.delete(initLines,1,axis=0)
#Do fitting with initLines as first guess
linesP,flag=_complex_fit(x,yDat,yFit,initz,
@@ -421,7 +423,7 @@
"""
#Set up a bunch of empty lines
- testP = na.zeros((10,2,3))
+ testP = np.zeros((10,2,3))
testP[0,0,:]=[1E18,20,initz]
testP[1,0,:]=[1E18,40,initz]
@@ -542,7 +544,7 @@
errBound = 10*errBound*len(yb)
#Generate a fit and find the difference to data
- yFitb=_gen_flux_lines(xb,na.array([p]),speciesDict)
+ yFitb=_gen_flux_lines(xb,np.array([p]),speciesDict)
dif =yb-yFitb
@@ -557,7 +559,7 @@
break
#Remove all bad line fits
- linesP = na.delete(linesP,removeLines,axis=0)
+ linesP = np.delete(linesP,removeLines,axis=0)
return linesP
@@ -755,7 +757,7 @@
if firstLine:
break
- flux = na.exp(-y)
+ flux = np.exp(-y)
return flux
def _gen_tau(t, p, f, Gamma, lambda_unshifted):
@@ -768,7 +770,7 @@
a=7.95774715459E-15*Gamma*lambda_unshifted/b
x=299792.458/b*(lambda_unshifted*(1+z)/t-1)
- H = na.zeros(len(x))
+ H = np.zeros(len(x))
H = voigt(a,x)
tau = tau_o*H
@@ -910,9 +912,9 @@
# Make the final line parameters. Its annoying because
# one or both regions may have fit to nothing
- if na.size(p1)> 0 and na.size(p2)>0:
- p = na.r_[p1,p2]
- elif na.size(p1) > 0:
+ if np.size(p1)> 0 and np.size(p2)>0:
+ p = np.r_[p1,p2]
+ elif np.size(p1) > 0:
p = p1
else:
p = p2
@@ -952,7 +954,7 @@
# max and min to prevent boundary errors
flux = _gen_flux_lines(x,[line],speciesDict,firstLine=True)
- flux = na.r_[flux[:max(b[1]-10,0)], flux[min(b[2]+10,len(x)):]]
+ flux = np.r_[flux[:max(b[1]-10,0)], flux[min(b[2]+10,len(x)):]]
#Find regions that are absorbing outside the region we fit
flux_dif = 1 - flux
@@ -971,7 +973,7 @@
remove_lines.append(i)
if remove_lines:
- p = na.delete(p, remove_lines, axis=0)
+ p = np.delete(p, remove_lines, axis=0)
return p
diff -r ce08b4644d20723154a7b0811fb1ef483cd1bf23 -r d85047922d9e1cbfc557566e8c00c8ae54d1779e yt/analysis_modules/photon_simulator/spectral_models.py
--- a/yt/analysis_modules/photon_simulator/spectral_models.py
+++ b/yt/analysis_modules/photon_simulator/spectral_models.py
@@ -22,14 +22,10 @@
except ImportError:
pass
-try:
- import xspec
- from scipy.integrate import cumtrapz
- from scipy import stats
-except ImportError:
- pass
-from yt.utilities.on_demand_imports import _astropy
+from yt.utilities.on_demand_imports import _astropy, _scipy
+
pyfits = _astropy.pyfits
+stats = _scipy.stats
from yt.utilities.physical_constants import hcgs, clight, erg_per_keV, amu_cgs
@@ -212,11 +208,14 @@
try:
self.line_handle = pyfits.open(self.linefile)
except IOError:
- mylog.error("LINE file %s does not exist" % (self.linefile))
+ mylog.error("LINE file %s does not exist" % self.linefile)
+ raise IOError("LINE file %s does not exist" % self.linefile)
try:
self.coco_handle = pyfits.open(self.cocofile)
except IOError:
- mylog.error("COCO file %s does not exist" % (self.cocofile))
+ mylog.error("COCO file %s does not exist" % self.cocofile)
+ raise IOError("COCO file %s does not exist" % self.cocofile)
+
self.Tvals = self.line_handle[1].data.field("kT")
self.dTvals = np.diff(self.Tvals)
self.minlam = self.wvbins.min()
@@ -224,18 +223,18 @@
def _make_spectrum(self, element, tindex):
- tmpspec = np.zeros((self.nchan))
+ tmpspec = np.zeros(self.nchan)
i = np.where((self.line_handle[tindex].data.field('element') == element) &
(self.line_handle[tindex].data.field('lambda') > self.minlam) &
(self.line_handle[tindex].data.field('lambda') < self.maxlam))[0]
- vec = np.zeros((self.nchan))
+ vec = np.zeros(self.nchan)
E0 = hc.value/self.line_handle[tindex].data.field('lambda')[i]
amp = self.line_handle[tindex].data.field('epsilon')[i]
ebins = self.ebins.ndarray_view()
if self.thermal_broad:
- vec = np.zeros((self.nchan))
+ vec = np.zeros(self.nchan)
sigma = E0*np.sqrt(self.Tvals[tindex]*erg_per_keV/(self.A[element]*amu_cgs))/clight.value
for E, sig, a in zip(E0, sigma, amp):
cdf = stats.norm(E,sig).cdf(ebins)
@@ -270,10 +269,10 @@
"""
Get the thermal emission spectrum given a temperature *kT* in keV.
"""
- cspec_l = np.zeros((self.nchan))
- mspec_l = np.zeros((self.nchan))
- cspec_r = np.zeros((self.nchan))
- mspec_r = np.zeros((self.nchan))
+ cspec_l = np.zeros(self.nchan)
+ mspec_l = np.zeros(self.nchan)
+ cspec_r = np.zeros(self.nchan)
+ mspec_r = np.zeros(self.nchan)
tindex = np.searchsorted(self.Tvals, kT)-1
if tindex >= self.Tvals.shape[0]-1 or tindex < 0:
return cspec_l*cm3/units.s, mspec_l*cm3/units.s
diff -r ce08b4644d20723154a7b0811fb1ef483cd1bf23 -r d85047922d9e1cbfc557566e8c00c8ae54d1779e yt/utilities/on_demand_imports.py
--- a/yt/utilities/on_demand_imports.py
+++ b/yt/utilities/on_demand_imports.py
@@ -10,7 +10,20 @@
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
+class NotAModule(object):
+ """
+ A class to implement an informative error message that will be outputted if
+ someone tries to use an on-demand import without having the requisite package installed.
+ """
+ def __init__(self, pkg_name):
+ self.pkg_name = pkg_name
+
+ def __getattr__(self, item):
+ raise ImportError("This functionality requires the %s package to be installed."
+ % self.pkg_name)
+
class astropy_imports:
+ _name = "astropy"
_pyfits = None
@property
def pyfits(self):
@@ -19,7 +32,7 @@
import astropy.io.fits as pyfits
self.log
except ImportError:
- pyfits = None
+ pyfits = NotAModule(self._name)
self._pyfits = pyfits
return self._pyfits
@@ -31,7 +44,7 @@
import astropy.wcs as pywcs
self.log
except ImportError:
- pywcs = None
+ pywcs = NotAModule(self._name)
self._pywcs = pywcs
return self._pywcs
@@ -44,7 +57,7 @@
if log.exception_logging_enabled():
log.disable_exception_logging()
except ImportError:
- log = None
+ log = NotAModule(self._name)
self._log = log
return self._log
@@ -55,7 +68,7 @@
try:
from astropy import units
except ImportError:
- units = None
+ units = NotAModule(self._name)
self._units = units
return self._units
@@ -67,8 +80,56 @@
import astropy.convolution as conv
self.log
except ImportError:
- conv = None
+ conv = NotAModule(self._name)
self._conv = conv
return self._conv
-_astropy = astropy_imports()
\ No newline at end of file
+_astropy = astropy_imports()
+
+class scipy_imports:
+ _name = "scipy"
+ _integrate = None
+ @property
+ def integrate(self):
+ if self._integrate is None:
+ try:
+ import scipy.integrate as integrate
+ except ImportError:
+ integrate = NotAModule(self._name)
+ self._integrate = integrate
+ return self._integrate
+
+ _stats = None
+ @property
+ def stats(self):
+ if self._stats is None:
+ try:
+ import scipy.stats as stats
+ except ImportError:
+ stats = NotAModule(self._name)
+ self._stats = stats
+ return self._stats
+
+ _optimize = None
+ @property
+ def optimize(self):
+ if self._optimize is None:
+ try:
+ import scipy.optimize as optimize
+ except ImportError:
+ optimize = NotAModule(self._name)
+ self._optimize = optimize
+ return self._optimize
+
+ _interpolate = None
+ @property
+ def interpolate(self):
+ if self._interpolate is None:
+ try:
+ import scipy.interpolate as interpolate
+ except ImportError:
+ interpolate = NotAModule(self._name)
+ self._interpolate = interpolate
+ return self._interpolate
+
+_scipy = scipy_imports()
\ No newline at end of file
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