Mercurial > repos > muon-spectroscopy-computational-project > larch_athena
changeset 1:2b3115342fef draft
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_athena commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
| author | muon-spectroscopy-computational-project |
|---|---|
| date | Wed, 06 Dec 2023 13:03:55 +0000 |
| parents | ae2f265ecf8e |
| children | a1e26990131c |
| files | common.py larch_athena.py larch_athena.xml macros.xml test-data/ffi1.tabular test-data/multiple.prj |
| diffstat | 6 files changed, 710 insertions(+), 169 deletions(-) [+] |
line wrap: on
line diff
--- a/common.py Tue Nov 14 15:34:40 2023 +0000 +++ b/common.py Wed Dec 06 13:03:55 2023 +0000 @@ -7,38 +7,145 @@ def get_group(athena_group: AthenaGroup, key: str = None) -> Group: + group_keys = list(athena_group._athena_groups.keys()) if key is None: - group_keys = list(athena_group._athena_groups.keys()) key = group_keys[0] - return extract_athenagroup(athena_group._athena_groups[key]) + else: + key = key.replace("-", "_") + + try: + return extract_athenagroup(athena_group._athena_groups[key]) + except KeyError as e: + raise KeyError(f"{key} not in {group_keys}") from e + + +def read_all_groups(dat_file: str, key: str = None) -> "dict[str, Group]": + # Cannot rely on do_ABC as _larch is None + athena_group = read_athena( + dat_file, + do_preedge=False, + do_bkg=False, + do_fft=False, + ) + all_groups = {} + for key in athena_group._athena_groups.keys(): + group = get_group(athena_group, key) + pre_edge_with_defaults(group=group) + xftf_with_defaults(group=group) + all_groups[key] = group + + return all_groups + + +def read_group(dat_file: str, key: str = None): + # Cannot rely on do_ABC as _larch is None + athena_group = read_athena( + dat_file, + do_preedge=False, + do_bkg=False, + do_fft=False, + ) + group = get_group(athena_group, key) + pre_edge_with_defaults(group=group) + xftf_with_defaults(group=group) + return group -def read_group(dat_file: str, key: str = None, xftf_params: dict = None): - athena_group = read_athena(dat_file) - group = get_group(athena_group, key) - bkg_parameters = group.athena_params.bkg - print(group.athena_params.fft) - print(group.athena_params.fft.__dict__) - pre_edge( - group, - e0=bkg_parameters.e0, - pre1=bkg_parameters.pre1, - pre2=bkg_parameters.pre2, - norm1=bkg_parameters.nor1, - norm2=bkg_parameters.nor2, - nnorm=bkg_parameters.nnorm, - make_flat=bkg_parameters.flatten, +def pre_edge_with_defaults(group: Group, settings: dict = None): + merged_settings = {} + try: + bkg_parameters = group.athena_params.bkg + except AttributeError as e: + print(f"Cannot load group.athena_params.bkg from group:\n{e}") + bkg_parameters = None + + keys = ( + ("e0", "e0", None), + ("pre1", "pre1", None), + ("pre2", "pre2", None), + ("norm1", "nor1", None), + ("norm2", "nor2", None), + ("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), ) - autobk(group) - if xftf_params is None: - xftf(group) - else: - print(xftf_params) - xftf(group, **xftf_params) - xftf_details = Group() - setattr(xftf_details, "call_args", xftf_params) - group.xftf_details = xftf_details - return group + for key, parameters_key, default in keys: + extract_attribute( + merged_settings, key, bkg_parameters, parameters_key, default + ) + + if settings: + for k, v in settings.items(): + if k == "nvict": + print( + "WARNING: `nvict` can be used for pre-edge but is not " + "saved to file, so value used will not be accessible in " + "future operations using this Athena .prj" + ) + merged_settings[k] = v + + print(f"Pre-edge normalization with {merged_settings}") + try: + pre_edge(group, **merged_settings) + except Warning as e: + raise Warning( + "Unable to perform pre-edge fitting with:\n\n" + f"energy:\n{group.energy}\n\nmu:{group.mu}\n\n" + "Consider checking the correct columns have been extracted" + ) from e + autobk(group, pre_edge_kws=merged_settings) + + +def xftf_with_defaults(group: Group, settings: dict = None): + merged_settings = {} + try: + fft_parameters = group.athena_params.fft + except AttributeError as e: + print(f"Cannot load group.athena_params.fft from group:\n{e}") + fft_parameters = None + + keys = ( + ("kmin", "kmin", 0), + ("kmax", "kmax", 20), + ("dk", "dk", 1), + ("kweight", "kw", 2), + ("kweight", "kweight", 2), + ("window", "kwindow", "kaiser"), + ) + for key, parameters_key, default in keys: + extract_attribute( + merged_settings, key, fft_parameters, parameters_key, default + ) + + if settings: + for k, v in settings.items(): + merged_settings[k] = v + + print(f"XFTF with {merged_settings}") + xftf(group, **merged_settings) + xftf_details = Group() + setattr(xftf_details, "call_args", merged_settings) + group.xftf_details = xftf_details + + +def extract_attribute( + merged_settings: dict, + key: str, + parameters_group: Group, + parameters_key: str, + default: "str|int" = None, +): + if parameters_group is not None: + try: + merged_settings[key] = getattr(parameters_group, parameters_key) + return + except AttributeError: + pass + + if default is not None: + merged_settings[key] = default def read_groups(dat_files: "list[str]", key: str = None) -> Iterable[Group]:
--- a/larch_athena.py Tue Nov 14 15:34:40 2023 +0000 +++ b/larch_athena.py Wed Dec 06 13:03:55 2023 +0000 @@ -4,7 +4,9 @@ import re import sys -from common import read_group +from common import ( + pre_edge_with_defaults, read_all_groups, read_group, xftf_with_defaults +) from larch.io import ( create_athena, @@ -14,7 +16,7 @@ set_array_labels, ) from larch.symboltable import Group -from larch.xafs import autobk, pre_edge, rebin_xafs, xftf +from larch.xafs import rebin_xafs import matplotlib import matplotlib.pyplot as plt @@ -27,13 +29,11 @@ self, energy_column: str, mu_column: str, - xftf_params: dict, data_format: str, - extract_group: str = None, + extract_group: "dict[str, str]" = None, ): self.energy_column = energy_column self.mu_column = mu_column - self.xftf_params = xftf_params self.data_format = data_format self.extract_group = extract_group @@ -72,13 +72,24 @@ self, filepath: str, is_zipped: bool = False, - ) -> "dict[str,Group]": + ) -> "tuple[dict, bool]": if is_zipped: return self.load_zipped_files() print(f"Attempting to read from {filepath}") if self.data_format == "athena": - group = read_group(filepath, self.extract_group, self.xftf_params) + if self.extract_group["extract_group"] == "single": + group = read_group(filepath, self.extract_group["group_name"]) + return {"out": group} + elif self.extract_group["extract_group"] == "multiple": + groups = {} + for repeat in self.extract_group["multiple"]: + name = repeat["group_name"] + groups[name] = read_group(filepath, name) + return groups + else: + return read_all_groups(filepath) + else: # Try ascii anyway try: @@ -90,7 +101,9 @@ except (UnicodeDecodeError, TypeError): # Indicates this isn't plaintext, try h5 group = self.load_h5(filepath) - return {"out": group} + pre_edge_with_defaults(group) + xftf_with_defaults(group) + return {"out": group} def load_ascii(self, dat_file): with open(dat_file) as f: @@ -156,27 +169,27 @@ if "energy" in labels: print("'energy' present in column headers") - elif self.energy_column is not None: + elif self.energy_column: if self.energy_column.lower() in labels: labels[labels.index(self.energy_column.lower())] = "energy" else: raise ValueError(f"{self.energy_column} not found in {labels}") else: for i, label in enumerate(labels): - if label == "col1" or label.endswith("energy"): + if label in ("col1", "ef") or label.endswith("energy"): labels[i] = "energy" break if "mu" in labels: print("'mu' present in column headers") - elif self.mu_column is not None: + elif self.mu_column: if self.mu_column.lower() in labels: labels[labels.index(self.mu_column.lower())] = "mu" else: raise ValueError(f"{self.mu_column} not found in {labels}") else: for i, label in enumerate(labels): - if label in ["col2", "xmu", "lni0it", "ffi0"]: + if label in ["col2", "xmu", "lni0it", "ffi0", "ff/i1"]: labels[i] = "mu" break @@ -189,29 +202,24 @@ def calibrate_energy( xafs_group: Group, - energy_0: float, - energy_min: float, - energy_max: float, - energy_format: str, + calibration_e0: float = None, + energy_min: float = None, + energy_max: float = None, ): - if energy_0 is not None: - print(f"Recalibrating energy edge from {xafs_group.e0} to {energy_0}") - xafs_group.energy = xafs_group.energy + energy_0 - xafs_group.e0 - xafs_group.e0 = energy_0 + if calibration_e0 is not None: + print(f"Recalibrating edge from {xafs_group.e0} to {calibration_e0}") + xafs_group.energy = xafs_group.energy + calibration_e0 - xafs_group.e0 + xafs_group.e0 = calibration_e0 if not (energy_min or energy_max): return xafs_group - if energy_min: - if energy_format == "relative": - energy_min += xafs_group.e0 + if energy_min is not None: index_min = np.searchsorted(xafs_group.energy, energy_min) else: index_min = 0 - if energy_max: - if energy_format == "relative": - energy_max += xafs_group.e0 + if energy_max is not None: index_max = np.searchsorted(xafs_group.energy, energy_max) else: index_max = len(xafs_group.energy) @@ -240,81 +248,57 @@ def main( xas_data: Group, - input_values: dict, + do_calibrate: bool, + calibrate_settings: dict, + do_rebin: bool, + do_pre_edge: bool, + pre_edge_settings: dict, + do_xftf: bool, + xftf_settings: dict, + plot_graph: bool, + annotation: str, path_key: str = "out", ): - energy_0 = input_values["variables"]["energy_0"] - if energy_0 is None and hasattr(xas_data, "e0"): - energy_0 = xas_data.e0 - - energy_format = input_values["variables"]["energy_format"] - pre1 = input_values["variables"]["pre1"] - pre2 = input_values["variables"]["pre2"] - pre1 = validate_pre(pre1, energy_0, energy_format) - pre2 = validate_pre(pre2, energy_0, energy_format) - - pre_edge( - energy=xas_data.energy, - mu=xas_data.mu, - group=xas_data, - e0=energy_0, - pre1=pre1, - pre2=pre2, - ) + if do_calibrate: + print(f"Calibrating energy with {calibrate_settings}") + xas_data = calibrate_energy(xas_data, **calibrate_settings) + # After re-calibrating, will need to redo pre-edge with new range + do_pre_edge = True - energy_min = input_values["variables"]["energy_min"] - energy_max = input_values["variables"]["energy_max"] - xas_data = calibrate_energy( - xas_data, - energy_0, - energy_min, - energy_max, - energy_format=energy_format, - ) + if do_rebin: + print("Re-binning data") + rebin_xafs( + energy=xas_data.energy, + mu=xas_data.mu, + group=xas_data, + **pre_edge_settings, + ) + xas_data = xas_data.rebinned + # After re-bin, will need to redo pre-edge + do_pre_edge = True - if input_values["rebin"]: - print(xas_data.energy, xas_data.mu) - rebin_xafs(energy=xas_data.energy, mu=xas_data.mu, group=xas_data) - xas_data = xas_data.rebinned - pre_edge(energy=xas_data.energy, mu=xas_data.mu, group=xas_data) + if do_pre_edge: + pre_edge_with_defaults(xas_data, pre_edge_settings) - try: - autobk(xas_data) - except ValueError as e: - raise ValueError( - f"autobk failed with energy={xas_data.energy}, mu={xas_data.mu}.\n" - "This may occur if the edge is not included in the above ranges." - ) from e - xftf(xas_data, **xftf_params) + if do_xftf: + xftf_with_defaults(xas_data, xftf_settings) - if input_values["plot_graph"]: + 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) xas_project = create_athena(f"prj/{path_key}.prj") xas_project.add_group(xas_data) - if input_values["annotation"]: + if annotation: group = next(iter(xas_project.groups.values())) - group.args["annotation"] = input_values["annotation"] + group.args["annotation"] = annotation xas_project.save() # Ensure that we do not run out of memory when running on large zips gc.collect() -def validate_pre(pre, energy_0, energy_format): - if pre is not None and energy_format == "absolute": - if energy_0 is None: - raise ValueError( - "Edge energy must be set manually or be present in the " - "existing Athena project if using absolute format." - ) - pre -= energy_0 - - return pre - - def plot_derivative(plot_path: str, xafs_group: Group): plt.figure() plt.plot(xafs_group.energy, xafs_group.dmude) @@ -363,9 +347,8 @@ ) else: is_zipped = False - xftf_params = input_values["variables"]["xftf"] + extract_group = None - if "extract_group" in input_values["merge_inputs"]["format"]: extract_group = input_values["merge_inputs"]["format"]["extract_group"] @@ -379,7 +362,6 @@ reader = Reader( energy_column=energy_column, mu_column=mu_column, - xftf_params=xftf_params, data_format=data_format, extract_group=extract_group, ) @@ -388,9 +370,35 @@ merge_inputs=merge_inputs, is_zipped=is_zipped, ) + + calibrate_items = input_values["processing"]["calibrate"].items() + calibrate_settings = {k: v for k, v in calibrate_items if v is not None} + do_calibrate = calibrate_settings.pop("calibrate") == "true" + + do_rebin = input_values["processing"].pop("rebin") + + pre_edge_items = input_values["processing"]["pre_edge"].items() + pre_edge_settings = {k: v for k, v in pre_edge_items if v is not None} + do_pre_edge = pre_edge_settings.pop("pre_edge") == "true" + + xftf_items = input_values["processing"]["xftf"].items() + xftf_settings = {k: v for k, v in xftf_items if v is not None} + do_xftf = xftf_settings.pop("xftf") == "true" + + plot_graph = input_values["plot_graph"] + annotation = input_values["annotation"] + for key, group in keyed_data.items(): main( group, - input_values=input_values, + do_calibrate=do_calibrate, + calibrate_settings=calibrate_settings, + do_rebin=do_rebin, + do_pre_edge=do_pre_edge, + pre_edge_settings=pre_edge_settings, + do_xftf=do_xftf, + xftf_settings=xftf_settings, + plot_graph=plot_graph, + annotation=annotation, path_key=key, )
--- a/larch_athena.xml Tue Nov 14 15:34:40 2023 +0000 +++ b/larch_athena.xml Wed Dec 06 13:03:55 2023 +0000 @@ -4,7 +4,7 @@ <!-- version of underlying tool (PEP 440) --> <token name="@TOOL_VERSION@">0.9.71</token> <!-- version of this tool wrapper (integer) --> - <token name="@WRAPPER_VERSION@">0</token> + <token name="@WRAPPER_VERSION@">1</token> <!-- citation should be updated with every underlying tool version --> <!-- typical fields to update are version, month, year, and doi --> <token name="@TOOL_CITATION@">10.1088/1742-6596/430/1/012007</token> @@ -15,11 +15,26 @@ </param> </xml> <xml name="extract_group"> - <param name="extract_group" type="text" optional="true" label="Extract group" help="Which group to extract and process from the Athena project (will use first group in file if unset)"/> + <conditional name="extract_group"> + <param name="extract_group" type="select" label="Group extraction" help="Method of handling group extraction. Extracting all or multiple named groups will result in multiple outputs, unless merging groups is also true."> + <option value="single" selected="true">Extract single</option> + <option value="multiple">Extract multiple</option> + <option value="all">Extract all</option> + </param> + <when value="single"> + <param name="group_name" type="text" optional="true" label="Group label" help="Which group to extract and process from the Athena project (will use first group in file if unset)"/> + </when> + <when value="multiple"> + <repeat name="multiple" min="1" default="1" title="Groups"> + <param name="group_name" type="text" label="Group label" help="Which group to extract and process from the Athena project (will use first group in file if unset)"/> + </repeat> + </when> + <when value="all"/> + </conditional> </xml> <xml name="columns"> - <param name="energy_column" type="text" optional="true" label="Energy column" help="If set, this column we be used as 'energy'. Otherwise, will identify columns ending with 'energy' or labelled 'col1'."/> - <param name="mu_column" type="text" optional="true" label="μ column" help="If set, this column we be used as 'mu'. Otherwise, will identify the first column labelled as either 'col2', 'xmu', 'lni0it' or 'FFI0'."/> + <param name="energy_column" type="text" optional="true" label="Energy column" help="If set, this column we be used as 'energy'. Otherwise, will identify the first column ending with 'energy' or labelled 'col1' 'Ef'."/> + <param name="mu_column" type="text" optional="true" label="μ column" help="If set, this column we be used as 'mu'. Otherwise, will identify the first column labelled as either 'col2', 'xmu', 'lni0it', 'FFI0' or 'FF/I1'."/> </xml> <xml name="is_zipped"> <param name="is_zipped" type="select" display="radio" label="Inputs Zipped" help="Whether plaintext input files are zipped together into one directory, or not."> @@ -40,6 +55,7 @@ </requirements> <required_files> <include type="literal" path="larch_athena.py"/> + <include type="literal" path="common.py"/> </required_files> <command detect_errors="exit_code"><![CDATA[ mkdir prj edge flat derivative @@ -111,16 +127,55 @@ </when> </conditional> <param name="annotation" type="text" label="Annotation" optional="true" help="If set, will annotate the output project(s) with this string. This will be used to generate legends when plotting data."/> - <section name="variables" title="Processing Options"> - <param name="energy_0" type="float" label="Edge energy (eV)" optional="true" help="If set, data will be calibrated so that the edge occurs at this energy (after merging, if relevant)."/> - <expand macro="energy_limits"/> - <param name="pre1" type="float" label="Pre-edge fit lower energy (eV)" optional="true" help="The lower edge of the region used for the pre-edge fitting, if unset will either use existing value or a default based on the data."/> - <param name="pre2" type="float" label="Pre-edge fit upper energy (eV)" optional="true" help="The upper edge of the region used for the pre-edge fitting, if unset will either use existing value or a default based on the data."/> - <section name="xftf" title="XFTF"> - <expand macro="xftf_params"/> - </section> + <section name="processing" expanded="true" title="Processing Options" help="By default, the following processing steps will be performed either with default values, or those contained in the input Athena project (if used). If specified here, these values will be used instead for process in sequence."> + <conditional name="calibrate"> + <param name="calibrate" type="select" label="Calibrate energy" help="If set, will shift the spectrum so that its (automatically determined) edge occurs at the specified value, and any values outside the range will be discarded."> + <option value="" selected="true">False</option> + <option value="true">True</option> + </param> + <when value=""/> + <when value="true"> + <param name="calibration_e0" type="float" label="Calibration energy (eV)" optional="true" help="If set, data will be calibrated so that the edge occurs at this energy (after merging, if relevant). Note that this is different from specifying E0 in the pre-edge normalization, as this will the x-axis of the data (so that the Nth x point will no longer align with the Nth y point)."/> + <param name="energy_min" type="float" label="Minimum energy (eV)" optional="true" help="If set, data will be cropped below this value in electron volts (after re-calibrating)."/> + <param name="energy_max" type="float" label="Maximum energy (eV)" optional="true" help="If set, data will be cropped above this value in electron volts (after re-calibrating)."/> + </when> + </conditional> + <param name="rebin" type="boolean" label="Re-bin data" help="Whether to re-bin along the energy axis to automatically ensure appropriate levels of precision in the pre-edge, near-edge and extended region of the spectrum."/> + <conditional name="pre_edge"> + <param name="pre_edge" type="select" label="Pre-edge normalization" help="If set, will (re)perform forward pre-edge normalization using provided values."> + <option value="" selected="true">False</option> + <option value="true">True</option> + </param> + <when value=""/> + <when value="true"> + <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."/> + <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)."/> + <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)."/> + <param argument="nvict" type="integer" label="Energy exponent" optional="true" help="Edge fitting will be performed against μ*E**n where n is defined here. This is 0 by default."/> + </when> + </conditional> + <conditional name="xftf"> + <param name="xftf" type="select" label="XFTF" help="If set, will (re)perform forward Fourier Transform using provided values."> + <option value="" selected="true">False</option> + <option value="true">True</option> + </param> + <when value=""/> + <when value="true"> + <param argument="kmin" type="float" optional="true" min="0.0" help="Minimum k value."/> + <param argument="kmax" type="float" optional="true" min="0.0" help="Maximum k value."/> + <param argument="kweight" type="float" optional="true" help="Exponent for weighting spectra by raising k to this power."/> + <param argument="dk" type="float" optional="true" help="Tapering parameter for Fourier Transform window."/> + <param argument="window" type="select" optional="true" help="Fourier Transform window type."> + <option value="hanning">Hanning (cosine-squared taper)</option> + <option value="parzen">Parzen (linear taper)</option> + <option value="welch">Welch (quadratic taper)</option> + <option value="gaussian">Gaussian function window</option> + <option value="sine">Sine function window</option> + <option value="kaiser">Kaiser-Bessel function-derived window</option> + </param> + </when> + </conditional> </section> - <param name="rebin" type="boolean" label="Re-bin data" help="Whether to re-bin along the energy axis to ensure appropriate levels of precision in the pre-edge, near-edge and extended region of the spectrum."/> <param name="plot_graph" type="boolean" label="Plot graph" help="Whether to plot the pre/post edge fitting and the normalised xμ data."/> <param name="zip_outputs" type="boolean" label="Zip outputs" help="Whether to zip all outputs into one dataset."/> </inputs> @@ -129,53 +184,53 @@ <data name="out_zip" format="zip" from_work_dir="out_zip.zip" label="Zipped Athena project(s) ${annotation} ${on_string}"> <filter>zip_outputs</filter> </data> - <!-- Single outputs of differnt types if merging, or not using a zip --> + <!-- Single outputs of different types if merging, or not using a zip --> <data name="athena_project_file" format="prj" from_work_dir="prj/out.prj" label="Athena project ${annotation} ${on_string}"> <filter>not zip_outputs</filter> - <filter>merge_inputs["merge_inputs"] or (merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"] == "")</filter> + <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> </data> <data name="edge_plot" format="png" from_work_dir="edge/out.png" label="Edge fitting ${annotation} ${on_string}"> <filter>plot_graph</filter> <filter>not zip_outputs</filter> - <filter>merge_inputs["merge_inputs"] or (merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"] == "")</filter> + <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> </data> <data name="flat_plot" format="png" from_work_dir="flat/out.png" label="Flattened plot ${annotation} ${on_string}"> <filter>plot_graph</filter> <filter>not zip_outputs</filter> - <filter>merge_inputs["merge_inputs"] or (merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"] == "")</filter> + <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> </data> <data name="derivative_plot" format="png" from_work_dir="derivative/out.png" label="Derivative plot ${annotation} ${on_string}"> <filter>plot_graph</filter> <filter>not zip_outputs</filter> - <filter>merge_inputs["merge_inputs"] or merge_inputs["format"]["dat_file"].extension != "zip"</filter> - <filter>merge_inputs["merge_inputs"] or (merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"] == "")</filter> + <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> </data> - <!-- Directories of outputs if using single, non-merged zip as input --> + <!-- Directories of outputs if using single, non-merged zip as input or extracting multiple/all Athena groups --> <collection name="athena_project_file_collection" format="prj" type="list" label="Athena projects ${annotation} ${on_string}"> <discover_datasets pattern="__name_and_ext__" directory="prj"/> <filter>not zip_outputs</filter> - <filter>merge_inputs["merge_inputs"] == "" and merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]</filter> + <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> </collection> <collection name="edge_plot_collection" format="png" type="list" label="Edge fittings ${annotation} ${on_string}"> <discover_datasets pattern="__name_and_ext__" directory="edge"/> <filter>plot_graph</filter> <filter>not zip_outputs</filter> - <filter>merge_inputs["merge_inputs"] == "" and merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]</filter> + <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> </collection> <collection name="flat_plot_collection" format="png" type="list" label="Flattened plots ${annotation} ${on_string}"> <discover_datasets pattern="__name_and_ext__" directory="flat"/> <filter>plot_graph</filter> <filter>not zip_outputs</filter> - <filter>merge_inputs["merge_inputs"] == "" and merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]</filter> + <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> </collection> <collection name="derivative_plot_collection" format="png" type="list" label="Derivative plots ${annotation} ${on_string}"> <discover_datasets pattern="__name_and_ext__" directory="derivative"/> <filter>plot_graph</filter> <filter>not zip_outputs</filter> - <filter>merge_inputs["merge_inputs"] == "" and merge_inputs["format"]["format"] == "plaintext" and merge_inputs["format"]["is_zipped"]["is_zipped"]</filter> + <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> </collection> </outputs> <tests> + <!-- 1 --> <test expect_num_outputs="1"> <param name="dat_file" value="test.xmu"/> <output name="athena_project_file"> @@ -184,6 +239,7 @@ </assert_contents> </output> </test> + <!-- 2 --> <test expect_num_outputs="1"> <param name="dat_file" value="ffi0.tabular"/> <output name="athena_project_file"> @@ -192,12 +248,22 @@ </assert_contents> </output> </test> + <!-- 3 --> + <test expect_num_outputs="1"> + <param name="dat_file" value="ffi1.tabular"/> + <output name="athena_project_file"> + <assert_contents> + <has_size value="4400" delta="100"/> + </assert_contents> + </output> + </test> + <!-- 4 --> <test expect_num_outputs="4"> <param name="dat_file" value="test.xmu"/> <param name="plot_graph" value="true"/> <output name="athena_project_file"> <assert_contents> - <has_size value="5405" delta="10"/> + <has_size value="5400" delta="100"/> </assert_contents> </output> <output name="edge_plot"> @@ -216,6 +282,7 @@ </assert_contents> </output> </test> + <!-- 5 --> <test expect_num_outputs="4"> <param name="is_zipped" value="true"/> <param name="dat_file" value="test.zip"/> @@ -225,6 +292,7 @@ <output_collection name="flat_plot_collection" type="list" count="2"/> <output_collection name="derivative_plot_collection" type="list" count="2"/> </test> + <!-- 6 --> <test expect_num_outputs="1"> <param name="is_zipped" value="true"/> <param name="dat_file" value="h5.zip"/> @@ -236,9 +304,10 @@ </assert_contents> </output> </test> + <!-- 7 --> <test expect_num_outputs="1"> <param name="dat_file" value="test.xmu"/> - <param name="energy_format" value="absolute"/> + <param name="calibrate" value="true"/> <param name="energy_min" value="7000"/> <output name="athena_project_file"> <assert_contents> @@ -246,9 +315,10 @@ </assert_contents> </output> </test> + <!-- 8 --> <test expect_num_outputs="4"> <param name="dat_file" value="test.xmu"/> - <param name="energy_format" value="absolute"/> + <param name="calibrate" value="true"/> <param name="energy_min" value="7000"/> <param name="energy_max" value="7200"/> <param name="plot_graph" value="true"/> @@ -259,32 +329,34 @@ </output> <output name="edge_plot"> <assert_contents> - <has_size value="44430" delta="10"/> + <has_size value="44900" delta="100"/> </assert_contents> </output> <output name="flat_plot"> <assert_contents> - <has_size value="37310" delta="10"/> + <has_size value="39400" delta="100"/> </assert_contents> </output> <output name="derivative_plot"> <assert_contents> - <has_size value="46390" delta="10"/> + <has_size value="45900" delta="100"/> </assert_contents> </output> </test> + <!-- 9 --> <test expect_num_outputs="1"> <param name="dat_file" value="test.xmu"/> - <param name="energy_format" value="absolute"/> - <param name="energy_0" value="7050"/> + <param name="calibrate" value="true"/> + <param name="calibration_e0" value="7050"/> <param name="energy_min" value="7000"/> <param name="energy_max" value="7200"/> <output name="athena_project_file"> <assert_contents> - <has_size value="3300" delta="50"/> + <has_size value="3600" delta="100"/> </assert_contents> </output> </test> + <!-- 10 --> <test expect_num_outputs="1"> <param name="dat_file" value="test.xmu"/> <param name="rebin" value="true"/> @@ -294,6 +366,7 @@ </assert_contents> </output> </test> + <!-- 11 --> <test expect_num_outputs="1"> <param name="merge_inputs" value="true"/> <param name="dat_file" value="262875_PtSn_OCO_Abu_1.nxs,262876_PtSn_OCO_Abu_2.nxs"/> @@ -303,6 +376,7 @@ </assert_contents> </output> </test> + <!-- 12 --> <test expect_num_outputs="1"> <param name="merge_inputs" value="true"/> <param name="is_zipped" value="true"/> @@ -313,6 +387,7 @@ </assert_contents> </output> </test> + <!-- 13 --> <test expect_num_outputs="1"> <param name="format" value="athena"/> <param name="dat_file" value="test.prj"/> @@ -322,6 +397,22 @@ </assert_contents> </output> </test> + <!-- 14: Extract multiple groups from Athena .prj --> + <test expect_num_outputs="1"> + <param name="format" value="athena"/> + <param name="extract_group" value="multiple"/> + <param name="group_name" value="merge"/> + <param name="group_name" value="d__Ref_PtSn_OC_MERGE_CALIBRATE"/> + <param name="dat_file" value="multiple.prj"/> + <output_collection name="athena_project_file_collection" type="list" count="2"/> + </test> + <!-- 15: Extract all groups from Athena .prj --> + <test expect_num_outputs="1"> + <param name="format" value="athena"/> + <param name="extract_group" value="all"/> + <param name="dat_file" value="multiple.prj"/> + <output_collection name="athena_project_file_collection" type="list" count="9"/> + </test> </tests> <help><