Repository 'larch_athena'
hg clone https://toolshed.g2.bx.psu.edu/repos/muon-spectroscopy-computational-project/larch_athena

Changeset 2:a1e26990131c (2024-03-04)
Previous changeset 1:2b3115342fef (2023-12-06) Next changeset 3:82e9dd980916 (2024-03-22)
Commit message:
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_athena commit 0f66842e802430e887d1c6cb7be1cc5436408fd2
modified:
common.py
larch_athena.py
larch_athena.xml
b
diff -r 2b3115342fef -r a1e26990131c common.py
--- a/common.py Wed Dec 06 13:03:55 2023 +0000
+++ b/common.py Mon Mar 04 11:43:19 2024 +0000
b
@@ -29,6 +29,7 @@
     )
     all_groups = {}
     for key in athena_group._athena_groups.keys():
+        print(f"\nExtracting group {key}")
         group = get_group(athena_group, key)
         pre_edge_with_defaults(group=group)
         xftf_with_defaults(group=group)
@@ -68,8 +69,7 @@
         ("nnorm", "nnorm", None),
         ("make_flat", "flatten", None),
         ("step", "step", None),
-        # This cannot be read from file as it is not stored by Larch (0.9.71)
-        # ("nvict", "nvict", None),
+        ("nvict", "nvict", None),
     )
     for key, parameters_key, default in keys:
         extract_attribute(
b
diff -r 2b3115342fef -r a1e26990131c larch_athena.py
--- a/larch_athena.py Wed Dec 06 13:03:55 2023 +0000
+++ b/larch_athena.py Mon Mar 04 11:43:19 2024 +0000
[
@@ -63,16 +63,18 @@
         else:
             all_groups = []
             for filepath in dat_files.split(","):
-                group = self.load_single_file(filepath)["out"]
-                all_groups.append(group)
+                for group in self.load_single_file(filepath).values():
+                    all_groups.append(group)
 
-        return merge_groups(all_groups, xarray="energy", yarray="mu")
+        merged_group = merge_groups(all_groups, xarray="energy", yarray="mu")
+        pre_edge_with_defaults(merged_group)
+        return merged_group
 
     def load_single_file(
         self,
         filepath: str,
         is_zipped: bool = False,
-    ) -> "tuple[dict, bool]":
+    ) -> dict:
         if is_zipped:
             return self.load_zipped_files()
 
@@ -85,6 +87,7 @@
                 groups = {}
                 for repeat in self.extract_group["multiple"]:
                     name = repeat["group_name"]
+                    print(f"\nExtracting group {name}")
                     groups[name] = read_group(filepath, name)
                 return groups
             else:
@@ -141,8 +144,6 @@
         all_paths.sort(key=lambda x: x[0])
         file_total = sum([len(f) for _, _, f in all_paths])
         print(f"{file_total} files found")
-        key_length = len(str(file_total))
-        i = 0
         keyed_data = {}
         for dirpath, _, filenames in all_paths:
             try:
@@ -155,11 +156,13 @@
                 filenames.sort()
 
             for filename in filenames:
-                key = str(i).zfill(key_length)
+                if len(all_paths) > 1:
+                    key = f"{dirpath}_{filename}"
+                else:
+                    key = filename
                 filepath = os.path.join(dirpath, filename)
                 xas_data = self.load_single_file(filepath)
                 keyed_data[key] = xas_data["out"]
-                i += 1
 
         return keyed_data
 
b
diff -r 2b3115342fef -r a1e26990131c larch_athena.xml
--- a/larch_athena.xml Wed Dec 06 13:03:55 2023 +0000
+++ b/larch_athena.xml Mon Mar 04 11:43:19 2024 +0000
[
b'@@ -2,9 +2,9 @@\n     <description>generate Athena projects from XAFS data</description>\n     <macros>\n         <!-- version of underlying tool (PEP 440) -->\n-        <token name="@TOOL_VERSION@">0.9.71</token>\n+        <token name="@TOOL_VERSION@">0.9.74</token>\n         <!-- version of this tool wrapper (integer) -->\n-        <token name="@WRAPPER_VERSION@">1</token>\n+        <token name="@WRAPPER_VERSION@">0</token>\n         <!-- citation should be updated with every underlying tool version -->\n         <!-- typical fields to update are version, month, year, and doi -->\n         <token name="@TOOL_CITATION@">10.1088/1742-6596/430/1/012007</token>\n@@ -120,7 +120,7 @@\n                         <expand macro="columns"/>\n                     </when>\n                     <when value="athena">\n-                        <param name="dat_file" type="data" format="prj" multiple="true" label="Athena project" help="X-ray Absorption Spectroscopy (XAS) data, which will be merged, in Athena project format"/>\n+                        <param name="dat_file" type="data" format="prj" multiple="true" label="Athena project" help="X-ray Absorption Spectroscopy (XAS) data, which will be merged, in Athena project format. Note that when merging Athena groups, background parameters set in file will be lost, and automatic default used unless defined below."/>\n                         <expand macro="extract_group"/>\n                     </when>\n                 </conditional>\n@@ -151,6 +151,10 @@\n                     <param argument="e0" type="float" label="Edge energy (eV)" optional="true" help="If set, normalization will use this as the location of the edge rather than automatically determining it."/>\n                     <param argument="pre1" type="float" max="0" label="Pre-edge fit lower energy (eV)" optional="true" help="The lower end of the region used for the pre-edge fitting, relative to the edge energy (and therefore negative)."/>\n                     <param argument="pre2" type="float" max="0" label="Pre-edge fit upper energy (eV)" optional="true" help="The upper end of the region used for the pre-edge fitting, relative to the edge energy (and therefore negative)."/>\n+                    <param argument="norm1" type="float" min="0" label="Post-edge fit lower energy (eV)" optional="true" help="The lower end of the region used for the post-edge fitting, relative to the edge energy (and therefore positive)."/>\n+                    <param argument="norm2" type="float" min="0" label="Post-edge fit upper energy (eV)" optional="true" help="The upper end of the region used for the post-edge fitting, relative to the edge energy (and therefore positive)."/>\n+                    <param argument="nnorm" type="integer" min="0" max="5" label="Post-edge fit polynomial degree" optional="true" help="The degree of the polynomial used to fit in the post-edge region."/>\n+                    <param argument="step" type="float" min="0" label="Edge step" optional="true" help="Magnitude of the step in \xce\xbc between the pre and post-edge regions at the edge energy."/>\n                     <param argument="nvict" type="integer" label="Energy exponent" optional="true" help="Edge fitting will be performed against \xce\xbc*E**n where n is defined here. This is 0 by default."/>\n                 </when>\n             </conditional>\n@@ -187,46 +191,46 @@\n         <!-- Single outputs of different types if merging, or not using a zip -->\n         <data name="athena_project_file" format="prj" from_work_dir="prj/out.prj" label="Athena project ${annotation} ${on_string}">\n             <filter>not zip_outputs</filter>\n-            <filter>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"))</filter>\n+            <filter>not (merge_inputs["merge_inputs"] == "" and ((merge_inp'..b'>\n+            <filter>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"))</filter>\n         </collection>\n     </outputs>\n     <tests>\n@@ -235,7 +239,7 @@\n             <param name="dat_file" value="test.xmu"/>\n             <output name="athena_project_file">\n                 <assert_contents>\n-                    <has_size value="5405" delta="10"/>\n+                    <has_size value="5400" delta="100"/>\n                 </assert_contents>\n             </output>\n         </test>\n@@ -387,7 +391,34 @@\n                 </assert_contents>\n             </output>\n         </test>\n-        <!-- 13 -->\n+        <!-- 13: Test merging and plotting multiple prj inputs -->\n+        <test expect_num_outputs="4">\n+            <param name="merge_inputs" value="true"/>\n+            <param name="format" value="athena"/>\n+            <param name="dat_file" value="test.prj,test.prj"/>\n+            <param name="plot_graph" value="true"/>\n+            <output name="athena_project_file">\n+                <assert_contents>\n+                    <has_size value="4500" delta="100"/>\n+                </assert_contents>\n+            </output>\n+            <output name="edge_plot">\n+                <assert_contents>\n+                    <has_size value="54200" delta="100"/>\n+                </assert_contents>\n+            </output>\n+            <output name="flat_plot">\n+                <assert_contents>\n+                    <has_size value="39400" delta="100"/>\n+                </assert_contents>\n+            </output>\n+            <output name="derivative_plot">\n+                <assert_contents>\n+                    <has_size value="41800" delta="100"/>\n+                </assert_contents>\n+            </output>\n+        </test>\n+        <!-- 14 -->\n         <test expect_num_outputs="1">\n             <param name="format" value="athena"/>\n             <param name="dat_file" value="test.prj"/>\n@@ -397,22 +428,34 @@\n                 </assert_contents>\n             </output>\n         </test>\n-        <!-- 14: Extract multiple groups from Athena .prj -->\n+        <!-- 15: Extract multiple groups from Athena .prj -->\n         <test expect_num_outputs="1">\n             <param name="format" value="athena"/>\n             <param name="extract_group" value="multiple"/>\n             <param name="group_name" value="merge"/>\n-            <param name="group_name" value="d__Ref_PtSn_OC_MERGE_CALIBRATE"/>\n+            <param name="group_name" value="d_Ref_PtSn_OC_MERGE_CALIBRATE"/>\n             <param name="dat_file" value="multiple.prj"/>\n             <output_collection name="athena_project_file_collection" type="list" count="2"/>\n         </test>\n-        <!-- 15: Extract all groups from Athena .prj -->\n+        <!-- 16: Extract all groups from Athena .prj -->\n         <test expect_num_outputs="1">\n             <param name="format" value="athena"/>\n             <param name="extract_group" value="all"/>\n             <param name="dat_file" value="multiple.prj"/>\n             <output_collection name="athena_project_file_collection" type="list" count="9"/>\n         </test>\n+        <!-- 17: Extract and merge all groups from Athena .prj -->\n+        <test expect_num_outputs="1">\n+            <param name="merge_inputs" value="true"/>\n+            <param name="format" value="athena"/>\n+            <param name="extract_group" value="all"/>\n+            <param name="dat_file" value="multiple.prj"/>\n+            <output name="athena_project_file">\n+                <assert_contents>\n+                    <has_size value="26000" delta="100"/>\n+                </assert_contents>\n+            </output>\n+        </test>\n     </tests>\n     <help><![CDATA[\n         Using Larch, create an Athena project file from the input X-ray Absorption Fine Structure (XAFS) data file.\n'