Commit c7511900 authored by syz's avatar syz
Browse files

moved plot_1d_spectrum and plot_2d_spectrogram to be_viz_utils

parent cf4d7d29
......@@ -22,7 +22,8 @@ from ...io_utils import getAvailableMem, recommendCores
from ...microdata import MicroDataset, MicroDataGroup
from ....analysis.optimize import Optimize
from ....processing.proc_utils import buildHistogram
from ....viz.plot_utils import plot_1d_spectrum, plot_2d_spectrogram, plot_histgrams
from ....viz.plot_utils import plot_histgrams
from ....viz.be_viz_utils import plot_1d_spectrum, plot_2d_spectrogram
nf32 = np.dtype({'names': ['super_band', 'inter_bin_band', 'sub_band'],
'formats': [np.float32, np.float32, np.float32]})
......
......@@ -15,7 +15,7 @@ from IPython.display import display
from matplotlib import pyplot as plt
from .plot_utils import plot_loops, plot_map_stack, get_cmap_object, plot_map, save_fig_filebox_button, \
set_tick_font_size
set_tick_font_size, plot_complex_loop_stack, plot_complex_map_stack
from ..analysis.utils.be_loop import loop_fit_function
from ..analysis.utils.be_sho import SHOfunc
from ..io.hdf_utils import reshape_to_Ndims, getAuxData, get_sort_order, get_dimensionality, get_attr, \
......@@ -1414,3 +1414,71 @@ def _add_loop_parameters(axes, switching_coef_vec):
ax.axhline(switching_coef_vec[pos]['R-'], c='r', ls='-.', label='R-')
return axes
def plot_1d_spectrum(data_vec, freq, title, **kwargs):
"""
Plots the Step averaged BE response
Parameters
------------
data_vec : 1D numpy array
Response of one BE pulse
freq : 1D numpy array
BE frequency that serves as the X axis of the plot
title : String
Plot group name
Returns
---------
fig : Matplotlib.pyplot figure
Figure handle
axes : Matplotlib.pyplot axis
Axis handle
"""
if len(data_vec) != len(freq):
raise ValueError('Incompatible data sizes! spectrum: '
+ str(len(data_vec)) + ', frequency: ' + str(freq.shape))
freq *= 1E-3 # to kHz
title = title + ': mean UDVS, mean spatial response'
fig, axes = plot_complex_loop_stack(np.expand_dims(data_vec, axis=0), freq, title=title,
subtitle_prefix='', num_comps=1, x_label='Frequency (kHz)',
figsize=(5, 3), amp_units='V', **kwargs)
return fig, axes
def plot_2d_spectrogram(mean_spectrogram, freq, title=None, **kwargs):
"""
Plots the position averaged spectrogram
Parameters
------------
mean_spectrogram : 2D numpy complex array
Means spectrogram arranged as [frequency, UDVS step]
freq : 1D numpy float array
BE frequency that serves as the X axes of the plot
title : str, optional
Plot group name
Returns
---------
fig : Matplotlib.pyplot figure
Figure handle
axes : Matplotlib.pyplot axes
Axis handle
"""
if mean_spectrogram.shape[1] != freq.size:
if mean_spectrogram.shape[0] == freq.size:
mean_spectrogram = mean_spectrogram.T
else:
raise ValueError('plot_2d_spectrogram: Incompatible data sizes!!!! spectrogram: '
+ str(mean_spectrogram.shape) + ', frequency: ' + str(freq.shape))
freq *= 1E-3 # to kHz
fig, axes = plot_complex_map_stack(np.expand_dims(mean_spectrogram, axis=0), num_comps=1, title=title,
x_label='Frequency (kHz)', y_label='UDVS step', subtitle_prefix='',
extent=[freq[0], freq[-1], 0, mean_spectrogram.shape[0]],
figsize=(5, 3), origin='lower', stdevs=None, amp_units='V',
**kwargs)
return fig, axes
\ No newline at end of file
......@@ -9,18 +9,20 @@ Created on Thu May 05 13:29:12 2016
from __future__ import division, print_function, absolute_import, unicode_literals
import inspect
from warnings import warn
import os
import sys
from warnings import warn
import h5py
import ipywidgets as widgets
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy
from scipy.signal import blackman
import ipywidgets as widgets
from matplotlib.colors import LinearSegmentedColormap
from mpl_toolkits.axes_grid1 import ImageGrid
from scipy.signal import blackman
from ..io.hdf_utils import reshape_to_Ndims, get_formatted_labels, get_data_descriptor
# mpl.rcParams.keys() # gets all allowable keys
......@@ -1271,76 +1273,6 @@ def plot_cluster_dendrogram(label_mat, e_vals, num_comp, num_cluster, mode='Full
return fig
def plot_1d_spectrum(data_vec, freq, title, **kwargs):
"""
Plots the Step averaged BE response
Parameters
------------
data_vec : 1D numpy array
Response of one BE pulse
freq : 1D numpy array
BE frequency that serves as the X axis of the plot
title : String
Plot group name
Returns
---------
fig : Matplotlib.pyplot figure
Figure handle
axes : Matplotlib.pyplot axis
Axis handle
"""
if len(data_vec) != len(freq):
raise ValueError('Incompatible data sizes! spectrum: '
+ str(len(data_vec)) + ', frequency: ' + str(freq.shape))
freq *= 1E-3 # to kHz
title = title + ': mean UDVS, mean spatial response'
fig, axes = plot_complex_loop_stack(np.expand_dims(data_vec, axis=0), freq, title=title,
subtitle_prefix='', num_comps=1, x_label='Frequency (kHz)',
figsize=(5, 3), amp_units='V', **kwargs)
return fig, axes
###############################################################################
def plot_2d_spectrogram(mean_spectrogram, freq, title=None, **kwargs):
"""
Plots the position averaged spectrogram
Parameters
------------
mean_spectrogram : 2D numpy complex array
Means spectrogram arranged as [frequency, UDVS step]
freq : 1D numpy float array
BE frequency that serves as the X axes of the plot
title : str, optional
Plot group name
Returns
---------
fig : Matplotlib.pyplot figure
Figure handle
axes : Matplotlib.pyplot axes
Axis handle
"""
if mean_spectrogram.shape[1] != freq.size:
if mean_spectrogram.shape[0] == freq.size:
mean_spectrogram = mean_spectrogram.T
else:
raise ValueError('plot_2d_spectrogram: Incompatible data sizes!!!! spectrogram: '
+ str(mean_spectrogram.shape) + ', frequency: ' + str(freq.shape))
freq *= 1E-3 # to kHz
fig, axes = plot_complex_map_stack(np.expand_dims(mean_spectrogram, axis=0), num_comps=1, title=title,
x_label='Frequency (kHz)', y_label='UDVS step', subtitle_prefix='',
extent=[freq[0], freq[-1], 0, mean_spectrogram.shape[0]],
figsize=(5, 3), origin='lower', stdevs=None, amp_units='V',
**kwargs)
return fig, axes
###############################################################################
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment