Coverage for kwave/reconstruction/tools.py: 19%

36 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-24 11:55 -0700

1import numpy as np 

2from uff import Position 

3 

4 

5def log_compression(signal, cf, normalize=False): 

6 """ 

7 Log compress an input signal. 

8 

9 Args: 

10 signal: signal to be log compressed 

11 cf: compression factor 

12 normalize (bool): when true, signal is normalized before compression 

13 

14 Returns: signal: log-compressed signal 

15 """ 

16 if normalize: 

17 ms = max(signal) 

18 signal = ms * (np.log10(1 + cf * signal / ms) / np.log10(1 + cf)) 

19 else: 

20 signal = np.log10(1 + cf * signal) / np.log10(1 + cf) 

21 return signal 

22 

23 

24def apodize(distance, aperture, window): 

25 """ 

26 Function that assigns different apodization to a set of pixels and elements 

27 

28 To avoid the indetermination when both distance and aperture tend to 0 

29 """ 

30 

31 

32 if window == 'none': 

33 apod = np.ones(np.size(distance)) 

34 elif window == 'boxcar': 

35 apod = np.double(distance <= aperture / 2.0) 

36 elif window == 'hanning': 

37 apod = np.double(distance <= aperture / 2) * (0.5 + 0.5 * np.cos(2 * np.pi * distance / aperture)) 

38 elif window == 'hamming': 

39 apod = np.double(distance <= aperture) / 2 * (0.53836 + 0.46164 * np.cos(2 * np.pi * distance / aperture)) 

40 elif window == 'tukey25': 

41 roll = 0.25 

42 apod = (distance < (aperture / 2 * (1 - roll))) + (distance > (aperture / 2 * (1 - roll))) * ( 

43 distance < (aperture / 2)) * 0.5 * (1 + np.cos(2 * np.pi / roll * (distance / aperture - roll / 2 - 1 / 2))) 

44 elif window == 'tukey50': 

45 roll = 0.5 

46 apod = (distance < (aperture / 2 * (1 - roll))) + (distance > (aperture / 2 * (1 - roll))) * ( 

47 distance < (aperture / 2)) * 0.5 * (1 + np.cos(2 * np.pi / roll * (distance / aperture - roll / 2 - 1 / 2))) 

48 elif window == 'tukey75': 

49 roll = 0.75 

50 apod = (distance < (aperture / 2 * (1 - roll))) + (distance > (aperture / 2 * (1 - roll))) * ( 

51 distance < (aperture / 2)) * 0.5 * (1 + np.cos(2 * np.pi / roll * (distance / aperture - roll / 2 - 1 / 2))) 

52 else: 

53 raise ValueError('Unknown window type. Known types are: boxcar, hamming, hanning, tukey25, tukey50, tukey75.') 

54 

55 return apod 

56 

57 

58def get_t0(transmit_wave): 

59 serialized_tx_wave = transmit_wave.time_zero_reference_point.serialize() 

60 return np.array(Position.deserialize(serialized_tx_wave)) 

61 

62 

63def get_origin_array(channel_data, transmit_wave): 

64 serialized_origin = channel_data.unique_waves[transmit_wave.wave - 1].origin.position.serialize() 

65 return np.array( 

66 Position.deserialize(serialized_origin)) 

67 

68 

69def make_time_vector(num_samples, sampling_freq, time_offset): 

70 return np.linspace(start=0, num=num_samples, 

71 stop=num_samples / sampling_freq) + time_offset