diff --git a/src/apanalysis.py b/src/apanalysis.py index 213a9af63fad181c46851326ccf26e2d7b065824..2dad19b184b6ddbe583c460dbecb0e6082a4f894 100644 --- a/src/apanalysis.py +++ b/src/apanalysis.py @@ -200,7 +200,7 @@ def remove_stimuli(signal, stimuli, fs, copy=True, max_stim_duration_ms=25): return fsig, np.array(stims) -def load_file(fn: str): +def load_file(fn: str, tscl = -1, vmscl = -1): if not os.path.exists(fn): raise Exception('Error: Cannot open datafile.') @@ -213,10 +213,28 @@ def load_file(fn: str): except: try: data = np.loadtxt(fn, skiprows=1) - #data[:,0] *= 1000 - #data[:,1] *= 100 + + if tscl == -1: + # Autoscaling of time column to end up in ms + dt = np.average(np.diff(data[:,0])) + if dt <= 0.001: # if this was ms, f_s would be >= 1MHz + tscl = 1000. + data[:,0] *= tscl + + if vmscl == -1: + # Automatic scaling of V column to end up in mV + vmm = np.abs(np.median(data[:,1])) + if vmm <= 0.1: # TODO less than mikrovolts? + vmscl = 1000. + elif 0.1 < vmm <= 1.: + vmscl = 100. + elif 1. < vmm <= 10.: + vmscl = 10. + else: + vmscl = 1. + data[:,1] *= vmscl + aps = [data] - except: print('Unable to load from file', fn) raise Exception('Unable to load from file {}'.format(fn))