Commit 693e3bf7 authored by CompPhysChris's avatar CompPhysChris Committed by GitHub
Browse files

Merge pull request #62 from pycroscopy/cnms_dev

Cnms dev
parents e97c2d77 16f3c570
......@@ -115,29 +115,64 @@ class BELoopModel(Model):
return super(BELoopModel, self)._isLegal(h5_main, variables)
def simulate_script(self):
# def simulate_script(self):
#
# self._create_projection_datasets()
# max_pos, sho_spec_inds_per_forc, metrics_spec_inds_per_forc = self._get_sho_chunk_sizes(10, verbose=True)
#
# # turn this into a loop
# forc_chunk_index = 0
# pos_chunk_index = 0
#
# dc_vec, loops_2d, nd_mat_shape_dc_first, order_dc_offset_reverse = self._get_projection_data(
# forc_chunk_index, max_pos, metrics_spec_inds_per_forc, pos_chunk_index, sho_spec_inds_per_forc)
#
# # step 8: perform loop unfolding
# projected_loops_2d, loop_metrics_1d = self._project_loop_batch(dc_vec, np.transpose(loops_2d))
# print('Finished projecting all loops')
# print 'Projected loops of shape:', projected_loops_2d.shape, ', need to bring to:', nd_mat_shape_dc_first
# print 'Loop metrics of shape:', loop_metrics_1d.shape, ', need to bring to:', nd_mat_shape_dc_first[1:]
#
# # test the reshapes back
# projected_loops_2d = self._reshape_projected_loops_for_h5(projected_loops_2d,
# order_dc_offset_reverse,
# nd_mat_shape_dc_first)
# metrics_2d, success = self._reshape_results_for_h5(loop_metrics_1d, nd_mat_shape_dc_first)
def _set_guess(self, h5_guess):
"""
Setup to run the fit on an existing guess dataset. Sets the attributes
normally defined during doGuess.
self._create_projection_datasets()
max_pos, sho_spec_inds_per_forc, metrics_spec_inds_per_forc = self._get_sho_chunk_sizes(10, verbose=True)
Parameters
----------
h5_guess : h5py.Dataset
Dataset object containing the guesses
# turn this into a loop
forc_chunk_index = 0
pos_chunk_index = 0
"""
'''
Get the Spectroscopic and Position datasets from `self.h5_main`
'''
self._sho_spec_inds = getAuxData(self.h5_main, auxDataName=['Spectroscopic_Indices'])[0]
self._sho_spec_vals = getAuxData(self.h5_main, auxDataName=['Spectroscopic_Values'])[0]
self._sho_pos_inds = getAuxData(self.h5_main, auxDataName=['Position_Indices'])[0]
dc_vec, loops_2d, nd_mat_shape_dc_first, order_dc_offset_reverse = self._get_projection_data(
forc_chunk_index, max_pos, metrics_spec_inds_per_forc, pos_chunk_index, sho_spec_inds_per_forc)
'''
Find the Spectroscopic index for the DC_Offset
'''
dc_ind = np.argwhere(self._sho_spec_vals.attrs['labels'] == 'DC_Offset').squeeze()
self._dc_spec_index = dc_ind
self._dc_offset_index = 1 + dc_ind
# step 8: perform loop unfolding
projected_loops_2d, loop_metrics_1d = self._project_loop_batch(dc_vec, np.transpose(loops_2d))
print('Finished projecting all loops')
print 'Projected loops of shape:', projected_loops_2d.shape, ', need to bring to:', nd_mat_shape_dc_first
print 'Loop metrics of shape:', loop_metrics_1d.shape, ', need to bring to:', nd_mat_shape_dc_first[1:]
'''
Get the group and projection datasets
'''
self._h5_group = h5_guess.parent
self.h5_projected_loops = self._h5_group['Projected_Loops']
self.h5_loop_metrics = self._h5_group['Loop_Metrics']
self._met_spec_inds = self._h5_group['Loop_Metrics_Indices']
# test the reshapes back
projected_loops_2d = self._reshape_projected_loops_for_h5(projected_loops_2d,
order_dc_offset_reverse,
nd_mat_shape_dc_first)
metrics_2d, success = self._reshape_results_for_h5(loop_metrics_1d, nd_mat_shape_dc_first)
self.h5_guess = h5_guess
def doGuess(self, max_mem=None, processors=None, verbose=False, get_loop_parameters=True):
"""
......@@ -145,7 +180,8 @@ class BELoopModel(Model):
Parameters
----------
processors : uint, optional
Number of processors to use for computing. Currently this is a serial operation
Number of processors to use for computing. Currently this is a serial operation and this attribute is
ignored.
Default None, output of psutil.cpu_count - 2 is used
max_mem : uint, optional
Memory in MB to use for computation
......@@ -224,7 +260,7 @@ class BELoopModel(Model):
def doFit(self, processors=None, max_mem=None, solver_type='least_squares', solver_options={'jac': '2-point'},
obj_func={'class': 'BE_Fit_Methods', 'obj_func': 'BE_LOOP', 'xvals': np.array([])},
get_loop_parameters=True):
get_loop_parameters=True, h5_guess=None):
"""
Fit the loops
......@@ -246,15 +282,15 @@ class BELoopModel(Model):
get_loop_parameters : bool, optional
Should the physical loop parameters be calculated after the guess is done
Default True
h5_guess : h5py.Dataset
Existing guess to use as input to fit.
Default None
Returns
-------
results: list
List of the results returned by the solver
"""
if self.h5_guess is None:
print("You need to guess before fitting\n")
return None
if processors is None:
processors = self._maxCpus
else:
......@@ -263,6 +299,12 @@ class BELoopModel(Model):
if max_mem is None:
max_mem = self._maxDataChunk
if h5_guess is not None:
self._set_guess(h5_guess)
elif self.h5_guess is None:
print("You need to guess before fitting\n")
return None
self._createFitDataset()
self._get_sho_chunk_sizes(max_mem, verbose=True)
......
......@@ -141,7 +141,6 @@ class BESHOmodel(Model):
'''
copyAttributes(self.h5_guess, self.h5_fit, skip_refs=False)
def _getFrequencyVector(self):
"""
Assumes that the data is reshape-able
......@@ -231,13 +230,38 @@ class BESHOmodel(Model):
# ask super to take care of the rest, which is a standardized operation
super(BESHOmodel, self)._setResults(is_guess)
def _set_guess(self, h5_guess):
"""
Setup to run the fit on an existing guess dataset. Sets the attributes
normally defined during doGuess.
Parameters
----------
h5_guess : h5py.Dataset
Dataset object containing the guesses
"""
h5_spec_inds = getAuxData(self.h5_main, auxDataName=['Spectroscopic_Indices'])[0]
self.step_start_inds = np.where(h5_spec_inds[0] == 0)[0]
self.num_udvs_steps = len(self.step_start_inds)
# find the frequency vector and hold in memory
self._getFrequencyVector()
self.is_reshapable = isReshapable(self.h5_main, self.step_start_inds)
self.h5_guess = h5_guess
def doGuess(self, processors=None, strategy='complex_gaussian',
options={"peak_widths": np.array([10,200]),"peak_step":20}):
options={"peak_widths": np.array([10, 200]), "peak_step": 20}):
"""
Parameters
----------
data
processors: int
Number of processors to use during parallel guess
Default None, output of psutil.cpu_count - 2 is used
strategy: string
Default is 'Wavelet_Peaks'.
Can be one of ['wavelet_peaks', 'relative_maximum', 'gaussian_processes']. For updated list, run GuessMethods.methods
......@@ -245,10 +269,6 @@ class BESHOmodel(Model):
Default Options for wavelet_peaks{"peaks_widths": np.array([10,200]), "peak_step":20}.
Dictionary of options passed to strategy. For more info see GuessMethods documentation.
kwargs:
processors: int
number of processors to use. Default all processors on the system except for 1.
Returns
-------
......@@ -265,23 +285,25 @@ class BESHOmodel(Model):
options = {'frequencies': freq_vec}
super(BESHOmodel, self).doGuess(processors=processors, strategy=strategy, options=options)
def doFit(self, processors=None, solver_type='least_squares',solver_options={'jac':'cs'},
obj_func={'class': 'Fit_Methods', 'obj_func': 'SHO', 'xvals': np.array([])}):
def doFit(self, processors=None, solver_type='least_squares', solver_options={'jac':'cs'},
obj_func={'class': 'Fit_Methods', 'obj_func': 'SHO', 'xvals': np.array([])},
h5_guess=None):
"""
Parameters
----------
processors: int
Default is 1.
processors : int
Number of processors to use.
strategy: string
Default None, output of psutil.cpu_count - 2 is used
strategy : string
Default is 'Wavelet_Peaks'.
Can be one of ['wavelet_peaks', 'relative_maximum', 'gaussian_processes']. For updated list, run GuessMethods.methods
options: dict
options : dict
Default {"peaks_widths": np.array([10,200])}}.
Dictionary of options passed to strategy. For more info see GuessMethods documentation.
h5_guess : h5py.Dataset
Existing guess to use as input to fit.
Default None
Returns
-------
......@@ -292,11 +314,15 @@ class BESHOmodel(Model):
else:
processors = min(processors, self._maxCpus)
if h5_guess is not None:
self._set_guess(h5_guess)
self._createFitDatasets()
self._start_pos = 0
xvals = self.freq_vec
results = super(BESHOmodel, self).doFit(processors=processors, solver_type=solver_type, solver_options=solver_options,
obj_func={'class':'Fit_Methods','obj_func':'SHO', 'xvals':xvals})
results = super(BESHOmodel, self).doFit(processors=processors, solver_type=solver_type,
solver_options=solver_options,
obj_func={'class': 'Fit_Methods', 'obj_func': 'SHO', 'xvals': xvals})
return results
def _reformatResults(self, results, strategy='wavelet_peaks', verbose=False):
......
......@@ -29,7 +29,7 @@ class BEPSndfTranslator(Translator):
"""
Translates Band Excitation Polarization Switching (BEPS) datasets from .dat
files to .h5
"""
def translate(self, data_filepath, show_plots=True, save_plots=True, do_histogram=False, debug=False):
......@@ -202,7 +202,7 @@ class BEPSndfTranslator(Translator):
self.ds_pixel_start_indx = pixel_ind
h5_refs = self.__initialize_meas_group(self.max_pixels - pixel_ind, current_pixels)
# print('reading Pixel {} of {}'.format(pixel_ind,self.max_pixels))
print('reading Pixel {} of {}'.format(pixel_ind,self.max_pixels))
self.__append_pixel_data(current_pixels)
prev_pixels = current_pixels
......@@ -497,13 +497,15 @@ class BEPSndfTranslator(Translator):
if self.__num_wave_types__ == 1 and not self.halve_udvs_steps:
"""Technically, this will be taken care of in the later (general) part but
since this condition is more common it is worth writing for specifically"""
data_vec = pixel_data[self.__unique_waves__[0]].spectrogram_vec
noise_mat = np.float32(pixel_data[self.__unique_waves__[0]].noise_floor_mat)
zero_pix = self.__unique_waves__[0]
data_vec = pixel_data[zero_pix].spectrogram_vec
noise_mat = np.float32(pixel_data[zero_pix].noise_floor_mat)
# Storing a list of lists since we don't know how many pixels we will find in this measurement group
self.pos_vals_list.append([pixel_data[0].x_value, pixel_data[0].y_value,
pixel_data[0].z_value])
self.pos_vals_list.append([pixel_data[zero_pix].x_value, pixel_data[zero_pix].y_value,
pixel_data[zero_pix].z_value])
else:
......@@ -959,7 +961,8 @@ class BEPSndfPixel(object):
data_vec : 1D float numpy array
Data contained within each pixel
harm: unsigned int
Harmonic of the BE waveform. absolute value of the wave type used to normalize the response waveform.
Harmonic of the BE waveform. absolute value of the wave type used to normalize the response waveform.
"""
harm = abs(harm)
......@@ -1066,20 +1069,20 @@ class BEPSndfPixel(object):
Notes
-----
*Typical things that change during BEPS*
1. BE parameters:
a. Center Frequency, Band Width - changes in the BE_bin_w
b. Amplitude, Phase Variation, Band Edge Smoothing, Band Edge Trim - Harder to find out what happened exactly
- FFT should show changes
c. BE repeats, desired duration - changes in the spectrogram length?
2. VS Parameters:
a. Amplitude, Phase shift - Changes in the AC_amp_vec / DC offset
b. Offset, Read voltage - Shows up in the DC offset
c. Steps per full Cycle - Changes in DC offset / AC amplitude ....
d. Number of cycles, Cycle fraction, In and out of field - changes in the length of DC offset etc.
e. FORC - should all show up in DC / AC amplitude
3. IO parameters : don't change really
4. grid parameters : cannot do anything about this.
*Typical things that change during BEPS*
1. BE parameters:
a. Center Frequency, Band Width - changes in the BE_bin_w
b. Amplitude, Phase Variation, Band Edge Smoothing, Band Edge Trim - Harder to find out what happened
exactly - FFT should show changes
c. BE repeats, desired duration - changes in the spectrogram length?
2. VS Parameters:
a. Amplitude, Phase shift - Changes in the AC_amp_vec / DC offset
b. Offset, Read voltage - Shows up in the DC offset
c. Steps per full Cycle - Changes in DC offset / AC amplitude ....
d. Number of cycles, Cycle fraction, In and out of field - changes in the length of DC offset etc.
e. FORC - should all show up in DC / AC amplitude
3. IO parameters : don't change really
4. grid parameters : cannot do anything about this.
"""
disp_on = True
......
Supports Markdown
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