diff --git a/pyrs/core/pyrscore.py b/pyrs/core/pyrscore.py index ad0652aab..125e26958 100644 --- a/pyrs/core/pyrscore.py +++ b/pyrs/core/pyrscore.py @@ -2,7 +2,7 @@ from pyrs.utilities import checkdatatypes from pyrs.core import instrument_geometry from pyrs.utilities import file_util -from pyrs.core import peak_fit_factory +from pyrs.peaks import PeakFitEngineFactory, SupportedPeakProfiles, SupportedBackgroundTypes from pyrs.utilities.rs_project_file import HidraConstants, HidraProjectFile, HidraProjectFileMode from pyrs.core import strain_stress_calculator from pyrs.core import reduction_manager @@ -10,9 +10,6 @@ import os import numpy -# Define Constants -SUPPORTED_PEAK_TYPES = ['PseudoVoigt', 'Gaussian', 'Voigt'] # 'Lorentzian': No a profile of HB2B - class PyRsCore(object): """ @@ -108,8 +105,7 @@ def init_peak_fit_engine(self, fit_tag): # get workspace workspace = self.reduction_service.get_hidra_workspace(fit_tag) # create a controller from factory - self._peak_fitting_dict[fit_tag] = peak_fit_factory.PeakFitEngineFactory.getInstance('Mantid')(workspace, - None) + self._peak_fitting_dict[fit_tag] = PeakFitEngineFactory.getInstance('Mantid')(workspace, None) # set wave length: TODO - #81+ - shall be a way to use calibrated or non-calibrated wave_length_dict = workspace.get_wavelength(calibrated=False, throw_if_not_set=False) if wave_length_dict is not None: @@ -154,10 +150,8 @@ def fit_peaks(self, project_name="", # Check Inputs checkdatatypes.check_dict('Peak fitting (information) parameters', peaks_fitting_setup) - checkdatatypes.check_string_variable('Peak type', peak_type, - peak_fit_factory.SupportedPeakProfiles) - checkdatatypes.check_string_variable('Background type', background_type, - peak_fit_factory.SupportedBackgroundTypes) + checkdatatypes.check_string_variable('Peak type', peak_type, SupportedPeakProfiles) + checkdatatypes.check_string_variable('Background type', background_type, SupportedBackgroundTypes) # Deal with sub runs if sub_run_list is None: @@ -647,4 +641,4 @@ def supported_peak_types(self): list of supported peaks' types for fitting :return: """ - return SUPPORTED_PEAK_TYPES[:] + return SupportedPeakProfiles[:] diff --git a/pyrs/core/summary_generator.py b/pyrs/core/summary_generator.py index 8fcc34dd8..a6747eb02 100644 --- a/pyrs/core/summary_generator.py +++ b/pyrs/core/summary_generator.py @@ -97,7 +97,7 @@ def write_csv(self, sample_logs, peak_collections, tolerance=1E-10): ---------- sample_logs: ~pyrs.dataobjects.SampleLogs peak_collections: list - list of :py:obj:`~pyrs.core.peak_collection.PeakCollection` + list of :py:obj:`~pyrs.peaks.PeakCollection` tolerance : float relative tolerance of variance to treat a sample log as a constant value and bring into extended header diff --git a/pyrs/peaks/__init__.py b/pyrs/peaks/__init__.py new file mode 100644 index 000000000..e388566e0 --- /dev/null +++ b/pyrs/peaks/__init__.py @@ -0,0 +1,7 @@ +# flake8: noqa +from __future__ import (absolute_import, division, print_function) # python3 compatibility + +from .peak_collection import * +from .peak_fit_factory import * + +__all__ = peak_collection.__all__ + peak_fit_factory.__all__ diff --git a/pyrs/core/mantid_fit_peak.py b/pyrs/peaks/mantid_fit_peak.py similarity index 97% rename from pyrs/core/mantid_fit_peak.py rename to pyrs/peaks/mantid_fit_peak.py index 2ac473b28..038507a04 100644 --- a/pyrs/core/mantid_fit_peak.py +++ b/pyrs/peaks/mantid_fit_peak.py @@ -1,17 +1,19 @@ # Peak fitting engine by calling mantid +from .peak_fit_engine import PeakFitEngine from pyrs.core import mantid_helper +from pyrs.core.peak_profile_utility import Gaussian, PseudoVoigt from pyrs.utilities import checkdatatypes -from pyrs.core import peak_fit_engine -from pyrs.core.peak_collection import PeakCollection +from pyrs.peaks import PeakCollection import numpy as np from mantid.api import AnalysisDataService from mantid.simpleapi import CreateWorkspace, FitPeaks +__all__ = ['MantidPeakFitEngine'] DEBUG = False # Flag for debugging mode -class MantidPeakFitEngine(peak_fit_engine.PeakFitEngine): +class MantidPeakFitEngine(PeakFitEngine): """ peak fitting engine class for mantid """ @@ -34,8 +36,6 @@ def __init__(self, workspace, mask_name): self._fitted_function_error_table = None # fitted function parameters' fitting error table workspace self._model_matrix_ws = None # MatrixWorkspace of the model from fitted function parameters - return - def _create_peak_center_ws(self, peak_center): """ Create peak center workspace :param peak_center: float or numpy array @@ -110,38 +110,36 @@ def _set_default_peak_params_value(self, peak_function_name, peak_range): parameter names (native), parameter values (as a list in str) """ - from peak_profile_utility import Gaussian, PseudoVoigt - # Specify instrument resolution for both Gaussian and FWHM hidra_fwhm = 0.5 # Estimate estimated_heights, flat_bkgds = self.estimate_peak_height(peak_range) max_estimated_height = estimated_heights.max() - flat_bkgd = flat_bkgds[np.argmax(estimated_heights)] + # do not pass A0 to FitPeaks # Make the difference between peak profiles if peak_function_name == 'Gaussian': # Gaussian - peak_param_names = '{}, {}'.format('Height', 'Sigma', 'A0') + peak_param_names = '{}, {}'.format('Height', 'Sigma') # sigma instrument_sigma = Gaussian.cal_sigma(hidra_fwhm) # set value - peak_param_values = "{}, {}".format(max_estimated_height, instrument_sigma, flat_bkgd) + peak_param_values = "{}, {}".format(max_estimated_height, instrument_sigma) elif peak_function_name == 'PseudoVoigt': # Pseudo-voig default_mixing = 0.6 - peak_param_names = '{}, {}, {}'.format('Mixing', 'Intensity', 'FWHM', 'A0') + peak_param_names = '{}, {}, {}'.format('Mixing', 'Intensity', 'FWHM') # intensity max_intensity = PseudoVoigt.cal_intensity(max_estimated_height, hidra_fwhm, default_mixing) # set values - peak_param_values = "{}, {}, {}".format(default_mixing, max_intensity, hidra_fwhm, flat_bkgds) + peak_param_values = "{}, {}, {}".format(default_mixing, max_intensity, hidra_fwhm) else: # Non-supported case @@ -322,7 +320,7 @@ def fit_multiple_peaks(self, sub_run_range, peak_function_name, background_funct Returns ------- Dict - dictionary of ~pyrs.core.peak_collection.PeakCollection with peak tag as key + dictionary of ~pyrs.peaks.PeakCollection with peak tag as key """ peak_collection_dict = dict() @@ -362,7 +360,7 @@ def _set_profile_parameters_values_from_fitting(self, peak_tag, sub_runs, peak_p Returns ------- - ~pyrs.core.peak_collecton.PeakCollection + ~pyrs.peaks.PeakCollection Fitted peak's information """ diff --git a/pyrs/core/peak_collection.py b/pyrs/peaks/peak_collection.py similarity index 99% rename from pyrs/core/peak_collection.py rename to pyrs/peaks/peak_collection.py index dbb401dc3..ac2a0f5df 100644 --- a/pyrs/core/peak_collection.py +++ b/pyrs/peaks/peak_collection.py @@ -5,6 +5,8 @@ from pyrs.utilities import checkdatatypes from pyrs.core.peak_profile_utility import get_effective_parameters_converter, PeakShape, BackgroundFunction +__all__ = ['PeakCollection'] + class PeakCollection(object): """ diff --git a/pyrs/core/peak_fit_engine.py b/pyrs/peaks/peak_fit_engine.py similarity index 99% rename from pyrs/core/peak_fit_engine.py rename to pyrs/peaks/peak_fit_engine.py index fb182687f..d155e6116 100644 --- a/pyrs/core/peak_fit_engine.py +++ b/pyrs/peaks/peak_fit_engine.py @@ -6,6 +6,8 @@ from pyrs.core.peak_profile_utility import PeakShape from pyrs.utilities import checkdatatypes +__all__ = ['PeakFitEngine'] + class PeakFitEngine(object): """ @@ -247,7 +249,7 @@ def fit_multiple_peaks(self, sub_run_range, peak_function_name, background_funct Returns ------- - List of ~pyrs.core.peak_collection.PeakCollection + List of ~pyrs.peaks.PeakCollection """ raise NotImplementedError('Virtual base class member method fit_multiple_peaks') @@ -346,7 +348,7 @@ def get_peaks(self, peak_tag): Returns ------- - pyrs.core.peak_collection.PeakCollection + pyrs.peaks.PeakCollection Collection of peak information """ diff --git a/pyrs/core/peak_fit_factory.py b/pyrs/peaks/peak_fit_factory.py similarity index 60% rename from pyrs/core/peak_fit_factory.py rename to pyrs/peaks/peak_fit_factory.py index ba11bd861..d35ae443e 100644 --- a/pyrs/core/peak_fit_factory.py +++ b/pyrs/peaks/peak_fit_factory.py @@ -1,27 +1,27 @@ # Peak fitting engine -from pyrs.core import mantid_fit_peak from pyrs.utilities import checkdatatypes SupportedPeakProfiles = ['Gaussian', 'PseudoVoigt', 'Voigt'] SupportedBackgroundTypes = ['Flat', 'Linear', 'Quadratic'] +__all__ = ['PeakFitEngineFactory', 'SupportedPeakProfiles', 'SupportedBackgroundTypes'] + class PeakFitEngineFactory(object): """ Peak fitting engine factory """ @staticmethod - def getInstance(engine_name): + def getInstance(name): """ Get instance of Peak fitting engine - :param engine_name: - :return: """ - checkdatatypes.check_string_variable('Peak fitting engine', engine_name, ['Mantid', 'PyRS']) + checkdatatypes.check_string_variable('Peak fitting engine', name, ['Mantid', 'PyRS']) + + # this must be here for now to stop circular imports + from .mantid_fit_peak import MantidPeakFitEngine - if engine_name == 'Mantid': - engine_class = mantid_fit_peak.MantidPeakFitEngine + if name == 'Mantid': + return MantidPeakFitEngine else: raise RuntimeError('Implement general scipy peak fitting engine') - - return engine_class diff --git a/pyrs/core/scipypeakfitengine.py b/pyrs/peaks/scipypeakfitengine.py similarity index 96% rename from pyrs/core/scipypeakfitengine.py rename to pyrs/peaks/scipypeakfitengine.py index a9a882155..b5991537e 100644 --- a/pyrs/core/scipypeakfitengine.py +++ b/pyrs/peaks/scipypeakfitengine.py @@ -1,201 +1,205 @@ -from pyrs.core.peak_fit_engine import PeakFitEngine -from scipy.optimize import leastsq -import numpy as np -from pyrs.utilities import checkdatatypes - - -class ScipyPeakFitEngine(PeakFitEngine): - """peak fitting engine class for mantid - - Peak fitting engine by calling mantid - Set up the testing environment for PyVDrive commands - - """ - - def __init__(self, data_set_list, ref_id): - """ - initialization - :param data_set_list: - :param ref_id: - :param - """ - self.fitted_ws = None - - super(ScipyPeakFitEngine, self).__init__(data_set_list, ref_id) - - return - - @staticmethod - def calculate_peak(X, Data, TTH, peak_function_name, background_function_name, ReturnModel=False): - """ static method to calculate peak - :param X: - :param Data: - :param TTH: - :param peak_function_name: - :param background_function_name: - :param ReturnModel: - :return: - """ - checkdatatypes.check_string_variable('Peak profile function', peak_function_name) - - model_y = np.zeros_like(Data) - - if peak_function_name == 'Lorentzian': - # Lorentzian - x0 = X[0] - N = X[1] - f = X[2] - model_y += N * 2. / np.pi * 1 / f * 1 / (1 + 4 * (TTH - x0) ** 2 / f ** 2) - - elif peak_function_name == 'Gaussian': - # Gaussian - x0 = X[0] - N = X[1] - f = X[2] - model_y += N * 2. * np.sqrt(np.log(2) / np.pi) * 1 / f * np.exp(-np.log(2) * 4 * (TTH - x0) ** 2 / f ** 2) - - elif peak_function_name == 'PseudoVoigt': - x0 = X[0] - N = X[1] - f = X[2] - w = X[3] - model_y += N * (1. - w) * 2. / np.pi * 1 / f * 1 / (1 + 4 * (TTH - x0) ** 2 / f ** 2) + N * ( - w) * 2. * np.sqrt(np.log(2) / np.pi) * 1 / f * np.exp(-np.log(2) * 4 * (TTH - x0) ** 2 / f ** 2) - - if background_function_name == 'Linear': - model_y += X[-2:][0] * TTH + X[-2:][1] - elif background_function_name == 'Quadratic': - model_y += X[-3:][0] * TTH * TTH + X[-3:][1] * TTH + X[-3:][2] - - if ReturnModel: - return [TTH, model_y] - else: - return Data - model_y - - def fit_peaks(self, peak_function_name, background_function_name, scan_index=None): - """ - fit peaks - :param peak_function_name: - :param background_function_name: - :param scan_index: - :return: - """ - checkdatatypes.check_string_variable('Peak function name', peak_function_name) - checkdatatypes.check_string_variable('Background function name', background_function_name) - - M = [] - - # for i in range(self._data_workspace[2]): - for i in range(self._num_data_set): - Data = self._data_set[i].vec_x # self._data_workspace[1][i] - TTH = self._data_set[i].vec_y # self._data_workspace[0][i] - - MaxIndex = np.where(np.max(Data) == Data)[0][0] - - Pos = TTH[MaxIndex] - LL = np.where((Pos - 1.) < TTH)[0][0] - UL = np.where((Pos + 1.) > TTH)[0][-1:][0] - IA = np.sum(Data[LL:UL]) * (TTH[1] - TTH[0]) - f = IA / Data[MaxIndex] - if peak_function_name == 'PseudoVoigt': - x0 = [Pos, IA, f, 0.99] - else: - x0 = [Pos, IA, f] - - if background_function_name.split(' ')[0] == 'Linear': - x0.append(0) - x0.append(Data[0]) - else: - x0.append(0) - x0.append(0) - x0.append(Data[0]) - - result = leastsq(self.calculate_peak, x0, - args=(Data, TTH, peak_function_name, background_function_name.split(' ')[0]), - full_output=True, ftol=1.e-15, xtol=1.e-15) - - M.append(result[0]) - - M = np.array(M) - print('M is of shape {}'.format(M.shape)) - - # process output - # TODO FIXME - pandas is disabled due to deployment conflict with numpy for Python2.7 - # Develop another data structure to replace pandas.DataFrame! - # create pandas data frame - # self.peak_pos_ws = M[:, 0] - # if peak_function_name == 'PseudoVoigt': - # self.func_param_ws = pd.DataFrame( - # data={'PeakCentre': M[:, 0], 'Height': M[:, 1], 'FWHM': M[:, 2], 'Mixing': M[:, 3]}) - # elif peak_function_name == 'Lorentzian': - # self.func_param_ws = pd.DataFrame( - # data={'PeakCentre': M[:, 0], 'Amplitude': M[:, 1], 'FWHM': M[:, 2], 'chi2': 0}) - # else: - # self.func_param_ws = pd.DataFrame( - # data={'PeakCentre': M[:, 0].T, 'Height': M[:, 1], 'Sigma': M[:, 2] / 2.3548, 'chi2': 0}) - - # calculate patterns - CalcPatts = [] - for log_index in range(self._data_workspace[2]): - CalcPatts.append(self.calculate_peak(M[log_index, :], self._data_workspace[1][log_index], - self._data_workspace[0] - [log_index], - peak_function_name, background_function_name.split(' ')[0], - ReturnModel=True)) - - self.fitted_ws = np.array(CalcPatts) - - print('[DB...BAT] function parameters keys: {}'.format(self.func_param_ws.keys)) - - return - - def calculate_fitted_peaks(self, scan_index): - """ - get the calculated peak's value - :param scan_index: - :return: - """ - # TODO - vec_x = self.fitted_ws[scan_index][0].T - vec_y = self.fitted_ws[scan_index][1].T - - return vec_x, vec_y - - def get_function_parameter_names(self): - """ - get function parameters' names - :return: - """ - return self.func_param_ws.keys() - - def get_number_scans(self): - """ - get number of scans in input data to fit - :return: - """ -# if self._data_workspace is None: -# raise RuntimeError('No data is set up!') -# -# return self._data_workspace.getNumberHistograms() - - return self._data_workspace[2] - - def get_fitted_params(self, param_name): - """ - - :return: - """ -# col_names = self.func_param_ws.getColumnNames() -# if param_name in col_names: -# col_index = col_names.index(param_name) -# else: -# raise RuntimeError('Function parameter {0} does not exist.'.format(param_name)) -# -# param_vec = np.ndarray(shape=(self._data_workspace[2]), dtype='float') -# for row_index in range(self._data_workspace[2]): -# print self.func_param_ws[param_name] -# print self.func_param_ws[param_name][row_index][0] - -# param_vec[row_index] = self.func_param_ws[param_name][row_index][0] - - return self.func_param_ws[param_name].values +from .peak_fit_engine import PeakFitEngine +from scipy.optimize import leastsq +import numpy as np +from pyrs.utilities import checkdatatypes + +__all__ = ['ScipyPeakFitEngine'] + + +class ScipyPeakFitEngine(PeakFitEngine): + """peak fitting engine class for mantid + + Peak fitting engine by calling mantid + Set up the testing environment for PyVDrive commands + + """ + + def __init__(self, data_set_list, ref_id): + """ + initialization + :param data_set_list: + :param ref_id: + :param + """ + self.fitted_ws = None + + super(ScipyPeakFitEngine, self).__init__(data_set_list, ref_id) + + return + + @staticmethod + def calculate_peak(X, Data, TTH, peak_function_name, background_function_name, ReturnModel=False): + """ static method to calculate peak + :param X: + :param Data: + :param TTH: + :param peak_function_name: + :param background_function_name: + :param ReturnModel: + :return: + """ + checkdatatypes.check_string_variable('Peak profile function', peak_function_name) + + model_y = np.zeros_like(Data) + + if peak_function_name == 'Lorentzian': + # Lorentzian + x0 = X[0] + N = X[1] + f = X[2] + model_y += N * 2. / np.pi * 1 / f * 1 / (1 + 4 * (TTH - x0) ** 2 / f ** 2) + + elif peak_function_name == 'Gaussian': + # Gaussian + x0 = X[0] + N = X[1] + f = X[2] + model_y += N * 2. * np.sqrt(np.log(2) / np.pi) * 1 / f * np.exp(-np.log(2) * 4 * (TTH - x0) ** 2 / f ** 2) + + elif peak_function_name == 'PseudoVoigt': + x0 = X[0] + N = X[1] + f = X[2] + w = X[3] + model_y += N * (1. - w) * 2. / np.pi * 1 / f * 1 / (1 + 4 * (TTH - x0) ** 2 / f ** 2) + N * ( + w) * 2. * np.sqrt(np.log(2) / np.pi) * 1 / f * np.exp(-np.log(2) * 4 * (TTH - x0) ** 2 / f ** 2) + + if background_function_name == 'Linear': + model_y += X[-2:][0] * TTH + X[-2:][1] + elif background_function_name == 'Quadratic': + model_y += X[-3:][0] * TTH * TTH + X[-3:][1] * TTH + X[-3:][2] + + if ReturnModel: + return [TTH, model_y] + else: + return Data - model_y + + # TODO signature doesn't match base class + def fit_peaks(self, peak_function_name, background_function_name, scan_index=None): + """ + fit peaks + :param peak_function_name: + :param background_function_name: + :param scan_index: + :return: + """ + checkdatatypes.check_string_variable('Peak function name', peak_function_name) + checkdatatypes.check_string_variable('Background function name', background_function_name) + + M = [] + + # for i in range(self._data_workspace[2]): + for i in range(self._num_data_set): + Data = self._data_set[i].vec_x # self._data_workspace[1][i] + TTH = self._data_set[i].vec_y # self._data_workspace[0][i] + + MaxIndex = np.where(np.max(Data) == Data)[0][0] + + Pos = TTH[MaxIndex] + LL = np.where((Pos - 1.) < TTH)[0][0] + UL = np.where((Pos + 1.) > TTH)[0][-1:][0] + IA = np.sum(Data[LL:UL]) * (TTH[1] - TTH[0]) + f = IA / Data[MaxIndex] + if peak_function_name == 'PseudoVoigt': + x0 = [Pos, IA, f, 0.99] + else: + x0 = [Pos, IA, f] + + if background_function_name.split(' ')[0] == 'Linear': + x0.append(0) + x0.append(Data[0]) + else: + x0.append(0) + x0.append(0) + x0.append(Data[0]) + + result = leastsq(self.calculate_peak, x0, + args=(Data, TTH, peak_function_name, background_function_name.split(' ')[0]), + full_output=True, ftol=1.e-15, xtol=1.e-15) + + M.append(result[0]) + + M = np.array(M) + print('M is of shape {}'.format(M.shape)) + + # process output + # TODO FIXME - pandas is disabled due to deployment conflict with numpy for Python2.7 + # Develop another data structure to replace pandas.DataFrame! + # create pandas data frame + # self.peak_pos_ws = M[:, 0] + # if peak_function_name == 'PseudoVoigt': + # self.func_param_ws = pd.DataFrame( + # data={'PeakCentre': M[:, 0], 'Height': M[:, 1], 'FWHM': M[:, 2], 'Mixing': M[:, 3]}) + # elif peak_function_name == 'Lorentzian': + # self.func_param_ws = pd.DataFrame( + # data={'PeakCentre': M[:, 0], 'Amplitude': M[:, 1], 'FWHM': M[:, 2], 'chi2': 0}) + # else: + # self.func_param_ws = pd.DataFrame( + # data={'PeakCentre': M[:, 0].T, 'Height': M[:, 1], 'Sigma': M[:, 2] / 2.3548, 'chi2': 0}) + + # calculate patterns + CalcPatts = [] + for log_index in range(self._data_workspace[2]): + CalcPatts.append(self.calculate_peak(M[log_index, :], self._data_workspace[1][log_index], + self._data_workspace[0] + [log_index], + peak_function_name, background_function_name.split(' ')[0], + ReturnModel=True)) + + self.fitted_ws = np.array(CalcPatts) + + print('[DB...BAT] function parameters keys: {}'.format(self.func_param_ws.keys)) + + return + + # TODO arguments don't match base class + def calculate_fitted_peaks(self, scan_index): + """ + get the calculated peak's value + :param scan_index: + :return: + """ + # TODO + vec_x = self.fitted_ws[scan_index][0].T + vec_y = self.fitted_ws[scan_index][1].T + + return vec_x, vec_y + + def get_function_parameter_names(self): + """ + get function parameters' names + :return: + """ + return self.func_param_ws.keys() + + def get_number_scans(self): + """ + get number of scans in input data to fit + :return: + """ +# if self._data_workspace is None: +# raise RuntimeError('No data is set up!') +# +# return self._data_workspace.getNumberHistograms() + + return self._data_workspace[2] + + def get_fitted_params(self, param_name): + """ + + :return: + """ +# col_names = self.func_param_ws.getColumnNames() +# if param_name in col_names: +# col_index = col_names.index(param_name) +# else: +# raise RuntimeError('Function parameter {0} does not exist.'.format(param_name)) +# +# param_vec = np.ndarray(shape=(self._data_workspace[2]), dtype='float') +# for row_index in range(self._data_workspace[2]): +# print self.func_param_ws[param_name] +# print self.func_param_ws[param_name][row_index][0] + +# param_vec[row_index] = self.func_param_ws[param_name][row_index][0] + + return self.func_param_ws[param_name].values diff --git a/pyrs/utilities/rs_project_file.py b/pyrs/utilities/rs_project_file.py index 849f80ad2..904a4918c 100644 --- a/pyrs/utilities/rs_project_file.py +++ b/pyrs/utilities/rs_project_file.py @@ -6,7 +6,7 @@ import os from pyrs.utilities import checkdatatypes from pyrs.core.instrument_geometry import AnglerCameraDetectorGeometry, HidraSetup -from pyrs.core.peak_collection import PeakCollection +from pyrs.peaks import PeakCollection from pyrs.dataobjects import SampleLogs diff --git a/tests/integration/test_peak_fitting.py b/tests/integration/test_peak_fitting.py index 3554f9fa8..95662f45b 100644 --- a/tests/integration/test_peak_fitting.py +++ b/tests/integration/test_peak_fitting.py @@ -2,12 +2,12 @@ # Test class and methods implemented for peak fitting import numpy from pyrs.core import pyrscore -from pyrs.core.peak_collection import PeakCollection +from pyrs.peaks import PeakCollection from pyrs.core.peak_profile_utility import PeakShape, BackgroundFunction from pyrs.core.summary_generator import SummaryGenerator from pyrs.dataobjects import SampleLogs from pyrs.utilities.rs_project_file import HidraProjectFile -from pyrs.core import peak_fit_factory +from pyrs.peaks import PeakFitEngineFactory import h5py from pyrs.core import peak_profile_utility from matplotlib import pyplot as plt @@ -225,7 +225,7 @@ def test_retrieve_fit_metadata(source_project_file, output_project_file, peak_ty # Set peak fitting engine # create a controller from factory - fit_engine = peak_fit_factory.PeakFitEngineFactory.getInstance('Mantid')(hd_ws, None) + fit_engine = PeakFitEngineFactory.getInstance('Mantid')(hd_ws, None) # Fit peak fit_engine.fit_multiple_peaks(sub_run_range=(None, None), # default is all sub runs @@ -348,7 +348,7 @@ def test_improve_quality(): # Set peak fitting engine # create a controller from factory - fit_engine = peak_fit_factory.PeakFitEngineFactory.getInstance('Mantid')(hd_ws, None) + fit_engine = PeakFitEngineFactory.getInstance('Mantid')(hd_ws, None) peak_type = 'Gaussian' diff --git a/tests/unit/test_hidra_project_file.py b/tests/unit/test_hidra_project_file.py index edcd03e84..4b20dd615 100644 --- a/tests/unit/test_hidra_project_file.py +++ b/tests/unit/test_hidra_project_file.py @@ -6,7 +6,7 @@ import numpy as np import datetime from pyrs.core import peak_profile_utility -from pyrs.core.peak_collection import PeakCollection +from pyrs.peaks import PeakCollection import pytest diff --git a/tests/unit/test_peak_fit_engine.py b/tests/unit/test_peak_fit_engine.py index 5e2425d05..3fb8faf27 100644 --- a/tests/unit/test_peak_fit_engine.py +++ b/tests/unit/test_peak_fit_engine.py @@ -1,5 +1,5 @@ import numpy as np -from pyrs.core.mantid_fit_peak import MantidPeakFitEngine +from pyrs.peaks import PeakFitEngineFactory from pyrs.core.workspaces import HidraWorkspace from pyrs.core.peak_profile_utility import pseudo_voigt, PeakShape, BackgroundFunction from pyrs.core.peak_profile_utility import Gaussian, PseudoVoigt @@ -230,7 +230,7 @@ def test_1_gaussian_1_subrun(): # Generate test workspace and initialize fit engine gaussian_workspace = generate_hydra_workspace_single_subrun('Gaussian', min_x, max_x, num_x, [peak_center], [peak_range], [10.]) - fit_engine = MantidPeakFitEngine(gaussian_workspace, mask_name=None) + fit_engine = PeakFitEngineFactory.getInstance('Mantid')(gaussian_workspace, mask_name=None) # Fit m_tag = 'UnitTestGaussian' @@ -292,7 +292,7 @@ def test_2_gaussian_1_subrun(): # Generate test workspace and initialize fit engine gaussian_workspace = generate_hydra_workspace_single_subrun('Gaussian', min_x, max_x, num_x, peak_centers, peak_ranges, peak_intensities) - fit_engine = MantidPeakFitEngine(gaussian_workspace, mask_name=None) + fit_engine = PeakFitEngineFactory.getInstance('Mantid')(gaussian_workspace, mask_name=None) # Fit fit_engine.fit_multiple_peaks(sub_run_range=(1, 1), @@ -390,7 +390,7 @@ def test_2_gaussian_3_subruns(): test_hd_ws = generate_hydra_workspace_multiple_sub_runs('3 G 3 S', test_2g_dict) # Fit - fit_engine = MantidPeakFitEngine(test_hd_ws, mask_name=None) + fit_engine = PeakFitEngineFactory.getInstance('Mantid')(test_hd_ws, mask_name=None) fit_engine.fit_multiple_peaks(sub_run_range=(1, 3), peak_function_name='Gaussian', background_function_name='Linear', @@ -500,7 +500,7 @@ def test_3_gaussian_3_subruns(): test_hd_ws = generate_hydra_workspace_multiple_sub_runs('3 G 3 S', test_2g_dict) # Fit - fit_engine = MantidPeakFitEngine(test_hd_ws, mask_name=None) + fit_engine = PeakFitEngineFactory.getInstance('Mantid')(test_hd_ws, mask_name=None) fit_engine.fit_multiple_peaks(sub_run_range=(1, 3), peak_function_name='Gaussian', background_function_name='Linear', @@ -550,7 +550,7 @@ def test_1_pv_1_subrun(): pv_workspace = generate_hydra_workspace_single_subrun('PseudoVoigt', min_x, max_x, num_x, [peak_center], [peak_range], [100.]) - fit_engine = MantidPeakFitEngine(pv_workspace, mask_name=None) + fit_engine = PeakFitEngineFactory.getInstance('Mantid')(pv_workspace, mask_name=None) # Fit peak_tag = 'UnitTestPseudoVoigt'