Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homogeneous_medium_for sensor only receive signal #46

Closed
lmonsterrr opened this issue Oct 24, 2022 · 2 comments · Fixed by #174
Closed

Homogeneous_medium_for sensor only receive signal #46

lmonsterrr opened this issue Oct 24, 2022 · 2 comments · Fixed by #174

Comments

@lmonsterrr
Copy link

lmonsterrr commented Oct 24, 2022

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

@waltsims
Copy link
Owner

waltsims commented Oct 26, 2022

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants