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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
249 commits
Select commit Hold shift + click to select a range
d0d3467
draft
Alexboiboi Mar 21, 2022
c872219
remove duplicates on src sens getters
Alexboiboi Mar 22, 2022
65d4f45
add nested coll support for mpl
Alexboiboi Mar 22, 2022
293f953
support nested collection for plotly
Alexboiboi Mar 22, 2022
3797dd9
add setters
Alexboiboi Mar 22, 2022
ad0ef38
update set_children_styles
Alexboiboi Mar 22, 2022
2efd47b
update collection.remove to be search recursively
Alexboiboi Mar 22, 2022
bd74757
add describe method
Alexboiboi Mar 22, 2022
1e20d76
adapt getBH to nested collections
Alexboiboi Mar 22, 2022
a0aba8a
remove irrelevant todos
Alexboiboi Mar 22, 2022
b259623
add TODOS
Alexboiboi Mar 22, 2022
32c2457
remove print statement
Alexboiboi Mar 22, 2022
1346ff3
add self to collection.describe()
Alexboiboi Mar 23, 2022
84dd359
add parent/child philosophy
Alexboiboi Mar 23, 2022
2909485
fix regression
Alexboiboi Mar 23, 2022
7b6915e
add override_parent to Collection
Alexboiboi Mar 23, 2022
8fb87b7
fix __add__
Alexboiboi Mar 23, 2022
fa1ab95
add collection repr, also nested
Alexboiboi Mar 23, 2022
e699379
fix remove and make private
Alexboiboi Mar 23, 2022
a6646c0
testbug fix
Alexboiboi Mar 23, 2022
6b0d953
mini syntax sugar
Alexboiboi Mar 23, 2022
9df03fc
fix nested rotation
Alexboiboi Mar 23, 2022
4f85bbb
remove unused imports
Alexboiboi Mar 23, 2022
81b7361
mini color fix
Alexboiboi Mar 23, 2022
0865e96
rework collection.describe()
Alexboiboi Mar 23, 2022
e882fc2
fix parent setter
OrtnerMichael Mar 24, 2022
ed06142
fix override
OrtnerMichael Mar 24, 2022
c8a122c
fix plus, remove minus
OrtnerMichael Mar 24, 2022
2f732ed
add describe and repr_html to all objects
Alexboiboi Mar 24, 2022
3d1a23e
add properties
Alexboiboi Mar 24, 2022
cefbfcf
prettify
Alexboiboi Mar 24, 2022
35d1e8f
fix collection setter
Alexboiboi Mar 24, 2022
08040ad
docstring
Alexboiboi Mar 24, 2022
77ac6d1
docstrings
Alexboiboi Mar 24, 2022
80b90ea
+ - behavior fixing
OrtnerMichael Mar 25, 2022
43a29c2
replace labels with desc
Alexboiboi Mar 25, 2022
d55b75b
add basic tests
Alexboiboi Mar 25, 2022
ebe3afe
include errors='raise' in remove
OrtnerMichael Mar 25, 2022
4fa9e79
only *arg object inputs for collections
OrtnerMichael Mar 25, 2022
a8f35c1
removed Collection "special" repr
OrtnerMichael Mar 25, 2022
52db636
remove allows *args
OrtnerMichael Mar 25, 2022
ed28492
draft
Alexboiboi Mar 25, 2022
13c00c6
fixing and adding tests
OrtnerMichael Mar 26, 2022
6414d5f
remove now useless radd
OrtnerMichael Mar 26, 2022
efcd8e1
fix copy parent bug
OrtnerMichael Mar 26, 2022
8e2e396
fix tests and misc
OrtnerMichael Mar 26, 2022
1277c9c
refactoring
Alexboiboi Mar 26, 2022
5fe0dcf
completing tests, full coverage
OrtnerMichael Mar 26, 2022
f69c3da
pylint
OrtnerMichael Mar 26, 2022
7b95f96
meaningful renaming
Alexboiboi Mar 26, 2022
be3fd97
collection and parent docstrings
OrtnerMichael Mar 26, 2022
8953368
use orient concat on rotated sensors
Alexboiboi Mar 26, 2022
2cad99a
docstings + long forgotten properties
OrtnerMichael Mar 26, 2022
533b7f0
Merge branch 'main' of https://github.com/magpylib/magpylib into nest…
OrtnerMichael Mar 26, 2022
ff743d7
make compatible with python 3.7
Alexboiboi Mar 26, 2022
63a3392
changelog and pull from main
OrtnerMichael Mar 26, 2022
f0c2430
Merge branch 'nested-collections-mi' of https://github.com/magpylib/m…
Alexboiboi Mar 27, 2022
a69a7e6
remove describe method
Alexboiboi Mar 27, 2022
690716d
remove unused import
Alexboiboi Mar 27, 2022
6246c63
Merge branch 'extended-repr' of https://github.com/magpylib/magpylib …
Alexboiboi Mar 27, 2022
87f8f95
coverage
Alexboiboi Mar 27, 2022
be9594d
remove print statement
Alexboiboi Mar 27, 2022
9eb8833
pylint
Alexboiboi Mar 27, 2022
ed34753
Merge branch 'nested-collections' of https://github.com/magpylib/magp…
Alexboiboi Mar 27, 2022
3901218
add pixel pretty describe
Alexboiboi Mar 27, 2022
28e73cc
Merge branch 'nested-collections' of https://github.com/magpylib/magp…
Alexboiboi Mar 27, 2022
a451183
allow different pix shapes with pixel_agg
Alexboiboi Mar 27, 2022
39a0f24
add input check
Alexboiboi Mar 28, 2022
f9c6c25
fix input checks
Alexboiboi Mar 28, 2022
2ae7603
fix orientation tiling&repeating
Alexboiboi Mar 28, 2022
14fe6f7
mini bug fix
Alexboiboi Mar 28, 2022
3082e6b
add tests
Alexboiboi Mar 28, 2022
70901b2
fix input_checks syntax test
Alexboiboi Mar 28, 2022
b824a05
fix plotly mulitidimensional pixel display
Alexboiboi Mar 28, 2022
1b39624
Merge branch 'nested-collections' of https://github.com/magpylib/magp…
Alexboiboi Mar 28, 2022
4b16c01
describe, repr, tests and changelog
OrtnerMichael Mar 28, 2022
64dacb1
Merge branch 'nested-collections' of https://github.com/magpylib/magp…
OrtnerMichael Mar 28, 2022
5bbe4f2
Merge branch 'nested-collections' of https://github.com/magpylib/magp…
Alexboiboi Mar 28, 2022
7ddba34
draft
Alexboiboi Mar 29, 2022
241a435
remove print statement
Alexboiboi Mar 30, 2022
54ffae4
collection setter override parents
OrtnerMichael Mar 30, 2022
5ee8fb2
remove print statement
Alexboiboi Mar 30, 2022
30df483
refactor getBHdict
Alexboiboi Mar 30, 2022
770dba7
remove obsolete comment
Alexboiboi Mar 30, 2022
5c023fa
pylint
Alexboiboi Mar 30, 2022
2049386
core function argument consistency
Alexboiboi Mar 30, 2022
f2aec9f
remove return self of reset()
OrtnerMichael Mar 30, 2022
1d26fde
allow collection/add/remove flat list input
OrtnerMichael Mar 30, 2022
876556d
take reset change back
OrtnerMichael Mar 30, 2022
4991cff
complete docs
OrtnerMichael Mar 30, 2022
47163b5
remove introduction from init
OrtnerMichael Mar 30, 2022
24ab34f
implement field func
Alexboiboi Mar 30, 2022
b46c06e
fix docs
Alexboiboi Mar 30, 2022
c38f452
coverage
Alexboiboi Mar 30, 2022
42c003c
coverage
Alexboiboi Mar 30, 2022
3c8594c
Merge branch 'nested-collections' of https://github.com/magpylib/magp…
Alexboiboi Mar 30, 2022
a5d3977
extend pixel_agg testing
Alexboiboi Mar 30, 2022
e857ada
Merge branch 'sensor-pixel-aggregation' of https://github.com/magpyli…
Alexboiboi Mar 30, 2022
dee53b4
fix bad tiling bug
Alexboiboi Mar 30, 2022
a134ba7
add test
Alexboiboi Mar 31, 2022
c675812
Merge branch 'main' of https://github.com/magpylib/magpylib into cust…
Alexboiboi Mar 31, 2022
57be573
fix example
Alexboiboi Mar 31, 2022
7ea73cd
Merge branch 'custom-field-func-rework' of https://github.com/magpyli…
Alexboiboi Mar 31, 2022
bc5fe3d
fix tile_group_property
Alexboiboi Mar 31, 2022
da21c56
remove print statement
Alexboiboi Mar 31, 2022
d01195f
make tiling vs superposition test more general
Alexboiboi Mar 31, 2022
99a0a35
make tiling vs superposition test more general
Alexboiboi Mar 31, 2022
38bf735
Merge branch 'getBH-pixel-tiling-bug' of https://github.com/magpylib/…
Alexboiboi Mar 31, 2022
1221107
fix current_line_field call
Alexboiboi Mar 31, 2022
f07c1dc
fix pixel_agg
Alexboiboi Mar 31, 2022
249f247
Merge branch 'main' of https://github.com/magpylib/magpylib into refa…
Alexboiboi Apr 1, 2022
ccc070c
finish merge
Alexboiboi Apr 1, 2022
801d3f5
Merge branch 'main' of https://github.com/magpylib/magpylib into refa…
Alexboiboi Apr 7, 2022
cd98829
add pandas
Alexboiboi Apr 21, 2022
70cd5ed
draft
Alexboiboi Apr 21, 2022
cc16bc6
typo
Alexboiboi Apr 21, 2022
a0259f7
pylint
Alexboiboi Apr 21, 2022
9807990
add pandas
Alexboiboi Apr 21, 2022
6b3990a
update docstrings
Alexboiboi Apr 21, 2022
eabed09
install .dev on circleci
Alexboiboi Apr 21, 2022
eacf02c
Merge branch 'getBH-dataframe' of https://github.com/magpylib/magpyli…
Alexboiboi Apr 28, 2022
a80b136
code style
Alexboiboi Apr 28, 2022
e5f9e0f
fix tests
Alexboiboi Apr 28, 2022
09432ab
docstring
Alexboiboi Apr 28, 2022
234b131
move getBHdict module into level2 getBH
Alexboiboi May 7, 2022
056de0c
refactoring
Alexboiboi May 7, 2022
689ba02
move matplotlib folder
Alexboiboi Jun 17, 2022
9344e9a
remove double input checks
Alexboiboi Jun 17, 2022
cd05dca
refactoring
Alexboiboi Jun 18, 2022
1b928c3
pyvista draft implementation
Alexboiboi Jun 18, 2022
0a0c51f
remove scalar bar
Alexboiboi Jun 18, 2022
e994abd
fix remove scalar bar
Alexboiboi Jun 18, 2022
f91249a
typo
Alexboiboi Jun 18, 2022
93d27f0
add back animation
Alexboiboi Jun 18, 2022
2d5cffe
add matplotlib auto backend
Alexboiboi Jun 18, 2022
a22c352
add colorscale caching
Alexboiboi Jun 20, 2022
7ea02db
remove print statement
Alexboiboi Jun 20, 2022
1848b79
add cached colorscale to colormap translator
Alexboiboi Jun 20, 2022
531fa80
add facecolor subdivision for matplotlib_auto
Alexboiboi Jun 20, 2022
7e362e2
remove bad import
Alexboiboi Jun 20, 2022
5d750ca
add mag arrows for generic traces
Alexboiboi Jun 20, 2022
5fb470b
run precommit
Alexboiboi Jun 20, 2022
086c6f7
fix subdivide mesh by facecolor
Alexboiboi Jun 20, 2022
cf3a5d2
renaming
Alexboiboi Jun 21, 2022
775e814
make animation generic
Alexboiboi Jun 21, 2022
6e8381d
handle markers in main show function
Alexboiboi Jun 21, 2022
1f487a8
pylint
Alexboiboi Jun 21, 2022
d325e1e
draft matplotlib_auto animation
Alexboiboi Jun 21, 2022
ee33848
add return animation object option
Alexboiboi Jun 22, 2022
2c72917
archive matplotlib old
Alexboiboi Jun 22, 2022
2e1e941
make extra trace generic
Alexboiboi Jun 22, 2022
735d905
remove pyvista (now generic branch)
Alexboiboi Jun 23, 2022
b73ac85
Merge branch 'main' of https://github.com/magpylib/magpylib into getB…
Alexboiboi Jun 23, 2022
1cefe1d
Merge branch 'getBH-dataframe' of https://github.com/magpylib/magpyli…
Alexboiboi Jun 23, 2022
ddd6d20
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jun 23, 2022
8a84eca
animation kwargs handling bug fix
Alexboiboi Jun 23, 2022
0463120
simplify structure and avoid redundancy
Alexboiboi Jun 24, 2022
f3d68c3
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jun 24, 2022
0856e58
fix import paths
Alexboiboi Jun 24, 2022
79c8ec2
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jun 24, 2022
03dc2f0
remove superfluous nan value in scatter mag arrow
Alexboiboi Jun 25, 2022
eb5113e
pylint
Alexboiboi Jun 25, 2022
c143164
lgtm
Alexboiboi Jun 25, 2022
6dd11a2
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jun 25, 2022
beaddc0
add symb and line style translation for mpl
Alexboiboi Jun 26, 2022
f716d66
fix animation with user axes
Alexboiboi Jun 26, 2022
bddecf5
fix output dataframe ignored
Alexboiboi Jun 26, 2022
8bb17ec
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jun 26, 2022
d4a3b0c
add tests
Alexboiboi Jun 27, 2022
f29eadc
add changelog entry
Alexboiboi Jun 27, 2022
6e44c73
add example
Alexboiboi Jun 27, 2022
a1e32b9
black
Alexboiboi Jun 27, 2022
d26d129
test cov
Alexboiboi Jun 27, 2022
5be9d28
Merge branch 'getBH-dataframe' of https://github.com/magpylib/magpyli…
Alexboiboi Jun 27, 2022
6be285b
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jun 27, 2022
6a876dc
pylint
Alexboiboi Jun 27, 2022
2fdfaec
fix traces grouping
Alexboiboi Jun 27, 2022
160508c
draft extra model3d compatibility
Alexboiboi Jun 27, 2022
ac31716
fix tests
Alexboiboi Jun 27, 2022
cd54336
modify for generic backend
Alexboiboi Jun 28, 2022
d4106be
document generic backend traces
Alexboiboi Jun 28, 2022
b115aa4
fix bad arrow orientation with (0,0-1)
Alexboiboi Jun 28, 2022
07bd8a2
minibug f-string fix
OrtnerMichael Jun 30, 2022
f750d2b
docstrings minifix
OrtnerMichael Jun 30, 2022
c12a9a8
modify introduction
OrtnerMichael Jun 30, 2022
a5ef24d
fix dataframe output with pixel_agg
Alexboiboi Jun 30, 2022
5f121e0
Merge branch 'getBH-dataframe' of https://github.com/magpylib/magpyli…
Alexboiboi Jun 30, 2022
cff092f
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jun 30, 2022
4cf807b
Merge branch 'display-backend-rework' of https://github.com/magpylib/…
Alexboiboi Jun 30, 2022
3afe83d
Merge branch 'main' of https://github.com/magpylib/magpylib into refa…
Alexboiboi Jun 30, 2022
f234291
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jun 30, 2022
a8bd864
remove unused test
Alexboiboi Jul 2, 2022
2cd8215
refactoring
Alexboiboi Jul 2, 2022
8f96fc6
typo
Alexboiboi Jul 2, 2022
ade08e3
move line tiling to field function
Alexboiboi Jul 3, 2022
59b44df
avoid tiling warning with vertices with diff len
Alexboiboi Jul 3, 2022
9eeb250
refactor field_func
Alexboiboi Jul 4, 2022
36be73d
Register field functions
Alexboiboi Jul 4, 2022
bd6f548
automatize imports
Alexboiboi Jul 4, 2022
c0ef6aa
automatize imports
Alexboiboi Jul 4, 2022
3ac23a7
Merge branch 'refactor-getBH-02' of https://github.com/magpylib/magpy…
Alexboiboi Jul 4, 2022
cb0b053
back to explicit imports
Alexboiboi Jul 4, 2022
eef27c5
renaming modules finish
Alexboiboi Jul 4, 2022
48b066a
refactor param dims properties
Alexboiboi Jul 4, 2022
28a86ec
merge get_BH_wrap functions into one file
Alexboiboi Jul 4, 2022
d4ed868
pylint
Alexboiboi Jul 5, 2022
85e0cbb
update backend docstrings
Alexboiboi Jul 5, 2022
9be2655
register kind
Alexboiboi Jul 6, 2022
ac00e65
add matplotlib numbering
Alexboiboi Jul 6, 2022
948c4b7
return_fig, update_layout and layout
Alexboiboi Jul 8, 2022
81aff03
Merge branch 'display-backend-rework' of https://github.com/magpylib/…
Alexboiboi Jul 8, 2022
370c8c8
fig show bug fix plotly
Alexboiboi Jul 8, 2022
dbe541d
Merge branch 'display-backend-rework' of https://github.com/magpylib/…
Alexboiboi Jul 8, 2022
a67f7ef
Merge branch 'display-backend-rework' of https://github.com/magpylib/…
Alexboiboi Jul 8, 2022
9c55dc6
Merge branch 'refactor-getBH-02' of https://github.com/magpylib/magpy…
Alexboiboi Jul 8, 2022
26cc7be
Merge branch 'display-backend-rework' of https://github.com/magpylib/…
Alexboiboi Jul 8, 2022
b8543fa
Merge branch 'refactor-getBH-02' of https://github.com/magpylib/magpy…
Alexboiboi Jul 8, 2022
f04c1ff
fix bad pull from display-rework
Alexboiboi Jul 8, 2022
20674c5
pylint
Alexboiboi Jul 12, 2022
b6204fb
draft getbdict vert feature
Alexboiboi Jul 15, 2022
3a26966
fix tests
Alexboiboi Jul 15, 2022
7f1a3dc
pull from refactor_getbh
Alexboiboi Jul 15, 2022
6809069
pylint
Alexboiboi Jul 15, 2022
e43979b
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jul 16, 2022
af6a813
fix getB dict Line with "scalar" vertices
Alexboiboi Jul 19, 2022
fdc4585
fix mag show bug
Alexboiboi Jul 21, 2022
d8a0a95
update compound example with generic extra trace
Alexboiboi Jul 21, 2022
2953e0e
remove unused files
Alexboiboi Jul 21, 2022
0896545
coverage
Alexboiboi Jul 21, 2022
35bcad5
fix ragged seq tiling for gebhdict line
Alexboiboi Jul 21, 2022
5445d32
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jul 21, 2022
69df834
coverage
Alexboiboi Jul 21, 2022
3f07ccf
coverage
Alexboiboi Jul 22, 2022
30402bc
update changelog
Alexboiboi Jul 22, 2022
374302c
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jul 22, 2022
7cb090c
update changelog
Alexboiboi Jul 22, 2022
f314fff
frame duration for mpl
Alexboiboi Jul 22, 2022
062b19e
refactor inheritance
Alexboiboi Jul 23, 2022
9235004
move field func logic to BaseSource class
Alexboiboi Jul 23, 2022
444e4cb
refactor Registering classes with a metaclass
Alexboiboi Jul 24, 2022
6937acc
fix subclassing sideeffect with metaclass
Alexboiboi Jul 24, 2022
0065377
pylint cycling import fix
Alexboiboi Jul 24, 2022
b976f63
Merge branch 'refactor-getBH-temp' of https://github.com/magpylib/mag…
Alexboiboi Jul 25, 2022
4b09f8a
finish pull from refactor-getBH-temp
Alexboiboi Jul 25, 2022
4e3d9fb
coverage
Alexboiboi Jul 26, 2022
51896e3
Merge branch 'refactor-getBH' of https://github.com/magpylib/magpylib…
Alexboiboi Jul 26, 2022
6831f42
Merge branch 'display-backend-rework-temp' of https://github.com/magp…
Alexboiboi Jul 26, 2022
183eeac
Merge branch 'main' of https://github.com/magpylib/magpylib into disp…
Alexboiboi Jul 26, 2022
d3bb95b
small refactoring of magnet and current style
Alexboiboi Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' of https://github.com/magpylib/magpylib into refa…
…ctor-getBH
  • Loading branch information
