Forward models

Solvers for forward problems in SQUID-based current imaging.

This module contains various classes to parametrize, accelerate and solve the calculation of SQUID microscopy signals from 1D and 2D current distributions.

For kernel plotting functions, we refer to forwardplotting.py.

class sottools.forward.Forward1DParameters(Lscan=1.0, Wdevice=0.5, Nscan=2, gamma=0.0, rho1=0.1, rho2=0.2, height=0.2, phi=0.0, invert_normal=False, invert_scan=False)

Bases: object

Parameters describing a 1D forwrad calculation from current to SOT image.

The forward pass of the 1D model relies on parameters describing: - The spatial resolution and constraints of the model - The properties of the SQUID sensor modeled - The properties of the 1D underlying current distribution

Not every parameter can be set manually, and sometimes the model adjusts parameters upon setting. This is to ensure that the forward model always abides by these rules:

  1. All spatial axes are symmetric around zero.

  2. Number of points N is even.

3. The y-axis runs from -L/2 to L/2-dy, where L is the length of the y-axis and dy is the step.

The simplest way to ensure these rules are abided by is to make the following constraints and assumptions:

  1. The user sets L and N, dy is calculated as L/N and odd N is rejected.

  2. The user can choose to specify the current distribution on a model- defined y-axis, or provide both an y-axis and distrbution which will be resampled.

  3. Gamma is not pi/2 or -pi/2

The forward model takes into account the angle gamma between the SQUID scan directiona and the current direction. This means that there is no direct convolution between the current distribution and the SQUID response curve; instead, the convolution converts the current distribution into a SQUID curve along a projected y-axis y’’ related to the scanned y-axis by y’’ = y * cos(gamma). To calculate SQUID signals, the projected signal is first calculated, upon which the x-axis is rescaled.

Parameters:
  • Lscan (float) – Length of the scanned y-axis on which the SQUID signal is calculated.

  • Wdevice (float) – Length of the device y-axis on which the current distribution is defined.

  • Nscan (int) – Number of points in the scanned y-axis on which the SQUID signal is calculated. Must be even.

  • gamma (float) – Angle between the SQUID scan direction and the current direction.

  • rho1 (float) – Inner radius of the SQUID.

  • rho2 (float) – Outer radius of the SQUID.

  • height (float) – Height of the SQUID above the device.

  • phi (float) – Angle between the SQUID normal and the device plane.

  • invert_normal (bool) – If True, the SQUID normal is inverted. This flips the sign of the SQUID signal.

  • invert_scan (bool) – If True, the SQUID scan direction is inverted. This inverts the y-axis.

rho1

Inner radius of the SQUID.

Type:

float

rho2

Outer radius of the SQUID.

Type:

float

height

Height of the SQUID above the device.

Type:

float

phi

Angle between the SQUID normal and the device plane.

Type:

float

property dyscan: float

Step size of the scanned y-axis.

Returns a float representing the step size of the scanned y-axis.

property Ndevice: int

Number of points in the device y-axis.

Returns an integer representing the number of points in the device y-axis.

property Lproj: float

Length of the projected y-axis over which the SQUID scans.

Returns a float.

property dyproj: float

Step size of the projected y-axis over which the SQUID scans.

Returns a float.

property Lscan: float

Length of the scanned y-axis on which the SQUID signal is calculated.

Returns a float.

property gamma: float

Angle between the SQUID scan direction and the current direction.

Returns a float.

property Nscan: int

Number of points in the scanned (data) y-axis.

Returns an integer.

property Wdevice: float

Length of the device y-axis on which the current distribution is defined.

Returns a float.

property yscan: Tensor

The scanned x-axis on which the SQUID signal is calculated.

property yproj: Tensor

The projected x-axis on which the SQUID signal is calculated.

property ydevice: Tensor

The y-axis on which the current distribution is defined.

It contains Ndevice points and has length Wdevice. If Ndevice is even: runs from -Wdevice/2 to Wdevice/2-dyproj. Element Ndevice/2 is at y=0. If Ndevice is odd: runs from -Wdevice/2 to Wdevice/2. Element (Ndevice-1)/2 is at y=0.

property phi_eff: float

Effective angle between the SQUID normal and the device plane.

This calculation takes into account flipping of the scan direction. Returns a float.

property kernel_sign: float

Overal sign of the kernel.

Again, this takes into account flipping of the scan direction and the SQUID normal. Returns a float.

class sottools.forward.Forward1D(params, n_alpha=32, n_rho=32, device=None, mu0=1.2566370614359172, verbose=False)

Bases: object

Computes 1D SOT linetraces from a 1D current distribution on a device.

The forward model for 1D current reconstruction. An instance of this class uses Forward1DParameters to pre-compute the SQUID-response kernel (Foward1D._precompute_kernel) and can then use this kernel to convert between a current distribution j(y’’) on the device and a squid signal S(y) along the scan-axis.

