Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for unset dimension or unset excitation when displaying objects. #640

Merged
merged 77 commits into from Aug 4, 2023

Conversation

Alexboiboi
Copy link
Member

@Alexboiboi Alexboiboi commented Jul 29, 2023

Related Issues

Notes

This PR allows to display objects that have no set dimension or vertices, or no set excitation.
Note that the TriangularMesh class cannot be initialized without setting vertices and faces, yet (see #641).

Examples

import magpylib as magpy

# test show if mag, curr or mom are not set

objs = [
    magpy.magnet.Cuboid(dimension=(1, 1, 1)),
    magpy.magnet.Cylinder(dimension=(1, 1)),
    magpy.magnet.CylinderSegment(dimension=(0, 1, 1, 45, 120)),
    magpy.magnet.Tetrahedron(vertices=[(0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1)]),
    magpy.magnet.TriangularMesh(
        vertices=((0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1)),
        faces=((0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)),
    ),
    magpy.magnet.Sphere(diameter=1),
    magpy.misc.Triangle(vertices=[(0, 0, 0), (1, 0, 0), (0, 1, 0)]),
    magpy.misc.Dipole(),
    magpy.current.Line(vertices=[[0, -1, 0], [0, 1, 0]]),
    magpy.current.Loop(diameter=1, current=0),
]
for i, o in enumerate(objs):
    o.move((i * 1.5, 0, 0))
magpy.show(*objs, style_magnetization_mode="color+arrow", layout_height=600)


# test completely unset objects
objs = [
    magpy.magnet.Cuboid(),
    magpy.magnet.Cylinder(),
    magpy.magnet.CylinderSegment(),
    magpy.magnet.Sphere(),
    magpy.magnet.Tetrahedron(),
    # magpy.magnet.TriangularMesh(), not possible yet
    magpy.misc.Triangle(),
    magpy.misc.Dipole(),
    magpy.current.Line(),
    magpy.current.Loop(),
]

for i, o in enumerate(objs):
    o.move((1.5 * i, 0, 0))
magpy.show(*objs, layout_height=600)
image image

@Alexboiboi Alexboiboi self-assigned this Jul 29, 2023
@Alexboiboi Alexboiboi added this to the 4.4 milestone Jul 29, 2023
@codecov
Copy link

codecov bot commented Jul 29, 2023

Codecov Report

Merging #640 (1225ab1) into main (1ba3897) will increase coverage by 0.22%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #640      +/-   ##
==========================================
+ Coverage   98.97%   99.20%   +0.22%     
==========================================
  Files          55       55              
  Lines        6960     7000      +40     
==========================================
+ Hits         6889     6944      +55     
+ Misses         71       56      -15     
Files Changed Coverage Δ
magpylib/_src/defaults/defaults_values.py 100.00% <ø> (ø)
magpylib/_src/display/backend_matplotlib.py 100.00% <100.00%> (ø)
magpylib/_src/display/backend_pyvista.py 81.54% <100.00%> (+0.11%) ⬆️
magpylib/_src/display/display.py 100.00% <100.00%> (ø)
magpylib/_src/display/traces_core.py 100.00% <100.00%> (+3.28%) ⬆️
magpylib/_src/display/traces_generic.py 100.00% <100.00%> (ø)
magpylib/_src/display/traces_utility.py 99.27% <100.00%> (+1.03%) ⬆️
magpylib/_src/fields/field_wrap_BH.py 100.00% <100.00%> (ø)
magpylib/_src/input_checks.py 100.00% <100.00%> (ø)
magpylib/_src/obj_classes/class_BaseGeo.py 100.00% <100.00%> (ø)
... and 5 more

@Alexboiboi Alexboiboi mentioned this pull request Jul 31, 2023
7 tasks
Boisselet Alexandre (IFAT DC ATV SC D TE2) added 2 commits July 31, 2023 10:53
@OrtnerMichael
Copy link
Member

When objects have been initialized without dimension plotly displays them nicely. Pyvista is hardly visible (also all dots seem to have the same color) and matpltlotlib not at all.

@Alexboiboi
Copy link
Member Author

@OrtnerMichael

Should work now, thanks for reviewing. It took a bit more work in the end. I also refactored some dimension and excitations checks since it is part of the topic

import magpylib as magpy

for backend in magpy.SUPPORTED_PLOTTING_BACKENDS:
    c=magpy.magnet.Cuboid().move([(1.5 * i, j, 0) for j in range(10)], start=0)
    magpy.show(*objs, layout_height=600, zoom=1, backend=backend)

image
image
image

magpylib/_src/display/traces_core.py Dismissed Show dismissed Hide dismissed
Copy link
Member

@OrtnerMichael OrtnerMichael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good :)

@OrtnerMichael OrtnerMichael merged commit 5fd6d25 into main Aug 4, 2023
12 checks passed
@OrtnerMichael OrtnerMichael deleted the show-unset branch August 4, 2023 12:40
@Alexboiboi
Copy link
Member Author

fyi, pyvista does not support different symbols, hence the square instead of circle like in mpl or plotly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Objects with unset dimension or unset excitation should be displayable
2 participants