diff --git a/droplets/droplets.py b/droplets/droplets.py index 4edc126..9dc58da 100644 --- a/droplets/droplets.py +++ b/droplets/droplets.py @@ -280,7 +280,8 @@ def get_dtype(cls, **kwargs) -> DTypeList: :class:`numpy.dtype`: the (structured) dtype associated with this class """ position = np.atleast_1d(kwargs.pop("position")) - assert not kwargs # no more keyword arguments + if kwargs: + raise ValueError(f"Leftover keyword arguments: {kwargs}") dim = len(position) return [("position", float, (dim,)), ("radius", float)] @@ -789,7 +790,8 @@ def amplitudes(self) -> np.ndarray: @amplitudes.setter def amplitudes(self, value: np.ndarray | None = None) -> None: if value is None: - assert self.modes == 0 + if self.modes != 0: + raise ValueError("Require values for amplitudes") self.data["amplitudes"] = np.broadcast_to(0.0, (0,)) else: self.data["amplitudes"] = np.broadcast_to(value, (self.modes,)) diff --git a/droplets/emulsions.py b/droplets/emulsions.py index ee71f3e..69aa397 100644 --- a/droplets/emulsions.py +++ b/droplets/emulsions.py @@ -153,7 +153,8 @@ def get_position(): else: bnds = np.atleast_2d(grid_or_bounds) - assert bnds.ndim == 2 and bnds.shape[0] > 0 and bnds.shape[1] == 2 + if bnds.ndim != 2 or bnds.shape[0] == 0 or bnds.shape[1] != 2: + raise ValueError(f"Bounds must be array of shape (n, 2), got {bnds}") def get_position(): return rng.uniform(bnds[:, 0], bnds[:, 1]) diff --git a/droplets/image_analysis.py b/droplets/image_analysis.py index 82e7911..f5f4b16 100644 --- a/droplets/image_analysis.py +++ b/droplets/image_analysis.py @@ -417,7 +417,8 @@ def locate_droplets( Returns: :class:`~droplets.emulsions.Emulsion`: All detected droplets """ - assert isinstance(phase_field, ScalarField) + if not isinstance(phase_field, ScalarField): + raise TypeError("`phase_field` must be ScalarField") dim = phase_field.grid.dim # dimensionality of the space if modes > 0 and dim not in [2, 3]: @@ -581,7 +582,8 @@ def refine_droplet( :class:`~droplets.droplets.DiffuseDroplet`: The refined droplet as an instance of the argument `droplet` """ - assert isinstance(phase_field, ScalarField) + if not isinstance(phase_field, ScalarField): + raise TypeError("`phase_field` must be ScalarField") if least_squares_params is None: least_squares_params = {} if tolerance is not None: diff --git a/droplets/tools/spherical.py b/droplets/tools/spherical.py index 263d6f5..c485617 100644 --- a/droplets/tools/spherical.py +++ b/droplets/tools/spherical.py @@ -320,7 +320,8 @@ def points_cartesian_to_spherical(points: np.ndarray) -> np.ndarray: :class:`~numpy.ndarray`: Points (r, θ, φ) in spherical coordinates """ points = np.atleast_1d(points) - assert points.shape[-1] == 3, "Points must have 3 coordinates" + if points.shape[-1] != 3: + raise DimensionError("Points must have 3 coordinates") ps_spherical = np.empty(points.shape) # calculate radius in [0, infinity] @@ -343,7 +344,8 @@ def points_spherical_to_cartesian(points: np.ndarray) -> np.ndarray: :class:`~numpy.ndarray`: Points in Cartesian coordinates """ points = np.atleast_1d(points) - assert points.shape[-1] == 3, "Points must have 3 coordinates" + if points.shape[-1] != 3: + raise DimensionError("Points must have 3 coordinates") sin_θ = np.sin(points[..., 1]) ps_cartesian = np.empty(points.shape)