Alexboiboi committed Apr 1, 2022
commit 249f247ccb950bbd18fbf576f283521d175bfafd
11 changes: 5 additions & 6 deletions docs/_pages/page_01_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ One central motivation behind the `Collection` class is enabling users to build

**User-defined 3D models** (traces) for any object that will be displayed by `show`, can be stored in `style.model3d.data`. A trace itself is a dictionary that contains all information necessary for plotting, and can be added with the method `style.model3d.data.add_trace`. In the example gallery {ref}`examples-3d-models` it is explained how to create custom traces with standard plotting backends such as `scatter3d` or `mesh3d` in Plotly, or `plot`, `plot_surface` and `plot_trisurf` in Matplotlib. Some pre-defined models are also provided for easy parts visualization.

**User-defined source objects** are easily realized with the `CustomSource` class. Such a custom source object is provided with a user-defined field computation function, that is stored in the attribute `field_func` and is used when `getB` and `getH` are called. The provided function must accept a `field` argument as a string (`'B'` or `'H'`) and an `observer` array with shape (n,3), and return the field with a similar shape. Details on working with custom sources are given in {ref}`examples-custom-source-objects`.
**User-defined source objects** are easily realized with the `CustomSource` class. Such a custom source object is provided with a user-defined field computation function, that is stored in the attribute `field_func` and is used when `getB` and `getH` are called. Similar to core functions, `field_func` must have the two positional arguments `field` (can be `'B'` or `'H'`) and `observers` (must accept ndarrays of shape (n,3)), and return the respective fields in units of \[mT\] and \[kA/m\] in the same shape. Details on working with custom sources are given in {ref}`examples-custom-source-objects`.

