fourier

Class summary

FourierTransform(func[, args, inv, ...]) One dimensional Fourier transform using scipy.quad

Function summary

cosine_transform(func, w[, args, a, b]) Fourier cosine transform
func_mirror_for_even_weight(x, *myargs) Mirror a function abount the y-axis
func_mirror_for_odd_weight(x, *myargs) Rotate function by 180 degrees (or mirror about x and y-axis in turn).
imag_func(x, *myargs) Imaginary part of a function
real_func(x, *myargs) Real part of a function
sine_transform(func, w[, args, a, b]) Fourier sine transform
v2dcosine_transform(f, s1, s2[, args, m, ...]) Cosine transform of f(x, y) at transform variable s1, s2
vcosine_transform(f, s[, args, m, ng, ...]) Cosine transform of f(x) at transform variable s

Module listing

Fourier transforms.

class geotecha.mathematics.fourier.FourierTransform(func, args=(), inv=False, func_is_real=False, func_is_imag=False, real_part_even=False, real_part_odd=False, imag_part_even=False, imag_part_odd=False, a=0.0, b=inf)[source]

Bases: object

One dimensional Fourier transform using scipy.quad

Note that any function that can divide by zero may cause problems because QUADPACK includes the end points in integration.

Parameters:

func : function

Function to transform. func is called by func(x, *args)

args : tuple, optional

tuple of arguments to pass to func. Default args=().

inv : True/False, optional

If True then the inverse Fourier transform will be performed. Default inv=False.

func_is_real : True/False, optional

If True then func is purely real. It returns a real number. default func_is_real=False.

func_is_imag : True/False, optional

If True then func is purely imaginary. It returns a real number that should be multiplied by i. Default func_is_imag=False

real_part_even : True/False, optional

If True then the real part of func is even. Default real_part_even=False.

real_part_odd : True/False, optional

If True then the real part of func is odd. Default real_part_odd=False.

imag_part_even : True/False, optional

If True then the imaginary part of func is even. Default imag_part_even=False.

imag_part_odd : True/False, optional

If True then the imaginary part of func is odd. Default imag_part_odd=False.

a, b : float, optional

Integration limits. Defualt a=0.0, b=np.inf

Attributes

inv_sign (float) The sign of some expressions change for the inverse fourier transform, inv_sign accounts for that sign change. If inv=True, inv_sign=-1; If inv=False, inv_sign=+1.
inv_const (float) For inverse fourier transform all expressions are multiplied by 1/(2*pi).

Methods

__call__(s) Perform 1d Fourier transform at s
imag_func(x) Imaginary part of func
mfe(x) Mirror func for even weight function
mfie(x) Mirror imag(func) for even weight function
mfio(x) Mirror imag(func) for odd weight function
mfo(x) Mirror func for odd weight function
mfre(x) Mirror real(func) for even weight function
mfro(x) Mirror real(func) for odd weight function
real_func(x) Real part of func
imag_func(x)[source]

Imaginary part of func

mfe(x)[source]

Mirror func for even weight function

mfie(x)[source]

Mirror imag(func) for even weight function

mfio(x)[source]

Mirror imag(func) for odd weight function

mfo(x)[source]

Mirror func for odd weight function

mfre(x)[source]

Mirror real(func) for even weight function

mfro(x)[source]

Mirror real(func) for odd weight function

real_func(x)[source]

Real part of func

geotecha.mathematics.fourier.cosine_transform(func, w, args=(), a=0.0, b=inf)[source]

Fourier cosine transform

Note that any function that can divide by zero may cause problems because QUADPACK includes the end points in integration.

Parameters:

func : function/callable

Function to transform. func will be called func(x, *args). func must return a real.

w : float

Transform variable.

args : tuple, optional

Arguments to pass to func

a, b : float, optional

Integration limits. Defualt a=0.0, b=np.inf.

Returns:

value : float

Value of transform at w

err : float

Error estimate from quadpack

Notes

The fourier cosine transform is given by:

\[F_c=\mathcal{F}_c\{f(x)\}(w) = \int_0^{\infty}f(x)\cos(wx)\,\mathrm{d}x\]
geotecha.mathematics.fourier.func_mirror_for_even_weight(x, *myargs)[source]

Mirror a function abount the y-axis

Given a composite function f(x) * w(x) where w(x) is an even weighting function, return g(x) such that g(x)*w(x) gives same value as f(-x)*w(-x). This can be useful in transforming a fourier cosine integral with negative integation limits to one with positive limits.

Parameters:

x : float

Value to evaluate function at.

func : function/callable

Function to mirror. Always the first argument after x.

myargs : optional

Any remaining arguments will be passed to func.

Returns:

out : ndarray

Value of func(-x, *myargs).

See also

func_mirror_for_odd_weight
mirror for an odd weight function

Examples

>>> def f(x, a):
...  return a*x+1
>>> func_mirror_for_even_weight(5, f, 2)
-9
>>> def ff(x, a):
...  return a*x + 1.j
>>> func_mirror_for_even_weight(3, real_func, ff, 4)
-12.0
geotecha.mathematics.fourier.func_mirror_for_odd_weight(x, *myargs)[source]

Rotate function by 180 degrees (or mirror about x and y-axis in turn).

