comparison larch_lcf.py @ 1:6c28339b73f7 draft

planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
author muon-spectroscopy-computational-project
date Wed, 06 Dec 2023 13:04:01 +0000
parents f59731986b61
children c2d5bfef5b63
comparison
equal deleted inserted replaced
0:f59731986b61 1:6c28339b73f7
11 11
12 12
13 def plot( 13 def plot(
14 group_to_fit: Group, 14 group_to_fit: Group,
15 fit_group: Group, 15 fit_group: Group,
16 energy_min: float, 16 x_limit_min: float,
17 energy_max: float, 17 x_limit_max: float,
18 ): 18 ):
19 formatted_label = "" 19 formatted_label = ""
20 for label, weight in fit_group.weights.items(): 20 for label, weight in fit_group.weights.items():
21 formatted_label += f"{label}: {weight:.3%}\n" 21 formatted_label += f"{label}: {weight:.3%}\n"
22 22
35 linewidth=2, 35 linewidth=2,
36 color="orange", 36 color="orange",
37 linestyle="--", 37 linestyle="--",
38 ) 38 )
39 plt.grid(color="black", linestyle=":", linewidth=1) # show and format grid 39 plt.grid(color="black", linestyle=":", linewidth=1) # show and format grid
40 plt.xlim(energy_min, energy_max) 40 plt.xlim(x_limit_min, x_limit_max)
41 plt.xlabel("Energy (eV)") 41 plt.xlabel("Energy (eV)")
42 plt.ylabel("normalised x$\mu$(E)") # noqa: W605 42 plt.ylabel("normalised x$\mu$(E)") # noqa: W605
43 plt.legend() 43 plt.legend()
44 plt.savefig("plot.png", format="png") 44 plt.savefig("plot.png", format="png")
45 plt.close("all") 45 plt.close("all")
65 for component in input_values["components"]: 65 for component in input_values["components"]:
66 component_group = read_group(component["component_file"]) 66 component_group = read_group(component["component_file"])
67 set_label(component_group, component["label"]) 67 set_label(component_group, component["label"])
68 component_groups.append(component_group) 68 component_groups.append(component_group)
69 69
70 fit_group = lincombo_fit(group_to_fit, component_groups) 70 energy_min = input_values["energy_min"]
71 energy_max = input_values["energy_max"]
72 fit_group = lincombo_fit(
73 group=group_to_fit,
74 components=component_groups,
75 xmin=energy_min,
76 xmax=energy_max,
77 )
71 print(f"Goodness of fit (rfactor): {fit_group.rfactor:.6%}") 78 print(f"Goodness of fit (rfactor): {fit_group.rfactor:.6%}")
72 79
73 energy_min = input_values["energy_min"] 80 x_limit_min = input_values["x_limit_min"]
74 energy_max = input_values["energy_max"] 81 x_limit_max = input_values["x_limit_max"]
75 if input_values["energy_format"] == "relative": 82 plot(group_to_fit, fit_group, x_limit_min, x_limit_max)
76 e0 = group_to_fit.e0
77 if energy_min is not None:
78 energy_min += e0
79 if energy_max is not None:
80 energy_max += e0
81
82 plot(group_to_fit, fit_group, energy_min, energy_max)