Commit 0683623c authored by Somnath, Suhas's avatar Somnath, Suhas
Browse files

Bug fixes to BE SHO guess and visualization

parent 3afd6f67
......@@ -232,7 +232,7 @@ class BESHOmodel(Model):
# ask super to take care of the rest, which is a standardized operation
super(BESHOmodel, self)._setResults(is_guess)
def computeGuess(self, strategy='wavelet_peaks', options={"peak_widths": np.array([10,200])}, **kwargs):
def computeGuess(self, strategy='wavelet_peaks', options={'peak_widths': np.array([50, 150]), 'peak_step':20}, **kwargs):
'''
Parameters
......@@ -245,7 +245,7 @@ class BESHOmodel(Model):
-------
'''
super(BESHOmodel, self).computeGuess(strategy=strategy, **options)
super(BESHOmodel, self).computeGuess(strategy=strategy, options=options)
def _reformatResults(self, results, strategy='wavelet_peaks', verbose=False):
"""
......@@ -264,11 +264,13 @@ class BESHOmodel(Model):
# peak_inds = np.array([pixel[0] for pixel in results])
peak_inds = np.zeros(shape=(len(results)), dtype=np.uint32)
for pix_ind, pixel in enumerate(results):
try:
if len(pixel) == 1: # majority of cases - one peak found
peak_inds[pix_ind] = pixel[0]
except IndexError:
pass # don't bother if it was empty. it will be set to 0 anyway
elif len(pixel) == 0: # no peak found
peak_inds[pix_ind] = int(0.5*self.data.shape[1]) # set to center of band
else: # more than one peak found
dist = np.abs(np.array(pixel) - int(0.5*self.data.shape[1]))
peak_inds[pix_ind] = pixel[np.argmin(dist)] # set to peak closest to center of band
if verbose: print('Peak positions of shape {}'.format(peak_inds.shape))
# First get the value (from the raw data) at these positions:
comp_vals = np.array(
......@@ -278,7 +280,7 @@ class BESHOmodel(Model):
sho_vec['Phase [rad]'] = np.angle(comp_vals) # Phase in radians
sho_vec['Frequency [Hz]'] = self.freq_vec[peak_inds] # Frequency
sho_vec['Quality Factor'] = np.ones_like(results) * 10 # Quality factor
# Add something here for the R^2
return sho_vec
......
......@@ -39,8 +39,10 @@ class GuessMethods(object):
# vector = args
try:
peakwidth_bounds = kwargs.get('peak_widths')
wavelet_widths = np.linspace(peakwidth_bounds[0],peakwidth_bounds[1],20)
kwargs.pop('peak_widths')
peak_width_step = kwargs.get('peak_step', 20)
kwargs.pop('peak_step')
wavelet_widths = np.linspace(peakwidth_bounds[0],peakwidth_bounds[1],peak_width_step)
def wpeaks(vector):
peakIndices = find_peaks_cwt(np.abs(vector), wavelet_widths,**kwargs)
return peakIndices
......
......@@ -1096,7 +1096,7 @@ def visualizeSHOResults(h5_main, save_plots=True, show_plots=True):
if meas_type == 'AC modulation mode with time reversal':
center = int(h5_spec_vals.shape[1] * 0.5)
ac_vec = h5_spec_vals[h5_spec_vals.attrs['AC_Amplitude']][0:center]
ac_vec = np.squeeze(h5_spec_vals[h5_spec_vals.attrs['AC_Amplitude']][0:center])
forw_resp = np.squeeze(amp_mat[:, slice(0, center)])
plt_title = grp_name + '_Forward_Loops'
if save_plots:
......@@ -1119,7 +1119,7 @@ def visualizeSHOResults(h5_main, save_plots=True, show_plots=True):
save_path=plt_path)
else:
# plot loops at a few locations
dc_vec = h5_spec_vals[h5_spec_vals.attrs['DC_Offset']]
dc_vec = np.squeeze(h5_spec_vals[h5_spec_vals.attrs['DC_Offset']])
if chan_grp.parent.attrs['VS_measure_in_field_loops'] == 'in and out-of-field':
in_phase = np.squeeze(phase_mat[:, slice(0, None, 2)])
......
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