While each of these features can be used individually, the combination of the two (own source class with own 3D representation) enables a high level of customization in Magpylib. Such user-defined objects will feel like native Magpylib objects and can be used in combination with all other features, which is demonstrated in the following example:

Expand All @@ -550,12 +550,11 @@ import numpy as np
import plotly.graph_objects as go
import magpylib as magpy

# define B-field function for custom source
def easter_field(field, observer):
# define B/H field function for custom source
def easter_field(field, observers):
""" points in z-direction and decays with 1/r^3"""
if field=='B':
dist = np.linalg.norm(observer, axis=1)
return np.c_[np.zeros((len(observer),2)), 1/dist**3]
dist = np.linalg.norm(observers, axis=1)
return np.c_[np.zeros((len(observers),2)), 1/dist**3]

# create custom source
egg = magpy.misc.CustomSource(
Expand Down
11 changes: 5 additions & 6 deletions docs/examples/examples_04_custom_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ kernelspec:
(examples-custom-source-objects)=
# Custom source objects

The class `CustomSource` allows users to integrate their own custom-objects into the Magpylib interface. The `field_func` argument can be provided with a function that is called with `getB` and `getH`.

This custom field function is treated like a core functions. It must accept a `field` argument (`'B'` or `'H'`), an `observer` argument (array_like, shape (n,3)) and return the respective field with a similar shape. A fundamental example how to create a custom source object is shown below:
The class `CustomSource` allows users to integrate their own custom-object field computation into the Magpylib interface. For this, the argument `field_func` must be provided with a function that is then automatically called with `getB` and `getH`. This custom field function is treated like a core function. It must have the positional arguments `field` (with values `'B'` or `'H'`), and `observers` (must accept array_like, shape (n,3)) and return the B-field in units of \[mT\] and the H-field in units of \[kA/m\] with a similar shape. A fundamental example how to create a custom source object is shown below:

```{code-cell} ipython3
import numpy as np
import magpylib as magpy

# define field function
def custom_field(field, observer):
def custom_field(field, observers):
""" user defined custom field
position input: array_like, shape (n,3)
returns: B-field, ndarray, shape (n,3)
"""
if field=='B':
return np.array(observer)*2
return np.array(observers)*2
return np.array(observers)

# custom source
source = magpy.misc.CustomSource(field_func=custom_field)
Expand Down Expand Up @@ -68,7 +67,7 @@ trace_pole = magpy.graphics.model3d.make_Ellipsoid(
# combine four monopole custom sources into a quadrupole collection
def create_pole(charge):
""" create a monopole object"""
field = lambda field, observer: monopole_field(charge, observer)
field = lambda field, observers: monopole_field(charge, observers)
monopole = magpy.misc.CustomSource(
field_func=field,
style_model3d_showdefault=False,
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/examples_22_field_interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ def interpolate_field(data, method="linear", bounds_error=False, fill_value=np.n
rgi = RegularGridInterpolator((X, Y, Z), f.reshape(nx, ny, nz), **kwargs)
field_interp.append(rgi)

def field_func(field, observer):
if field=='B':
return np.array([field(observer) for field in field_interp]).T
def field_func(field, observers):
return np.array([f(observers) for f in field_interp]).T
return field_func
```

Expand Down
4 changes: 2 additions & 2 deletions magpylib/_src/fields/field_BH_cuboid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def magnet_cuboid_field(
field: str,
observer: np.ndarray,
observers: np.ndarray,
magnetization: np.ndarray,
dimension: np.ndarray) -> np.ndarray:
"""Magnetic field of a homogeneously magnetized cuboid.
Expand All @@ -22,7 +22,7 @@ def magnet_cuboid_field(
If `field='B'` return B-field in units of [mT], if `field='H'` return H-field
in units of [kA/m].

observer: ndarray, shape (n,3)
observers: ndarray, shape (n,3)
Observer positions (x,y,z) in Cartesian coordinates in units of [mm].

magnetization: ndarray, shape (n,3)
Expand Down
4 changes: 2 additions & 2 deletions magpylib/_src/fields/field_BH_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def fieldH_cylinder_diametral(
# ON INTERFACE
def magnet_cylinder_field(
field: str,
observer: np.ndarray,
observers: np.ndarray,
magnetization: np.ndarray,
dimension: np.ndarray,
) -> np.ndarray:
Expand All @@ -219,7 +219,7 @@ def magnet_cylinder_field(
If `field='B'` return B-field in units of [mT], if `field='H'` return H-field
in units of [kA/m].

observer: ndarray, shape (n,3)
observers: ndarray, shape (n,3)
Observer positions (x,y,z) in Cartesian coordinates in units of [mm].

magnetization: ndarray, shape (n,3)
Expand Down
4 changes: 2 additions & 2 deletions magpylib/_src/fields/field_BH_cylinder_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ def magnet_cylinder_segment_core(

def magnet_cylinder_segment_field(
field: str,
observer: np.ndarray,
observers: np.ndarray,
magnetization: np.ndarray,
dimension: np.ndarray,
) -> np.ndarray:
Expand All @@ -1366,7 +1366,7 @@ def magnet_cylinder_segment_field(
If `field='B'` return B-field in units of [mT], if `field='H'` return H-field
in units of [kA/m].

observer: ndarray, shape (n,3)
observers: ndarray, shape (n,3)
Observer positions (x,y,z) in Cartesian coordinates in units of [mm].

magnetization: ndarray, shape (n,3)
Expand Down
4 changes: 2 additions & 2 deletions magpylib/_src/fields/field_BH_dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def dipole_field(
field: str,
observer: np.ndarray,
observers: np.ndarray,
moment: np.ndarray,
) -> np.ndarray:
"""Magnetic field of a dipole moment.
Expand All @@ -20,7 +20,7 @@ def dipole_field(
field: str, default=`'B'`
If `field='B'` return B-field in units of [mT], if `field='H'` return H-field

observer: ndarray, shape (n,3)
observers: ndarray, shape (n,3)
Observer positions (x,y,z) in Cartesian coordinates in units of [mm].
in units of [kA/m].

Expand Down
22 changes: 11 additions & 11 deletions magpylib/_src/fields/field_BH_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def current_vertices_field(
field: str,
observer: np.ndarray,
observers: np.ndarray,
current: np.ndarray,
vertices: list=None,
segment_start=None, # list of mix3 ndarrays
Expand All @@ -30,10 +30,10 @@ def current_vertices_field(
- B-field (ndarray nx3): B-field vectors at pos_obs in units of mT
"""
if vertices is None:
return current_line_field(field, observer, current, segment_start, segment_end)
return current_line_field(field, observers, current, segment_start, segment_end)

nv = len(vertices) # number of input vertex_sets
npp = int(observer.shape[0]/nv) # number of position vectors
npp = int(observers.shape[0]/nv) # number of position vectors
nvs = [len(vset)-1 for vset in vertices] # length of vertex sets
nseg = sum(nvs) # number of segments

Expand All @@ -43,16 +43,16 @@ def current_vertices_field(
pos_end = np.concatenate([vert[1:] for vert in vertices])

# create input for vectorized computation in one go
observer = np.reshape(observer, (nv, npp,3))
observer = np.repeat(observer, nvs, axis=0)
observer = np.reshape(observer, (-1, 3))
observers = np.reshape(observers, (nv, npp,3))
observers = np.repeat(observers, nvs, axis=0)
observers = np.reshape(observers, (-1, 3))

curr_tile = np.repeat(curr_tile, npp)
pos_start = np.repeat(pos_start, npp, axis=0)
pos_end = np.repeat(pos_end, npp, axis=0)

# compute field
field = current_line_field(field, observer, curr_tile, pos_start, pos_end)
field = current_line_field(field, observers, curr_tile, pos_start, pos_end)
field = np.reshape(field, (nseg, npp, 3))

# sum for each vertex set
Expand All @@ -65,7 +65,7 @@ def current_vertices_field(
# ON INTERFACE
def current_line_field(
field: str,
observer: np.ndarray,
observers: np.ndarray,
current: np.ndarray,
segment_start: np.ndarray,
segment_end: np.ndarray,
Expand All @@ -81,7 +81,7 @@ def current_line_field(
If `field='B'` return B-field in units of [mT], if `field='H'` return H-field
in units of [kA/m].

observer: ndarray, shape (n,3)
observers: ndarray, shape (n,3)
Observer positions (x,y,z) in Cartesian coordinates in units of [mm].

current: ndarray, shape (n,)
Expand Down Expand Up @@ -138,10 +138,10 @@ def current_line_field(
current = current[not_mask0]
segment_start = segment_start[not_mask0]
segment_end = segment_end[not_mask0]
observer = observer[not_mask0]
observers = observers[not_mask0]

# rename
p1,p2,po = segment_start, segment_end, observer
p1,p2,po = segment_start, segment_end, observers

# make dimensionless (avoid all large/small input problems) by introducing
# the segment length as characteristic length scale.
Expand Down
4 changes: 2 additions & 2 deletions magpylib/_src/fields/field_BH_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# ON INTERFACE
def current_loop_field(
field: str,
observer: np.ndarray,
observers: np.ndarray,
current: np.ndarray,
diameter: np.ndarray,
) -> np.ndarray:
Expand All @@ -27,7 +27,7 @@ def current_loop_field(
If `field='B'` return B-field in units of [mT], if `field='H'` return H-field
in units of [kA/m].

observer: ndarray, shape (n,3)
observers: ndarray, shape (n,3)
Observer positions (x,y,z) in Cartesian coordinates in units of [mm].

current: ndarray, shape (n,)
Expand Down
4 changes: 2 additions & 2 deletions magpylib/_src/fields/field_BH_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def magnet_sphere_field(
field: str,
observer: np.ndarray,
observers: np.ndarray,
magnetization: np.ndarray,
diameter: np.ndarray,
)->np.ndarray:
Expand All @@ -23,7 +23,7 @@ def magnet_sphere_field(
If `field='B'` return B-field in units of [mT], if `field='H'` return H-field
in units of [kA/m].

observer: ndarray, shape (n,3)
observers: ndarray, shape (n,3)
Observer positions (x,y,z) in Cartesian coordinates in units of [mm].

magnetization: ndarray, shape (n,3)
Expand Down
14 changes: 5 additions & 9 deletions magpylib/_src/fields/field_wrap_BH_level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def getBH_level1(
source_type: str,
position: np.ndarray,
orientation: np.ndarray,
observer: np.ndarray,
observers: np.ndarray,
**kwargs: dict,
) -> np.ndarray:
"""Vectorized field computation
Expand All @@ -45,19 +45,15 @@ def getBH_level1(
# pylint: disable=too-many-branches

# transform obs_pos into source CS
pos_rel_rot = orientation.apply(observer - position, inverse=True)
pos_rel_rot = orientation.apply(observers - position, inverse=True)

# collect dictionary inputs and compute field
field_func = FIELD_FUNCTIONS.get(source_type, None)

if source_type == 'CustomSource':
if source_type == "CustomSource":
field = kwargs["field"]
if kwargs.get('field_func', None) is not None:
BH = kwargs['field_func'](field, pos_rel_rot)
else:
raise MagpylibInternalError(
'No field calculation not provided for CustomSource class'
)
if kwargs.get("field_func", None) is not None:
BH = kwargs["field_func"](field, pos_rel_rot)
elif field_func is not None:
BH = field_func(observer=pos_rel_rot, **kwargs)
else:
Expand Down
2 changes: 1 addition & 1 deletion magpylib/_src/fields/field_wrap_BH_level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def getBH_level2(
if isinstance(sources, str):
return getBH_dict_level2(
source_type=sources,
observer=observers,
observers=observers,
field=field,
squeeze=squeeze,
**kwargs,
Expand Down
11 changes: 5 additions & 6 deletions magpylib/_src/fields/field_wrap_BH_level2_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


PARAM_TILE_DIMS = {
"observer": 2,
"observers": 2,
"position": 2,
"orientation": 2,
"magnetization": 2,
Expand All @@ -23,15 +23,15 @@

def getBH_dict_level2(
source_type,
observer,
observers,
*,
field: str,
position=(0, 0, 0),
orientation=R.identity(),
squeeze=True,
**kwargs: dict,
) -> np.ndarray:
""" Direct interface access to vectorized computation
"""Direct interface access to vectorized computation

Parameters
----------
Expand Down Expand Up @@ -66,7 +66,7 @@ def getBH_dict_level2(
" when using the direct interface."
)

kwargs["observer"] = observer
kwargs["observers"] = observers
kwargs["position"] = position

# change orientation to Rotation numpy array for tiling
Expand All @@ -79,8 +79,7 @@ def getBH_dict_level2(
val = np.array(val, dtype=float)
except TypeError as err:
raise MagpylibBadUserInput(
f"{key} input must be array-like.\n"
f"Instead received {val}"
f"{key} input must be array-like.\n" f"Instead received {val}"
) from err
tdim = PARAM_TILE_DIMS.get(key, 1)
if val.ndim == tdim:
Expand Down
43 changes: 16 additions & 27 deletions magpylib/_src/input_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,33 +133,22 @@ def validate_field_func(val):
- needs to be a callable
- input and output shape must match
"""
if val is not None:
msg = ""
if not callable(val):
msg = f"Instead received {type(val).__name__}."
else:
fn_args = inspect.getfullargspec(val).args
if fn_args[:2] != ["field", "observer"]:
msg = f"Instead received a callable, the first two args being: {fn_args[:2]}"
else:
out = val("B", np.array([[1, 2, 3], [4, 5, 6]]))
out_shape = np.array(out).shape
if out_shape != (2, 3):
msg = (
"Function test call with observer of shape (2,3) failed, "
f"instead received shape {out_shape}."
)

if msg:
raise MagpylibBadUserInput(
"Input parameter `field_func` must be a callable "
"accepting the two positional arguments `field` and `observer` "
"(e.g. `def myfieldfunc(field, observer, ...): ...`. The `field` argument must "
"accept one of ('B','H') and the `observer` an ndarray of shape (n,3). "
"The returned field must be an ndarray matching the observer shape.\n"
+ msg
)
return val
if val is None:
return None

if not callable(val):
raise MagpylibBadUserInput(
"Input parameter `field_func` must be a callable.\n"
f"Instead received {type(val).__name__}."
)

fn_args = inspect.getfullargspec(val).args
if fn_args[:2] != ["field", "observers"]:
raise MagpylibBadUserInput(
"Input parameter `field_func` must have two positional args"
" called 'field' and 'observers'.\n"
f"Instead received a callable where the first two args are: {fn_args[:2]}"
)

for field in ['B', 'H']:
out = val(field, np.array([[1, 2, 3], [4, 5, 6]]))
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.