mmt_multipole_inversion#

Subpackages#

Submodules#

Package Contents#

Classes#

MultipoleInversion

Class to perform multipole inversions of a magnetic scan surface into

MagneticSample

Class for the specification of a scan grid detecting the out plane flux of

Attributes#

class mmt_multipole_inversion.MultipoleInversion(sample_config_file, sample_arrays, expansion_limit='quadrupole', verbose=True, sus_functions_module='spherical_harmonics_basis')#

Bases: object

Class to perform multipole inversions of a magnetic scan surface into multiple magnetic sources located within a sample. Specifications of the scan grid and the magnetic particles in the sample can be generated using the MagneticSample class.

Parameters
  • sample_config_file (Union[str, pathlib.Path]) –

  • sample_arrays (Optional[Union[str, pathlib.Path]]) –

  • expansion_limit (ExpOptions) –

  • verbose (bool) –

  • sus_functions_module (SusOptions) –

property expansion_limit(self)#
generate_measurement_mesh(self)#

Generate coordinates for the measurement mesh The number of grid points in each direction (xy) are calculated by rounding the lateral size by the grid step size, e.g. round(Sx / Sdx)

generate_forward_matrix(self, optimization='numba')#

Generate the forward matrix adding the field contribution from all the particles for every grid point at the scan surface. The field is computed from the scalar potential of the particles approximated with the multipole expansion up to the order specified by self.expansion_limit

Parameters
optimization

The method to optimize the calculation of the matrix elements: numba or cuda

compute_inversion(self, method='sp_pinv', **method_kwargs)#

Computes the multipole inversion. Results are saved in the inv_multipole_moments and inv_Bz_array variables. This method requires the generation of the Q matrix, hence the generate_forward_matrix method using numba is called if Q has not been set. To optimize the calculation of Q, call the function before this method.

Parameters
method
The numerical method to perform the inversion. Options:

np_pinv -> Numpy’s pinv sp_pinv -> Scipy’s pinv (not recommended -> memory issues) sp_pinv2 -> Scipy’s pinv2 (this will call sp_pinv instead)

**method_kwargs

Extra parameters passed to Numpy or Scipy functions. For Numpy, the tolerance can be set using rcond while for Scipy it is recommended to use atol and rtol. See their documentations for detailed information.

save_multipole_moments(self, save_name='TIME_STAMP', basedir='.')#

Save the multipole values in npz files. Values are computed from the inversion using the compute_inversion method.

class mmt_multipole_inversion.MagneticSample(Hz, Sx, Sy, Sdx, Sdy, Lx, Ly, Lz, scan_origin=(0.0, 0.0), bz_field_module='spherical_harmonics_basis')#

Bases: object

Class for the specification of a scan grid detecting the out plane flux of the magnetic field generated by an arbitrary number of magnetic sources. The magnetic sources can be dipoles, quadrupoles or octupoles. The scan grid is defined in the XY plane, at a given height above the magnetic sample containing the point sources.

This class calculates the magnetic field from the point sources and adds them to generate the total flux at every area of the scan grid mesh.

                   Sdx
                ___/___
               /      /            Scan Grid
         _     ______________________________
  Sdy_ /     /       /      /       /       /
      /_    /_______/______/_______/_______/__      _
           /       /      /       /       /   /|     |
          / ______/______/_______/_______/   / |     |_ Lz
         /       /      /       /       /   /  |     |
     _  /_______/______/_______/_______/   /   |     |
Hx _|     /                O              /  O |    _|
    |_   /______________________________ /    /
        |                               |    /
        |            O                  |   /
        |   O                           |  /
        |    dipole               O     | /
        |_______________________________|/  Sample
get_metadict(self)#

Generate a dictionary with the keys defined in the _metadict variable. Values are obtained by calling the class instance attributes defined in the _metadict values. Because scan origin is a sequence, it is split in x and y components. This method is used to export sample properties as a json file.

generate_random_particles(self, N_particles=100, Ms=480000.0, seed=42, rmin=[0.1, 0.1, 0.1], rmax=[0.9, 0.9, 0.9])#

Generate a sample of dipole particles randomly distributed across the sample region. The dipole moments of the particles are randomly generated based on the saturation magnetization value Ms

Parameters
N_particles

Number of particles

Ms

Saturation magnetisation

seed

random number generator seed

rmin, rmax

minimum and maximum scale factors for the limits of the locations of the particles. The factors scale the sample dimensions in every dimension. For example, particles spread over the sample but close to the surface can be modelled by

rmin = [0.1, 0.1, 0.7] rmax = [0.9, 0.9, 0.9]

This means particle positions in the x-direction will vary between 0.1 and 0.9 of Lx, and so on.

generate_particles_from_array(self, positions, dipole_moments, volumes, quadrupole_moments=None, octupole_moments=None)#

Generate particles in the sample from arrays specified manually

Parameters
positions

N x 3 array (m units)

dipole_moments

N x 3 array (A m^2 unitS)

volumes

N x 3 array (m^3 units)

quadrupole_moments

N x 5 array with quadrupole moments

octupole_moments

N x 7 array with octupole moments

Notes

The multipole options need to be redefined (it depends on the basis we are expressing the multipole expansion)

generate_measurement_mesh(self)#

Generate the magnetic flux array at the scan surface, i.e. calculate the total Bz contribution from the particles at every grid point of the scan surface

generate_noised_Bz_array(self, std_dev, seed=4242)#

Add uncorrelated noise to the magnetic flux (Bz array). The new array is stored in self.Bz_array_noised Update the seed if necessar. For the seed a random number generator can be passed instead of an int.

save_data(self, filename='TIME_STAMP', basedir='', noised_array=False)#

Save the system properties as a json file and relevant arrays in a npz file: Bz_array, particle_positions, magnetization and volumes.

Parameters
filename

Name appended to the dictionary and arrays base name

basedir

An optional directory to which data is going to be stored

noised_array

Save the noised Bz_array instead of the original array

plot_sample(self, ax, contours=30, contourlines=15, contourf_args=dict(cmap='RdYlBu'), contour_args=dict(colors='k', linewidths=0.2), scatter_args=dict(c='k'), dimension_scale=1.0, data_scale=1.0, noised_array=False, imshow_args=None)#

(WILL BE REMOVED IN FUTURE) Plot the scan surface and the particles beneath using their xy position

Optional:

If imshow_args is specified, this functions uses imshow instead of contourf to plot the colored background with Bz_array. In this case, all the contourf args are ignored

Returns :: cf, c1, c2

where cf is the contour plot object showing Bz, c1 its contour lines and c2 the scatter plot with the particle positions

mmt_multipole_inversion.__author__ = D. Cortés-Ortuño, K. Fabian, L. V. de Groot#
mmt_multipole_inversion.__email__ = d.i.cortes@uu.nl#
mmt_multipole_inversion.__license__ = MIT#
mmt_multipole_inversion.__summary__ = Library to generate scan grid measurements from multipole sources and perform numerical inversions#
mmt_multipole_inversion.__title__ = mmt_multipole_inversion#
mmt_multipole_inversion.__uri__ = https://github.com/Micromagnetic-Tomography/mmt_multipole_inversion#
mmt_multipole_inversion.__version__ = 1.0#