How to use the pyxrf.core.utils.gaussian_fwhm_to_sigma function in pyxrf

To help you get started, we’ve selected a few pyxrf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NSLS-II / PyXRF / pyxrf / model / fit_spectrum.py View on Github external
energy_small_value = 0.001
        self.add_userpeak_energy = max(self.add_userpeak_energy, energy_small_value)
        self.add_userpeak_fwhm = max(self.add_userpeak_fwhm, energy_small_value)

        self._update_userpeak_energy()
        self._update_userpeak_fwhm()

        # Find and save the value of peak maximum. Restore the maximum after FWHM is changed.
        # Note, that ``peak_sigma`` and ``peak_area`` may change if energy changes,
        #   but ``peak_max`` must remain the same (for better visual presentation)
        peak_sigma = gaussian_fwhm_to_sigma(self.add_userpeak_fwhm_old)
        peak_area = self.param_dict[self.name_userpeak_area]["value"]
        peak_max = gaussian_area_to_max(peak_area, peak_sigma)  # Keep this value

        # Restore peak height by adjusting the area (for new fwhm)
        peak_sigma = gaussian_fwhm_to_sigma(self.add_userpeak_fwhm)
        peak_area = gaussian_max_to_area(peak_max, peak_sigma)
        self.param_dict[self.name_userpeak_area]["value"] = peak_area

        # Create copies
        self.add_userpeak_fwhm_old = self.add_userpeak_fwhm

        logger.debug(f"The parameters of the user defined peak. The new values:\n"
                     f"          Energy: {self.add_userpeak_energy} keV\n"
github NSLS-II / PyXRF / pyxrf / model / fit_spectrum.py View on Github external
# Ensure, that the values are greater than some small value to ensure that
        #   there is no computational problems.
        # Energy resolution for the existing beamlines is 0.01 keV, so 0.001 is small
        #   enough both for center energy and FWHM.
        energy_small_value = 0.001
        self.add_userpeak_energy = max(self.add_userpeak_energy, energy_small_value)
        self.add_userpeak_fwhm = max(self.add_userpeak_fwhm, energy_small_value)

        self._update_userpeak_energy()
        self._update_userpeak_fwhm()

        # Find and save the value of peak maximum. Restore the maximum after FWHM is changed.
        # Note, that ``peak_sigma`` and ``peak_area`` may change if energy changes,
        #   but ``peak_max`` must remain the same (for better visual presentation)
        peak_sigma = gaussian_fwhm_to_sigma(self.add_userpeak_fwhm_old)
        peak_area = self.param_dict[self.name_userpeak_area]["value"]
        peak_max = gaussian_area_to_max(peak_area, peak_sigma)  # Keep this value

        # Restore peak height by adjusting the area (for new fwhm)
        peak_sigma = gaussian_fwhm_to_sigma(self.add_userpeak_fwhm)
        peak_area = gaussian_max_to_area(peak_max, peak_sigma)
        self.param_dict[self.name_userpeak_area]["value"] = peak_area

        # Create copies
        self.add_userpeak_fwhm_old = self.add_userpeak_fwhm

        logger.debug(f"The parameters of the user defined peak. The new values:\n"
                     f"          Energy: {self.add_userpeak_energy} keV\n"
github NSLS-II / PyXRF / pyxrf / model / fit_spectrum.py View on Github external
def _compute_fwhm_base(self):
        # Computes 'sigma' value based on default parameters and peak energy (for Userpeaks)
        #   does not include corrections for fwhm
        # If both peak center (energy) and fwhm is updated, energy needs to be set first,
        #   since it is used in computation of ``fwhm_base``

        sigma = gaussian_fwhm_to_sigma(self.param_model.default_parameters["fwhm_offset"]["value"])

        sigma_sqr = self.param_dict[self.name_userpeak_dcenter]["value"] + 5.0  # center
        sigma_sqr *= self.param_model.default_parameters["non_fitting_values"]["epsilon"]  # epsilon
        sigma_sqr *= self.param_model.default_parameters["fwhm_fanoprime"]["value"]  # fanoprime
        sigma_sqr += sigma * sigma  # We have computed the expression under sqrt

        sigma_total = np.sqrt(sigma_sqr)

        return gaussian_sigma_to_fwhm(sigma_total)
github NSLS-II / PyXRF / pyxrf / model / fit_spectrum.py View on Github external
def _update_userpeak_fwhm(self):

        fwhm_base = self._compute_fwhm_base()
        fwhm = self.add_userpeak_fwhm - fwhm_base

        sigma = gaussian_fwhm_to_sigma(fwhm)

        v_center = self.param_dict[self.name_userpeak_dsigma]["value"]
        v_max = self.param_dict[self.name_userpeak_dsigma]["max"]
        v_min = self.param_dict[self.name_userpeak_dsigma]["min"]
        # Keep the possible range for value change the same
        self.param_dict[self.name_userpeak_dsigma]["value"] = sigma
        self.param_dict[self.name_userpeak_dsigma]["max"] = sigma + v_max - v_center
        self.param_dict[self.name_userpeak_dsigma]["min"] = sigma - (v_center - v_min)