Skip to content

Commit

Permalink
Integrate loguru for warning and info logs
Browse files Browse the repository at this point in the history
  • Loading branch information
maestroque committed Apr 15, 2024
1 parent 6dd3ce2 commit d33b5ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions peakdet/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ def workflow(*, file_template, modality, fs, source='MRI', channel=1,
"""

# output file
print('OUTPUT FILE:\t\t{}\n'.format(output))
logger.info('OUTPUT FILE:\t\t{}\n'.format(output))
# grab files from file template
print('FILE TEMPLATE:\t{}\n'.format(file_template))
logger.info('FILE TEMPLATE:\t{}\n'.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 '
'specifying desired output measurements. Please '
Expand All @@ -168,10 +168,10 @@ def workflow(*, file_template, modality, fs, source='MRI', channel=1,
# requested on command line, warn and use existing measurements so
# as not to totally fork up existing file
if eheader != head:
warnings.warn('Desired output file already exists and requested '
'measurements do not match with measurements in '
'existing output file. Using the pre-existing '
'measurements, instead.')
logger.warning('Desired output file already exists and requested '
'measurements do not match with measurements in '
'existing output file. Using the pre-existing '
'measurements, instead.')
measurements = [f.strip() for f in eheader.split(',')[1:]]
head = ''
# if output file doesn't exist, nbd
Expand All @@ -183,7 +183,7 @@ def workflow(*, file_template, modality, fs, source='MRI', channel=1,
# 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(os.path.dirname(fname),
Expand Down
6 changes: 3 additions & 3 deletions peakdet/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def load_rtpeaks(fname, channel, fs):
"""

if fname.startswith('/'):
warnings.warn('Provided file seems to be an absolute path. In order '
'to ensure full reproducibility it is recommended that '
'a relative path is provided.')
logger.warning('Provided file seems to be an absolute path. In order '
'to ensure full reproducibility it is recommended that '
'a relative path is provided.')

with open(fname, 'r') as src:
header = src.readline().strip().split(',')
Expand Down
16 changes: 8 additions & 8 deletions peakdet/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def load_physio(data, *, fs=None, dtype=None, history=None,
# if we got a numpy array, load that into a Physio object
elif isinstance(data, np.ndarray):
if history is None:
warnings.warn('Loading data from a numpy array without providing a'
'history will render reproducibility functions '
'useless! Continuing anyways.')
logger.warning('Loading data from a numpy array without providing a'
'history will render reproducibility functions '
'useless! Continuing anyways.')
phys = physio.Physio(np.asarray(data, dtype=dtype), fs=fs,
history=history)
# create a new Physio object out of a provided Physio object
Expand All @@ -81,7 +81,7 @@ def load_physio(data, *, fs=None, dtype=None, history=None,
# reset sampling rate, as requested
if fs is not None and fs != phys.fs:
if not np.isnan(phys.fs):
warnings.warn('Provided sampling rate does not match loaded rate. '
logger.warning('Provided sampling rate does not match loaded rate. '
'Resetting loaded sampling rate {} to provided {}'
.format(phys.fs, fs))
phys._fs = fs
Expand Down Expand Up @@ -151,7 +151,7 @@ def load_history(file, verbose=False):
data = None
for (func, kwargs) in history:
if verbose:
print('Rerunning {}'.format(func))
logger.info('Rerunning {}'.format(func))
# loading functions don't have `data` input because it should be the
# first thing in `history` (when the data was originally loaded!).
# for safety, check if `data` is None; someone could have potentially
Expand Down Expand Up @@ -197,9 +197,9 @@ def save_history(file, data):

data = check_physio(data)
if len(data.history) == 0:
warnings.warn('History of provided Physio object is empty. Saving '
'anyway, but reloading this file will result in an '
'error.')
logger.warning('History of provided Physio object is empty. Saving '
'anyway, but reloading this file will result in an '
'error.')
file += '.json' if not file.endswith('.json') else ''
with open(file, 'w') as dest:
json.dump(data.history, dest, indent=4)
Expand Down

0 comments on commit d33b5ac

Please sign in to comment.