Skip to main content

Python lib to calculate the magnetization of grains using the dipole cuboids model

Project description

DOI License: MIT Documentation Status

MMT Numerical Libraries: Dipole Cuboid Inversion

Python library for the calculation of magnetizations of magnetic grain sources, which are modelled as homogeneously magnetized particles, using an aggregation of cuboids. The method requires both the position of grains and magnetic surface data from the Micromagnetic Tomography project. This is achieved by:

  • Modelling the grains as aggregation of cuboids. This data is input into this library's main class called DipoleCuboidInversion.

  • Creating a forward matrix, which is also known as Green's matrix, that is obtained from the analytical formulation of the demagnetizing field of the cuboids. This matrix is multiplied by the degrees of freedom of the system which are the magnetizations of all the grains in the sample. The multiplication results into the magnetic field signal imprinted into the scan surface. The DipoleCuboidInversion class accepts the scan surface data as a text input file or Numpy matrix and has methods to calculate the Green's matrix.

  • Numerically inverting the scan surface data into the grains to obtain their individual magnetizations. The inversion is obtained by calculating the pseudo-inverse of the Green's matrix using Numpy or Scipy.

The mmt_dipole_cuboid_inversion library is optimized to populate the Green's matrix using either: Numba (compiled function), C parallelized with OpenMP (parallelization in the number of particles) or NVidia CUDA (high performance parallelization via the number of sensors in the scan surface).

Installation

Via PyPI and pip (note PyPI names use - instead of _)

pip install mmt-dipole-cuboid-inversion

Or you can use Poetry (recommended for development and CUDA, see below)

poetry install

Documentation

Please visit the official Documentation

CUDA

To build the code with the cuda option to populate the Green's matrix, it is necessary to define the CUDAHOME variable pointing to the cuda folder (assuming you have a functional cuda installation), e.g.

export CUDAHOME=/usr/local/cuda-11.5/

Then you can compile the code using poetry install.

Poetry

This library is built using the poetry library. After cloning the repository a virtualenv will be created automatically when running poetry install, unless you are already in a virtualenv, for example, creating one via conda. Within this environment it is possible to run and test the code using poetry run:

git clone https://github.com/Micromagnetic-Tomography/mmt_dipole_cuboid_inversion
cd mmt_dipole_cuboid_inversion
poetry install
poetry run python test/generate_single_dipole.py

For more information see this link. If the package requires to be built for publication (in the PyPI repository for example) or to be installed via pip, you can run

poetry build

This will produce a dist folder containing a tar.gz file and a wheel file. These files can be installed via pip.

PyPI

Install from PyPI. Only Linux and Windows builds are currently available.

pip install mmt-dipole-cuboid-inversion

How to use

You can call the class by doing:

import mmt_dipole_cuboid_inversion as dci

data = dci.DipoleCuboidInversion(...)
...

An Example notebook file with example data is included.

Cite

If you find this library useful please cite us (you might need LaTeX's url package). Check Github's Citation in the About menu, or the following Bibtex entries:

@Misc{Out2023,
  author       = {Out, Frenk and Cortés-Ortuño, David and Kosters, Martha and Fabian, Karl and de Groot, Lennart V.},
  title        = {{MMT Numerical Libraries: Dipole Cuboid Inversion}},
  publisher    = {Zenodo},
  note         = {Github: \url{https://github.com/Micromagnetic-Tomography/mmt_dipole_cuboid_inversion}},
  year         = {2023},
  doi          = {10.5281/zenodo.7823450},
  url          = {https://doi.org/10.5281/zenodo.7823450},
}

If you have a new version of biblatex you can also use @Software instead of @Misc, and add a version={} entry. You can also cite the paper with the theoretical framework of this library:

@article{Out2023,
...
}

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mmt_dipole_cuboid_inversion-1.0.tar.gz (141.8 kB view hashes)

Uploaded Source

Built Distributions

mmt_dipole_cuboid_inversion-1.0-cp310-cp310-win_amd64.whl (205.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

mmt_dipole_cuboid_inversion-1.0-cp310-cp310-manylinux_2_35_x86_64.whl (527.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

mmt_dipole_cuboid_inversion-1.0-cp39-cp39-win_amd64.whl (206.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

mmt_dipole_cuboid_inversion-1.0-cp39-cp39-manylinux_2_35_x86_64.whl (531.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.35+ x86-64

mmt_dipole_cuboid_inversion-1.0-cp38-cp38-win_amd64.whl (206.4 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

mmt_dipole_cuboid_inversion-1.0-cp38-cp38-manylinux_2_35_x86_64.whl (531.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.35+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page