Skip to content

Commit 3c5dedd

Browse files
authored
Merge pull request #279 from h-mayorquin/add_cirulcar_auto_shape
Add circular auto-shape option
2 parents c075eb3 + 9203853 commit 3c5dedd

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/probeinterface/probe.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,38 @@ def set_planar_contour(self, contour_polygon: list):
333333
raise ValueError(f"contour_polygon.shape[1] {contour_polygon.shape[1]} and ndim {self.ndim} do not match!")
334334
self.probe_planar_contour = contour_polygon
335335

336-
def create_auto_shape(self, probe_type: "tip" | "rect" = "tip", margin: float = 20.0):
337-
"""Create planar contour automatically based on probe contact positions.
336+
def create_auto_shape(self, probe_type: "tip" | "rect" | "circular" = "tip", margin: float = 20.0):
337+
"""Create a planar contour automatically based on probe contact positions.
338+
339+
This function generates a 2D polygon that outlines the shape of the probe, adjusted
340+
by a specified margin. The resulting contour is set as the planar contour of the probe.
338341
339342
Parameters
340343
----------
341-
probe_type : "tip" | "rect", default: "tip"
342-
The probe type ('tip' or 'rect')
343-
margin : float, default: 20.0
344-
The margin to add to the contact positions
344+
probe_type : {"tip", "rect", "circular"}, default: "tip"
345+
The type of probe used to collect contact data:
345346
347+
* "tip": Assumes a single-point contact probe. The generated contour is
348+
a rectangle with a triangular "tip" extending downwards.
349+
* "rect": Assumes a rectangular contact probe. The generated contour is
350+
a rectangle.
351+
* "circular": Assumes a circular contact probe. The generated contour
352+
is a circle.
353+
354+
margin : float, default: 20.0
355+
The margin to add around the contact positions. The behavior varies by
356+
probe type:
357+
358+
* "tip": The margin is added around the rectangular portion of the contour
359+
and to the base of the tip. The tip itself is extended downwards by
360+
four times the margin value.
361+
* "rect": The margin is added evenly around all sides of the rectangle.
362+
* "circular": The margin is added to the radius of the circle.
363+
364+
Notes
365+
-----
366+
This function is designed for 2D data only. If you have 3D data, consider projecting
367+
it onto a plane before using this method.
346368
"""
347369
if self.ndim != 2:
348370
raise ValueError(f"Auto shape is supported only for 2d, you have ndim {self.ndim}")
@@ -383,8 +405,19 @@ def create_auto_shape(self, probe_type: "tip" | "rect" = "tip", margin: float =
383405
(x1, y0),
384406
(x1, y1),
385407
]
408+
elif probe_type == "circular":
409+
radius_x = (x1 - x0) / 2
410+
radius_y = (y1 - y0) / 2
411+
center = ((x0 + x1) / 2, (y0 + y1) / 2)
412+
radius = max(radius_x, radius_y) + margin
413+
num_vertices = 100
414+
theta = np.linspace(0, 2 * np.pi, num_vertices, endpoint=False)
415+
x = center[0] + radius * np.cos(theta)
416+
y = center[1] + radius * np.sin(theta)
417+
vertices = np.vstack((x, y)).T
418+
polygon += vertices.tolist()
386419
else:
387-
raise ValueError(f"'probe_type' can only be 'rect' or 'tip, you have entered {probe_type}")
420+
raise ValueError(f"'probe_type' can only be 'rect, 'tip' or 'circular', you have entered {probe_type}")
388421

389422
self.set_planar_contour(polygon)
390423

tests/test_probe.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def test_probe():
3333
vertices = [(-20, -30), (20, -110), (60, -30), (60, 190), (-20, 190)]
3434
probe.set_planar_contour(vertices)
3535

36-
# auto shape
36+
# auto shape (test no error)
37+
probe.create_auto_shape(probe_type="rect")
38+
probe.create_auto_shape(probe_type="circular")
3739
probe.create_auto_shape()
3840

3941
# annotation

0 commit comments

Comments
 (0)