Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58dce50

Browse files
committed
Merge branch 'main' of https://github.com/magpylib/magpylib into force_integration
2 parents b282888 + 3a77b84 commit 58dce50

35 files changed

+1898
-719
lines changed

.binder/apt.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

.binder/labconfig/default_setting_overrides.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

.binder/postBuild

Lines changed: 0 additions & 6 deletions
This file was deleted.

.binder/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ Thumbs.db
158158
*~
159159
*.swp
160160
__temp*.py
161+
__temp*.ipynb
161162

162163
# uv
163164
uv.lock

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ repos:
4040
- id: prettier
4141
types_or: [yaml, markdown, html, css, scss, javascript, json]
4242
args: [--prose-wrap=always]
43-
exclude: ^docs/ # messes up colon fences for grids in docs
43+
# Exclude docs (messes up colon fences for grids)
44+
# Excclude test YAML files from formatting (messes up fig data diffs)
45+
exclude: ^docs/|^tests/.*\.ya?ml$
4446

4547
- repo: https://github.com/astral-sh/ruff-pre-commit
4648
rev: "v0.13.0"

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
([#887](https://github.com/magpylib/magpylib/issues/887),
1111
[#847](https://github.com/magpylib/magpylib/issues/847),
1212
[#787](https://github.com/magpylib/magpylib/issues/787))
13+
- Adding magnet modelling tutorial ([#813](https://github.com/magpylib/magpylib/issues/813),)
14+
- Added new `style.pixel.field` parameters to quickly represent vector fields
15+
([#793](https://github.com/magpylib/magpylib/pull/793))
1316
- Added the `current_sheet_Hfield` core computation function, and the classes
1417
`TriangleStrip` and `TriangleSheet` enabling current sheets in the object
1518
oriented interface. ([#788](https://github.com/magpylib/magpylib/issues/788))

docs/_pages/user_guide/docs/docs_styles.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,100 @@ magpy.show(args, **kwargs, backend="plotly")
568568
```{code-cell} ipython3
569569
570570
```
571+
572+
(styles-pixel-vectorfield)=
573+
574+
## Pixel Field
575+
576+
:::{versionadded} 5.2
577+
Pixel Vector Field
578+
:::
579+
580+
The `pixel` of a `Sensor` object can be visualized as arrows representing the values of the vector fields B, H, J, or M. This allows for quick and intuitive inspection of the field distributions.
581+
582+
### Parameters (`style.pixel.field`)
583+
584+
- **`source`** *(default=`None`)*:
585+
Defines the field source of the vector field representation.
586+
- `None`: No field representation is shown
587+
- `"B"`, `"Hxy"`, `"Jxyz"`, etc.: Colors are mapped to the magnitude of the specified field.
588+
589+
- **`symbol`** *(default=`"cone"`)*:
590+
Specifies the rendering symbol for field values.
591+
- `"none"`: `pixel.symbol` representation takes precedence of `pixel.field.symbol`.
592+
- `"cone"`: 3D cone representation.
593+
- `"arrow3d"`: 3D arrow representation.
594+
- `"arrow"`: 2D line-based arrow.
595+
596+
- **`shownull`** *(default=`True`)*:
597+
Toggles the visibility of pixel with zero and invalid field vectors.
598+
- `True`: Null vectors are displayed.
599+
- `False`: Null vectors are hidden.
600+
601+
- **`sizescaling`** *(default=`"uniform"`)*:
602+
Determines how arrow size relates to the `source` magnitude.
603+
- `"uniform"`: Uniform arrow size.
604+
- `"linear"`: Size proportional to magnitude.
605+
- `"log"`: Size proportional to the normalized logarithm of the magnitude.
606+
- `"log^n"`: Size proportional to the normalized nth (2 to 9) logarithm of the magnitude.
607+
608+
- **`sizemin`** *(default=`0.1`)*
609+
Minimum relative size of field symbols. A float between 0 and 1.
610+
When displaying field vectors this controls how small the symbols
611+
can become relative to their maximum size. A value of 0 allows symbols to shrink to zero size,
612+
while 0.5 ensures symbols are at least 50% of their maximum size.
613+
614+
- **`colorscaling`** *(default=`"uniform"`)*:
615+
Determines how arrow color relates to the `source` magnitude.
616+
- `"uniform"`: Uniform color for all arrows.
617+
- `"linear"`: Color scaling proportional to magnitude.
618+
- `"log"`: Color scaling proportional to the normalized logarithm of the magnitude.
619+
- `"log^n"`: Color scaling proportional to the normalized nth (2 to 9) logarithm of the magnitude.
620+
621+
- **`colormap`** *(default=`"Viridis"`)*:
622+
Specifies the colormap used for color mapping. Supports standard color maps (e.g., `"Viridis"`, `"Inferno"`, `"Magma"`, etc.) compatible with both Plotly and Matplotlib.
623+
624+
```{note}
625+
- Pixels with zero or invalid field values are rendered using the default representation (`point`/`box` or according to `style.pixel.symbol`).
626+
- Magnitude normalization is performed individually for each sensor along its path.
627+
- `style.pixel.size` controls also the arrow size.
628+
```
629+
630+
### Pixel Field Minimal Example
631+
632+
The following example demonstrates how to visualize the `Sensor` pixel array as a vector field using the `style.pixel.field` settings.
633+
634+
```{code-cell} ipython3
635+
:tags: [hide-input]
636+
637+
import numpy as np
638+
import magpylib as magpy
639+
640+
# Define a cuboid magnet
641+
cube = magpy.magnet.Cuboid(
642+
polarization=(0, 0, 1),
643+
dimension=(1, 1, 1),
644+
)
645+
646+
# Create a 2D grid of pixel positions in the xy-plane
647+
xy_grid = np.mgrid[-2:2:15j, -2:2:15j, 0:0:1j].T[0]
648+
649+
# Define pixel field style
650+
pixel_style = {
651+
"source" : "B",
652+
"symbol" : "arrow3d",
653+
"sizemode" : "uniform",
654+
"shownull" : True,
655+
"colormap" : "Magma"
656+
}
657+
658+
# Create sensor with pixel array and applied style
659+
sens = magpy.Sensor(
660+
pixel=xy_grid,
661+
position=(0,0,2),
662+
style_pixel_field=pixel_style,
663+
)
664+
665+
# Display the sensor and magnet using the Plotly backend
666+
magpy.show([sens, cube], backend='plotly')
667+
```

docs/_pages/user_guide/examples/examples_index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@
9494
:img-bottom: ../../../_static/images/examples_icon_vis_pv_streamlines.png
9595
:::
9696

97+
:::{grid-item-card} {ref}`examples-vis-vectorfield`
98+
:text-align: center
99+
:link: examples-vis-vectorfield
100+
:link-type: ref
101+
:link-alt: link to example
102+
:img-bottom: ../../../_static/images/examples_icon_vis_vectorfield.png
103+
:::
104+
97105

98106

99107
::::
@@ -304,6 +312,7 @@ examples_vis_animations.md
304312
examples_vis_subplots.md
305313
examples_vis_mpl_streamplot.md
306314
examples_vis_pv_streamlines.md
315+
examples_vis_vectorfield.md
307316
308317
examples_shapes_superpos.md
309318
examples_shapes_convex_hull.md

0 commit comments

Comments
 (0)