Skip to content

Commit 723bcc2

Browse files
Fixed Droplet.from_volume method. (#83)
Fixed some type issues
1 parent 0649e86 commit 723bcc2

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

droplets/droplet_tracks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def contiguous_true_regions(condition: np.ndarray) -> np.ndarray:
4848
is the start index of the region and the second column is the end index
4949
"""
5050
if len(condition) == 0:
51-
return np.empty((0, 2), dtype=np.intc)
51+
return np.empty((0, 2), dtype=np.intc) # type: ignore
5252

5353
# convert condition array to integer
5454
condition = np.asarray(condition, np.intc)
@@ -294,7 +294,7 @@ def _from_hdf_dataset(cls, dataset) -> DropletTrack:
294294
times = dataset["time"]
295295
droplet_data = rfn.rec_drop_fields(dataset, "time")
296296
for time, data in zip(times, droplet_data):
297-
droplet = droplet_from_data(droplet_class, data) # type: ignore
297+
droplet = droplet_from_data(droplet_class, data)
298298
obj.append(droplet, time=time) # type: ignore
299299

300300
return obj

droplets/droplets.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,21 @@ def data_bounds(self) -> tuple[np.ndarray, np.ndarray]:
300300
return l, h
301301

302302
@classmethod
303-
def from_volume(cls, position: np.ndarray, volume: float):
304-
"""Construct a droplet from given volume instead of radius.
303+
def from_volume(cls, position: np.ndarray, volume: float, **kwargs):
304+
r"""Construct a droplet from given volume instead of radius.
305305
306306
Args:
307307
position (:class:`~numpy.ndarray`):
308308
Center of the droplet
309309
volume (float):
310310
Volume of the droplet
311-
interface_width (float, optional):
312-
Width of the interface
311+
\**kwargs:
312+
Additional arguments are forwarded to the class initializer. This can
313+
for instance be used to set the interfacial width.
313314
"""
314315
dim = len(np.array(position, np.double, ndmin=1))
315316
radius = spherical.radius_from_volume(volume, dim)
316-
return cls(position, radius)
317+
return cls(position, radius, **kwargs)
317318

318319
@property
319320
def position(self) -> np.ndarray:
@@ -781,7 +782,7 @@ def data_bounds(self) -> tuple[np.ndarray, np.ndarray]:
781782
@property
782783
def modes(self) -> int:
783784
"""int: number of perturbation modes"""
784-
shape = self.data.dtype.fields["amplitudes"][0].shape
785+
shape = self.data.dtype.fields["amplitudes"][0].shape # type: ignore
785786
return int(shape[0]) if shape else 1
786787

787788
@property

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ omit = ['*/test*']
120120

121121
[tool.mypy]
122122
python_version = "3.9"
123-
plugins = "numpy.typing.mypy_plugin"
124123
warn_return_any = true
125124
warn_unused_configs = true
126125
warn_unused_ignores = true

tests/test_droplets.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def test_perturbed_droplet_2d():
6262
d.interface_position(0.1)
6363
d.interface_curvature(0.1)
6464

65+
d = droplets.PerturbedDroplet2D.from_volume(
66+
[0, 1], 10, interface_width=0.1, amplitudes=[0.0, 0.1, 0.2]
67+
)
68+
assert d.volume == pytest.approx(10, 0.1)
69+
assert d.interface_width == pytest.approx(0.1)
70+
6571

6672
def test_perturbed_droplet_3d():
6773
"""Test methods of perturbed droplets in 3d."""

0 commit comments

Comments
 (0)