Parameters:
  • params (Forward1DParameters) – An instance of Forward1DParameters containing the parameters for the forward model.

  • n_alpha (int) – Number of alpha angles to use in the kernel precomputation. Defaults to 32.

  • n_rho (int) – Number of rho values to use in the kernel precomputation. Defaults to 32.

  • device (torch.device) – The device on which to perform all torch computations. Defaults to CPU.

  • mu0 (float) – Permeability of free space. Sets the units of the problem. Default is 4*pi*1e-1 which corresponds to units of um, uA, uT.

  • verbose (bool) – If True, prints progress during kernel precomputation. Defaults to False.

Notes

Old fitting code was unit-less. This limit can be recovered by setting mu0=4*pi, in which case all factors mu0/4pi disappear from the equations.

property params: Forward1DParameters

The parameters that describe the forward model calculation.

Returns an instance of Forward1DParameters.

forward_t(current)

Compute the 1D SQUID signal from a 1D current distribution on the device.

Uses the pre-computed kernel and Fourier methods to calculate the 1D SQUID signal from the 1D current distribution on the device. Accelerated fully using Torch, which also ensures compatibility with GPU acceleration and autodifferentiation. For single-shot use, without autodifferentiation, it is easier to interface with the forward() model, which is a NumPy wrapper around this function.

Parameters:

current (torch.Tensor) – A tensor of shape (Ndevice,) representing the current distribution j(y’’) on the device.

Returns:

signal – A tensor of shape (Nscan,) representing the SQUID signal on the y axis.

Return type:

torch.Tensor

forward(current)

NumPy wrapper for forward_t(). See forward_t() for details.

Parameters:

current (ndarray)

Return type:

ndarray

class sottools.forward.Forward2DParameters(Lx=1.0, Ly=1.0, Nx=2, Ny=2, rho1=0.1, rho2=0.2, height=0.2, phi=0.0, invert_normal=False, invert_scan=False)

Bases: object

Parameters describing a 2D forwrad calculation from current to SOT image.

The forward pass of the 2D model relies on parameters describing: - The spatial resolution and constraints of the model - The properties of the SQUID sensor modeled - The properties of the 2D underlying current distribution Unlike Forward1D, Forward2D has the SQUID and sample plane share a grid.

Parameters:
  • Lx (float) – Length of the scanned x-axis on which the SQUID signal is calculated.

  • Ly (float) – Length of the scanned y-axis on which the SQUID signal is calculated.

  • Nx (int) – Number of points in the scanned x-axis on which the SQUID signal is calculated. Must be even.

  • Ny (int) – Number of points in the scanned y-axis on which the SQUID signal is calculated. Must be even. Ly/Ny must equal Lx/Nx to ensure square pixels.

  • rho1 (float) – Inner radius of the SQUID.

  • rho2 (float) – Outer radius of the SQUID.

  • height (float) – Height of the SQUID above the device.

  • phi (float) – Angle between the SQUID normal and the device plane.

  • invert_normal (bool) – If True, the SQUID normal is inverted. This flips the sign of the SQUID signal.

  • invert_scan (bool) – If True, the SQUID scan direction is inverted. This inverts the y-axis.

Lx

Length of the scanned x-axis on which the SQUID signal is calculated.

Type:

float

Ly

Length of the scanned y-axis on which the SQUID signal is calculated.

Type:

float

rho1

Inner radius of the SQUID.

Type:

float

rho2

Outer radius of the SQUID.

Type:

float

height

Height of the SQUID above the device.

Type:

float

phi

Angle between the SQUID normal and the device plane.

Type:

float

invert_normal

If True, the SQUID normal is inverted. This flips the sign of the SQUID signal.

Type:

bool

invert_scan

If True, the SQUID scan direction is inverted. This inverts the y-axis.

Type:

bool

property Nx: int

Amount of points in the x-axis on which the SQUID signal is calculated.

property Ny: int

Amount of points in the y-axis on which the SQUID signal is calculated.

property x: Tensor

The scanned x-axis on which the SQUID signal is calculated.

Returns a torch.Tensor of shape (Nx,) representing the x-axis which runs from -L/2 to L/2-dx.

property y: Tensor

The projected x-axis on which the SQUID signal is calculated.

Returns a torch.Tensor of shape (Ny,) representing the y-axis which runs from -L/2 to L/2-dy.

property xx: Tensor

The x-axis (grid) on which the SQUID signal is calculated.

Returns a torch.Tensor of shape (Nx, Ny) representing the x-coordinate grid.

property yy: Tensor

The y-axis (grid) on which the SQUID signal is calculated.

Returns a torch.Tensor of shape (Nx, Ny) representing the y-coordinate grid.

property phi_eff: float

invert_scan works in the scan frame, phi -> -phi.

Type:

Effective tilt

property kernel1_sign: float

K1(x,-y;-phi) = -K1(x,y;phi).

Type:

Sign of the Jx-coupling kernel

property kernel2_sign: float

