### Create Magnets and Sensors Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Instantiate magnetic sources like Cuboid magnets and observers like Sensors using their respective classes. Ensure inputs are in SI units. ```python import magpylib as magpy # Create a Cuboid magnet with magnetic polarization # of 1 T pointing in x-direction and sides of # 1, 2 and 3 cm respectively (notice the use of SI units). cube = magpy.magnet.Cuboid(polarization=(1, 0, 0), dimension=(0.01, 0.02, 0.03)) # Create a Sensor for measuring the field sensor = magpy.Sensor() ``` -------------------------------- ### Visualize Magnetic System Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Use the show() function to render a 3D visualization of your magnetic system, supporting backends like Plotly. ```python # Use the show() function to view your system # through Matplotlib, Plotly or Pyvista backends. magpy.show(cube, sensor, backend="plotly") ``` -------------------------------- ### Displaying Sensors in Collection System Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html Demonstrates how to include sensors in the visualization of a magnetic system. Use the `sensors` keyword argument within the `displaySystem` method of a Collection object. ```python Collection.displaySystem(sensors=...) ``` -------------------------------- ### Compute Magnetic Field using magpylib.getB Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html Demonstrates the primary method for computing magnetic fields. It supports various input types for sources and observers, including single sources, collections, sensors, and lists of positions. The output shape is standardized for consistent analysis. ```python source.getB(*observers) sensor.getB(*sources) magpylib.getB(sources, observers) ``` -------------------------------- ### Sensor Class Initialization and Usage Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html Introduces the Sensor class for creating coordinate system-aware sensor objects. These objects can be positioned, rotated, and moved, allowing for relative B-Field measurements from arbitrary locations. ```python Sensor ``` -------------------------------- ### Direct Field Computation with magpylib.getBv Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html Provides direct access to field computation formulas, largely replacing older `getBv_XXX` functions. All input arrays must have a consistent length N or length 1, as constants are automatically tiled. This method is optimized for speed. ```python magpylib.getBv(**kwargs) ``` -------------------------------- ### Create a Pyramid Magnet from Convex Hull Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Generate a magnet with a complex shape, such as a pyramid, by defining a set of points and using the `from_ConvexHull` method. This creates a triangular surface mesh. ```python import numpy as np import magpylib as magpy # Create a Pyramid magnet points = np.array( [ (-1, -1, 0), (-1, 1, 0), (1, -1, 0), (1, 1, 0), (0, 0, 2), ] ) pyramid = magpy.magnet.TriangularMesh.from_ConvexHull( magnetization=(0, 0, 1e6), points=points, ) # Display the magnet graphically pyramid.show() ``` -------------------------------- ### Vectorized Field Computation with magpylib.getBv (Argument Order) Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html Note the flipped argument order for position arguments in `getBv` functions in Magpylib 2.3.0b. The source position `POSm` now precedes the observer position `POSo`. ```python # IMPORTANT: position arguments of getBv functions have been flipped! # First comes the source position POSm THEN the observer position POSo! ``` -------------------------------- ### Displaying System with Specified Figure Size Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html Allows customization of the figure size when displaying a magnetic system. Use the `figsize` keyword argument with the `displaySystem` function. ```python displaySystem(figsize=...) ``` -------------------------------- ### Object Representation for Console Evaluation Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html All source classes now have a `__repr__` built-in, enabling quick console evaluations. Simply call a defined object in your Python shell to print its attributes. ```python __repr__ ``` -------------------------------- ### Top-level displaySystem Function Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html The `displaySystem` function is now a top-level function, no longer a method of the Collection class. This change simplifies its usage and integration into workflows. ```python displaySystem ``` -------------------------------- ### Create and Manipulate a Collection of Magnets Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Group multiple Magpylib objects into a Collection. Operations applied to the collection are applied to all its members, allowing for collective transformations. ```python import magpylib as magpy # Create objects obj1 = magpy.Sensor() obj2 = magpy.magnet.Cuboid(polarization=(0, 0, 1), dimension=(0.01, 0.02, 0.03)) # Group objects coll = magpy.Collection(obj1, obj2) # Manipulate Collection coll.move((0.001, 0.002, 0.003)) print(obj1.position) # -> [0.001 0.002 0.003] print(obj2.position) # -> [0.001 0.002 0.003] ``` -------------------------------- ### Customize Graphic Styles for Magnets Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Apply custom visual styles to Magpylib magnet objects, such as color and magnetization representation. This allows for detailed control over the graphical output. ```python import magpylib as magpy # Create Cuboid magnet with custom style cube = magpy.magnet.Cuboid( polarization=(0, 0, 1), dimension=(0.01, 0.01, 0.01), style_color="r", style_magnetization_mode="arrow", ) # Create Cylinder magnet with custom style cyl = magpy.magnet.Cylinder( polarization=(0, 0, 1), dimension=(0.01, 0.01), position=(0.02, 0, 0), style_magnetization_color_mode="bicolor", style_magnetization_color_north="m", style_magnetization_color_south="c", ) magpy.show(cube, cyl) ``` -------------------------------- ### Magpylib Package Functions Source: https://magpylib.readthedocs.io/en/stable/_pages/API_reference.html This section lists the top-level functions available in the magpylib package. ```APIDOC ## magpylib package functions This section lists the top-level functions available in the magpylib package. ### `getB()` Calculates the magnetic field. ### `getFT()` Calculates the magnetic field. ### `getH()` Calculates the magnetic field. ### `getJ()` Calculates the magnetic field. ### `getM()` Calculates the magnetic field. ### `show()` Displays the current magnetic field visualization. ### `show_context()` Displays the context of the magnetic field calculation. ``` -------------------------------- ### Compute Magnetic Field Using Functional Interface Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Calculate magnetic fields efficiently using Magpylib's functional interface. This bypasses object initialization overhead, enabling faster computations for multiple parameters. ```python from magpylib.func import cuboid_field # Compute the magnetic field via the functional interface. B = cuboid_field( field="B", observers=[(-1, 0, 1), (0, 0, 2), (2, 0, 2)], dimensions=[(1, 1, 1), (2, 2, 2), (3, 3, 3)], polarizations=(0, 0, 1), ) print(B.round(3)) ``` -------------------------------- ### Vectorized Math Functions Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html New vectorized versions of mathematical functions have been added to the 'math' subpackage, supporting the library's move towards NumPy-native vectorized code for performance improvements. ```python math ``` -------------------------------- ### Magpylib Package Classes Source: https://magpylib.readthedocs.io/en/stable/_pages/API_reference.html This section lists the main classes available in the magpylib package. ```APIDOC ## magpylib package classes This section lists the main classes available in the magpylib package. ### `Collection` A class to manage a collection of magnetic sources. ### `Sensor` A class representing a magnetic field sensor. ``` -------------------------------- ### Animate Magnet Path Rotation Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Generate an animation of a magnet's movement or rotation along a defined path. The `plotly` backend is recommended for smooth animations. The `animation=True` flag enables this feature. ```python import numpy as np import magpylib as magpy # Create magnet with path cube = magpy.magnet.Cuboid( magnetization=(0, 0, 1), dimension=(1, 1, 1), ) cube.rotate_from_angax(angle=np.linspace(10, 360, 18), axis="x") # Generate an animation with `show()` cube.show(animation=True, backend="plotly") ``` -------------------------------- ### Compute Force and Torque (F, T) Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Calculate the force and torque between magnetic objects using the getFT() function. Ensure target objects have a defined 'meshing' parameter for numerical accuracy. ```python import magpylib as magpy cube = magpy.magnet.Cuboid(dimension=(1, 1, 1), polarization=(0.1, 0.2, 0.3)) loop = magpy.current.Circle( diameter=2, current=1e3, position=(0, 0, 1), meshing=40, ) F, T = magpy.getFT(cube, loop) print(f"force: {F.round(2)} N") # force: [ 13.67 27.33 -82. ] N print(f"torque: {T.round(2)} N*m") # torque: [-8.54 4.27 0. ] N*m ``` -------------------------------- ### Compute Magnetic Field Intensity (H) with magpylib.getH Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html Returns the magnetic field intensity in kA/m. This function complements `getB()` and is part of the new vectorized evaluation capabilities for improved performance with large datasets. ```python magpylib.getH() ``` -------------------------------- ### Rotation using angleAxisRotation Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html The public function for rotating positions around an arbitrary axis is now named `angleAxisRotation`. The former private `angleAxisRotation` has been renamed to `angleAxisRotation_priv`. ```python angleAxisRotation ``` -------------------------------- ### Compute Magnetic Field Along a Path Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Calculate the magnetic field at a specific observer position for a magnet whose position is defined by a path. The field is computed for each point along the path. ```python sphere.position = np.linspace((-0.02, 0, 0), (0.02, 0, 0), 7) # The field is automatically computed for every path position B = sphere.getB((0, 0, 0.01)) print(B.round(3)) ``` -------------------------------- ### Cylinder Field Computation Configuration Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html Configuration setting for the number of iterations in Cylinder field computation. This replaces the previous `niter` keyword argument in the Cylinder field computation. ```python Config.ITER_CYLINDER=50 ``` -------------------------------- ### Compute Magnetic Field (B, H, J, M) Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Calculate magnetic fields (B, H, J, M) at specified points or sensor objects. Magpylib utilizes vectorized computation for performance; avoid Python loops. ```python # Compute the B-field for some positions. points = [(0, 0, -0.01), (0, 0, 0), (0, 0, 0.01)] # in SI Units (m) B = magpy.getB(cube, points) print(B.round(2)) # [[ 0.26 0.07 0.08] # [ 0.28 0.05 0. ] # [ 0.26 0.07 -0.08]] # in SI Units (T) # Compute the H-field at the sensor. H = magpy.getH(cube, sensor) print(H.round()) # -> [51017. 24210. 0.] # in SI Units (A/m) ``` -------------------------------- ### Manipulate Object Position and Orientation Source: https://magpylib.readthedocs.io/en/stable/_pages/user_guide/guide_start_02_fundamentals.html Set and modify the position and orientation attributes of Magpylib objects. Use move() and rotate_from_angax() for relative transformations. ```python # By default, the position of a Magpylib object is # (0, 0, 0) and its orientation is the unit rotation, # given by a scipy rotation object. print(cube.position) # -> [0. 0. 0.] print(cube.orientation.as_rotvec()) # -> [0. 0. 0.] # Manipulate object position and orientation by # setting the respective attributes (10 mm in x # direction and rotate about z by 45 deg): from scipy.spatial.transform import Rotation as R cube.position = (0.01, 0, 0) cube.orientation = R.from_rotvec((0, 0, 45), degrees=True) print(cube.position) # -> [0.01 0. 0. ] print(cube.orientation.as_rotvec(degrees=True)) # -> [0. 0. 45.] # Apply relative motion with the powerful move() # and rotate() methods. sensor.move((-0.01, 0, 0)) sensor.rotate_from_angax(angle=-45, axis="z") print(sensor.position) # -> [-0.01 0. 0. ] print(sensor.orientation.as_rotvec(degrees=True)) # -> [ 0. 0. -45.] ``` -------------------------------- ### Draw into existing subplot axes with Collection.displaySystem Source: https://magpylib.readthedocs.io/en/stable/_pages/changelog_.html Use the `subplotAx` keyword argument to draw magnetic field visualizations into a pre-existing, 3D-projected Matplotlib subplot. Ensure figure properties are manually set in `pyplot.figure()` to prevent plot distortion when using subplots. ```python Collection.displaySystem(subplotAx=None) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.