Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/jaxtyping-0.2.36
Browse files Browse the repository at this point in the history
  • Loading branch information
waltsims authored Nov 19, 2024
2 parents ebc1b2d + 85be199 commit 6875beb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion kwave/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion kwave/ktransducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion kwave/utils/kwave_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions kwave/utils/matlab.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Tuple, Union, Optional, List

from beartype import beartype as typechecker
import numpy as np


Expand Down Expand Up @@ -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.
Expand All @@ -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], ...]:
Expand Down

0 comments on commit 6875beb

Please sign in to comment.