mmt_multipole_inversion
#
Subpackages#
mmt_multipole_inversion.magnetic_sample_modules
mmt_multipole_inversion.multipole_field
mmt_multipole_inversion.susceptibility_modules
mmt_multipole_inversion.susceptibility_modules.cuda
mmt_multipole_inversion.susceptibility_modules._flux_integration_sympy
mmt_multipole_inversion.susceptibility_modules.cartesian_spherical_harmonics
mmt_multipole_inversion.susceptibility_modules.maxwell_cartesian_polynomials
mmt_multipole_inversion.susceptibility_modules.spherical_harmonics_basis
mmt_multipole_inversion.susceptibility_modules.spherical_harmonics_basis_area
mmt_multipole_inversion.susceptibility_modules.spherical_harmonics_basis_volume
Submodules#
Package Contents#
Classes#
Class to perform multipole inversions |
|
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
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. The sensors of the magnetic scan surface are modelled either as point sensors or sensor with cuboid shape (volume).
- 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
- Parameters
optimization (_MethodOptions) –
Notes
In case of using one of the _area or _volume susceptibility modules, where the sensor is modelled in 2D or 3D, remember to specify the self.sensor_dims tuple with the dimensions of the sensor
- compute_inversion(self, method='sp_pinv', sigma_field_noise=None, **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)
- sigma_field_noise
If a float is specified, a covariance matrix is produced and stored in the covariance_matrix variable. This matrix uses the value of sigma as the standard deviation of uncorrelated noise in the magnetic flux field. Units are T m^2. In addition, the standard deviation of the magnetic moments are calculated and stored in the inv_moments_std 2D array where every row has the results per grain. For details, see [F. Out et al. Geochemistry, Geophysics, Geosystems 23(4). 2022]
- **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.
- Parameters
method (_InvMethodOps) –
sigma_field_noise (Optional[float]) –
- save_multipole_moments(self, save_name='TIME_STAMP', basedir='.', save_moments_std=False)#
Save the multipole values in npz files.
Values need to be computed using the compute_inversion method.
- Parameters
- save_name
File name of the npz file
- basedir
Base directory where results are saved. Will be created if it does not exist
- save_moments_std
Add the standard deviation of the magnetic moments to the npz file in case the sigma_field_noise was specified in the inversion
- Parameters
save_name (str) –
basedir (Union[pathlib.Path, str]) –
save_moments_std (bool) –
- Return type
None
- class mmt_multipole_inversion.MagneticSample(Hz, Sx, Sy, Sdx, Sdy, Lx, Ly, Lz, sensor_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.__copyright__#
- 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#