Example #1
0
 def __init__(self, width, folding='Gauss'):
     self.width = width
     if folding == 'Gauss':
         self.func = Gauss(width)
     elif folding == 'Lorentz':
         self.func = Lorentz(width)
     elif folding == None:
         self.func = None
     else:
         raise RuntimeError('unknown folding "' + folding + '"')
Example #2
0
 def __init__(self, width,
              folding='Gauss'):
     self.width = width
     if folding == 'Gauss':
         self.func = Gauss(width)
     elif folding == 'Lorentz':
         self.func = Lorentz(width)
     elif folding == None:
         self.func = None
     else:
         raise RuntimeError('unknown folding "' + folding + '"')
Example #3
0
 def __init__(self, width, folding='Gauss'):
     self.width = width
     if folding == 'Gauss':
         self.func = Gauss(width)
     elif folding == 'Lorentz':
         self.func = Lorentz(width)
     elif folding == 'ComplexGauss':
         self.func = ComplexGauss(width)
     elif folding == 'ComplexLorentz':
         self.func = ComplexLorentz(width)
     elif folding == 'RealLorentzPole':
         self.func = LorentzPole(width, imag=False)
     elif folding == 'ImaginaryLorentzPole':
         self.func = LorentzPole(width, imag=True)
     elif folding == 'Voigt':
         self.func = Voigt(width)
     elif folding is None:
         self.func = None
     else:
         raise RuntimeError('unknown folding "' + folding + '"')
Example #4
0
class Folder:
    """Fold a function with normalised Gaussians or Lorentzians"""
    def __init__(self, width,
                 folding='Gauss'):
        self.width = width
        if folding == 'Gauss':
            self.func = Gauss(width)
        elif folding == 'Lorentz':
            self.func = Lorentz(width)
        elif folding == None:
            self.func = None
        else:
            raise RuntimeError('unknown folding "' + folding + '"')

    def fold(self, x, y, dx=None, min=None, max=None):
        X = np.array(x)
        assert len(X.shape) == 1
        Y = np.array(y)
        assert X.shape[0] == Y.shape[0]

        if self.func is None:
            xl = X
            yl = Y
        else:
            if min is None:
                min = np.min(X) - 4 * self.width
            if max is None:
                max = np.max(X) + 4 * self.width
            if dx is None:
                dx = self.width / 4.

            xl = np.arange(min, max + 0.5 * dx, dx)
                
            # weight matrix
            weightm = np.empty((xl.shape[0], X.shape[0]))
            for i, x in enumerate(X):
                weightm[:, i] = self.func.get(xl - x)

            yl = np.dot(weightm, Y)
            
        return xl, yl
Example #5
0
class Folder:
    """Fold a function with normalised Gaussians or Lorentzians"""
    def __init__(self, width, folding='Gauss'):
        self.width = width
        if folding == 'Gauss':
            self.func = Gauss(width)
        elif folding == 'Lorentz':
            self.func = Lorentz(width)
        elif folding == None:
            self.func = None
        else:
            raise RuntimeError('unknown folding "' + folding + '"')

    def fold(self, x, y, dx=None, min=None, max=None):
        X = np.array(x)
        assert len(X.shape) == 1
        Y = np.array(y)
        assert X.shape[0] == Y.shape[0]

        if self.func is None:
            xl = X
            yl = Y
        else:
            if min is None:
                min = np.min(X) - 4 * self.width
            if max is None:
                max = np.max(X) + 4 * self.width
            if dx is None:
                dx = self.width / 4.

            xl = np.arange(min, max + 0.5 * dx, dx)

            # weight matrix
            weightm = np.empty((xl.shape[0], X.shape[0]))
            for i, x in enumerate(X):
                weightm[:, i] = self.func.get(xl - x)

            yl = np.dot(weightm, Y)

        return xl, yl
Example #6
0
from math import exp, pi, sqrt
import numpy as np

from gpaw.gauss import Gauss, Lorentz
from gpaw.test import equal
from gpaw.utilities.folder import Folder

# Gauss and Lorentz functions

width = 0.5
x = 1.5

equal(Gauss(width).get(x), 
      exp(- x**2 / 2 / width**2) / sqrt(2 * pi) / width, 
      1.e-15)
equal(Lorentz(width).get(x), 
      width / (x**2 + width**2) / pi, 
      1.e-15)

# folder function

for name in ['Gauss', 'Lorentz']:
    folder = Folder(width, name)

    x = [0, 2]
    y = [[2, 0, 1], [1, 1, 1]]

    xl, yl = folder.fold(x, y, dx=.7)

    # check first value
    if name == 'Lorentz':
Example #7
0
from math import exp, pi, sqrt
import numpy as np

from gpaw.gauss import Gauss, Lorentz
from gpaw.test import equal
from gpaw.utilities.folder import Folder, Voigt

# Gauss and Lorentz functions

width = 0.5
x = 1.5

equal(Gauss(width).get(x),
      exp(- x**2 / 2 / width**2) / sqrt(2 * pi) / width,
      1.e-15)
equal(Lorentz(width).get(x),
      width / (x**2 + width**2) / pi,
      1.e-15)

# folder function

for name in ['Gauss', 'Lorentz', 'Voigt']:
    folder = Folder(width, name)

    x = [0, 2]
    y = [[2, 0, 1], [1, 1, 1]]

    xl, yl = folder.fold(x, y, dx=.7)

    # check first value
    exec('func = {0}(width)'.format(name))