# HG changeset patch # User muon-spectroscopy-computational-project # Date 1711117407 0 # Node ID 82e9dd980916628c2ed22ed076a45062eaabfee3 # Parent a1e26990131cd4742d87f66ac99507dbe6df5e95 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_athena commit d4c7e090dc5c94395d7e1574845ac2c76f2e4f5f diff -r a1e26990131c -r 82e9dd980916 common.py --- a/common.py Mon Mar 04 11:43:19 2024 +0000 +++ b/common.py Fri Mar 22 14:23:27 2024 +0000 @@ -73,7 +73,11 @@ ) for key, parameters_key, default in keys: extract_attribute( - merged_settings, key, bkg_parameters, parameters_key, default + merged_settings=merged_settings, + key=key, + parameters_group=bkg_parameters, + parameters_key=parameters_key, + default=default, ) if settings: @@ -116,7 +120,11 @@ ) for key, parameters_key, default in keys: extract_attribute( - merged_settings, key, fft_parameters, parameters_key, default + merged_settings=merged_settings, + key=key, + parameters_group=fft_parameters, + parameters_key=parameters_key, + default=default, ) if settings: diff -r a1e26990131c -r 82e9dd980916 larch_athena.py --- a/larch_athena.py Mon Mar 04 11:43:19 2024 +0000 +++ b/larch_athena.py Fri Mar 22 14:23:27 2024 +0000 @@ -5,7 +5,10 @@ import sys from common import ( - pre_edge_with_defaults, read_all_groups, read_group, xftf_with_defaults + pre_edge_with_defaults, + read_all_groups, + read_group, + xftf_with_defaults, ) from larch.io import ( @@ -45,12 +48,14 @@ ) -> "dict[str, Group]": if merge_inputs: out_group = self.merge_files( - dat_files=dat_file, is_zipped=is_zipped + dat_files=dat_file, + is_zipped=is_zipped, ) return {"out": out_group} else: return self.load_single_file( - filepath=dat_file, is_zipped=is_zipped + filepath=dat_file, + is_zipped=is_zipped, ) def merge_files( @@ -258,7 +263,7 @@ pre_edge_settings: dict, do_xftf: bool, xftf_settings: dict, - plot_graph: bool, + plot_graph: list, annotation: str, path_key: str = "out", ): @@ -287,9 +292,11 @@ xftf_with_defaults(xas_data, xftf_settings) if plot_graph: - plot_edge_fits(f"edge/{path_key}.png", xas_data) - plot_flattened(f"flat/{path_key}.png", xas_data) - plot_derivative(f"derivative/{path_key}.png", xas_data) + plot_graphs( + plot_path=f"plot/{path_key}.png", + xas_data=xas_data, + plot_keys=plot_graph, + ) xas_project = create_athena(f"prj/{path_key}.prj") xas_project.add_group(xas_data) @@ -302,36 +309,43 @@ gc.collect() -def plot_derivative(plot_path: str, xafs_group: Group): - plt.figure() - plt.plot(xafs_group.energy, xafs_group.dmude) - plt.grid(color="r", linestyle=":", linewidth=1) - plt.xlabel("Energy (eV)") - plt.ylabel("Derivative normalised to x$\mu$(E)") # noqa: W605 - plt.savefig(plot_path, format="png") - plt.close("all") - +def plot_graphs( + plot_path: str, + xas_data: Group, + plot_keys: list, +) -> None: + nrows = len(plot_keys) + index = 1 + plt.figure(figsize=(6.4, nrows * 4.8)) + if "edge" in plot_keys: + plt.subplot(nrows, 1, index) + plt.plot(xas_data.energy, xas_data.pre_edge, "g", label="pre-edge") + plt.plot(xas_data.energy, xas_data.post_edge, "r", label="post-edge") + plt.plot(xas_data.energy, xas_data.mu, "b", label="fit data") + plt.grid(color="r", linestyle=":", linewidth=1) + plt.xlabel("Energy (eV)") + plt.ylabel("x$\mu$(E)") # noqa: W605 + plt.title("Pre-edge and post_edge fitting to $\mu$") # noqa: W605 + plt.legend() + index += 1 -def plot_edge_fits(plot_path: str, xafs_group: Group): - plt.figure() - plt.plot(xafs_group.energy, xafs_group.pre_edge, "g", label="pre-edge") - plt.plot(xafs_group.energy, xafs_group.post_edge, "r", label="post-edge") - plt.plot(xafs_group.energy, xafs_group.mu, "b", label="fit data") - plt.grid(color="r", linestyle=":", linewidth=1) - plt.xlabel("Energy (eV)") - plt.ylabel("x$\mu$(E)") # noqa: W605 - plt.title("pre-edge and post_edge fitting to $\mu$") # noqa: W605 - plt.legend() - plt.savefig(plot_path, format="png") - plt.close("all") + if "flat" in plot_keys: + plt.subplot(nrows, 1, index) + plt.plot(xas_data.energy, xas_data.flat) + plt.grid(color="r", linestyle=":", linewidth=1) + plt.xlabel("Energy (eV)") + plt.ylabel("Flattened x$\mu$(E)") # noqa: W605 + index += 1 + if "dmude" in plot_keys: + plt.subplot(nrows, 1, index) + plt.plot(xas_data.energy, xas_data.dmude) + plt.grid(color="r", linestyle=":", linewidth=1) + plt.xlabel("Energy (eV)") + plt.ylabel("Derivative normalised to x$\mu$(E)") # noqa: W605 + index += 1 -def plot_flattened(plot_path: str, xafs_group: Group): - plt.figure() - plt.plot(xafs_group.energy, xafs_group.flat) - plt.grid(color="r", linestyle=":", linewidth=1) - plt.xlabel("Energy (eV)") - plt.ylabel("normalised x$\mu$(E)") # noqa: W605 + plt.tight_layout(rect=(0, 0, 0.88, 1)) plt.savefig(plot_path, format="png") plt.close("all") diff -r a1e26990131c -r 82e9dd980916 larch_athena.xml --- a/larch_athena.xml Mon Mar 04 11:43:19 2024 +0000 +++ b/larch_athena.xml Fri Mar 22 14:23:27 2024 +0000 @@ -4,7 +4,7 @@ 0.9.74 - 0 + 1 10.1088/1742-6596/430/1/012007 @@ -58,7 +58,7 @@ - + @@ -180,7 +180,11 @@ - + + + + + @@ -193,17 +197,7 @@ not zip_outputs not (merge_inputs["merge_inputs"] == "" and ((merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]) or (merge_inputs["format"]["format"] == "athena" and merge_inputs["format"]["extract_group"]["extract_group"] != "single"))) - - plot_graph - not zip_outputs - not (merge_inputs["merge_inputs"] == "" and ((merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]) or (merge_inputs["format"]["format"] == "athena" and merge_inputs["format"]["extract_group"]["extract_group"] != "single"))) - - - plot_graph - not zip_outputs - not (merge_inputs["merge_inputs"] == "" and ((merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]) or (merge_inputs["format"]["format"] == "athena" and merge_inputs["format"]["extract_group"]["extract_group"] != "single"))) - - + plot_graph not zip_outputs not (merge_inputs["merge_inputs"] == "" and ((merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]) or (merge_inputs["format"]["format"] == "athena" and merge_inputs["format"]["extract_group"]["extract_group"] != "single"))) @@ -214,20 +208,8 @@ not zip_outputs merge_inputs["merge_inputs"] == "" and ((merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]) or (merge_inputs["format"]["format"] == "athena" and merge_inputs["format"]["extract_group"]["extract_group"] != "single")) - - - plot_graph - not zip_outputs - merge_inputs["merge_inputs"] == "" and ((merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]) or (merge_inputs["format"]["format"] == "athena" and merge_inputs["format"]["extract_group"]["extract_group"] != "single")) - - - - plot_graph - not zip_outputs - merge_inputs["merge_inputs"] == "" and ((merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]) or (merge_inputs["format"]["format"] == "athena" and merge_inputs["format"]["extract_group"]["extract_group"] != "single")) - - - + + plot_graph not zip_outputs merge_inputs["merge_inputs"] == "" and ((merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]) or (merge_inputs["format"]["format"] == "athena" and merge_inputs["format"]["extract_group"]["extract_group"] != "single")) @@ -262,49 +244,37 @@ - + - + - - - - - - + - - - - - - + - + - + - - - + - + - + @@ -320,30 +290,20 @@ - + - + - - - - - - + - - - - - - + @@ -392,29 +352,19 @@ - + - + - - - - - - + - - - - - - +