k-wave-python icon indicating copy to clipboard operation
k-wave-python copied to clipboard

Homogeneous_medium_for sensor only receive signal

Open lmonsterrr opened this issue 3 years ago • 1 comments

Hi Walter, Sorry to bother you again. I would like to implement a project that only include k-wave simulation about the transducer/sensor receive the acoustic signal from source. BTW, is this the definition of transducer in your code is the device can transmmit signal and sensor : the device only receive signal? When I try to save the sensor_data in a similar way as your example in your 'bmode_reconstruction_example.py' Some error retruns about 'kSensor' object has no attribute 'combine_sensor_data'

Code info: ` import os from tempfile import gettempdir

from kwave.ksource import kSource from kwave.kspaceFirstOrder2D import kspaceFirstOrder2DC from kwave.kspaceFirstOrder2D import kspaceFirstOrder2DG from kwave.utils.maputils import makeDisc, makeCartCircle from kwave.utils import dotdict from kwave.ktransducer import * from kwave.kmedium import kWaveMedium from copy import deepcopy

pathname = '/home/wx/hdd1/k-wave-python/examples'

Nx = 128 # number of grid points in the x (row) direction Ny = 128 # number of grid points in the y (column) direction dx = 0.1e-3 # grid point spacing in the x direction [m] dy = 0.1e-3 # grid point spacing in the y direction [m] kgrid = kWaveGrid([Nx, Ny], [dx, dy])

t_end = (Nx * dx) * 2.2 / 1500 # [s] kgrid.makeTime(1500, t_end=t_end)

medium = kWaveMedium(sound_speed=1500, alpha_coeff=0.75, alpha_power=1.5)

disc_magnitude = 5 # [Pa] disc_x_pos = 50 # [grid points] disc_y_pos = 50 # [grid points] disc_radius = 8 # [grid points] disc_1 = disc_magnitude * makeDisc(Nx, Ny, disc_x_pos, disc_y_pos, disc_radius)

disc_magnitude = 3 # [Pa] disc_x_pos = 80 # [grid points] disc_y_pos = 60 # [grid points] disc_radius = 5 # [grid points] disc_2 = disc_magnitude * makeDisc(Nx, Ny, disc_x_pos, disc_y_pos, disc_radius)

source = kSource() source.p0 = disc_1 + disc_2

sensor_radius = 4e-3 # [m] num_sensor_points = 50 sensor_mask = makeCartCircle(sensor_radius, num_sensor_points) sensor = kSensor(sensor_mask) input_filename = f'example_input.h5' input_file_full_path = os.path.join(pathname, input_filename) print(input_file_full_path)

input_args = { 'SaveToDisk':input_file_full_path, 'SaveToDiskExit': False } sensor_data = kspaceFirstOrder2DG(**{ 'medium': medium, 'kgrid': kgrid, 'source': source, 'sensor': sensor, **input_args }) Error info: File "/home/wx/anaconda3/envs/py39k-wave/lib/python3.9/site-packages/kwave/kspaceFirstOrder2D.py", line 386, in kspaceFirstOrder2D return k_sim.sensor.combine_sensor_data(sensor_data) AttributeError: 'kSensor' object has no attribute 'combine_sensor_data'`

Thanks for you help again, and I would like to become the beta tester of windows. Thank you agagin.

Best Regards Chenzhe Li

lmonsterrr avatar Oct 24 '22 10:10 lmonsterrr

Thanks for bringing this up. The project is by no means perfect and I will have a look at this case later this week.

As far as running on windows, by cloning the current master branch and following the development instructions, you should be able to get k-wave-python running on Windows.

Let me know if you have any troubles with that. I'm happy to try to help.

waltsims avatar Oct 26 '22 17:10 waltsims

with PR #174 the following example will run:

import os

from kwave.kspaceFirstOrder2D import kspaceFirstOrder2D
from kwave.options.simulation_execution_options import SimulationExecutionOptions
from kwave.options.simulation_options import SimulationOptions

from kwave.data import Vector
from kwave.ksource import kSource
from kwave.utils.mapgen import make_disc, make_cart_circle
from kwave.ktransducer import *
from kwave.kmedium import kWaveMedium

Nx = 128 # number of grid points in the x (row) direction
Ny = 128 # number of grid points in the y (column) direction
dx = 0.1e-3 # grid point spacing in the x direction [m]
dy = 0.1e-3 # grid point spacing in the y direction [m]
kgrid = kWaveGrid([Nx, Ny], [dx, dy])

t_end = (Nx * dx) * 2.2 / 1500 # [s]
kgrid.makeTime(1500, t_end=t_end)

medium = kWaveMedium(sound_speed=1500, alpha_coeff=0.75, alpha_power=1.5)

disc_magnitude = 5 # [Pa]
disc_x_pos = 50 # [grid points]
disc_y_pos = 50 # [grid points]
disc_radius = 8 # [grid points]
disc_1 = disc_magnitude * make_disc(Vector([Nx, Ny]), Vector([disc_x_pos, disc_y_pos]), disc_radius)

disc_magnitude = 3 # [Pa]
disc_x_pos = 80 # [grid points]
disc_y_pos = 60 # [grid points]
disc_radius = 5 # [grid points]
disc_2 = disc_magnitude * make_disc(Vector([Nx, Ny]), Vector([disc_x_pos, disc_y_pos]), disc_radius)

source = kSource()
source.p0 = disc_1 + disc_2

sensor_radius = 4e-3 # [m]
num_sensor_points = 50
sensor_mask = make_cart_circle(sensor_radius, num_sensor_points)
sensor = kSensor(sensor_mask)
input_filename = f'example_input.h5'
input_file_full_path = os.path.join("./", input_filename)
print(input_file_full_path)

simulation_options = SimulationOptions(
    pml_inside=False,
    pml_auto=True,
    save_to_disk=True,
    input_filename=input_filename,
    save_to_disk_exit=False
)
# run the simulation
sensor_data = kspaceFirstOrder2D(
    medium=medium,
    kgrid=kgrid,
    source=source,
    sensor=sensor,
    simulation_options=simulation_options,
    execution_options=SimulationExecutionOptions(is_gpu_simulation=True)
)

Hope this helps.

-Walter

waltsims avatar Jul 30 '23 04:07 waltsims