1- # -*- coding: utf-8 -*-
21"""
32Functions for loading and saving data and analyses
43"""
@@ -42,7 +41,6 @@ def load_physio(data, *, fs=None, dtype=None, history=None, allow_pickle=False):
4241 TypeError
4342 If provided `data` is unable to be loaded
4443 """
45-
4644 # first check if the file was made with `save_physio`; otherwise, try to
4745 # load it as a plain text file and instantiate a history
4846 if isinstance (data , str ):
@@ -53,13 +51,13 @@ def load_physio(data, *, fs=None, dtype=None, history=None, allow_pickle=False):
5351 inp [attr ] = inp [attr ].dtype .type (inp [attr ])
5452 except KeyError :
5553 raise ValueError (
56- "Provided npz file {} must have all of "
57- "the following attributes: {}" . format ( data , EXPECTED )
54+ f "Provided npz file { data } must have all of "
55+ f "the following attributes: { EXPECTED } "
5856 )
5957 # fix history, which needs to be list-of-tuple
6058 if inp ["history" ] is not None :
6159 inp ["history" ] = list (map (tuple , inp ["history" ]))
62- except (IOError , OSError , ValueError ):
60+ except (OSError , ValueError ):
6361 inp = dict (data = np .loadtxt (data ), history = [utils ._get_call (exclude = [])])
6462 logger .debug ("Instantiating Physio object from a file" )
6563 phys = physio .Physio (** inp )
@@ -81,14 +79,14 @@ def load_physio(data, *, fs=None, dtype=None, history=None, allow_pickle=False):
8179 phys = utils .new_physio_like (data , data .data , fs = fs , dtype = dtype )
8280 phys ._history += [utils ._get_call ()]
8381 else :
84- raise TypeError ("Cannot load data of type {}" . format ( type (data )) )
82+ raise TypeError (f "Cannot load data of type { type (data )} " )
8583
8684 # reset sampling rate, as requested
8785 if fs is not None and fs != phys .fs :
8886 if not np .isnan (phys .fs ):
8987 logger .warning (
9088 "Provided sampling rate does not match loaded rate. "
91- "Resetting loaded sampling rate {} to provided {}" . format ( phys . fs , fs )
89+ f "Resetting loaded sampling rate { phys . fs } to provided { fs } "
9290 )
9391 phys ._fs = fs
9492 # coerce datatype, if needed
@@ -114,7 +112,6 @@ def save_physio(fname, data):
114112 fname : str
115113 Full filepath to saved output
116114 """
117-
118115 from peakdet .utils import check_physio
119116
120117 data = check_physio (data )
@@ -145,21 +142,20 @@ def load_history(file, verbose=False):
145142 file : str
146143 Full filepath to saved output
147144 """
148-
149145 # import inside function for safety!
150146 # we'll likely be replaying some functions from within this module...
151147 import peakdet
152148
153149 # grab history from provided JSON file
154- with open (file , "r" ) as src :
150+ with open (file ) as src :
155151 history = json .load (src )
156152
157153 # replay history from beginning and return resultant Physio object
158154 logger .info (f"Replaying history from { file } " )
159155 data = None
160156 for func , kwargs in history :
161157 if verbose :
162- logger .info ("Rerunning {}" . format ( func ) )
158+ logger .info (f "Rerunning { func } " )
163159 # loading functions don't have `data` input because it should be the
164160 # first thing in `history` (when the data was originally loaded!).
165161 # for safety, check if `data` is None; someone could have potentially
@@ -205,7 +201,6 @@ def save_history(file, data):
205201 file : str
206202 Full filepath to saved output
207203 """
208-
209204 from peakdet .utils import check_physio
210205
211206 data = check_physio (data )
0 commit comments