MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / _manual_input

Method _manual_input

pyxrf/model/parameters.py:626–702  ·  view source on GitHub ↗

Manually add an emission line (or peak). Parameters ---------- userpeak_center: float Center of the user defined peak. Ignored if emission line other than 'userpeak' is added

(self, userpeak_center=2.5)

Source from the content-addressed store, hash-verified

624 _remove_element_from_list(eline, self.param_new)
625
626 def _manual_input(self, userpeak_center=2.5):
627 """
628 Manually add an emission line (or peak).
629
630 Parameters
631 ----------
632 userpeak_center: float
633 Center of the user defined peak. Ignored if emission line other
634 than 'userpeak' is added
635 """
636
637 if self.e_name in self.EC.element_dict:
638 msg = f"Line '{self.e_name}' is in the list of selected lines. \nDuplicate entries are not allowed."
639 raise RuntimeError(msg)
640
641 default_area = 1e2
642
643 # Add the new data entry to the parameter dictionary. This operation is necessary for 'userpeak'
644 # lines, because they need to be placed to the specific position (by setting 'delta_center'
645 # parameter, while regular element lines are placed to their default positions.
646 d_energy = userpeak_center - 5.0
647
648 # PC.params will contain a deepcopy of 'self.param_new' with the new line added
649 PC = ParamController(self.param_new, [self.e_name])
650
651 if self.get_eline_name_category(self.e_name) == "userpeak":
652 energy = userpeak_center
653 # Default values for 'delta_center'
654 dc = copy.deepcopy(PC.params[f"{self.e_name}_delta_center"])
655 # Modify the default values in the dictionary of parameters
656 PC.params[f"{self.e_name}_delta_center"]["value"] = d_energy
657 PC.params[f"{self.e_name}_delta_center"]["min"] = d_energy - (dc["value"] - dc["min"])
658 PC.params[f"{self.e_name}_delta_center"]["max"] = d_energy + (dc["max"] - dc["value"])
659 elif self.get_eline_name_category(self.e_name) == "pileup":
660 energy = self.get_pileup_peak_energy(self.e_name)
661 else:
662 energy = get_energy(self.e_name)
663
664 param_tmp = PC.params
665 param_tmp = create_full_dict(param_tmp, fit_strategy_list)
666
667 # Add name to the name list
668 _add_element_to_list(self.e_name, param_tmp)
669
670 # 'self.param_new' is used to provide 'hint' values for the model, but all active
671 # emission lines in 'elemental_lines' will be included in the model.
672 # The model will contain lines in 'elemental_lines', Compton and elastic
673 x, data_out, area_dict = calculate_profile(
674 self.x0, self.y0, param_tmp, elemental_lines=[self.e_name], default_area=default_area
675 )
676
677 # Check if element profile was calculated successfully.
678 # Calculation may fail if the selected line is not activated.
679 # The calculation is performed using ``xraylib` library, so there is no
680 # control over it.
681 if self.e_name not in data_out:
682 raise Exception(f"Failed to add the emission line '{self.e_name}': line is not activated.")
683

Callers 1

add_peak_manualMethod · 0.95

Calls 10

get_energyFunction · 0.85
create_full_dictFunction · 0.85
_add_element_to_listFunction · 0.85
calculate_profileFunction · 0.85
PreFitStatusClass · 0.85
get_ZFunction · 0.85
add_to_dictMethod · 0.80
update_peak_ratioMethod · 0.80

Tested by

no test coverage detected