[python-xrayutilities] 01/02: Updated to upstream version 1.0.3

Eugen Wintersberger eugenwintersberger-guest at moszumanska.debian.org
Wed Dec 18 14:21:09 UTC 2013


This is an automated email from the git hooks/post-receive script.

eugenwintersberger-guest pushed a commit to branch master
in repository python-xrayutilities.

commit 5ae292dc3b3aedc4d5317c9679fcf9c53b565204
Author: Eugen Wintersberger <eugen.wintersberger at gmail.com>
Date:   Sun Oct 27 11:47:51 2013 +0100

    Updated to upstream version 1.0.3
    
    Could not reproduce the lintina warning Frederic saw on a testing image with
    pbuilder. We may need further investigation on this issue.
    
    The database issue still remains but should not be critical. It might come from
    the fact that when sphinx is importing the modules the database files are not
    available.
---
 CHANGES.txt                                        |   9 +++
 PKG-INFO                                           |  17 +++--
 README.txt                                         |  15 +++--
 debian/changelog                                   |   2 +-
 ...eature-forwarded-add-the-build_doc-target.patch |  64 -------------------
 debian/patches/series                              |   1 -
 debian/rules                                       |   2 +-
 doc/source/conf.py                                 |   2 +-
 doc/source/examples.rst                            |  18 ++++++
 doc/xrayutilities.info                             | Bin 645364 -> 0 bytes
 examples/xrayutilities_experiment_kappa.py         |   6 +-
 setup.py                                           |  43 ++++++++++++-
 xrayutilities.pdf                                  | Bin 591791 -> 599218 bytes
 xrayutilities/analysis/line_cuts3d.py              |   2 +-
 xrayutilities/analysis/sample_align.py             |   8 +--
 xrayutilities/experiment.py                        |   4 +-
 xrayutilities/math/__init__.py                     |   5 ++
 xrayutilities/math/fit.py                          |  71 ++++++++++++++++-----
 xrayutilities/math/functions.py                    |  61 ++++++++++++++++--
 19 files changed, 215 insertions(+), 115 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 2e72cf4..724416a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,12 @@
+v1.0.3, 2013-10-25
+
+* build_doc target for setup.py to help build docs (thanks to F. Picca)
+* fix python setup.py --help
+* add PseudoVoigt function in 1D
+* add Lorentzian peak shape in addition to Gaussian in new function
+  multPeakFit
+* some minor bug fixes
+
 v1.0.2, 2013-09-17
 
 * add documentation source to tarball
diff --git a/PKG-INFO b/PKG-INFO
index 87f90b1..0422223 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: xrayutilities
-Version: 1.0.2
+Version: 1.0.3
 Summary: package for x-ray diffraction data evaluation
 Home-page: http://xrayutilities.sourceforge.net
 Author: Dominik Kriegner
@@ -164,15 +164,18 @@ Description:
          
         in any web-browser, after the installation is finished.
         
-        To build the PDF documentation from the sources use sphinx:
+        To build the PDF documentation from the docu-sources use:
         
-          sphinx-build -b latex doc/source doc/latex
-          cd doc/latex; make 
+          python setup.py build_doc -b latex
+          cd build/sphinx/latex; make 
           
-        or generate a texinfo file using 
+        You will need sphinx and pdflatex including latex-recommended, latex-extra 
+        and fonts-recommended.
         
-          sphinx-build -b texinfo doc/source doc/texinfo
-          cd doc/texinfo; make 
+        Or generate a texinfo file using 
+        
+          python setup.py build_doc -b texinfo
+          cd build/sphinx/texinfo; make 
         
         
         PACKAGING
diff --git a/README.txt b/README.txt
index 8b5e4df..3093805 100644
--- a/README.txt
+++ b/README.txt
@@ -156,15 +156,18 @@ The API-documentation can also be browsed by ::
  
 in any web-browser, after the installation is finished.
 
-To build the PDF documentation from the sources use sphinx:
+To build the PDF documentation from the docu-sources use:
 
