How to use the pyxrf.model.guessparam.PreFitStatus 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
def create_EC_list(self, element_list):
        temp_dict = OrderedDict()
        for e in element_list:
            if e == "":
                pass
            elif '-' in e:  # pileup peaks
                e1, e2 = e.split('-')
                energy = float(get_energy(e1))+float(get_energy(e2))

                ps = PreFitStatus(z=get_Z(e),
                                  energy=str(energy), norm=1)
                temp_dict[e] = ps

            else:
                ename = e.split('_')[0]
                ps = PreFitStatus(z=get_Z(ename),
                                  energy=get_energy(e),
                                  norm=1)

                temp_dict[e] = ps
        self.EC.add_to_dict(temp_dict)
github NSLS-II / PyXRF / pyxrf / model / guessparam.py View on Github external
# add escape peak
        if param_dict['non_fitting_values']['escape_ratio'] > 0:
            pre_dict['escape'] = trim_escape_peak(self.data,
                                                  param_dict, len(self.y0))

        temp_dict = OrderedDict()
        for e in six.iterkeys(pre_dict):
            if e in ['background', 'escape']:
                spectrum = pre_dict[e]

                # summed spectrum here is not correct,
                # as the interval is assumed as 1, not energy interval
                # however area of background and escape is not used elsewhere, not important
                area = np.sum(spectrum)

                ps = PreFitStatus(z=get_Z(e), energy=get_energy(e),
                                  area=float(area), spectrum=spectrum,
                                  maxv=float(np.around(np.max(spectrum), self.max_area_dig)),
                                  norm=-1, lbd_stat=False)
                temp_dict[e] = ps

            elif '-' in e:  # pileup peaks
                e1, e2 = e.split('-')
                energy = float(get_energy(e1))+float(get_energy(e2))
                spectrum = pre_dict[e]
                area = area_dict[e]

                ps = PreFitStatus(z=get_Z(e), energy=str(energy),
                                  area=area, spectrum=spectrum,
                                  maxv=np.around(np.max(spectrum), self.max_area_dig),
                                  norm=-1, lbd_stat=False)
                temp_dict[e] = ps
github NSLS-II / PyXRF / pyxrf / model / guessparam.py View on Github external
# however area of background and escape is not used elsewhere, not important
                area = np.sum(spectrum)

                ps = PreFitStatus(z=get_Z(e), energy=get_energy(e),
                                  area=float(area), spectrum=spectrum,
                                  maxv=float(np.around(np.max(spectrum), self.max_area_dig)),
                                  norm=-1, lbd_stat=False)
                temp_dict[e] = ps

            elif '-' in e:  # pileup peaks
                e1, e2 = e.split('-')
                energy = float(get_energy(e1))+float(get_energy(e2))
                spectrum = pre_dict[e]
                area = area_dict[e]

                ps = PreFitStatus(z=get_Z(e), energy=str(energy),
                                  area=area, spectrum=spectrum,
                                  maxv=np.around(np.max(spectrum), self.max_area_dig),
                                  norm=-1, lbd_stat=False)
                temp_dict[e] = ps

            else:
                ename = e.split('_')[0]
                for k, v in six.iteritems(param_dict):
                    if ename in k and 'area' in k:
                        spectrum = pre_dict[e]
                        area = area_dict[e]

                    elif ename == 'compton' and k == 'compton_amplitude':
                        spectrum = pre_dict[e]
                        area = area_dict[e]
github NSLS-II / PyXRF / pyxrf / model / guessparam.py View on Github external
elemental_lines: list(str)
            The list of elemental lines to find. If ``None``, then all supported
            lines (K, L and M) are searched.
        """
        self.define_range()  # in case the energy calibraiton changes
        self.prefit_x, out_dict, area_dict = linear_spectrum_fitting(self.x0,
                                                                     self.y0,
                                                                     self.param_new,
                                                                     elemental_lines=elemental_lines)
        logger.info('Energy range: {}, {}'.format(
            self.param_new['non_fitting_values']['energy_bound_low']['value'],
            self.param_new['non_fitting_values']['energy_bound_high']['value']))

        prefit_dict = OrderedDict()
        for k, v in six.iteritems(out_dict):
            ps = PreFitStatus(z=get_Z(k),
                              energy=get_energy(k),
                              area=area_dict[k],
                              spectrum=v,
                              maxv=np.around(np.max(v), self.max_area_dig),
                              norm=-1,
                              lbd_stat=False)
            prefit_dict.update({k: ps})

        logger.info('Automatic Peak Finding found elements as : {}'.format(
            list(prefit_dict.keys())))
        self.EC.delete_all()
        self.EC.add_to_dict(prefit_dict)
github NSLS-II / PyXRF / pyxrf / model / guessparam.py View on Github external
default_area=default_area)

        # Check if element profile was calculated successfully.
        #   Calculation may fail if the selected line is not activated.
        #   The calculation is performed using ``xraylib` library, so there is no
        #   control over it.
        if self.e_name not in data_out:
            raise Exception(f"Failed to add the emission line '{self.e_name}': line is not activated.")

        # If model was generated successfully (the emission line was successfully added), then
        #   make temporary parameters permanent
        self.param_new = param_tmp

        ratio_v = self.add_element_intensity / np.max(data_out[self.e_name])

        ps = PreFitStatus(z=get_Z(self.e_name),
                          energy=get_energy(self.e_name),
                          area=area_dict[self.e_name]*ratio_v,
                          spectrum=data_out[self.e_name]*ratio_v,
                          maxv=self.add_element_intensity,
                          norm=-1,
                          status=True,    # for plotting
                          lbd_stat=False)

        self.EC.add_to_dict({self.e_name: ps})
github NSLS-II / PyXRF / pyxrf / model / guessparam.py View on Github external
if ename in k and 'area' in k:
                        spectrum = pre_dict[e]
                        area = area_dict[e]

                    elif ename == 'compton' and k == 'compton_amplitude':
                        spectrum = pre_dict[e]
                        area = area_dict[e]

                    elif ename == 'elastic' and k == 'coherent_sct_amplitude':
                        spectrum = pre_dict[e]
                        area = area_dict[e]

                    else:
                        continue

                    ps = PreFitStatus(z=get_Z(ename), energy=get_energy(e),
                                      area=area, spectrum=spectrum,
                                      maxv=np.around(np.max(spectrum), self.max_area_dig),
                                      norm=-1, lbd_stat=False)

                    temp_dict[e] = ps
        self.EC.add_to_dict(temp_dict)
github NSLS-II / PyXRF / pyxrf / model / guessparam.py View on Github external
if self.pileup_data['intensity'] > 0:
            e_name = self.generate_pileup_peak_name()
            # parse elemental lines into multiple lines

            x, data_out, area_dict = calculate_profile(self.x0,
                                                       self.y0,
                                                       self.param_new,
                                                       elemental_lines=[e_name],
                                                       default_area=default_area)
            energy_float = float(get_energy(self.pileup_data['element1'])) + \
                float(get_energy(self.pileup_data['element2']))
            energy = f"{energy_float:.4f}"

            ratio_v = self.pileup_data['intensity'] / np.max(data_out[e_name])

            ps = PreFitStatus(z=get_Z(e_name),
                              energy=energy,
                              area=area_dict[e_name]*ratio_v,
                              spectrum=data_out[e_name]*ratio_v,
                              maxv=self.pileup_data['intensity'],
                              norm=-1,
                              status=True,    # for plotting
                              lbd_stat=False)
            logger.info('{} peak is added'.format(e_name))
        else:
            raise Exception("Pile-up peak intensity is negative")
        self.EC.add_to_dict({e_name: ps})