Transformer

This module defines the Transformer class that performs the Fourier transforms

class pystog.transformer.Transformer[source]

The Transformer class is used to Fourier transform between the difference spaces. Either: a reciprocal space function -> real space function or a real space function -> reciprocal space function

Examples:
>>> import numpy
>>> from pystog import Transformer
>>> transformer = Transformer()
>>> q, sq = numpy.loadtxt("my_sofq_file.txt",unpack=True)
>>> r = numpy.linspace(0., 25., 2500)
>>> r, gr, dgr = transformer.S_to_G(q, sq, r)
>>> q = numpy.linspace(0., 25., 2500)
>>> q, sq, dsq = transformer.G_to_S(r, gr, q)
DCS_to_G(q, dcs, r, ddcs=None, **kwargs)[source]

Transforms from reciprocal space \frac{d \sigma}{d \Omega}(Q) to real space G_{PDFFIT}(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • dcs (numpy.array or list) – \frac{d \sigma}{d \Omega}(Q) vector
  • r (numpy.array or list) – r-space vector
  • ddcs (numpy.array or list) – \frac{d \sigma}{d \Omega}(Q) uncertainties
Returns:

r, G_{PDFFIT}(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

DCS_to_GK(q, dcs, r, ddcs=None, **kwargs)[source]

Transforms from reciprocal space \frac{d \sigma}{d \Omega}(Q) to real space G_{Keen Version}(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • dcs (numpy.array or list) – \frac{d \sigma}{d \Omega}(Q) vector
  • r (numpy.array or list) – r-space vector
  • ddcs (numpy.array or list) – \frac{d \sigma}{d \Omega}(Q) uncertainties
Returns:

r, G_{Keen Version}(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

DCS_to_g(q, dcs, r, ddcs=None, **kwargs)[source]

Transforms from reciprocal space \frac{d \sigma}{d \Omega}(Q) to real space g(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • dcs (numpy.array or list) – \frac{d \sigma}{d \Omega}(Q) vector
  • r (numpy.array or list) – r-space vector
  • ddcs (numpy.array or list) – \frac{d \sigma}{d \Omega}(Q) uncertainties
Returns:

r, g(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

FK_to_G(q, fq_keen, r, dfq_keen=None, **kwargs)[source]

Transforms from reciprocal space F(Q) to real space G_{PDFFIT}(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • fq_keen (numpy.array or list) – F(Q) vector
  • r (numpy.array or list) – r-space vector
  • dfq_keen (numpy.array or list) – F(Q) vector uncertainties
Returns:

r, G_{PDFFIT}(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

FK_to_GK(q, fq_keen, r, dfq_keen=None, **kwargs)[source]

Transforms from reciprocal space F(Q) to real space G_{Keen Version}(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • fq_keen (numpy.array or list) – F(Q) vector
  • r (numpy.array or list) – r-space vector
  • dfq_keen (numpy.array or list) – F(Q) vector uncertainties
Returns:

r, G_{Keen Version}(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

FK_to_g(q, fq_keen, r, dfq_keen=None, **kwargs)[source]

Transforms from reciprocal space F(Q) to real space g(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • fq_keen (numpy.array or list) – F(Q) vector
  • r (numpy.array or list) – r-space vector
  • dfq_keen (numpy.array or list) – F(Q) vector uncertainties
Returns:

r, g(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

F_to_G(q, fq, r, dfq=None, **kwargs)[source]

Transforms from reciprocal space Q[S(Q)-1] to real space G_{PDFFIT}(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • fq (numpy.array or list) – Q[S(Q)-1] vector
  • r (numpy.array or list) – r-space vector
  • dfq (numpy.array or list) – uncertainty on Q[S(Q)-1]
Returns:

r, G_{PDFFIT}(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

F_to_GK(q, fq, r, dfq=None, **kwargs)[source]

Transforms from reciprocal space Q[S(Q)-1] to real space G_{Keen Version}(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • fq (numpy.array or list) – Q[S(Q)-1] vector
  • r (numpy.array or list) – r-space vector
  • dfq (numpy.array or list) – uncertainty on Q[S(Q)-1]
Returns:

r, G_{Keen Version}(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

F_to_g(q, fq, r, dfq=None, **kwargs)[source]

Transforms from reciprocal space Q[S(Q)-1] to real space g(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • fq (numpy.array or list) – Q[S(Q)-1] vector
  • r (numpy.array or list) – r-space vector
  • dfq (numpy.array or list) – uncertainty on Q[S(Q)-1]
Returns:

r, g(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

GK_to_DCS(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space G_{Keen Version}(r) to reciprocal space \frac{d \sigma}{d \Omega}(Q)

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – G_{Keen Version}(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – G_{Keen Version}(r) uncertainties
Returns:

Q, \frac{d \sigma}{d \Omega}(Q), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

GK_to_F(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space G_{Keen Version}(r) to reciprocal space Q[S(Q)-1]

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – G_{Keen Version}(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – G_{Keen Version}(r) uncertainties
Returns:

Q, Q[S(Q)-1], and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

GK_to_FK(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space G_{Keen Version}(r) to reciprocal space F(Q)

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – G_{Keen Version}(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – G_{Keen Version}(r) uncertainties
Returns:

Q, F(Q), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

GK_to_S(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space G_{Keen Version}(r) to reciprocal space S(Q)

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – G_{Keen Version}(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – G_{Keen Version}(r) uncertainties
Returns:

Q, S(Q), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

G_to_DCS(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space G_{PDFFIT}(r) to reciprocal space \frac{d \sigma}{d \Omega}(Q)

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – G_{PDFFIT}(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – G_{PDFFIT}(r) uncertainties
Returns:

Q, \frac{d \sigma}{d \Omega}(Q), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

G_to_F(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space G_{PDFFIT}(r) to reciprocal space Q[S(Q)-1]

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – G_{PDFFIT}(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – G_{PDFFIT}(r) uncertainties
Returns:

Q, Q[S(Q)-1], and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

G_to_FK(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space G_{PDFFIT}(r) to reciprocal space F(Q)

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – G_{PDFFIT}(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – G_{PDFFIT}(r) uncertainties
Returns:

Q, F(Q), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

G_to_S(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space G_{PDFFIT}(r) to reciprocal space S(Q)

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – G_{PDFFIT}(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – G_{PDFFIT}(r) uncertainties
Returns:

Q, S(Q), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

S_to_G(q, sq, r, dsq=None, **kwargs)[source]

Transforms from reciprocal space S(Q) to real space G_{PDFFIT}(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • sq (numpy.array or list) – S(Q) vector
  • r (numpy.array or list) – r-space vector
  • dsq (numpy.array or list) – S(Q) uncertainties
Returns:

r, G_{PDFFIT}(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

S_to_GK(q, sq, r, dsq=None, **kwargs)[source]

Transforms from reciprocal space S(Q) to real space G_{Keen Version}(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • sq (numpy.array or list) – S(Q) vector
  • r (numpy.array or list) – r-space vector
  • dsq (numpy.array or list) – S(Q) uncertainties
Returns:

r, G_{Keen Version}(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

S_to_g(q, sq, r, dsq=None, **kwargs)[source]

Transforms from reciprocal space S(Q) to real space g(r)

Parameters:
  • q (numpy.array or list) – Q-space vector
  • sq (numpy.array or list) – S(Q) vector
  • r (numpy.array or list) – r-space vector
  • dsq (numpy.array or list) – S(Q) uncertainties
Returns:

r, g(r), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

apply_cropping(x, y, xmin, xmax, dy=None)[source]

Utility to crop x and y based on xmin and xmax along x. Provides the capability to specify the (Qmin,Qmax) or (Rmin,Rmax) in the Fourier transform

Parameters:
  • x (numpy.array or list) – domain vector
  • y (numpy.array or list) – range vector
  • xmin (float) – minimum x-value for crop
  • xmax (float) – maximum x-value for crop
  • dy (numpy.array or list) – uncertainty vector
Returns:

vector pair (x,y) with cropping applied

Return type:

(numpy.array, numpy.array, numpy.array)

fourier_transform(xin, yin, xout, xmin=None, xmax=None, dyin=None, **kwargs)[source]

The Fourier transform function. The kwargs argument allows for different modifications: Lorch dampening, omitted low-x range correction,

Parameters:
  • xin (numpy.array or list) – domain vector for space to be transformed from
  • yin (numpy.array or list) – range vector for space to be transformed from
  • xout (numpy.array or list) – domain vector for space to be transformed to
  • xmin (float) – minimum x-value for crop
  • xmax (float) – maximum x-value for crop
  • dyin (numpy.array or list) – uncertainty vector for yin
Returns:

vector pair of transformed domain, range vectors, and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

g_to_DCS(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space g(r) to reciprocal space \frac{d \sigma}{d \Omega}(Q)

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – g(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – g(r) uncertainties
Returns:

Q, \frac{d \sigma}{d \Omega}(Q), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

g_to_F(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space g(r) to reciprocal space Q[S(Q)-1]

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – g(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – g(r) uncertainties
Returns:

Q, Q[S(Q)-1], and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

g_to_FK(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space g(r) to reciprocal space F(Q)

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – g(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – g(r) uncertainties
Returns:

Q, F(Q), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array

g_to_S(r, gr, q, dgr=None, **kwargs)[source]

Transforms from real space g(r) to reciprocal space S(Q)

Parameters:
  • r (numpy.array or list) – r-space vector
  • gr (numpy.array or list) – g(r) vector
  • q (numpy.array or list) – Q-space vector
  • dgr (numpy.array or list) – g(r) uncertainties
Returns:

Q, S(Q), and uncertainties

Return type:

numpy.array, numpy.array, numpy.array