K2(x,-y;-phi) = +K2(x,y;phi).

Type:

Sign of the Jy-coupling kernel

class sottools.forward.Forward2DCurrent(params, n_alpha=32, n_rho=32, device=None, mu0=1.2566370614359172, verbose=False)

Bases: object

Forward calculation of 2D SQUID images from 2D current (Jx/Jy) distributions.

The forward model for 2D current reconstruction. An instance of this class uses Forward2DParameters to pre-compute the SQUID-response kernel (Foward2DCurrent._precompute_kernel1 and Foward2DCurrent._precompute_kernel2) and then uses this kernel to convert between a current distribution Jx/Jy on the device and a SQUID signal S on the same grid.

The implementation contains an approach to minimize wrapping artifacts in the convolution: 1. All convolutions are performed on a grid of size 3*Nx by 3*Ny to ensure sufficient padding protects against wrapping artifacts. 2. The current distributions are mirrored and extended over the entire 3*Nx by 3*Ny grid to simulate continuity. 3. Outside the main FOV, the current distributions are tapered to zero using a cos(pi*x) window over half Nx/Ny to prevent faraway imaginary currents from contributing to the SQUID signal.

Parameters:
  • params (Forward2DParameters) – An instance of Forward2DParameters containing the parameters for the forward model.

  • n_alpha (int) – Number of alpha angles to use in the kernel precomputation. Defaults to 32.

  • n_rho (int) – Number of rho values to use in the kernel precomputation. Defaults to 32.

  • device (torch.device) – The device on which to perform all torch computations. Defaults to CPU.

  • mu0 (float) – Permeability of free space. Sets the units of the problem. Default is 4*pi*1e-1 which corresponds to units of um, uA, uT.

  • verbose (bool) – If True, prints progress during kernel precomputation. Defaults to False.

Notes

Old fitting code was unit-less. This limit can be recovered by setting mu0=4*pi, in which case all factors mu0/4pi disappear from the equations.

property params: Forward2DParameters

The parameters that describe the forward model calculation.

forward_t(current_x, current_y)

Calculate the 2D SQUID signal from a 2D current distribution on the device.

Uses the pre-computed kernels and Fourier methods to calculate the 2D SQUID signal from the 2D current distribution on the device. Accelerated fully using Torch, which also ensures compatibility with GPU acceleration and autodifferentiation. For single-shot use, without autodifferentiation, it is easier to interface with the forward() model, which is a NumPy wrapper around this function.

Parameters:
  • current_x (torch.Tensor) – A tensor of shape (Nx, Ny) representing the x component of the current distribution j(x,y)

  • current_y (torch.Tensor) – A tensor of shape (Nx, Ny) representing the y component of the current distribution j(x,y)

Returns:

signal – A tensor of shape (Nx, Ny) representing the SQUID signal on the x and y axes.

Return type:

torch.Tensor

forward(current_x, current_y)

NumPy wrapper for forward_t(). See forward_t() for details.

Parameters:
Return type:

ndarray

class sottools.forward.MeshToGrid(mesh, forwardparams, device=None)

Bases: object

Converts between a streamfunction on a mesh and a current distribution on a grid.

Contains the full toolchain for converting a streamfucntion on a mesh to a current on a grid. This is what is required to perform a forward chain from an on-mesh streamfunction to a SQUID image. On-mesh streamfunctions are preferred over on-grid currents because they are guaranteed divergence free and guaranteed fit the boundary conditions of the problem.

Parameters:
  • mesh (SimplyConnectedCurrentMesh) – The mesh on which the streamfunction is defined.

  • forwardparams (Forward2DParameters) – The parameters describing the grid on which the current is defined.

  • device (torch.device) – The device on which to perform all torch computations. Defaults to CPU.

streamfunction_to_currents_t(g)

Calculate current densities on a grid from a streamfunction on a mesh.

Takes a streamfunction g defined on the mesh vertices and returns the current densities Jx, Jy on the grid. The grid points are taken from the forward parameters passed at construction. This function is fully Torch compatible and can be used with GPU acceleration and autodifferentiation. For single-shot use, without autodifferentiation, it is easier to interface with streamfunction_to_currents(), which is a NumPy wrapper around this function.

Parameters:

g (torch.Tensor) – A tensor of shape (N_vertices,) representing the streamfunction on the mesh vertices.

Returns:

  • Jx_grid (torch.Tensor) – A tensor of shape (Nx, Ny) representing the x component of the current distribution on the grid.

  • Jy_grid (torch.Tensor) – A tensor of shape (Nx, Ny) representing the y component of the current distribution on the grid.

Return type:

tuple[Tensor, Tensor]

streamfunction_to_currents(g)

NumPy wrapper for streamfunction_to_currents_t().

See streamfunction_to_currents_t() for details.

Parameters:

g (ndarray)

Return type:

tuple[ndarray, ndarray]

property mesh: SimplyConnectedCurrentMesh

The mesh on which the streamfunction is defined.