CXS Class
- class CXS(n, L=1.0, dq=1.0, f_probe=None, f_mask=None)
Bases:
ModuleBase class to compute the coherent X-ray scattering pattern of an object.
- Parameters:
n (int) – Dimension of reciprocal-space pattern
n x nfordq = 1(default). Whendq < 1, the new dimensionnwill be recomputed and saved as an attribute.L (float) – Length of the real-space simulation box
(L x L).dq (float) – Sampling in reciprocal space, i.e. the fraction of \(2 \pi/L\) at which to sample. Default is
dq = 1, corresponding to a spacing of \(2 \pi/L\).f_probe (float) – Standard deviation of the Gaussian probe intensity as a fraction of
L.f_mask (float) – Radius of center beam stop as a fraction of
n.
- Variables:
cmap (
matplotlib.colors.Colormap) – Default colormap for plotting.gmap (
matplotlib.colors.Colormap) –cmapwith an opacity gradient.q (
torch.tensor) – 1-D tensor of reciprocal space coordinates determined by the dimensionnand samplingdq.n (int) – Recomputed dimension of reciprocal-space pattern
n x nfor the input samplingdq.Q (
torch.tensor) – 2-D tensor of shape(n x n, 2)containing the reciprocal space coordinate grid.mask (
torch.tensor) – Boolean tensor storing the masked detector pixels.probe (
torch.nn.Conv2d) – Convolution operator for convolving the reciprocal space pattern with the probe.
- center_crop(y, k)
Crop
ydown to its centralk x kpixels.- Parameters:
y (
torch.tensor) – Tensor to crop.k (int) – Target dimension,
k x k.
- Returns:
y – Cropped tensor.
- Return type:
torch.tensorof shape(...,k,k)
- plot_example(ode, y, ntype=None, vmin=None, vmax=None, lmax=None)
Plot images visualizing the scattering conditions of a given example.
- Parameters:
ode (
ode) – ODE object of the system.y (
torch.tensor) – Solution of the system to plot.ntype (str) –
Type of normalization to apply when displaying the image. The options are:
none– No normalizationsym– Symmetric linear normalization scaleunit– Linear normalization between 0 and 1mod– Linear normalization modulo \(2 \pi\)log– Logarithmic normalization scalesymlog– Symmetric logarithmic normalization scaleNone– Linear normalization between the min. and max. values ofy
The default is
None.vmin (float, optional) – Minimum normalization value.
vmax (float, optional) – Maximum normalization value.
lmax (float, optional) – Maximum intensity, proxy for maximum expected event frequency of Poisson process. The default value is
None, corresponding to the ideal scattered intensity without Poisson sampling.
- Returns:
fig – Figure object.
- Return type:
matplotlib.figure
- plot_probe(ax, ec='white')
Plot the real and, optionally, reciprocal space views of the probe.
- Parameters:
ax (
matplotlib.axes) – Axis or list of axis objects on which to display the image(s).- Returns:
sm – List of scalar mappables storing the color scales of the two plots.
- Return type:
- shapes()
Print detector and probe shapes.
- class CXSGrid(N, n, L=1.0, dq=1.0, f_probe=None, f_mask=None, f=None, w=None, c=None, k=0)
Bases:
CXSClass to compute the coherent X-ray scattering pattern of an object on a uniform grid.
- Parameters:
N (int) – Dimension of real-space grid
N x N.n (int) – Dimension of reciprocal-space pattern
n x nfordq = 1(default). Whendq < 1, the new dimensionnwill be recomputed and saved as an attribute.L (float) – Length of the real-space simulation box
(L x L).dq (float) – Sampling in reciprocal space, i.e. the fraction of \(2 \pi/L\) at which to sample. Default is
dq = 1, corresponding to a spacing of \(2 \pi/L\).f_probe (float) – Standard deviation of the Gaussian probe intensity as a fraction of
L.f_mask (float) – Radius of center beam stop as a fraction of
n.f (str) – Form factor function to use. Current options are
phaseornone(identity).w (list) – List of relative weights on input channels.
c (list) – List of relative weights on non-magnetic and magnetic scattering channels.
- Variables:
cmap (
matplotlib.colors.Colormap) – Default colormap for plotting.gmap (
matplotlib.colors.Colormap) –cmapwith an opacity gradient.q (
torch.tensor) – 1-D tensor of reciprocal space coordinates determined by the dimensionnand samplingdq.n (int) – Recomputed dimension of reciprocal-space pattern
n x nfor the input samplingdq.Q (
torch.tensor) – 2-D tensor of shape(n x n, 2)containing the reciprocal space coordinate grid.mask (
torch.tensor) – Boolean tensor storing the masked detector pixels.probe (
torch.nn.Conv2d) – Convolution operator for convolving the reciprocal space pattern with the probe.
- I_xmcd(y)
Magnetic scattering channel intensity.
- Parameters:
y (
torch.tensor) – Tensor of orientations over the real-space grid.- Returns:
I – Scattered intensity.
- Return type:
torch.tensor
- I_xnm()
Non-magnetic scattering channel intensity.
- Returns:
I – Scattered intensity.
- Return type:
torch.tensor
- f_none(y)
Identity form factor.
- Parameters:
y (
torch.tensor) – Tensor of phases at which to evaluate the form factor.- Returns:
f – Form factor evaluated at each point in
y.- Return type:
torch.tensorof shapey.shape
- f_phase(y)
Orientation-dependent form factor.
- Parameters:
y (
torch.tensor) – Tensor of phases at which to evaluate the form factor.- Returns:
f – Form factor evaluated at each point in
y.- Return type:
torch.tensorof shapey.shape
- forward(y)
Compute the total scattered intensity.
- Parameters:
y (
torch.tensor) – Tensor of orientations over the real-space grid.- Returns:
I – Scattered intensity.
- Return type:
torch.tensor
- class CXSPoint(R, n, L=1.0, dq=1.0, f_probe=None, f_mask=None, c=None)
Bases:
CXSClass to compute the coherent X-ray scattering pattern of a point cloud of spherical objects.
- Parameters:
R (int) – Radius of spherical objects.
n (int) – Dimension of reciprocal-space pattern
n x nfordq = 1(default). Whendq < 1, the new dimensionnwill be recomputed and saved as an attribute.L (float) – Length of the real-space simulation box
(L x L).dq (float) – Sampling in reciprocal space, i.e. the fraction of \(2 \pi/L\) at which to sample. Default is
dq = 1, corresponding to a spacing of \(2 \pi/L\).f_probe (float) – Standard deviation of the Gaussian probe intensity as a fraction of
L.f_mask (float) – Radius of center beam stop as a fraction of
n.c (list) – List of relative weights on non-magnetic and magnetic scattering channels.
- Variables:
cmap (
matplotlib.colors.Colormap) – Default colormap for plotting.gmap (
matplotlib.colors.Colormap) –cmapwith an opacity gradient.q (
torch.tensor) – 1-D tensor of reciprocal space coordinates determined by the dimensionnand samplingdq.n (int) – Recomputed dimension of reciprocal-space pattern
n x nfor the input samplingdq.Q (
torch.tensor) – 2-D tensor of shape(n x n, 2)containing the reciprocal space coordinate grid.mask (
torch.tensor) – Boolean tensor storing the masked detector pixels.probe (
torch.nn.Conv2d) – Convolution operator for convolving the reciprocal space pattern with the probe.
- I_xmcd(ys)
Magnetic scattering channel intensity.
- Parameters:
ys (List of
torch.tensors) – List of tensors giving the orientations as well as the real and imaginary parts of the phase term.- Returns:
I – Scattered intensity.
- Return type:
torch.tensor
- I_xnm(ys)
Non-magnetic scattering channel intensity.
- Parameters:
ys (List of
torch.tensors) – List of tensors of the real and imaginary parts of the phase term.- Returns:
I – Scattered intensity.
- Return type:
torch.tensor
- f_coreshell(q, Rc, Rs, pc, ps, pa)
Normalized form factor of a core-shell particle.
- Parameters:
- Returns:
f – Form factor evaluated at each point in
q.- Return type:
torch.tensorof shapeq.shape
- f_phase(y)
Orientation-dependent form factor.
- Parameters:
y (
torch.tensor) – Tensor of phases at which to evaluate the form factor.- Returns:
f – Form factor evaluated at each point in
y.- Return type:
torch.tensorof shapey.shape
- f_sphere(q, R)
Normalized form factor of a sphere.
- Parameters:
q (
torch.tensor) – Tensor of reciprocal-space points at which to evaluate the form factor.R (float) – Radius of sphere.
- Returns:
f – Form factor evaluated at each point in
q.- Return type:
torch.tensorof shapeq.shape
- forward(y)
Compute the total scattered intensity.
- Parameters:
y (
torch.tensor) – Tensor of particle coordinates. The final dimension should correspond to orientations, if applicable.- Returns:
I – Scattered intensity.
- Return type:
torch.tensor