Skip to content

Commit

Permalink
remove changes from user brubbel
Browse files Browse the repository at this point in the history
  • Loading branch information
waltsims committed Dec 14, 2024
1 parent 6ccc328 commit dbc49dc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
5 changes: 2 additions & 3 deletions kwave/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ def _make_binary_executable(self):
raise FileNotFoundError(f"Binary not found at {binary_path}")
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]
command.extend(options.split(' '))
def run_simulation(self, input_filename: str, output_filename: str, options: list[str]) -> dotdict:
command = [str(self.execution_options.binary_path), "-i", input_filename, "-o", output_filename] + options

try:
with subprocess.Popen(
Expand Down
2 changes: 1 addition & 1 deletion kwave/kspaceFirstOrder2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,6 @@ def kspaceFirstOrder2D(
return

executor = Executor(simulation_options=simulation_options, execution_options=execution_options)
executor_options = execution_options.get_options_string(sensor=k_sim.sensor)
executor_options = execution_options.as_list(sensor=k_sim.sensor)
sensor_data = executor.run_simulation(k_sim.options.input_filename, k_sim.options.output_filename, options=executor_options)
return sensor_data
2 changes: 1 addition & 1 deletion kwave/kspaceFirstOrder3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,6 @@ def kspaceFirstOrder3D(
return

executor = Executor(simulation_options=simulation_options, execution_options=execution_options)
executor_options = execution_options.get_options_string(sensor=k_sim.sensor)
executor_options = execution_options.as_list(sensor=k_sim.sensor)
sensor_data = executor.run_simulation(k_sim.options.input_filename, k_sim.options.output_filename, options=executor_options)
return sensor_data
2 changes: 1 addition & 1 deletion kwave/kspaceFirstOrderAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,6 @@ def kspaceFirstOrderAS(
return

executor = Executor(simulation_options=simulation_options, execution_options=execution_options)
executor_options = execution_options.get_options_string(sensor=k_sim.sensor)
executor_options = execution_options.as_list(sensor=k_sim.sensor)
sensor_data = executor.run_simulation(k_sim.options.input_filename, k_sim.options.output_filename, options=executor_options)
return sensor_data
51 changes: 25 additions & 26 deletions kwave/options/simulation_execution_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
from typing import Optional, Union
import os
import warnings

from kwave import PLATFORM, BINARY_DIR
from kwave.ksensor import kSensor
Expand Down Expand Up @@ -149,51 +150,49 @@ def binary_dir(self, value: str):
)
self._binary_dir = Path(value)

def get_options_string(self, sensor: kSensor) -> str:
def as_list(self, sensor: kSensor) -> list[str]:
options_list = []
if self.device_num is not None and self.device_num < 0:
raise ValueError("Device number must be non-negative")

if self.device_num is not None:
options_list.append(f" -g {self.device_num}")
if self.device_num < 0:
raise ValueError("Device number must be non-negative")
options_list.append(f"-g {self.device_num}")

if self.num_threads is not None and PLATFORM != "windows":
options_list.append(f" -t {self.num_threads}")
options_list.append(f"-t {self.num_threads}")

if self.verbose_level > 0:
options_list.append(f" --verbose {self.verbose_level}")
options_list.append(f"--verbose {self.verbose_level}")

record_options_map = {
"p": "p_raw",
"p_max": "p_max",
"p_min": "p_min",
"p_rms": "p_rms",
"p_max_all": "p_max_all",
"p_min_all": "p_min_all",
"p_final": "p_final",
"u": "u_raw",
"u_max": "u_max",
"u_min": "u_min",
"u_rms": "u_rms",
"u_max_all": "u_max_all",
"u_min_all": "u_min_all",
"u_final": "u_final",
"p": "p_raw", "p_max": "p_max", "p_min": "p_min", "p_rms": "p_rms",
"p_max_all": "p_max_all", "p_min_all": "p_min_all", "p_final": "p_final",
"u": "u_raw", "u_max": "u_max", "u_min": "u_min", "u_rms": "u_rms",
"u_max_all": "u_max_all", "u_min_all": "u_min_all", "u_final": "u_final",
}

if sensor.record is not None:
matching_keys = set(sensor.record).intersection(record_options_map.keys())
for key in matching_keys:
options_list.append(f" --{record_options_map[key]}")
options_list.extend([f"--{record_options_map[key]}" for key in matching_keys])

if "u_non_staggered" in sensor.record or "I_avg" in sensor.record or "I" in sensor.record:
options_list.append(" --u_non_staggered_raw")
options_list.append("--u_non_staggered_raw")

if ("I_avg" in sensor.record or "I" in sensor.record) and ("p" not in sensor.record):
options_list.append(" --p_raw")
options_list.append("--p_raw")
else:
options_list.append(" --p_raw")
options_list.append("--p_raw")

if sensor.record_start_index is not None:
options_list.append(f" -s {sensor.record_start_index}")
options_list.append(f"-s {sensor.record_start_index}")

return options_list


def get_options_string(self, sensor: kSensor) -> str:
# raise a deprication warning
warnings.warn("This method is deprecated. Use `as_list` method instead.", DeprecationWarning)
options_list = self.as_list(sensor)

return " ".join(options_list)

Expand Down

0 comments on commit dbc49dc

Please sign in to comment.