How to use the pyxrf.core.utils.gaussian_sigma_to_fwhm 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
The function should be called right after adding a userpeak to update the fields
        for userpeak energy and fwhm. Uses data for the currently selected Userpeak
        (the peak should be selected at the time of creation!!!)
        """
        if (self.name_userpeak_dcenter not in self.param_dict) or \
                (self.name_userpeak_dsigma not in self.param_dict):
            return
        # Set energy
        v_center = self.param_dict[self.name_userpeak_dcenter]["value"]
        v_energy = v_center + 5.0
        v_energy = round(v_energy, 3)
        self.add_userpeak_energy = v_energy
        # Set fwhm
        fwhm_base = self._compute_fwhm_base()
        v_dsigma = self.param_dict[self.name_userpeak_dsigma]["value"]
        v_dfwhm = gaussian_sigma_to_fwhm(v_dsigma)
        v_fwhm = v_dfwhm + fwhm_base
        v_fwhm = round(v_fwhm, 5)
        self.add_userpeak_fwhm = v_fwhm
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
names = [name for name in self.elementinfo_list if "_area" in name]
                if names:
                    self.name_userpeak_area = names[0]
                else:
                    self.name_userpeak_area = ""

                if self.name_userpeak_dcenter and self.name_userpeak_dsigma:
                    # Userpeak always has energy of 5.0 keV, the user can set only the offset
                    #   This is the internal representation, but we must display and let the user
                    #   enter the true value of energy
                    self.add_userpeak_energy = \
                        self.param_dict[self.name_userpeak_dcenter]["value"] + 5.0
                    # Same with FWHM for the user defined peak.
                    #   Also, sigma must be converted to FWHM: FWHM = 2.355 * sigma
                    self.add_userpeak_fwhm = \
                        gaussian_sigma_to_fwhm(self.param_dict[self.name_userpeak_dsigma]["value"]) + \
                        self._compute_fwhm_base()

                    # Create copies (before rounding)
                    self.add_userpeak_fwhm_old = self.add_userpeak_fwhm

                    # Adjust formatting (5 digits after dot is sufficient)
                    self.add_userpeak_energy = float(f"{self.add_userpeak_energy:.5f}")
                    self.add_userpeak_fwhm = float(f"{self.add_userpeak_fwhm:.5f}")

        else:
            raise Exception(f"Line '{eline_name}' is not in the list of selected element lines.")