-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add gooey support #130
add gooey support #130
Changes from all commits
acb20a5
6490b83
7e458ee
c1d794d
38a4889
0ece116
f09bd49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
**Added:** | ||
|
||
* Gooey support so that the app can be run with GUI | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ numpy | |
diffpy.utils | ||
pandas | ||
scipy | ||
gooey |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ numpy | |
diffpy.utils | ||
pandas | ||
scipy | ||
gooey |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,156 @@ | ||
import sys | ||
from argparse import ArgumentParser | ||
|
||
from gooey import Gooey, GooeyParser | ||
|
||
from diffpy.labpdfproc.functions import CVE_METHODS, apply_corr, compute_cve | ||
from diffpy.labpdfproc.tools import known_sources, load_metadata, preprocessing_args | ||
from diffpy.utils.parsers.loaddata import loadData | ||
from diffpy.utils.scattering_objects.diffraction_objects import XQUANTITIES, Diffraction_object | ||
|
||
|
||
def define_arguments(): | ||
args = [ | ||
{ | ||
"name": ["mud"], | ||
"help": "Value of mu*D for your sample. Required.", | ||
"type": float, | ||
}, | ||
{ | ||
"name": ["input"], | ||
"help": ( | ||
"The filename(s) or folder(s) of the datafile(s) to load. " | ||
"Required.\nSupply a space-separated list of files or directories. " | ||
"Long lists can be supplied, one per line, in a file with name " | ||
"file_list.txt. If one or more directory is provided, all valid " | ||
"data-files in that directory will be processed. Examples of valid " | ||
"inputs are 'file.xy', 'data/file.xy', 'file.xy, data/file.xy', " | ||
"'.' (load everything in the current directory), 'data' (load " | ||
"everything in the folder ./data), 'data/file_list.txt' (load " | ||
"the list of files contained in the text-file called " | ||
"file_list.txt that can be found in the folder ./data), " | ||
"'./*.chi', 'data/*.chi' (load all files with extension .chi in the " | ||
"folder ./data)." | ||
), | ||
"nargs": "+", | ||
"widget": "MultiFileChooser", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we have cli we support a mixture of multiple files, folders, and wildcards. In gui I think we can only choose one of multiple file or folder for one argument. I can maybe add another argument for selecting folders? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, if that is the case in teh gui let's have them as separate inputs |
||
}, | ||
{ | ||
"name": ["-a", "--anode-type"], | ||
"help": ( | ||
f"The type of the x-ray source. Allowed values are " | ||
f"{*[known_sources], }. Either specify a known x-ray source or specify wavelength." | ||
), | ||
"default": "Mo", | ||
}, | ||
{ | ||
"name": ["-w", "--wavelength"], | ||
"help": ( | ||
"X-ray source wavelength in angstroms. Not needed if the anode-type " | ||
"is specified. This wavelength will override the anode wavelength if both are specified." | ||
), | ||
"type": float, | ||
}, | ||
{ | ||
"name": ["-o", "--output-directory"], | ||
"help": ( | ||
"The name of the output directory. If not specified " | ||
"then corrected files will be written to the current directory. " | ||
"If the specified directory doesn't exist it will be created." | ||
), | ||
"default": None, | ||
}, | ||
{ | ||
"name": ["-x", "--xtype"], | ||
"help": ( | ||
f"The quantity on the independent variable axis. Allowed " | ||
f"values: {*XQUANTITIES, }. If not specified then two-theta " | ||
f"is assumed for the independent variable." | ||
), | ||
"default": "tth", | ||
}, | ||
{ | ||
"name": ["-c", "--output-correction"], | ||
"help": ( | ||
"The absorption correction will be output to a file if this " | ||
"flag is set. Default is that it is not output." | ||
), | ||
"action": "store_true", | ||
}, | ||
{ | ||
"name": ["-f", "--force-overwrite"], | ||
"help": "Outputs will not overwrite existing file unless --force is specified.", | ||
"action": "store_true", | ||
}, | ||
{ | ||
"name": ["-m", "--method"], | ||
"help": ( | ||
f"The method for computing absorption correction. Allowed methods: {*CVE_METHODS, }. " | ||
f"Default method is polynomial interpolation if not specified. " | ||
), | ||
"default": "polynomial_interpolation", | ||
}, | ||
{ | ||
"name": ["-u", "--user-metadata"], | ||
"help": ( | ||
"Specify key-value pairs to be loaded into metadata using the format key=value. " | ||
"Separate pairs with whitespace, and ensure no whitespaces before or after the = sign. " | ||
"Avoid using = in keys. If multiple = signs are present, " | ||
"only the first separates the key and value. " | ||
"If a key or value contains whitespace, enclose it in quotes. " | ||
"For example, facility='NSLS II', 'facility=NSLS II', beamline=28ID-2, " | ||
"'beamline'='28ID-2', 'favorite color'=blue, are all valid key=value items. " | ||
), | ||
"nargs": "+", | ||
"metavar": "KEY=VALUE", | ||
}, | ||
{ | ||
"name": ["-n", "--username"], | ||
"help": ( | ||
"Username will be loaded from config files. Specify here " | ||
"only if you want to override that behavior at runtime. " | ||
), | ||
"default": None, | ||
}, | ||
{ | ||
"name": ["-e", "--email"], | ||
"help": ( | ||
"Email will be loaded from config files. Specify here " | ||
"only if you want to override that behavior at runtime. " | ||
), | ||
"default": None, | ||
}, | ||
{ | ||
"name": ["-z", "--z-scan-file"], | ||
"help": "Path to the z-scan file to be loaded to determine the mu*D value", | ||
"default": None, | ||
"widget": "FileChooser", | ||
}, | ||
] | ||
return args | ||
|
||
|
||
def get_args(override_cli_inputs=None): | ||
p = ArgumentParser() | ||
p.add_argument("mud", help="Value of mu*D for your " "sample. Required.", type=float) | ||
p.add_argument( | ||
"input", | ||
nargs="+", | ||
help=( | ||
"The filename(s) or folder(s) of the datafile(s) to load. " | ||
"Required.\nSupply a space-separated list of files or directories. " | ||
"Long lists can be supplied, one per line, in a file with name " | ||
"file_list.txt. If one or more directory is provided, all valid " | ||
"data-files in that directory will be processed. Examples of valid " | ||
"inputs are 'file.xy', 'data/file.xy', 'file.xy, data/file.xy', " | ||
"'.' (load everything in the current directory), 'data' (load " | ||
"everything in the folder ./data), 'data/file_list.txt' (load " | ||
"the list of files contained in the text-file called " | ||
"file_list.txt that can be found in the folder ./data), " | ||
"'./*.chi', 'data/*.chi' (load all files with extension .chi in the " | ||
"folder ./data)." | ||
), | ||
) | ||
p.add_argument( | ||
"-a", | ||
"--anode-type", | ||
help=( | ||
f"The type of the x-ray source. Allowed values are " | ||
f"{*[known_sources], }. Either specify a known x-ray source or specify wavelength." | ||
), | ||
default="Mo", | ||
) | ||
p.add_argument( | ||
"-w", | ||
"--wavelength", | ||
help=( | ||
"X-ray source wavelength in angstroms. Not needed if the anode-type " | ||
"is specified. This wavelength will override the anode wavelength if both are specified." | ||
), | ||
default=None, | ||
type=float, | ||
) | ||
p.add_argument( | ||
"-o", | ||
"--output-directory", | ||
help=( | ||
"The name of the output directory. If not specified " | ||
"then corrected files will be written to the current directory. " | ||
"If the specified directory doesn't exist it will be created." | ||
), | ||
default=None, | ||
) | ||
p.add_argument( | ||
"-x", | ||
"--xtype", | ||
help=( | ||
f"The quantity on the independent variable axis. Allowed " | ||
f"values: {*XQUANTITIES, }. If not specified then two-theta " | ||
f"is assumed for the independent variable." | ||
), | ||
default="tth", | ||
) | ||
p.add_argument( | ||
"-c", | ||
"--output-correction", | ||
action="store_true", | ||
help=( | ||
"The absorption correction will be output to a file if this " | ||
"flag is set. Default is that it is not output." | ||
), | ||
) | ||
p.add_argument( | ||
"-f", | ||
"--force-overwrite", | ||
action="store_true", | ||
help="Outputs will not overwrite existing file unless --force is specified.", | ||
) | ||
p.add_argument( | ||
"-m", | ||
"--method", | ||
help=( | ||
f"The method for computing absorption correction. Allowed methods: {*CVE_METHODS, }. " | ||
f"Default method is polynomial interpolation if not specified. " | ||
), | ||
default="polynomial_interpolation", | ||
) | ||
p.add_argument( | ||
"-u", | ||
"--user-metadata", | ||
metavar="KEY=VALUE", | ||
nargs="+", | ||
help=( | ||
"Specify key-value pairs to be loaded into metadata using the format key=value. " | ||
"Separate pairs with whitespace, and ensure no whitespaces before or after the = sign. " | ||
"Avoid using = in keys. If multiple = signs are present, only the first separates the key and value. " | ||
"If a key or value contains whitespace, enclose it in quotes. " | ||
"For example, facility='NSLS II', 'facility=NSLS II', beamline=28ID-2, " | ||
"'beamline'='28ID-2', 'favorite color'=blue, are all valid key=value items. " | ||
), | ||
) | ||
p.add_argument( | ||
"-n", | ||
"--username", | ||
help=( | ||
"Username will be loaded from config files. Specify here " | ||
"only if you want to override that behavior at runtime. " | ||
), | ||
default=None, | ||
) | ||
p.add_argument( | ||
"-e", | ||
"--email", | ||
help=( | ||
"Email will be loaded from config files. Specify here " | ||
"only if you want to override that behavior at runtime. " | ||
), | ||
default=None, | ||
) | ||
p.add_argument( | ||
"-z", | ||
"--z-scan-file", | ||
help="Path to the z-scan file to be loaded to determine the mu*D value", | ||
default=None, | ||
) | ||
for arg in define_arguments(): | ||
kwargs = {key: value for key, value in arg.items() if key != "name" and key != "widget"} | ||
p.add_argument(*arg["name"], **kwargs) | ||
args = p.parse_args(override_cli_inputs) | ||
return args | ||
|
||
|
||
@Gooey(required_cols=1, optional_cols=1, program_name="Labpdfproc GUI") | ||
def gooey_parser(): | ||
p = GooeyParser() | ||
for arg in define_arguments(): | ||
kwargs = {key: value for key, value in arg.items() if key != "name"} | ||
p.add_argument(*arg["name"], **kwargs) | ||
args = p.parse_args() | ||
return args | ||
|
||
|
||
def main(): | ||
args = get_args() | ||
args = gooey_parser() if len(sys.argv) == 1 or "--gui" in sys.argv else get_args() | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
args = preprocessing_args(args) | ||
|
||
for filepath in args.input_paths: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need to redefine the input and zscan file arguments for gui, I think it's easier if we put all arguments in a separate function, so that later when we update the arguments we only need to update this.