Given a composite function f(x) * w(x) where w(x) is an odd weighting function, return g(x) such that g(x)*w(x) gives same value as f(-x)*w(-x). This can be useful in transforming a fourier sine integral with negative integration limits to one with positive limits.

Parameters:

x : float

Value to evaluate function at.

func : function/callable

Function to mirror. Always the first argument after x.

myargs : optional

Any remaining arguments will be passed to func.

Returns:

out : ndarray

Value of -func(-x, *myargs)

See also

func_mirror_for_even_weight
mirror for an even wieght function

Examples

>>> def f(x, a):
...  return a*x+1
>>> func_mirror_for_odd_weight(5, f, 2)
9
>>> def ff(x, a):
...  return a*x + 1.j
>>> func_mirror_for_odd_weight(3, real_func, ff, 4)
12.0
geotecha.mathematics.fourier.imag_func(x, *myargs)[source]

Imaginary part of a function

Basically return np.imag(func(x, *myargs[1:])) where func is the first argument after x.

Parameters:

x : float

Value to evaluate function at.

func : function/callable

Function from which to return the imaginary part. Always the first argument after x

myargs : optional

Any remaining arguments will be passed to func(x, *myargs[1:]).

Returns:

out : ndarray

Imaginary part of func(x, *myargs).

See also

real_func
real part of function

Examples

>>> def f(x, a):
...  return a*x+a*1.j
>>> imag_func(2, f, 4)
4.0
>>> imag_func(3.j,f, 2)
8.0
>>> imag_func(np.array([3.j, 2.j]),f, 2)
array([ 8.,  6.])
geotecha.mathematics.fourier.real_func(x, *myargs)[source]

Real part of a function

Basically return np.real(func(x, *myargs[1:])) where func is the first argument after x.

Parameters:

x : float

Value to evaluate function at.

func : function/callable

Function from which to return the real part. Always the first argument after x.

myargs : optional

Any remaining arguments will be passed to func(x, *myargs[1:]).

Returns:

out : ndarray

Real part of func(x, *myargs)

See also

imag_func
imaginary part of function

Examples

>>> def f(x, a):
...  return a*x+a*1.j
>>> real_func(2, f, 4)
8.0
>>> real_func(3.j,f, 2)
0.0
>>> real_func(np.array([3.j, 1+2.j]),f, 2)
array([ 0.,  2.])
geotecha.mathematics.fourier.sine_transform(func, w, args=(), a=0.0, b=inf)[source]

Fourier sine transform

Note that any function that can divide by zero may cause problems because QUADPACK includes the end points in integration.

Parameters:

func : function/callable

Function to transform. func will be called func(x, *args). func must return a real.

w : float

Transform varibale.

args : tuple, optional

Arguments to pass to func

a, b : float, optional

Integration limits. Defualt a=0.0, b=np.inf.

Returns:

value : float

Value of transform at w.

err : float

Error estimate from quadpack.

Notes

The fourier sine transform is given by:

\[F_s=\mathcal{F}_s\{f(x)\}(w) = \int_0^{\infty}f(x)\sin(wx)\,\mathrm{d}x\]
geotecha.mathematics.fourier.v2dcosine_transform(f, s1, s2, args=(), m=20, ng=20, shanks_ind=None)[source]

Cosine transform of f(x, y) at transform variable s1, s2

Vectorised 2d cosine transform.

Parameters:

f : function or method

Function to apply 2D cosine trasnform to. f is called with f(x, y, *args).

s1, s2 : 1d array

Transformation variables. A grid of points will be made.

args : tuple, optional

Arguments to pass to f.

m : int, optional

Number of segments to break the integration interval into. Each segment will be between the zeros of the cos function, default m=20.

ng : [2-20, 32, 64, 100], optional

Number of gauss points to use in integration. Default ng=20.

shanks_ind : int, optional

Start position of intervals to start shanks extrapolation. default=None i.e. no extrapolation. Be careful when using shanks extrapolation; make sure you only begin to use it after the intgrand is well behaved.

Returns:

f : 1d array of float

value of transform at s

Notes

Careful with singularities. Because there is no way to increase the integration points at a particular sport the infinite behaviur may not be captured well. For example x**-0.5 should transform to sqrt(pi/2*w) but due to the sinularity at x=0 it does not converge well even using ng=100.

geotecha.mathematics.fourier.vcosine_transform(f, s, args=(), m=20, ng=20, shanks_ind=None)[source]

Cosine transform of f(x) at transform variable s

This is a vectorized cosine transform.

Parameters:

f : function or method

Function to apply cosine trasnform to. f is called with f(x, *args).

s : 1d array

Coordinate(s) to evaluate transform at.

args : tuple, optional

arguments to pass to f

m : int, optional

Number of segments to break the integration interval into. Each segment will be between the zeros of the cos function, Default m=20.

ng : [2-20, 32, 64, 100], optional

Number of gauss points to use in integration., Default ng=20.

shanks_ind : int, optional

Start position of intervals to start shanks extrapolation. Default shanks_ind=None i.e. no extrapolation. Be careful when using shanks extrapolation; make sure you only begin to use it after the intgrand is well behaved.

Returns:

f : 1d array of float

Value of transform at s

Notes

Careful with singularities. Because there is no way to increase the integration points at a particular spot the infinite behaviur may not be captured well. For example x**-0.5 should transform to sqrt(pi/2*w) but due to the sinularity at x=0 it does not converge well even using ng=100.