Post processing

class dynasor.post_processing.Weights(weights_coh, weights_incoh=None, supports_currents=True)[source]

Class holding weights and support functions for weighting of samples

Parameters
  • weights_coh (Dict[str, float]) – A dict with keys and values representing the atom types and their corresponding coherent scattering length, {'A': b_A }.

  • weights_incoh (Optional[Dict[str, float]]) – A dict with keys and values representing the atom types and their corresponding incoherent scattering length, {'A': b_A }.

  • supports_currents (bool) – whether or not the coherent weights should be applied to current-correlation functions

get_weight_coh(atom_type, q_norm=None)[source]

Get the coherent weight for a given atom type and q-vector norm.

get_weight_incoh(atom_type, q_norm=None)[source]

Get the incoherent weight for a given atom type and q-vector norm.

property supports_currents

Wether or not this Weights object supports weighting of current correlations.

property supports_incoherent

Whether or not this Weights object supports weighting of incoherent correlation functions.

dynasor.post_processing.compute_spherical_qpoint_average(sample, q_bins)[source]

Compute a spherical average over q-points for all the correlation functions in sample

If a q-bin does not contain any q-points, then a np.nan is inserted.

The q_min and q_max are determined from min/max of |q_points|, and will determine the q-bin range. These will be set as bin-centers for the first and last bins repsectivley.

Parameters
  • sample (Sample) – Input sample

  • q_bins (int) – number of radial q-point bins to use

Return type

Sample

dynasor.post_processing.fourier_cos(f, dx, q=None, axis=0)[source]

Calculates the direct Fourier cosine transform \(F(q)\) of a function \(f(x)\) using Filon’s integration method.

The array values f[0]..f[2n] are expected to correspond to \(f(0.0)\ldots f(2n\Delta x)\). Hence, f should contain an odd number of elements.

The transform is approximated by the integral \(F(q) = 2\int_{0}^{x_{max}} f(x) \cos(q x) dx\), where \(x_{max} = 2n \Delta x\).

Parameters
  • f (ndarray[Any, dtype[float]]) – function values; must contain an odd number of elements

  • dx (float) – spacing of x-axis (\(\Delta x\))

  • q (Optional[ndarray[Any, dtype[float]]]) – values of reciprocal axis, at which to evaluate transform; if q is not provided, linspace(0.0, 2*pi/dx, f.shape[axis]), will be used.

  • axis (int) – axis along which to carry out integration

Return type

Tuple[ndarray[Any, dtype[float]], ndarray[Any, dtype[float]]]

Returns

tuple of q and F values

Example

A common use case is

q, F = fourier_cos(f, dx)
dynasor.post_processing.get_weighted_sample(sample, weights)[source]

Weights correlation functions with atomic weighting factors

The weighting of a partial dynamic structure factor \(S_\mathrm{AB}(\boldsymbol{q}, \omega)\) for atom types \(A\) and \(B\) is carried out as

\[S_\mathrm{AB}(\boldsymbol{q}, \omega) = f_\mathrm{A}(\boldsymbol{q}) f_\mathrm{B}(\boldsymbol{q}) S_\mathrm{AB}(\boldsymbol{q}, \omega)\]

\(f_\mathrm{A}(\boldsymbol{q})\) and \(f_\mathrm{B}(\boldsymbol{q})\) are atom-type and \(\boldsymbol{q}\)-point dependent weights.

If sample has incoherent correlation functions, but weights does not contain information on how to weight the incoherent part, then it will be dropped from the returned Sample object (and analogously for current correlation functions).

Parameters
  • sample (Sample) – input sample to be weighted

  • weights (Weights) – object containing the weights \(f_\mathrm{X}(\boldsymbol{q})\)

Return type

Sample

Returns

A Sample instance with the weighted partial and total structure factors.