def beam_pattern_heatmap(self, save_fig=False): ''' Plot heatmap of Array Response including all Frequency and Azimuth Angle infomation ''' title = '{}_{}'.format('Beampattern_Heatmap', self.beam_label) if save_fig: fig_name = self._set_fig_name(title) else: fig_name = None freq = np.linspace(8000, 1, num=800, endpoint=True) response_matrix = np.zeros( (len(freq), len(constants.get('angle_range')))) for index, f in enumerate(freq): response_matrix[index:] = self.beam_pattern(f) #plot xticks = np.arange(0, len(constants.get('angle_range')), 60) yticks = np.arange(0, 900, 100) xticklabels = np.arange( 0, len(constants.get('angle_range')), 60, dtype=int) / 2.0 yticklabels = np.linspace(8, 0, num=9, endpoint=True, dtype=int) plot = Plot() plot.append_axes() plot.plot_heatmap(response_matrix) plot.set_pipeline(title=title, xticks=xticks, yticks=yticks, xticklabels=[int(tick) for tick in xticklabels], yticklabels=yticklabels, xlabel='Azimuth Angle[Deg]', ylabel='Freq[kHz]', fig_name=fig_name)
def beam_pattern_cartesian_multi_freq(self, save_fig=False): ''' Plot Array Response including several Frequencies and Azimuth Angle infomation ''' title = '{}_{}'.format('Beampattern_CartersianMultiFreq', self.beam_label) if save_fig: fig_name = self._set_fig_name(title) else: fig_name = None #frequency to plot freq_range = constants.get('freq_range_small') angle_range = np.degrees(constants.get('angle_range')) y_lim_lower = [] plot = Plot() plot.append_axes() for freq in freq_range: response_freq = self.beam_pattern(freq) y_lim_lower.append(np.min(response_freq)) plot.plot_vector(response_freq, angle_range, label='{} kHz'.format(freq / 1000)) y_lim_lower = np.maximum(-70, np.min(y_lim_lower)) plot.set_pipeline(title=title, ylim=(y_lim_lower, 1), xlim=(0, 180), legend='lower right', xlabel='Azimuth Angle[Deg]', ylabel='Beampattern[dB]', fig_name=fig_name)
def __frequency_fixed_noise_improvement_performance( self, wng_or_df, save_fig=True): ''' Only for frequency domain or beamforming performace for directivity and white noise gain case : draw directivity or white noise gain in only one figure Parameter --------- wng_or_df: string White Noise Gain or Directivity ''' freq_range = constants.get('freq_range_large') plot = Plot(figsize=(8, 6)) plot.append_axes() axis_limit_max = [] axis_limit_min = [] for beam_index, beam in enumerate(self._beamforming_list): gain_array = np.zeros_like(freq_range, dtype=np.float32) for freq_index, freq in enumerate(freq_range): if wng_or_df == 'White Noise Gain': gain_array[freq_index] = beam[ 'beam_instance'].white_noise_gain(freq) elif wng_or_df == 'Directivity': gain_array[freq_index] = beam['beam_instance'].directivity( freq) else: raise ValueError('Please check DF or WNG are allowed') axis_limit_max.append(np.max(gain_array)) axis_limit_min.append(np.min(gain_array)) plot.plot_vector(gain_array, freq_range, label=beam['beam_instance'].beam_label) if save_fig: fig_name = self.fig_name(wng_or_df) else: fig_name = None beamforming_dict = self._beamforming_list[0] title = '{wng_or_df} for {domain}Domain {dtype}Beamforming'.format( wng_or_df=wng_or_df, domain=(beamforming_dict.get('beam_domain')).capitalize(), dtype=(beamforming_dict.get('beam_type')).capitalize()) plot.set_pipeline(title=title, xlim=(0, 8000), ylim=(np.min(axis_limit_min) - 1, np.max(axis_limit_max) + 1), xlabel='Freq[Hz]', ylabel='dB', legend='lower right', fig_name=fig_name)
def beam_pattern_cartesian(self, save_fig=False): title = '{}_{}'.format('Beampattern_Cartesian', self.beam_label) if save_fig: fig_name = self._set_fig_name(title) else: fig_name = None response = self.beam_pattern() plot = Plot() plot.append_axes() plot.plot_vector(response, np.degrees(constants.get('angle_range'))) plot.set_pipeline(xlim=(0, 180), ylim=(np.min(response) - 1, np.max(response) + 1), title=title, xlabel='Azimuth Angle[Deg]', ylabel='Beampattern[dB]', fig_name=fig_name)
def _array_gain_freq_response(self, wng_or_df, plot=True, save_fig=False): ''' plot array gain agaist freq Parameters ---------- wng_or_df: string Directivity: draw directivity agaist frequency White_Noise_Gain: draw white_noise_gain agaist frequency ''' freq_range = constants.get('freq_range_large') array_gain = np.zeros_like(freq_range, dtype=np.float64) for freq_index, freq in enumerate(freq_range): if wng_or_df == 'White_Noise_Gain': array_gain[freq_index] = self.white_noise_gain(freq) elif wng_or_df == 'Directivity': array_gain[freq_index] = self.directivity(freq) if plot: title = '{}_{}'.format(wng_or_df, self.beam_label) if save_fig: fig_name = self._set_fig_name(title) else: fig_name = None # title = '{}_{}'.format(wng_or_df, self.title_tmp) # fig_name = os.path.join(self.pic_path ,'{}.png'.format(title)) plot = Plot() plot.append_axes() plot.plot_vector(array_gain, freq_range) plot.set_pipeline( title=title, xlabel='Freq[Hz]', ylabel=wng_or_df, xlim=[0, np.max(freq_range)], ylim=[np.min(array_gain) - 5, np.max(array_gain) + 5], fig_name=fig_name) return None return array_gain
def beam_pattern_polar(self, f, save_fig=False): title = '{}_{}_f_{}'.format('Beampattern_Polar', self.beam_label, f) if save_fig: fig_name = self._set_fig_name(title) else: fig_name = None response = self.beam_pattern(f) #expand to pi to 2*pi, when plot polar sweep_angle = np.concatenate((constants.get('angle_range'), (constants.get('angle_range') + np.pi)), axis=0) response = np.concatenate((response, np.fliplr([response])[0]), axis=0) plot = Plot() plot.append_axes(polar=True) plot.plot_vector(response, sweep_angle) plot.set_pipeline(xlim=(0, 2 * np.pi), ylim=(-50, np.max(response) + 1), title=title, xlabel='Azimuth Angle[Deg]', fig_name=fig_name)