Package: magpylib
Magpylib is a Python package for calculating3D static magnetic fieldsof magnets, line currents and other sources. The computation is based on explicit expressions and is thereforeextremely fast. Auser friendly APIenables convenient positioning of sources and observers.InstallationInstall from PyPI usingpippip install magpylibInstall from conda forge usingcondaconda install -c conda-forge magpylibMagpylib supportsPython3.8+and relies on common scientific computation librariesNumpy,Scipy,MatplotlibandPlotly. Optionally,Pyvistais recommended as graphical backend.RessourcesCheck out ourDocumentationfor detailed information.Please abide by ourCode of Conduct.Contribute throughDiscussionsand coding by following theContribution Guide. The Git projectIssuesgive an up-to-date list of potential enhancements and planned milestones. Propose new ones.AYoutube videointrodution to Magpylib v4.0.0 within theGSC network.Anopen-access paperfrom the year 2020 describes v2 of this library with most basic concepts still intact in later versions.QuickstartHere is an example how to use Magpylib.importmagpylibasmagpy# Create a Cuboid magnet with sides 1,2 and 3 mm respectively, and magnetization# (polarization) of 1000 mT pointing in x-direction.cube=magpy.magnet.Cuboid(magnetization=(1000,0,0),dimension=(1,2,3),)# By default, the magnet position is (0,0,0) and its orientation is the unit# rotation (given by a scipy rotation object), which corresponds to magnet sided# parallel to global coordinate axes.print(cube.position)# --> [0. 0. 0.]print(cube.orientation.as_rotvec())# --> [0. 0. 0.]# Manipulate object position and orientation through the respective attributes,# or by using the powerful `move` and `rotate` methods.cube.move((0,0,-2))cube.rotate_from_angax(angle=45,axis='z')print(cube.position)# --> [0. 0. -2.]print(cube.orientation.as_rotvec(degrees=True))# --> [0. 0. 45.]# Compute the magnetic field in units of mT at a set of observer positions. Magpylib# makes use of vectorized computation. Hand over all field computation instances,# e.g. different observer positions, at one funtion call. Avoid Python loops !!!observers=[(0,0,0),(1,0,0),(2,0,0)]B=magpy.getB(cube,observers)print(B.round())# --> [[-91. -91.   0.]#      [  1. -38.  84.]#      [ 18. -14.  26.]]# Sensors are observer objects that can have their own position and orientation.# Compute the H-field in units of kA/m.sensor=magpy.Sensor(position=(0,0,0))sensor.rotate_from_angax(angle=45,axis=(1,1,1))H=magpy.getH(cube,sensor)print(H.round())# --> [-95. -36. -14.]# Position and orientation attributes of Magpylib objects can be vectors of# multiple positions/orientations refered to as "paths". When computing the# magnetic field of an object with a path, it is computed at every path index.cube.position=[(0,0,-2),(1,0,-2),(2,0,-2)]B=cube.getB(sensor)print(B.round())# --> [[-119.  -45.  -18.]#      [   8.  -73.  -55.]#      [  15.  -30.   -8.]]# When several objects are involved and things are getting complex, make use of# the `show` function to view your system through Matplotlib, Plotly or Pyvista backends.magpy.show(cube,sensor,backend='pyvista')More details and other important features are described in detail in theDocumentation. Key features are:Collections: Group multiple objects for common manipulationComplex shapes: Create magnets with arbitrary shapesGraphics: Styling options, graphic backends, animations, and 3D modelsCustomSource: Integrate your own field implementationDirect interface: Bypass the object oriented interface (max speed)How can I cite this library ?We would be happy if you give us credit for our efforts. A valid bibtex entry for the2020 open-access paperwould be@article{ortner2020magpylib,
  title={Magpylib: A free Python package for magnetic field computation},
  author={Ortner, Michael and Bandeira, Lucas Gabriel Coliado},
  journal={SoftwareX},
  volume={11},
  pages={100466},
  year={2020},
  publisher={Elsevier}
}A valid software citation could be@software{magpylib,
    author = {{Michael-Ortner et al.}},
    title = {magpylib},
    url = {https://magpylib.readthedocs.io/en/latest/},
    version = {4.5.1},
    date = {2023-06-25},
}