From 0ab1e87a4bebbe5042c476c67bb0a8f08f936d3c Mon Sep 17 00:00:00 2001 From: brubbel <5667690+brubbel@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:12:48 +0100 Subject: [PATCH 1/3] bugfix simulation command options (#509) fixes https://github.com/waltsims/k-wave-python/issues/376 --- kwave/executor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kwave/executor.py b/kwave/executor.py index 4834d8c9..949c0c37 100644 --- a/kwave/executor.py +++ b/kwave/executor.py @@ -33,7 +33,8 @@ def _make_binary_executable(self): binary_path.chmod(binary_path.stat().st_mode | stat.S_IEXEC) def run_simulation(self, input_filename: str, output_filename: str, options: str): - command = [str(self.execution_options.binary_path), "-i", input_filename, "-o", output_filename, options] + command = [str(self.execution_options.binary_path), "-i", input_filename, "-o", output_filename] + command.extend(options.split(' ')) try: with subprocess.Popen( From 85be19928111d32bbbf17af72ee9af8324f11b28 Mon Sep 17 00:00:00 2001 From: Walter Simson Date: Tue, 19 Nov 2024 15:29:22 -0800 Subject: [PATCH 2/3] Fix numpy warnings (#510) * update linalg import * explicitly cast to intp * remove @typechecker * cast to int16 to replicate legacy behavior * update types for larger values * try uint16 * convert to uint16 * revert change * test two step * convert uint to unsigned int to allow negative indexing instead of wraparound with unsinged ints * fix type --- kwave/ktransducer.py | 2 +- kwave/utils/kwave_array.py | 2 +- kwave/utils/matlab.py | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kwave/ktransducer.py b/kwave/ktransducer.py index 176e3f05..0f0f3315 100644 --- a/kwave/ktransducer.py +++ b/kwave/ktransducer.py @@ -644,7 +644,7 @@ def delay_mask(self, mode=None): ].min() # -1s compatibility else: mask[unflatten_matlab_mask(mask, active_elements_index - 1)] += self.stored_beamforming_delays_offset # -1s compatibility - return mask.astype(np.uint8) + return mask.astype(np.uint16) @property def elevation_beamforming_delays(self): diff --git a/kwave/utils/kwave_array.py b/kwave/utils/kwave_array.py index 9996e055..3d666dbb 100644 --- a/kwave/utils/kwave_array.py +++ b/kwave/utils/kwave_array.py @@ -6,7 +6,7 @@ import numpy as np from numpy import arcsin, pi, cos, size, array -from numpy.linalg import linalg +import numpy.linalg as linalg from kwave.data import Vector from kwave.kgrid import kWaveGrid diff --git a/kwave/utils/matlab.py b/kwave/utils/matlab.py index a589380c..9c0e43c5 100644 --- a/kwave/utils/matlab.py +++ b/kwave/utils/matlab.py @@ -1,5 +1,5 @@ from typing import Tuple, Union, Optional, List - +from beartype import beartype as typechecker import numpy as np @@ -75,6 +75,7 @@ def matlab_find(arr: Union[List[int], np.ndarray], val: int = 0, mode: str = "ne return np.expand_dims(arr, -1) # compatibility, n => [n, 1] +@typechecker def matlab_mask(arr: np.ndarray, mask: np.ndarray, diff: Optional[int] = None) -> np.ndarray: """ Applies a mask to an array and returns the masked elements. @@ -89,10 +90,14 @@ def matlab_mask(arr: np.ndarray, mask: np.ndarray, diff: Optional[int] = None) - """ + if mask.dtype == "uint8": + mask = mask.astype("int8") + if diff is None: - return np.expand_dims(arr.ravel(order="F")[mask.ravel(order="F")], axis=-1) # compatibility, n => [n, 1] + flat_mask = mask.ravel(order="F") else: - return np.expand_dims(arr.ravel(order="F")[mask.ravel(order="F") + diff], axis=-1) # compatibility, n => [n, 1] + flat_mask = mask.ravel(order="F") + diff + return np.expand_dims(arr.ravel(order="F")[flat_mask], axis=-1) # compatibility, n => [n, 1] def unflatten_matlab_mask(arr: np.ndarray, mask: np.ndarray, diff: Optional[int] = None) -> Tuple[Union[int, np.ndarray], ...]: From 4111a76c662bf1e58c122d37315581000a428616 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:01:12 -0800 Subject: [PATCH 3/3] Bump jaxtyping from 0.2.34 to 0.2.36 (#508) --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b2baa243..5899e44a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ dependencies = [ "matplotlib==3.9.2", "numpy>=1.22.2,<2.2.0", "beartype==0.19.0", - "jaxtyping==0.2.34" + "jaxtyping==0.2.36" ] [project.urls]