Changelog#
The changelog provides a compressed history of the Magpylib development since its publication in 2019.
Unreleased - YYYY-MM-DD#
5.1.0 - 2024-10-09#
Fixed a bug where the magnetization arrow graphical representation would be anchored badly after rotation (#805)
Added
units_lengthinput to theshowfunction to allow displaying axes with different length units. This parameter can be set individually for each subplot. (#786)Small documentation and Readme improvement. Change naming from “explicit expression” to “analytical expression” as described in (#794).
Fixed Pvyvista plot bounds not fitting on animation. Also enables
zoomfeature which was not working until now. (#798)Fixed canvas layout being modified even when user-provided. Also added a new
canvas_updateparameter to choose the layout behavior (by default"auto") (#799)Documentation now includes force computation, which is still in a separate package “magpylib-force”, but which will be integrated into Magplyib in the coming months. (#787)
5.0.4 - 2024-06-18#
5.0.3 - 2024-06-03#
5.0.2 - 2024-05-21#
Fixed a display issue causing incorrect calculation of view box limits (#772)
Removed support for python 3.8 and 3.9 by now following the scientific-python.org support timelines (#773)
Fixed CI testing with newer backend versions (#774)
Updated site notice to mention the awarded “small development grant” by NumFocus. (#758)
Fixed inaccurate citation year for Yang publication (#764, with thanks to @feldnerd for the contribution!)
5.0.1 - 2024-04-12#
5.0.0 - 2024-03-13#
⚠️ Breaking Changes ⚠️#
The Magpylib inputs and outputs are now in SI Units.
The
magnetizationparameter has also been redefined to reflect the true physical magnetization quantity in units of A/m.
Other Improvements#
The
magnetizationparameter is now codependent with the newpolarizationparameter that is the physical magnetic polarization (#712) in units of TeslaAdded
getM(magnetization) andgetJ(polarization) top level functions and class methods reminiscent ofgetBandgetH.The
in_out(inside/outside) parameter is added to all field functions (getBHJM) to specify the location of the observers relative to the magnet body in order to increase performance (#717, #608)Review of documentation and adding a few requested things (#685, some of #659)
Added mu0 at top level as
magpylib.mu_0. The value of mu0 is taken from scipy and follows the 2019 redefinition. All internal computations now include this new value. (#714, #731)The core level now includes only the true bottom level implementations. (#727)
As Matplotlib graphic representation of 3D objects is terrible, we decided to go back to “arrow” graphic default mode when graphic backend is “Matplotlib”.(#735)
4.5.1 - 2023-12-28#
Fixed a field computation issue where H-field resulting from axial magnetization is computed incorrectly inside of Cylinders (#703)
4.5.0 - 2023-12-13#
4.4.1 - 2023-11-09#
4.4.0 - 2023-09-03#
Included self-intersection check in
TriangularMesh(#622)Fixed incorrect edge case of TriangularMesh reorientation (#644)
Discontinuous segments in
current.Lineare now accepted and correctly treated as separate lines (#632, #642)Objects can now be displayed with missing dimension and/or excitation (#640)
Added magnetization and current arrows
sizemodestyling option (absolute or scaled) (#639)Collectionobjects now also have a default description when displayed (number of children) (#634)legendstyle option (#650)Changed unit naming in text to comply with DIN Norm 641 (#614)
Improved documentation now boasting a contribution guide, a news-blog, an example and tutorial gallery, a getting started section and many other improvements (#621, #596, #580)
Improved numerical stability of
CylinderSegment, (#648, #651)
4.3.0 - 2023-06-25#
New
TriangularMeshmagnet class added to conveniently work with triangular surface meshes instead of large collections of individualTriangleobjects. TheTriangularMeshclass performs important checks (closed, connected, oriented) and can directly import Pyvista objects and for convex hull bodies. (#569, #598).Added magnetization coloring for
matplotlibbackend (#597)New automatic backend behavior, set to a dynamic default
autodepending on the current environment and the givencanvas, if provided. (#617)Drop python 3.7 support, following python life cycle. (#616)
4.2.0 - 2023-01-27#
(Re)introducing the powerful
misc.Triangleclass that can be used to compute magnetic fields of arbitrarily shaped bodies by approximating their surface with triangular faces. (#568)Introducing the
magnet.Tetrahedronclass as a derivate of the Triangle class. (#289)Change Pyvista plotting defaults when using
show(backend='pyvista')to fit better with other libraries. (#551)Added code of conduct attempting to align with NumFocus standards (#558)
Improved Loop field computation in terms of performance and numerical stability (#374)
Added
magnetization.modestyle to allow showing magnetization direction for any backend (#576)Documentation changes:
Correct conda install command
Integration of Triangle and Tetrahedron
Changed example gallery substructure
Rewritten and added some passages
Fixed some bugs, minor performance increase, internal refactoring
4.1.2 - 2023-01-15#
4.1.1 - 2022-08-11#
Fixed inverted y and z axes colors for sensor representations (#556)
4.1.0 - 2022-08-08#
Field computation
getB/getHnow supports 2D pandas.dataframe in addition to thenumpy.ndarrayas output type. (#523)Internal
getB/getHrefactoring. The direct interface with'Line'source argument now also accepts'vertices'as argument. (#540)Complete plotting backend rework to prepare for easy implementation of new backends, with minimal maintenance. (#539)
Improvements on the documentation
4.0.4 - 2022-06-09#
4.0.3 - 2022-05-13#
Fixed copy order Bug (#530)
4.0.2 - 2022-05-04#
4.0.1 - 2022-04-29#
Graphic performance update for Plotly when showing a large number of objects. (#524)
4.0.0 - 2022-04-14#
This is a major update that includes
API changes
New features
Improved internal workings
Magpylib class changes/fixes:#
Boxclass renamed toCuboid. (#350)Circularclass renamed toLoop. (#402)New
CylinderSegmentclass with dimension(r1,r2,h,phi1,phi2)with the inner radiusr1, the outer radiusr2the heighthand the cylinder section anglesphi1 < phi2. (#386, #385, #484, #480)New
CustomSourceclass for user defined field functions (#349, #409, #411, #506)All Magpylib objects can now be initialized without excitation and dimension attributes.
All classes now have the
parentattribute to reference to a collection they are part of. Any object can only have a single parent.All classes have the
describemethod which gives a quick object property overview.
Field computation changes/fixes:#
New computation core. Added top level subpackage
magpylib.corewhere all field implementations can be accessed directly without the position/orientation interface. (#376)Direct interface functions
getBdictandgetHdict(previouslygetBvandgetHv) are now integrated intogetBandgetH. See docs for details (#449)Generally improved field expressions: (#374)
Negative dimension input taken as absolute when only positive dimensions are allowed.
Scale invariant field evaluations.
Special cases caught within 1e-15 rtol and atol to account for numerical imprecision with positioning (e.g. object rotation).
Suppress Numpy divide/invalid warnings. return
np.nanas(0,0,0)(e.g. on magnet edges or on line currents) and allow return ofnp.inf.New closed form implementation for
Cylinderwith diametral magnetization is much faster (100-1000x) and numerically stable for smallr. (#404, #370)Improved numerical stability of current loop field. Now 12-14 correct digits everywhere. (#374)
Fixed
CollectionofLinesfield computation error. (#368)
Object oriented interface fixes and modifications:
With the new kwarg
pixel_aggit is now possible to apply a Numpy function with reducing functionality (likemean,min,average) to the pixel output. In this case, it is allowed to providegetBandgetHwith different observer input shapes. (#503)
Major graphic output overhaul:#
Styles:
displaynow calledshow, to be more in-line with standard graphic backends. Functionality completely overhauled to function with styles. (#453, #451)New
showarguments replace previous ones. Some are now handed over through styles.axis➡️canvasshow_direction➡️style_magnetization_showshow_path➡️style_path_show(#453)size_sensors&size_dipoles➡️style_sizesize_direction➡️style_magnetization_sizenew
zoomoption
Misc:
New documentation:#
Geometry interface modification#
Added all Scipy Rotation forms as rotation object methods. (#427)
moveandrotateinputs differentiate between scalar and vector input. Scalar input is applied to the whole path vector input is merged. (#438, #444, #442)moveandrotatemethods have defaultstart='auto'(scalar input:start=0-> applied to whole path, vector input:start=len_path-> append) instead ofstart=-1.moveandrotatemethods maintain collection geometry when applied to a collection.Improved
positionandorientationsetter methods in line withmoveandrotatefunctionality and maintainCollectiongeometry.Removed
incrementargument frommoveandrotatefunctions (#438, #444)
Modifications to the Collection class#
Collections can now contain
Source,Sensorand otherCollectionobjects and can function as source and observer inputs ingetBandgetH. (#502, #410, #415, #297)Instead of the property
Collection.sourcesthere are now theCollection.children,Collection.sources,Collection.sensorsandCollection.collectionsproperties. Setting these collection properties will automatically override parents. (#446, #502)Collectionhas it’s ownposition,orientationandstyle. (#444, #461)All methods applied to a collection maintain relative child-positions in the local reference frame.
Added
__len__dunder forCollection, so thatCollection.childrenlength is returned. (#383)-operation was removed.+operation now functions asa + b = Collection(a, b). Warning:a + b + cnow creates a nested collection !Allowed
Collection,addandremoveinput is now only*argsor a single flat list or tuple of Magpylib objects.addandremovehave some additional functionality related to child-parent relations.The
describemethod gives a great Collection tree overview.
Other changes/fixes:#
Magpylib error message improvement. Msg will now tell you what input is expected.
Magpylib object
copymethod now works properly (#477, #470, #476)Defaults and input checks (#406)
magpylib.Configparameters are now inmagpylib.defaults. (#387)config.ITERCYLINDERis now obsolete. The iterative solution replaced by a new analytical expression.config.inputchecksis removed - input checks are always performed.
3.0.5 - 2022-04-26#
fix docs build
3.0.4 - 2022-02-17#
fix
Collectionoperation tests
3.0.3 - 2022-02-17#
Fixed#
When adding with
Source + Collectionto create a newCollection, the original now remains unaffected (#472)
3.0.2 - 2021-06-27#
3.0.1 - 2021-06-27#
3.0.0 - 2021-06-27#
This is a major update that includes
API changes
New features
Improved internal workings
Added#
New
orientationproperty:The
orientationattribute stores the relative rotation of an object with respect to the reference orientation (defined in each class docstring).The default (
orientation=None) corresponds to a unit rotation.orientationis stored as ascipy.spatial.transform.Rotationobject.Calling the attribute
source.orientationreturns a Scipy Rotation objectR.Make use of all advantages of this great Scipy package:
define
R.from_rotvec()orR.from_quat()or …view with
R.as_rotvec()orR.as_quat()or …combine subsequent rotations
R1 * R2 * R3
Sensor pixel:
The new
Sensor(position, pixel, orientation)class has the argumentpixelwhich is(0,0,0)by default and refers to pixel positions inside the Sensor (in the Sensor local CS).pixelis an arbitrary array_like of the shape (N1, N2, …, 3).
Geometry paths:
The
positionandorientationattributes can now store paths in the global CS. For a path of length M the attributepositionis an array of the shape (M,3) andorientationis a Rotation object with length M. Each path position is associated with a respective rotation.Field computations
getB()andgetH()will evaluate the field for all source path positions.Paths can be set by hand
position = X,orientation = Y, but they can also conveniently be generated using therotateandmovemethods.Paths can be shown via the
show_path=Truekwarg indisplay(). By settingshow_path=xthe object will be displayed at everyx’th path step. This helps to follow up on object rotation along the path.All objects have a
reset_path()method defined to set their paths toposition=(0,0,0)andorientation=None.
Streamlining operation with all Magpylib objects:
All objects (Sensors, Sources, Collections) have additional direct access to
.display()method for quick self-inspection.getB()andgetH()methods for fast field computations__repr__attribute defined and will return their type and theirid.
Other new features:
The top-level
Configallows users to access and edit Magpylib default values.
Changed#
Renamed modules:
.magnetand.currentsub-packages were moved to the top level.The
.momentsub-package was renamed to.miscand was moved to the top level.The
.vectorsub-package was completely removed. Functionalities are mostly replaced by new top-level functiongetBv().The
.mathsub-package was removed. Functionalities are mostly provided by thescipy - Rotationpackage.
Renamed functions:
The top level function
displaySystem()was renamed todisplay().
Renamed attributes (parameters cannot be initialized in their short forms anymore):
angleandaxisare replaced byorientationdimensionis replaced bydiameterfor Loop and Sphere classes.angle&axisare replaced byorientation.
Modified rotate methods:
The class methods
.rotate(angle, axis, anchor)have been replaced by a new.rotate(rotation, anchor, increment, start)method whererotationist a scipyRotationobject.The original angle-axis-anchor rotation is now provided by the new method
.rotate_from_angax(angle, axis, anchor, increment, start, degrees).The argument
axiscan now easily be set to the global CS axes with"x","y","z".The anchor argument
anchor=0represents the origin(0,0,0).angleargument is in units of deg by default. It can now be set to rad using thedegreesargument.
The “move”-class method is now
.move(displacement, increment, start)Rotation and move methods can now be used to generate paths using vector input and the
incrementandstartarguments.All operations can now be chained (e.g.
.move_by().rotate().move_to())
Miscellaneous:
getB(pos)now takes single AND vector position arguments. If a vector is handed to getB it will automatically execute vectorized code from the vector module.In a finite region (size defined by
Config.EDGESIZE) about magnet edges and line currents the field evaluates to(0,0,0)instead of(NaN, NaN, NaN). Special case catching reduces performance slightly.
Updated#
Improved Computation:
The Box field is now more stable. Numerical instabilities in the outfield were completely removed.
Updated Field computation interface
There are two fundamental arguments for field computation:
The argument
sourcesrefers to a source/Collection or to a 1D list of L sources and/or Collections.The argument
observersrefers to a set of positions of shape (N1, N2, …, 3) or a Sensor withpixelshape (N1, N2, …, 3) or a 1D list of K Sensors.
With Magpylib3 there are several ways to compute the field:
source.getB(*observers)sensor.getB(*sources)magpylib.getB(sources, observers)
The output shape is always (L, M, K, N1, N2, …, 3) with L sources, M path positions, K sensors and N (pixel) positions.
Objects with shorter paths will be considered as static once their path ends while other paths continue.
magpylib.getBv(**kwargs)gives direct access to the field formulas and mostly replaces thegetBv_XXX()functionality of v2. All inputs must be arrays of length N or of length 1 (statics will be tiled).
While
getBvis the fastest way to compute the fields it is much more convenient to usegetB()which mostly provides the same performance. Specifically,the newgetB()automatically groups all inputs for combined vectorized evaluation. This leads to a massive speedup when dealing with large Collections of similar sources.In addition to
getB, the newgetHreturns the field in kA/m.
Removed#
the kwarg
niter=50does not exist anymore for the Cylinder field computation. The functionality was completely replaced by the config settingConfig.ITER_CYLINDER=50.
2.3.0b - 2020-01-17#
Changed#
Improved performance of
getBfor diametral magnetized Cylinders by 20%.getBof Line current now uses vectorized code which leads to massive performance enhancement.IMPORTANT: position arguments of
getBvfunctions have been flipped! First comes the source position POSm THEN the observer position POSo!
Added#
completed the library vector functionality adding magnet Cylinder, moment Dipole, current Loop and Line. This includes adding several private vectorized functions (e.g. ellipticV) to mathLib_vector, adding respective tests and docs examples.
2.1.0b - 2019-12-06#
Added#
Docstrings for vector functions.
displaySystemkwargfigsizebringing documentation up to speed
Fixed#
init file bug
2.0.0b - 2019-11-29#
This is a major update that includes
API changes New features Improved internal workings
Changed#
Restructuring
displaySystem is now a top-level function, not a Collection method anymore.
getBsweep and multiprocessing options have been completely removed, this functionality should be overtaken by the new vector functionality which uses the numpy native vectorized code paradigm. If mkl library is set (test by numpy.show_config()) numpy will also automatically use multiprocessing. Code parallelization at magpylib level should be done by hand.
Docstrings are adjusted to work better with intellisense. (Problems with *.rst code)
public rotatePosition() is now called angleAxisRotation(), former private angleAxisRotation is now called angleAxisRotation_priv().
Major rework of the documentation and examples.
Added#
Performance computation trough vector functionality included in new top-level subpackage “vector”
Vectorized versions of math functions added to “math” subpackage
1.2.1b0 - 2019-07-31#
Changed#
Optimized
getBcall (utility integrated)Improved Documentation (added Sensor class v1)
1.2.0b0 - 2019-07-16#
Added#
Sensor Class
This allows users to create a coordinate system-enabled Sensor object, which can be placed, rotated, moved, and oriented.
This object can take the B-Field of a system (be it single source or a Collection) with the added functionality of having its own reference in the coordinate space, allowing users to easily acquire relative B-Field measurements of a system from an arbitrarily placed sensor object.
Sensors in a list may be displayed in the
Collection.displaySystem()by using thesensorskeyword argument.
Added content to the
__repr__built-in to all source classes for quick console evaluations, simply call a defined object in your Python shell to print out its attributes.
Changed#
Edge cases in field calculations now return a proper RuntimeWarning instead of console prints
Fixed#
Unused imports and variables
1.1.1b0 - 2019-06-25#
Added#
Changelog
Changed#
Change
Collection.displaySystem()not having theblock=Falsesetting for matplotlib’spyplot.show()by default, this meant that outside interactive mode calling this function would hang the script until the plot was closed.If for some reason you want to block the application, you may still use
Collection.displaySystem()’ssuppress=Truekwarg then call pyplot.show() normally.This should cause no API changes, if you have problems please notify us.
Fixed#
Fixed multiprocessing enabled
Collection.getBsweep()for lots of objects with few positions causing great performance loss. This functionality now behaves as expected for the use case.Fixed
Collection.displaySystem()’s drawing of Dipole objects in external axes (plots) using thesubplotAxkwarg crashing the application. This functionality now behaves as expected for the use case.
1.1.0b0 - 2019-06-14#
Added#
Implemented one new kwarg for
Collection.displaySystem():subplotAx=NoneDraw into a subplot axe that already exists. The subplot needs to be 3D projectedThis allows for creating side-by-side plots using
displaySystem. Figure information must be set manually in pyplot.figure() in order to not squash the plots upon sub plotting.Click here for Example
Code: https://gist.github.com/lucasgcb/77d55f2fda688e2fb8e1e4a68bb830b8
Output:

Changed#
getBsweep()for Collections and Sources now always returns a Numpy arrayZero-length segments in Line sources now return
[0,0,0]and a warning, making it easier to draw spirals without letting users do this unaware.
Fixed#
Added a workaround fix for a rotation bug we are still working on.
1.0.2b0 - 2019-05-29#
Added#
MANIFEST.infile containing the LICENSE for bundling in PyPI
1.0.1b0 - 2019-05-28#
Added#
Issue and Pull Request Templates to Repository
Continuous Integration settings (Azure and Appveyor)
Code Coverage Reports with Codecov
Removed#
Support for Python 3.5 and under.
1.0.0b0 - 2019-05-21#
The first official release of the Magpylib library.
Added#
Source classes:
Box
Cylinder
Sphere
Loop Current
Current Line
Dipole
Collection class
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.