[docs]classkSensor:""" Sensor class for k-Wave simulations. """
[docs]def__init__(self,mask=None,record=None):""" Initialize a kSensor object. Args: mask: Binary matrix or a set of Cartesian points where the pressure is recorded at each time-step record: List of parameters to record (e.g., ["p", "p_final"]) """self._mask=maskself.record=record# cell array of the acoustic parameters to record in the form Recorderself._record_start_index=1# Directivity of the individual sensor pointsself.directivity=None# two element array specifying the center frequency and percentage bandwidth# of a frequency domain Gaussian filter applied to the sensor_dataself.frequency_response=None# DEPRECATED: Will be removed in v0.5self._time_reversal_boundary_data=None
@propertydefmask(self):""" Binary matrix or a set of Cartesian points where the pressure is recorded at each time-step """returnself._mask@mask.setterdefmask(self,val):self._mask=val
[docs]defexpand_grid(self,expand_size)->None:""" Enlarge the sensor mask (for Cartesian sensor masks and cuboid corners, this has already been converted to a binary mask for display in inputChecking) Args: expand_size: the number of elements to add in each dimension Returns: None """self.mask=expand_matrix(self.mask,expand_size,0)
@propertydefrecord_start_index(self):""" Time index to start recording if transducer is used as a sensor """returnself._record_start_index@record_start_index.setterdefrecord_start_index(self,val):# force the user index to be an integerself._record_start_index=int(round(val))@property@deprecated(version="0.4.1",reason="Use TimeReversal class instead")deftime_reversal_boundary_data(self):returnself._time_reversal_boundary_data@time_reversal_boundary_data.setter@deprecated(version="0.4.1",reason="Use TimeReversal class instead")deftime_reversal_boundary_data(self,value):self._time_reversal_boundary_data=value
[docs]@dataclassclasskSensorDirectivity(object):#: matrix of directivity angles (direction of maximum#: response) for each sensor element defined in#: sensor.mask. The angles are in radians where 0 = max#: sensitivity in x direction (up/down) and pi/2 or -pi/2#: = max sensitivity in y direction (left/right)angle:np.ndarray=None#: string defining the directivity pattern, valid inputs#: are 'pressure' (spatial averaging over the sensor#: surface equivalent to a sinc function) and 'gradient'pattern:str="pressure"#: equivalent element size (the larger the element size the more directional the response)size:float=None#: list of the unique directivity anglesunique_angles:np.ndarray=None#: It is precomputed to allow data casting, as kgrid.kx (etc) are computed on the fly.wavenumbers:np.ndarray=None
[docs]defset_default_size(self,kgrid)->None:""" Set the element size based on the kGrid Args: kgrid: Instance of `~kwave.kgrid.kWaveGrid` class Returns: None """DEFAULT_SIZE=10self.size=DEFAULT_SIZE*max(kgrid.dx,kgrid.dy)
[docs]defset_unique_angles(self,sensor_mask)->None:""" Assign unique_angles from sensor_mask Args: sensor_mask: Returns: None """self.unique_angles=np.unique(self.angle[sensor_mask==1])
[docs]defset_wavenumbers(self,kgrid)->None:""" Assign the wavenumber vectors Args: kgrid: Instance of `~kwave.kgrid.kWaveGrid` class Returns: None """self.wavenumbers=np.vstack([kgrid.ky.T,kgrid.kx.T])