mmt_dipole_cuboid_inversion#

Subpackages#

Submodules#

Package Contents#

Classes#

Attributes#

class mmt_dipole_cuboid_inversion.DipoleCuboidInversion(scan_domain=None, sensor_center_domain=None, scan_spacing=1e-06, scan_deltax=5e-07, scan_deltay=5e-07, scan_area=1e-12, scan_height=1e-06, verbose=True)#

Bases: object

Parameters:
  • scan_domain (Optional[numpy.typing.NDArray[numpy.float64]]) –

  • sensor_center_domain (Optional[numpy.typing.NDArray[numpy.float64]]) –

  • scan_spacing (float | Tuple[float, float]) –

  • scan_deltax (float) –

  • scan_deltay (float) –

  • scan_area (float) –

  • scan_height (float) –

  • verbose (bool) –

_SetScanDomainOps#
_PrepMatOps#
_MethodOps#
classmethod from_json(file_path, verbose=True)#

Instantiate the class using scanning surface params from a JSON file

The required JSON keys are:

'Scan domain LL-x-y'
'Scan domain UR-x-y'
'Sensor center domain LL-x-y'
'Sensor center domain UR-x-y'
'Scan spacing'
'Scan delta-x'
'Scan delta-y'
'Scan area'
'Scan height'
Parameters:
  • file_path (Union[pathlib.Path, str]) –

  • verbose (bool) –

Return type:

DipoleCuboidInversion

read_files(scan_data, cuboid_data, cuboid_scaling_factor, scan_matrix_reader_kwargs={}, cuboids_reader_kwargs={})#

Reads in scan data and cuboid data from text/csv files

Parameters:
scan_data

File path to a text or npy file, np.ndarray with (Nx columns, Ny rows), containing the scan data in Tesla

cuboid_data

File path, np.ndarray containing the location and size of the grains in micrometer, with format (x, y, z, dx, dy, dz, index)

cuboid_scaling_factor

Scaling factor for the cuboid positions and lengths

scan_matrix_reader_kwargs

Extra arguments to the reader of the scan file, e.g. delimiter=’,’

cuboids_reader_kwargs

Extra arguments to the reader of cuboid files, e.g. skiprows=2

Parameters:
  • scan_data (Union[pathlib.Path, str, numpy.typing.NDArray[numpy.float64]]) –

  • cuboid_data (Union[pathlib.Path, str, numpy.typing.NDArray[numpy.float64]]) –

  • cuboid_scaling_factor (float) –

set_scan_domain(gen_sd_mesh_from='sensor_center_domain', tol_sd_limits=1e-07)#

Sets the scan domain limits and spacings

This function might also correct the limits of the scan_domain attribute according to the size of the scan data matrix.

Parameters:
gen_sd_mesh_from

Method to set the limits or spacings of the scan domain. The sensor_center_domain will use the centers of the lower left and upper right sensors of the scan surface, which are defined in the variable of the same name. Similarly, The scan_domain uses the lower left and upper right coordinates of the scan surface, from the scan_domain variable. These two methods require the scan spacings, and the new domain limit is compared to the limits given by the upper right point in *_domain. The option sd_partitioned uses the matrix dimensions of scan_data to partition the scan_domain limits by re-defining the scan_spacing variable.

tol_sd_limits

Tolerance for checking scan_domain in two of the gen_sd_mesh_from methods

Parameters:
  • gen_sd_mesh_from (_SetScanDomainOps) –

  • tol_sd_limits (float) –

prepare_matrix(Origin=True, method='cython')#

Defines Numpy arrays and populates the forward matrix

The calculation uses the positions of the centers of the scan sensors, which are arranged in a 2D regular rectangular mesh.

Parameters:
Origin

If True, use the sensor_center_domain lower left coordinates as the scan grid origin. If False, set sensor grid origin at (0., 0.)

method

Populating the matrix can be done using either numba or cython or (nvidia) cuda optimisation. The cython function is parallelized with OpenMP thus the number of threads is specified from the OMP_NUM_THREADS system variable. This can be limited using set_max_num_threads in the tools module

Parameters:
  • Origin (bool) –

  • method (_PrepMatOps) –

calculate_inverse(method='scipy_pinv', store_inverse_G_matrix=False, **method_kwargs)#

Calculates the inverse and computes the magnetization. The solution is generated in the self.Mag variable. Optionally, the covariance matrix can be established.

Parameters:
method

The numerical inversion can be done using the SVD algorithms or the least squares method. The options available are:

  • scipy_lapack :: Uses scipy lapack wrappers for dgetrs and

    dgetrf to compute \(\mathbf{M}\) by solving the matrix least squares problem: \(Gᵀ * G * M = Gᵀ * ϕ_{scan}\)

  • scipy_pinv :: SVD method

  • scipy_pinv2 :: (Deprecated) SVD method, calls pinv

  • numpy_pinv :: SVD method

Parameters:
  • method (_MethodOps) –

  • store_inverse_G_matrix (bool) –

Return type:

None

Notes

Additional keyword arguments are passed to the solver, e.g:

calculate_inverse(method='numpy_pinv', rcond=1e-15)
obtain_magnetization(scan_data, cuboid_data, cuboid_scaling_factor, method_scan_domain='sensor_center_domain', method_populate='cython', method_inverse='scipy_pinv', **method_inverse_kwargs)#

Shortcut method to compute the magnetization of the grains

It calls four methods: read_files, set_scan_domain, prepare_matrix and calculate_inverse

Parameters:
scan_data

Matrix file or np.ndarray (Nx columns, Ny rows) containing the scan data in T

cuboid_data

File or np.ndarray (x, y, z, dx, dy, dz, index) containing location and size grains in micrometers

cuboid_scaling_factor

Scaling factor for the cuboid positions and lengths

method_scan_domain

Method to set the scan domain. See: set_scan_domain

method_populate

Method to populate the forward matrix. See: populate_matrix

method_inverse

Method to calculate the numerical inversion. See the docstring of calculate_inverse for details about the method parameters

Parameters:
  • scan_data (Path | str | npt.NDArray[np.float64]) –

  • cuboid_data (Path | str | npt.NDArray[np.float64]) –

  • cuboid_scaling_factor (float) –

  • method_scan_domain (_SetScanDomainOps) –

  • method_populate (_PrepMatOps) –

  • method_inverse (_MethodOps) –

save_results(Magfile, keyfile)#

Saves the magnetization to a specified Magfile file and the keys of the index of the particles in the key file file.

Parameters:
Magfile

Path to file to save the magnetization

keyfile

Path to file to save the identification (key) of all grains

Parameters:
  • Magfile (Path or str) –

  • keyfile (Path or str) –

forward_field(filepath=None, sigma=None)#

Calculates the forward field

Parameters:
filepath

Optional path to file to save the forward field

sigma

Standard deviation of Gaussian noise to be added in Tesla

Returns:
Forward_field

Optionally return forward magnetic field if no file path is input

Parameters:
  • filepath (Optional[str]) –

  • sigma (Optional[float]) –

mmt_dipole_cuboid_inversion.__author__ = 'F. Out, D. Cortés-Ortuño, M. Kosters, K. Fabian, L. V. de Groot'#
mmt_dipole_cuboid_inversion.__email__ = 'f.out@uu.nl'#
mmt_dipole_cuboid_inversion.__license__ = 'MIT'#
mmt_dipole_cuboid_inversion.__summary__ = 'Library to compute magnetizations from numerical inversions of surface scan data into grain...'#
mmt_dipole_cuboid_inversion.__title__ = 'mmt_dipole_cuboid_inversion'#
mmt_dipole_cuboid_inversion.__uri__ = 'https://github.com/Micromagnetic-Tomography/mmt_dipole_inverse'#
mmt_dipole_cuboid_inversion.__version__#