def assert_checks(fit_result, exp_params, obs_params, number_of_peakCollection, peak_profile_type=PeakShape.GAUSSIAN): """verified the fitted parameters Parameters ---------- fit_result: object results of the fitting exp_params: dict(float) parameters of original shape obs_params:List(float) parameter values of fitting number_of_peakCollection:Integer number of fitted peaks peak_profile_type : str type of peak profile Returns ------- """ assert len(fit_result.peakcollections) == number_of_peakCollection, 'Only one PeakCollection' assert fit_result.fitted assert fit_result.difference peak_profile_type = PeakShape.getShape(peak_profile_type) if peak_profile_type == PeakShape.GAUSSIAN: np.testing.assert_allclose(obs_params['PeakCentre'], exp_params['peak_center'], rtol=50.) # np.testing.assert_allclose(obs_params['Intensity'], exp_params['peak_intensity'], rtol=50.) # np.testing.assert_allclose(obs_params['FWHM'], exp_params['peak_FWHM'], rtol=50.) elif peak_profile_type == PeakShape.PSEUDOVOIGT: np.testing.assert_allclose(obs_params['Intensity'], exp_params['peak_intensity'], rtol=50.) np.testing.assert_allclose(obs_params['PeakCentre'], exp_params['peak_center'], rtol=50.) np.testing.assert_allclose(obs_params['FWHM'], exp_params['peak_FWHM'], rtol=50.)
def __init__(self, peak_tag, peak_profile, background_type, wavelength=np.nan, d_reference=np.nan): """Initialization Parameters ---------- peak_tag : str tag for the peak such as 'Si111' peak_profile : str Peak profile background_type : str Background type """ # Init variables from input self._tag = peak_tag # Init other parameters self._peak_profile = PeakShape.getShape(peak_profile) self._background_type = BackgroundFunction.getFunction(background_type) self._wavelength = wavelength self._d_reference = d_reference # sub run numbers: 1D array self._sub_run_array = SubRuns() # parameter values: numpy structured array self._params_value_array = None # parameter fitting error: numpy structured array self._params_error_array = None # fitting cost (chi2): numpy 1D array self._fit_cost_array = None # status messages: list of strings self._fit_status = None
def check_peak_shape_enum(peak_shape, num_native_params): """check peak shape enum Parameters ---------- peak_shape : str Peak shape num_native_params : integer number of native parameters Returns ------- """ assert PeakShape.getShape(peak_shape) == PeakShape[peak_shape.upper()] assert PeakShape.getShape( peak_shape.upper()) == PeakShape[peak_shape.upper()] with pytest.raises(KeyError): PeakShape.getShape('non-existant-peak-shape') assert len( PeakShape.getShape(peak_shape).native_parameters) == num_native_params
def __init__(self, peak_tag: str, peak_profile, background_type, wavelength: float = np.nan, d_reference: Union[float, np.ndarray] = np.nan, d_reference_error: Union[float, np.ndarray] = 0., projectfilename: str = '', runnumber: int = -1) -> None: """Initialization Parameters ---------- peak_tag : str tag for the peak such as 'Si111' peak_profile : str Peak profile background_type : str Background type """ # Init variables from input self._tag = peak_tag self._filename: str = '' self.projectfilename = projectfilename # use the setter self._runnumber: int = runnumber # Init other parameters self._peak_profile = PeakShape.getShape(peak_profile) self._background_type = BackgroundFunction.getFunction(background_type) self._wavelength = wavelength # sub run numbers: 1D array self._sub_run_array = SubRuns() # parameter values: numpy structured array self._params_value_array = None # parameter fitting error: numpy structured array self._params_error_array = None # fitting cost (chi2): numpy 1D array self._fit_cost_array = None # status messages: list of strings self._fit_status = None # must happen after the sub_run array is set self._d_reference: Optional[unumpy.uarray] self.set_d_reference(d_reference, d_reference_error)
def __init__(self, hidraworkspace, peak_function_name, background_function_name, wavelength, out_of_plane_angle): '''It is not expected that any subclass will need to implement this method. It is designed to unpack all of the information necessary for fitting.''' # configure logging for this class self._log = Logger(__name__) if out_of_plane_angle: # TODO variable should go into creating the mantid workspace raise NotImplementedError( 'Do not currently support out_of_plane_angle') # TODO generate_mantid_workspace should not use `mask_id` self._mtd_wksp = mantid_helper.generate_mantid_workspace( hidraworkspace, hidraworkspace.name, None) self._subruns = hidraworkspace.get_sub_runs() # create a self._peak_function = PeakShape.getShape(peak_function_name) self._background_function = BackgroundFunction.getFunction( background_function_name) self._wavelength = wavelength