-
Notifications
You must be signed in to change notification settings - Fork 20
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
Integrate Loguru #62
Merged
Merged
Integrate Loguru #62
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6dd3ce2
Add loguru exception catching
maestroque d33b5ac
Integrate loguru for warning and info logs
maestroque 72c427b
Add loguru in requirements
maestroque a9b0c18
Add loguru to setup.cfg
maestroque acd31cd
Disable loguru logs for library users
maestroque 537f48a
Add verbose option in CLI
maestroque bb7ce79
Fix loguru disabling for library users
maestroque 7070d70
Add logger enabling and configuring
maestroque 405254c
Leave logger.catch decorator only for the CLI workflow function
maestroque cbfc013
Remove unnecessary imports
maestroque 4d8ffa3
Add loguru as a main dependency
maestroque 3724928
Reformat using isort and black
maestroque 333e94b
CLI: minor fixes for verbose argument
maestroque afcc380
Remove Gooey from draft CLI implementation
maestroque be82040
Minor comment deletion and reformatting
maestroque 7fcb3ab
Add log level choice option in CLI
maestroque 3253566
Add logfile sink
maestroque 8dd3166
Add --verbose flag in the CLI
maestroque cd22a43
Add log level choosing for module usage
maestroque 2ac91a3
Add info and debug logs physio.py and operations.py functions
maestroque 81750e3
Add info logs on editor.py and io.py
maestroque 7f8fd6a
Fix warning catching assertions in tests
maestroque 86adcf3
Improve warning log assertions when there are multiple expected warni…
maestroque b52d13a
Style fix
maestroque 5af076b
Updating from master
maestroque c568cb2
Remove unused imports
maestroque 6c4dcde
Merge remote-tracking branch 'origin/master' into add-loguru
maestroque a78544c
Fix loguru not detecting module's name
maestroque a008c72
Add more logger utilities. Fix multiple logger instance bug
maestroque 8f6b944
Remove commented out line
maestroque b865617
Fix imports in cli/run.py
maestroque 145d48f
Make --quiet and --debug cli options mutually exclusive, remove matpl…
maestroque File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,16 @@ | |
import glob | ||
import os | ||
import sys | ||
import warnings | ||
|
||
import matplotlib | ||
|
||
matplotlib.use("WXAgg") | ||
from gooey import Gooey, GooeyParser | ||
import argparse | ||
import datetime | ||
|
||
from loguru import logger | ||
maestroque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# from gooey import Gooey, GooeyParser | ||
maestroque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import peakdet | ||
|
||
TARGET = "pythonw" if sys.platform == "darwin" else "python" | ||
|
@@ -41,19 +44,11 @@ | |
} | ||
|
||
|
||
@Gooey( | ||
program_name="Physio pipeline", | ||
program_description="Physiological processing pipeline", | ||
default_size=(800, 600), | ||
target=TARGET, | ||
) | ||
def get_parser(): | ||
"""Parser for GUI and command-line arguments""" | ||
parser = GooeyParser() | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"file_template", | ||
metavar="Filename template", | ||
widget="FileChooser", | ||
help="Select a representative file and replace all " | ||
'subject-specific information with a "?" symbol.' | ||
"\nFor example, subject_001_data.txt should " | ||
|
@@ -67,28 +62,24 @@ def get_parser(): | |
) | ||
inp_group.add_argument( | ||
"--modality", | ||
metavar="Modality", | ||
default="ECG", | ||
choices=list(MODALITIES.keys()), | ||
help="Modality of input data.", | ||
) | ||
inp_group.add_argument( | ||
"--fs", | ||
metavar="Sampling rate", | ||
default=1000.0, | ||
type=float, | ||
help="Sampling rate of input data.", | ||
) | ||
inp_group.add_argument( | ||
"--source", | ||
metavar="Source", | ||
default="rtpeaks", | ||
choices=list(LOADERS.keys()), | ||
help="Program used to collect the data.", | ||
) | ||
inp_group.add_argument( | ||
"--channel", | ||
metavar="Channel", | ||
default=1, | ||
type=int, | ||
help="Which channel of data to read from data " | ||
|
@@ -102,7 +93,6 @@ def get_parser(): | |
out_group.add_argument( | ||
"-o", | ||
"--output", | ||
metavar="Filename", | ||
default="peakdet.csv", | ||
help="Output filename for generated measurements.", | ||
) | ||
|
@@ -111,16 +101,13 @@ def get_parser(): | |
"--measurements", | ||
metavar="Measurements", | ||
nargs="+", | ||
widget="Listbox", | ||
choices=list(ATTR_CONV.keys()), | ||
default=["Average NN intervals", "Standard deviation of NN intervals"], | ||
help="Desired physiological measurements.\nChoose " | ||
"multiple with shift+click or ctrl+click.", | ||
help="Desired physiological measurements", | ||
) | ||
out_group.add_argument( | ||
"-s", | ||
"--savehistory", | ||
metavar="Save history", | ||
action="store_true", | ||
help="Whether to save history of data processing " "for each file.", | ||
) | ||
|
@@ -132,22 +119,45 @@ def get_parser(): | |
edit_group.add_argument( | ||
"-n", | ||
"--noedit", | ||
metavar="Editing", | ||
action="store_true", | ||
help="Turn off interactive editing.", | ||
) | ||
edit_group.add_argument( | ||
"-t", | ||
"--thresh", | ||
metavar="Threshold", | ||
default=0.2, | ||
type=float, | ||
help="Threshold for peak detection algorithm.", | ||
) | ||
edit_group.add_argument( | ||
"-debug", | ||
"--debug", | ||
dest="debug", | ||
action="store_true", | ||
help="Only print debugging info to log file. Default is False.", | ||
default=False, | ||
) | ||
edit_group.add_argument( | ||
"-quiet", | ||
"--quiet", | ||
dest="quiet", | ||
action="store_true", | ||
help="Only print warnings to log file. Default is False.", | ||
default=False, | ||
) | ||
edit_group.add_argument( | ||
"-verbose", | ||
"--verbose", | ||
dest="verbose", | ||
action="store_true", | ||
help="Print verbose error logs with diagnostics", | ||
default=False, | ||
) | ||
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. Could you add these three into a mutually exclusive group of arguments? 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. |
||
|
||
return parser | ||
|
||
|
||
@logger.catch | ||
def workflow( | ||
*, | ||
file_template, | ||
|
@@ -159,7 +169,10 @@ def workflow( | |
savehistory=True, | ||
noedit=False, | ||
thresh=0.2, | ||
measurements=ATTR_CONV.keys() | ||
measurements=ATTR_CONV.keys(), | ||
verbose=False, | ||
debug=False, | ||
quiet=False, | ||
): | ||
""" | ||
Basic workflow for physiological data | ||
|
@@ -190,17 +203,74 @@ def workflow( | |
measurements : list, optional | ||
Which HRV-related measurements to save from data. See ``peakdet.HRV`` | ||
for available measurements. Default: all available measurements. | ||
verbose : bool, optional | ||
Whether to include verbose logs when catching exceptions that include diagnostics | ||
""" | ||
outdir = os.path.dirname(output) | ||
logger.info(f"Current path is {outdir}") | ||
|
||
# Create logfile name | ||
basename = "peakdet" | ||
extension = "log" | ||
isotime = datetime.datetime.now().strftime("%Y-%m-%dT%H%M%S") | ||
logname = os.path.join(outdir, (basename + isotime + "." + extension)) | ||
|
||
logger.remove(0) | ||
if quiet: | ||
logger.add( | ||
sys.stderr, | ||
level="WARNING", | ||
colorize=True, | ||
backtrace=verbose, | ||
diagnose=verbose, | ||
) | ||
logger.add( | ||
logname, | ||
level="WARNING", | ||
colorize=False, | ||
backtrace=verbose, | ||
diagnose=verbose, | ||
) | ||
elif debug: | ||
logger.add( | ||
sys.stderr, | ||
level="DEBUG", | ||
colorize=True, | ||
backtrace=verbose, | ||
diagnose=verbose, | ||
) | ||
logger.add( | ||
logname, | ||
level="DEBUG", | ||
colorize=False, | ||
backtrace=verbose, | ||
diagnose=verbose, | ||
) | ||
else: | ||
logger.add( | ||
sys.stderr, | ||
level="INFO", | ||
colorize=True, | ||
backtrace=verbose, | ||
diagnose=verbose, | ||
) | ||
logger.add( | ||
logname, | ||
level="INFO", | ||
colorize=False, | ||
backtrace=verbose, | ||
diagnose=verbose, | ||
) | ||
|
||
# output file | ||
print("OUTPUT FILE:\t\t{}\n".format(output)) | ||
logger.info("OUTPUT FILE:\t\t{}".format(output)) | ||
# grab files from file template | ||
print("FILE TEMPLATE:\t{}\n".format(file_template)) | ||
logger.info("FILE TEMPLATE:\t{}".format(file_template)) | ||
files = glob.glob(file_template, recursive=True) | ||
|
||
# convert measurements to peakdet.HRV attribute friendly names | ||
try: | ||
print("REQUESTED MEASUREMENTS: {}\n".format(", ".join(measurements))) | ||
logger.info("REQUESTED MEASUREMENTS: {}\n".format(", ".join(measurements))) | ||
except TypeError: | ||
raise TypeError( | ||
"It looks like you didn't select any of the options " | ||
|
@@ -221,7 +291,7 @@ def workflow( | |
# requested on command line, warn and use existing measurements so | ||
# as not to totally fork up existing file | ||
if eheader != head: | ||
warnings.warn( | ||
logger.warning( | ||
"Desired output file already exists and requested " | ||
"measurements do not match with measurements in " | ||
"existing output file. Using the pre-existing " | ||
|
@@ -238,7 +308,7 @@ def workflow( | |
# iterate through all files and do peak detection with manual editing | ||
for fname in files: | ||
fname = os.path.relpath(fname) | ||
print("Currently processing {}".format(fname)) | ||
logger.info("Currently processing {}".format(fname)) | ||
|
||
# if we want to save history, this is the output name it would take | ||
outname = os.path.join( | ||
|
@@ -281,6 +351,7 @@ def workflow( | |
|
||
|
||
def main(): | ||
logger.enable("") | ||
opts = get_parser().parse_args() | ||
workflow(**vars(opts)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm sorry, I'm thick about this, but why are we importing and then disabling for peakdet?
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.
So that the loguru logger is disabled by default for library users, so they can enable it explicitly if they want to. This is not the case for the CLI however