-  sphinx-build -b latex doc/source doc/latex
-  cd doc/latex; make 
+  python setup.py build_doc -b latex
+  cd build/sphinx/latex; make 
   
-or generate a texinfo file using 
+You will need sphinx and pdflatex including latex-recommended, latex-extra 
+and fonts-recommended.
 
-  sphinx-build -b texinfo doc/source doc/texinfo
-  cd doc/texinfo; make 
+Or generate a texinfo file using 
+
+  python setup.py build_doc -b texinfo
+  cd build/sphinx/texinfo; make 
 
 
 PACKAGING
diff --git a/debian/changelog b/debian/changelog
index dab9baa..11bda06 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-python-xrayutilities (1.0.2-1) unstable; urgency=low
+python-xrayutilities (1.0.3-1) unstable; urgency=low
 
   * Initial release. (Closes: #723017)
 
diff --git a/debian/patches/0001-feature-forwarded-add-the-build_doc-target.patch b/debian/patches/0001-feature-forwarded-add-the-build_doc-target.patch
deleted file mode 100644
index a6221eb..0000000
--- a/debian/patches/0001-feature-forwarded-add-the-build_doc-target.patch
+++ /dev/null
@@ -1,64 +0,0 @@
-From: =?UTF-8?q?Picca=20Fr=C3=A9d=C3=A9ric-Emmanuel?= <picca at debian.org>
-Date: Sun, 20 Oct 2013 08:48:49 +0200
-Subject: feature forwarded add the build_doc target
-
----
- setup.py | 31 ++++++++++++++++++++++++++++++-
- 1 file changed, 30 insertions(+), 1 deletion(-)
-
-diff --git a/setup.py b/setup.py
-index 556ac85..7376d5f 100644
---- a/setup.py
-+++ b/setup.py
-@@ -64,6 +64,8 @@ class build_ext_subclass( build_ext ):
-                 e.extra_link_args = lopt[ c ]
-         build_ext.build_extensions(self)
- 
-+cmdclass = {'build_ext': build_ext_subclass}
-+
- with open('README.txt') as f:
-     long_description = f.read()
- 
-@@ -76,6 +78,33 @@ extmodul = Extension('xrayutilities.cxrayutilities',
-                                 os.path.join('xrayutilities','src','gridder3d.c')],
-                      define_macros = user_macros)
- 
-+try:
-+    import sphinx
-+    import sys
-+
-+    from sphinx.setup_command import BuildDoc
-+
-+    class build_doc(BuildDoc):
-+        def run(self):
-+            # make sure the python path is pointing to the newly built
-+            # code so that the documentation is built on this and not a
-+            # previously installed version
-+            build = self.get_finalized_command('build')
-+            sys.path.insert(0, os.path.abspath(build.build_lib))
-+            try:
-+                sphinx.setup_command.BuildDoc.run(self)
-+            except UnicodeDecodeError:
-+                print("ERROR: unable to build documentation"
-+                      " because Sphinx do not handle"
-+                      " source path with non-ASCII characters. Please"
-+                      " try to move the source package to another"
-+                      " location (path with *only* ASCII characters)")
-+            sys.path.pop(0)
-+
-+    cmdclass['build_doc'] = build_doc
-+except ImportError:
-+    pass
-+
- setup(name="xrayutilities",
-       version="1.0.2",
-       author="Eugen Wintersberger, Dominik Kriegner",
-@@ -96,7 +125,7 @@ setup(name="xrayutilities",
-       requires=['numpy','scipy','matplotlib','tables'],
-       include_dirs = [numpy.get_include()],
-       ext_modules = [extmodul],
--      cmdclass = {'build_ext': build_ext_subclass },
-+      cmdclass = cmdclass,
-       url="http://xrayutilities.sourceforge.net",
-       license="GPLv2",
-       script_args = args
diff --git a/debian/patches/series b/debian/patches/series
deleted file mode 100644
index 73f56d4..0000000
--- a/debian/patches/series
+++ /dev/null
@@ -1 +0,0 @@
-0001-feature-forwarded-add-the-build_doc-target.patch
diff --git a/debian/rules b/debian/rules
index 42f75cf..7572399 100755
--- a/debian/rules
+++ b/debian/rules
@@ -19,8 +19,8 @@ override_dh_auto_build-indep:
 	python setup.py build_doc
 
 override_dh_auto_install:
-	dh_auto_install
 	dh_numpy
+	dh_auto_install
 
 override_dh_install:
 	# Install everything excluding the *_d.so debug extensions to python-foo
diff --git a/doc/source/conf.py b/doc/source/conf.py
index dc6004f..0769066 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -50,7 +50,7 @@ copyright = u'2013, Dominik Kriegner, Eugen Wintersberger'
 # The short X.Y version.
 version = '1.0'
 # The full version, including alpha/beta/rc tags.
-release = '1.0.2'
+release = '1.0.3'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/doc/source/examples.rst b/doc/source/examples.rst
index c54fb35..54c7b21 100644
--- a/doc/source/examples.rst
+++ b/doc/source/examples.rst
@@ -381,6 +381,24 @@ The misalignment parameters can be fixed during the fitting.
     :linenos:
     :language: python
 
+A possible output of this script could be
+
+.. code-block:: python
+
+    fitted parameters: epsilon: 8.0712e-08 (2,['Parameter convergence'])
+    param: (cch1,cch2,pwidth1,pwidth2,tiltazimuth,tilt,detrot,outerangle_offset) 
+    param: 140.07 998.34 4.4545e-05 4.4996e-05 72.0 1.97 -0.792 -1.543
+    please check the resulting data (consider setting plot=True)
+    detector rotation axis / primary beam direction (given by user): ['z+', 'y-'] / x+
+    detector pixel directions / distance: z- y+ / 1
+    detector initialization with: init_area('z-','y+',cch1=140.07,cch2=998.34,Nch1=516,Nch2=516, pwidth1=4.4545e-05,pwidth2=4.4996e-05,distance=1.,detrot=-0.792,tiltazimuth=72.0,tilt=1.543)
+    AND ALWAYS USE an (additional) OFFSET of -1.9741deg in the OUTER DETECTOR ANGLE!
+
+
+The output gives the fitted detector parameters and compiles the python code line one needs to use to initialize the detector.
+Important to note is that the outer angle offset which was determined by the fit (-1.9741 degree in the aboves example) is not included in the initialization of the detector parameters BUT needs to be used in every call to the q-conversion function as offset. 
+This step needs to be performed manually by the user!
+
 Area detector (Variant 2)
 ^^^^^^^^^^^^^^^^^^^^^^^^^
 
diff --git a/doc/xrayutilities.info b/doc/xrayutilities.info
deleted file mode 100644
index 89b098b..0000000
Binary files a/doc/xrayutilities.info and /dev/null differ
diff --git a/examples/xrayutilities_experiment_kappa.py b/examples/xrayutilities_experiment_kappa.py
index 7e581ee..f064588 100644
--- a/examples/xrayutilities_experiment_kappa.py
+++ b/examples/xrayutilities_experiment_kappa.py
@@ -32,13 +32,13 @@ print qconv
 
 print("angles: 0,0,0,90")
 (qx,qy,qz) = qconv(0,0,0,90)
-print("Q= %6.3f %6.3f %6.3f (Abs: %6.3f)" %(qx[0],qy[0],qz[0],numpy.linalg.norm((qx,qy,qz))))
+print("Q= %6.3f %6.3f %6.3f (Abs: %6.3f)" %(qx,qy,qz,numpy.linalg.norm((qx,qy,qz))))
 
 print("angles: 90,0,0,90")
 (qx,qy,qz) = qconv(90,0,0,90)
-print("Q= %6.3f %6.3f %6.3f (Abs: %6.3f)" %(qx[0],qy[0],qz[0],numpy.linalg.norm((qx,qy,qz))))
+print("Q= %6.3f %6.3f %6.3f (Abs: %6.3f)" %(qx,qy,qz,numpy.linalg.norm((qx,qy,qz))))
 
 print("angles: 0,90,0,90")
 (qx,qy,qz) = qconv(0,90,0,90)
-print("Q= %6.3f %6.3f %6.3f (Abs: %6.3f)" %(qx[0],qy[0],qz[0],numpy.linalg.norm((qx,qy,qz))))
+print("Q= %6.3f %6.3f %6.3f (Abs: %6.3f)" %(qx,qy,qz,numpy.linalg.norm((qx,qy,qz))))
 
diff --git a/setup.py b/setup.py
index 556ac85..0448c14 100644
--- a/setup.py
+++ b/setup.py
@@ -21,12 +21,22 @@ from distutils.command.build_ext import build_ext
 from distutils.fancy_getopt import FancyGetopt
 import os.path
 import numpy
+import sys
 
 cliopts = []
 cliopts.append(("without-openmp",None,"build without OpenMP support"))
 
 options = FancyGetopt(option_table = cliopts)
-args,opts = options.getopt()
+
+#first read all the arguments passed to the script
+#we need to do this otherwise the --help commands would not work
+args = sys.argv[1:]
+try:
+    #search the arguments for options we would like to use
+    #get new args with the custom options stripped away
+    args,opts = options.getopt(args)
+except:
+    pass
 
 #set default flags
 without_openmp = False
@@ -64,6 +74,8 @@ class build_ext_subclass( build_ext ):
                 e.extra_link_args = lopt[ c ]
         build_ext.build_extensions(self)
 
+cmdclass = {'build_ext': build_ext_subclass}
+
 with open('README.txt') as f:
     long_description = f.read()
 
@@ -76,8 +88,33 @@ extmodul = Extension('xrayutilities.cxrayutilities',
                                 os.path.join('xrayutilities','src','gridder3d.c')],
                      define_macros = user_macros)
 
+try:
+    import sphinx
+    from sphinx.setup_command import BuildDoc
+
+    class build_doc(BuildDoc):
+        def run(self):
+            # make sure the python path is pointing to the newly built
+            # code so that the documentation is built on this and not a
+            # previously installed version
+            build = self.get_finalized_command('build')
+            sys.path.insert(0, os.path.abspath(build.build_lib))
+            try:
+                sphinx.setup_command.BuildDoc.run(self)
+            except UnicodeDecodeError:
+                print("ERROR: unable to build documentation"
+                      " because Sphinx do not handle"
+                      " source path with non-ASCII characters. Please"
+                      " try to move the source package to another"
+                      " location (path with *only* ASCII characters)")
+            sys.path.pop(0)
+
+    cmdclass['build_doc'] = build_doc
+except ImportError:
+    pass
+
 setup(name="xrayutilities",
-      version="1.0.2",
+      version="1.0.3",
       author="Eugen Wintersberger, Dominik Kriegner",
       description="package for x-ray diffraction data evaluation",
       classifiers=["Topic :: Scientific/Engineering :: Physics",
@@ -96,7 +133,7 @@ setup(name="xrayutilities",
       requires=['numpy','scipy','matplotlib','tables'],
       include_dirs = [numpy.get_include()],
       ext_modules = [extmodul],
-      cmdclass = {'build_ext': build_ext_subclass },
+      cmdclass = cmdclass,
       url="http://xrayutilities.sourceforge.net",
       license="GPLv2",
       script_args = args
diff --git a/xrayutilities.pdf b/xrayutilities.pdf
index 0c48857..7dfaa8f 100644
Binary files a/xrayutilities.pdf and b/xrayutilities.pdf differ
diff --git a/xrayutilities/analysis/line_cuts3d.py b/xrayutilities/analysis/line_cuts3d.py
index 6333109..ff9b66f 100644
--- a/xrayutilities/analysis/line_cuts3d.py
+++ b/xrayutilities/analysis/line_cuts3d.py
@@ -19,7 +19,7 @@ import numpy
 
 from .. import config
 from .. import experiment
-from .. import gridder as xugridder
+from .. import gridder3d as xugridder
 
 def getindex3d(x,y,z,xgrid,ygrid,zgrid):
     """
diff --git a/xrayutilities/analysis/sample_align.py b/xrayutilities/analysis/sample_align.py
index b3ded5f..c19ddba 100644
--- a/xrayutilities/analysis/sample_align.py
+++ b/xrayutilities/analysis/sample_align.py
@@ -1775,8 +1775,8 @@ def fit_bragg_peak(om,tt,psd,omalign,ttalign,exphxrd,frange=(0.03,0.03),plot=Tru
     else:
         [qx,qy,qz] = exphxrd.Ang2Q(om,tt)
     [qxsub,qysub,qzsub] = exphxrd.Ang2Q(omalign,ttalign)
-    params = [qysub[0],qzsub[0],0.001,0.001,psd.max(),0,0.]
-    params,covariance = math.fit_peak2d(qy.flatten(),qz.flatten(),psd.flatten(),params,[qysub[0]-frange[0],qysub[0]+frange[0],qzsub[0]-frange[1],qzsub[0]+frange[1]],math.Gauss2d,maxfev=10000)
+    params = [qysub,qzsub,0.001,0.001,psd.max(),0,0.]
+    params,covariance = math.fit_peak2d(qy.flatten(),qz.flatten(),psd.flatten(),params,[qysub-frange[0],qysub+frange[0],qzsub-frange[1],qzsub+frange[1]],math.Gauss2d,maxfev=10000)
     # correct params
     params[6] = params[6]%(numpy.pi)
     if params[5]<0 : params[5] = 0
@@ -1787,9 +1787,9 @@ def fit_bragg_peak(om,tt,psd,omalign,ttalign,exphxrd,frange=(0.03,0.03),plot=Tru
 
     if plot:
         plt.figure(); plt.clf()
-        from .. import gridder
+        from ..gridder2d import Gridder2D
         from .. import utilities
-        gridder = gridder.Gridder2D(400,400)
+        gridder = Gridder2D(400,400)
         gridder(qy,qz,psd)
         # calculate intensity which should be plotted
         INT = utilities.maplog(gridder.gdata.transpose(),4,0)
diff --git a/xrayutilities/experiment.py b/xrayutilities/experiment.py
index ab7c298..e61421e 100644
--- a/xrayutilities/experiment.py
+++ b/xrayutilities/experiment.py
@@ -1126,7 +1126,7 @@ class Experiment(object):
                 raise Exception("unknown keyword argument given: allowed are 'B': orthonormalization matrix, 'U': orientation matrix, 'mat': material object, 'dettype': string with detector type")
         
         if "B" in kwargs:
-            B = numpy.array(B)
+            B = numpy.array(kwargs['B'])
             kwargs.pop("B")
         elif "mat" in kwargs:
             mat = kwargs['mat']
@@ -1136,7 +1136,7 @@ class Experiment(object):
             B = numpy.identity(3)
 
         if "U" in kwargs:
-            U = numpy.array(U)
+            U = numpy.array(kwargs['U'])
             kwargs.pop("U")
         else:
             U = self._transform.matrix
diff --git a/xrayutilities/math/__init__.py b/xrayutilities/math/__init__.py
index 2fc491a..90c58fe 100644
--- a/xrayutilities/math/__init__.py
+++ b/xrayutilities/math/__init__.py
@@ -43,9 +43,14 @@ from .functions import Gauss2d
 from .functions import Gauss3d
 from .functions import TwoGauss2d
 from .functions import Lorentz1d
+from .functions import Lorentz1d_der_x
+from .functions import Lorentz1d_der_p
 from .functions import Lorentz2d
+from .functions import PseudoVoigt1d
 
 from .fit import fit_peak2d
 from .fit import gauss_fit
+from .fit import multPeakFit
+from .fit import multPeakPlot 
 from .fit import multGaussFit
 from .fit import multGaussPlot 
diff --git a/xrayutilities/math/fit.py b/xrayutilities/math/fit.py
index 2ff5b50..d51fca0 100644
--- a/xrayutilities/math/fit.py
+++ b/xrayutilities/math/fit.py
@@ -29,6 +29,7 @@ from scipy.odr import models
 
 from .. import config
 from .functions import Gauss1d,Gauss1d_der_x,Gauss1d_der_p
+from .functions import Lorentz1d,Lorentz1d_der_x,Lorentz1d_der_p
 
 try:
     from matplotlib import pyplot as plt
@@ -84,7 +85,7 @@ def gauss_fit(xdata,ydata,iparams=[],maxit=200):
     # use least-square fit
     myodr.set_job(fit_type=2)
 
-#    # DK comment out because this command triggers a synthax error with new scipy version 2013/5/7
+#    # DK commented out because this command triggers a synthax error with new scipy version 2013/5/7
 #    if config.VERBOSITY >= config.DEBUG:
 #        myodr.set_iprint(final=1)
 
@@ -157,9 +158,17 @@ def fit_peak2d(x,y,data,start,drange,fit_function,maxfev=2000):
     return p,pcov
 
 
-def multGaussFit(x,data,peakpos,peakwidth,dranges=None):
+def multGaussFit(*args,**kwargs):
     """
-    function to fit multiple Gaussian peaks with linear background to a set of data
+    convenience function to keep API stable
+    see multPeakFit for documentation
+    """
+    kwargs['peaktype']='Gaussian'
+    return multPeakFit(*args,**kwargs)
+
+def multPeakFit(x,data,peakpos,peakwidth,dranges=None,peaktype='Gaussian'):
+    """
+    function to fit multiple Gaussian/Lorentzian peaks with linear background to a set of data
 
     Parameters
     ----------
@@ -169,6 +178,7 @@ def multGaussFit(x,data,peakpos,peakwidth,dranges=None):
      peakwidth:  initial values for the peak width
      dranges:  list of tuples with (min,max) value of the data ranges to use.
                does not need to have the same number of entries as peakpos
+     peaktype: type of peaks to be used: can be either 'Gaussian' or 'Lorentzian'
 
     Returns
     -------
@@ -179,6 +189,15 @@ def multGaussFit(x,data,peakpos,peakwidth,dranges=None):
     amp:  list of amplitudes of the peaks derived by the fit
     background:  array of background values at positions x
     """
+    if peaktype=='Gaussian':
+        pfunc = Gauss1d
+        pfunc_derx = Gauss1d_der_x
+    elif peaktype=='Lorentzian':
+        pfunc = Lorentz1d
+        pfunc_derx = Lorentz1d_der_x
+    else:
+        raise ValueError('wrong value for parameter peaktype was given')
+
     def deriv_x(p, x):
         """
         function to calculate the derivative of the signal of multiple peaks and background w.r.t. the x-coordinate
@@ -191,7 +210,7 @@ def multGaussFit(x,data,peakpos,peakwidth,dranges=None):
 
         # sum up peak functions contributions
         for i in range(len(p)//3):
-            ldx = Gauss1d_der_x(x,p[3*i],p[3*i+1],p[3*i+2],0)
+            ldx = pfunc_derx(x,p[3*i],p[3*i+1],p[3*i+2],0)
             derx += ldx
 
         # background contribution
@@ -215,10 +234,15 @@ def multGaussFit(x,data,peakpos,peakwidth,dranges=None):
         # peak functions contributions
         for i in range(len(p)//3):
             lp = (p[3*i],p[3*i+1],p[3*i+2],0)
-            derp = numpy.append(derp,-2*(lp[0]-x)*Gauss1d(x,*lp))
-            derp = numpy.append(derp,(lp[0]-x)**2/(2*lp[1]**3)*Gauss1d(x,*lp))
-            derp = numpy.append(derp,Gauss1d(x,*lp)/lp[2])
-        
+            if peaktype == 'Gaussian':
+                derp = numpy.append(derp,-2*(lp[0]-x)*pfunc(x,*lp))
+                derp = numpy.append(derp,(lp[0]-x)**2/(2*lp[1]**3)*pfunc(x,*lp))
+                derp = numpy.append(derp,pfunc(x,*lp)/lp[2])
+            else: # Lorentzian
+                derp = numpy.append(derp,4*(x-lp[0])* lp[2]/lp[1]/(1+(2*(x-lp[0])/lp[1])**2)**2)
+                derp = numpy.append(derp,4*(lp[0]-x)* lp[2]/lp[1]**2/(1+(2*(x-lp[0])/lp[1])**2)**2)
+                derp = numpy.append(derp,1/(1+(2*(x-p[0])/p[1])**2))
+     
         # background contributions
         derp = numpy.append(derp,x)
         derp = numpy.append(derp,numpy.ones(x.size))
@@ -239,7 +263,7 @@ def multGaussFit(x,data,peakpos,peakwidth,dranges=None):
 
         # sum up peak functions
         for i in range(len(p)//3):
-            lf = Gauss1d(x,p[3*i],p[3*i+1],p[3*i+2],0)
+            lf = pfunc(x,p[3*i],p[3*i+1],p[3*i+2],0)
             f += lf
 
         # background
@@ -291,14 +315,14 @@ def multGaussFit(x,data,peakpos,peakwidth,dranges=None):
     fit = my_odr.run()
 
     if(config.VERBOSITY >= config.DEBUG):
-        print("XU.math.multGaussFit: fitted parameters")
+        print("XU.math.multPeakFit: fitted parameters")
         print(fit.beta)
     try:
         if fit.stopreason[0] not in ['Sum of squares convergence']:
-            print("XU.math.multGaussFit: fit NOT converged (%s)" %fit.stopreason[0])
+            print("XU.math.multPeakFit: fit NOT converged (%s)" %fit.stopreason[0])
             return None,None,None,None
     except:
-        print("XU.math.multGaussFit: fit most probably NOT converged (%s)" %str(fit.stopreason))
+        print("XU.math.multPeakFit: fit most probably NOT converged (%s)" %str(fit.stopreason))
         return None,None,None,None
     # prepare return values
     fpos = fit.beta[:-2:3]
@@ -308,9 +332,18 @@ def multGaussFit(x,data,peakpos,peakwidth,dranges=None):
 
     return fpos,fwidth,famp,background
 
-def multGaussPlot(x,fpos,fwidth,famp,background,dranges=None,fig="xu_plot",fact=1.):
+
+def multGaussPlot(*args,**kwargs):
+    """
+    convenience function to keep API stable
+    see multPeakPlot for documentation
+    """
+    kwargs['peaktype']='Gaussian'
+    return multPeakPlot(*args,**kwargs)
+
+def multPeakPlot(x,fpos,fwidth,famp,background,dranges=None,peaktype='Gaussian',fig="xu_plot",fact=1.):
     """
-    function to plot multiple Gaussian peaks with linear background 
+    function to plot multiple Gaussian/Lorentz peaks with background values given by an array 
 
     Parameters
     ----------
@@ -321,13 +354,14 @@ def multGaussPlot(x,fpos,fwidth,famp,background,dranges=None,fig="xu_plot",fact=
      background:  array with background values
      dranges:  list of tuples with (min,max) value of the data ranges to use.
                does not need to have the same number of entries as fpos
+     peaktype: type of peaks to be used: can be either 'Gaussian' or 'Lorentzian'
      fig:  matplotlib figure number or name
      fact: factor to use as multiplicator in the plot
     """
 
     try: plt.__name__
     except NameError:
-        print("XU.math.multGaussPlot: Warning: plot functionality not available")
+        print("XU.math.multPeakPlot: Warning: plot functionality not available")
         return
     
     plt.figure(fig)
@@ -346,7 +380,12 @@ def multGaussPlot(x,fpos,fwidth,famp,background,dranges=None,fig="xu_plot",fact=
 
     f = numpy.zeros(lx.size)
     for i in range(len(fpos)):
-        lf = Gauss1d(lx,fpos[i],fwidth[i],famp[i],0)
+        if peaktype=='Gaussian':
+            lf = Gauss1d(lx,fpos[i],fwidth[i],famp[i],0)
+        elif peaktype=='Lorentzian':
+            lf = Lorentz1d(lx,fpos[i],fwidth[i],famp[i],0)
+        else: 
+            raise ValueError('wrong value for parameter peaktype was given')
         f += lf
         plt.plot(lx,(lf+lb)*fact,'k:')
 
diff --git a/xrayutilities/math/functions.py b/xrayutilities/math/functions.py
index d72f546..cb0e101 100644
--- a/xrayutilities/math/functions.py
+++ b/xrayutilities/math/functions.py
@@ -111,7 +111,9 @@ def Gauss1d_der_x(x,*p):
     for parameter description see Gauss1d
     """
 
-    return 2*(p[0]-x)*Gauss1d(x,*p)
+    lp = numpy.copy(p)
+    lp[3] = 0
+    return 2*(p[0]-x)*Gauss1d(x,*lp)
 
 
 def Gauss1d_der_p(x,*p):
@@ -121,10 +123,11 @@ def Gauss1d_der_p(x,*p):
 
     for parameter description see Gauss1d
     """
-
-    r = numpy.concatenate(( -2*(p[0]-x)*Gauss1d(x,*p),\
-                            (p[0]-x)**2/(2*p[1]**3)*Gauss1d(x,*p),\
-                            Gauss1d(x,*p)/p[2],\
+    lp = numpy.copy(p)
+    lp[3] = 0
+    r = numpy.concatenate(( -2*(p[0]-x)*Gauss1d(x,*lp),\
+                            (p[0]-x)**2/(2*p[1]**3)*Gauss1d(x,*lp),\
+                            Gauss1d(x,*lp)/p[2],\
                             numpy.ones(x.shape,dtype=numpy.float) ))
     r.shape = (4,) + x.shape
 
@@ -225,6 +228,31 @@ def Lorentz1d(x,*p):
 
     return g
 
+def Lorentz1d_der_x(x,*p):
+    """
+    function to calculate the derivative of a Gaussian with respect to x
+
+    for parameter description see Lorentz1d
+    """
+
+    return 4*(p[0]-x)* p[2]/p[1]/(1+(2*(x-p[0])/p[1])**2)**2
+
+def Lorentz1d_der_p(x,*p):
+    """
+    function to calculate the derivative of a Gaussian with respect the
+    parameters p
+
+    for parameter description see Lorentz1d
+    """
+
+    r = numpy.concatenate(( 4*(x-p[0])* p[2]/p[1]/(1+(2*(x-p[0])/p[1])**2)**2,\
+                            4*(p[0]-x)* p[2]/p[1]**2/(1+(2*(x-p[0])/p[1])**2)**2,\
+                            1/(1+(2*(x-p[0])/p[1])**2),\
+                            numpy.ones(x.shape,dtype=numpy.float) ))
+    r.shape = (4,) + x.shape
+
+    return r
+
 def Lorentz2d(x,y,*p):
     """
     function to calculate a general two dimensional Lorentzian
@@ -251,6 +279,29 @@ def Lorentz2d(x,y,*p):
     return g
 
 
+def PseudoVoigt1d(x,*p):
+    """
+    function to calculate a pseudo Voigt function as linear combination of a Gauss and Lorentz peak
+
+    Parameters
+    ----------
+     p:     list of parameters of the Lorentz-function
+            [XCEN,FWHM,AMP,BACKGROUND,ETA]
+            ETA: 0 ...1  0 means pure Gauss and 1 means pure Lorentz 
+     x,y:   coordinate(s) where the function should be evaluated
+
+    Returns
+    -------
+    the value of the PseudoVoigt described by the parameters p
+    at position (x,y)
+
+    """
+
+    f = p[3]+p[2] * ( p[4]*(1/(1+(2*(x-p[0])/(p[1]/2.))**2)) + (1-p[4])*numpy.exp(-numpy.log(2)*((p[0]-x)/(p[1]/2.))**2) ) 
+
+    return f
+
+
 def Debye1(x):
     """
     function to calculate the first Debye function as needed

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-xrayutilities.git



More information about the debian-science-commits mailing list