Rescale (baseline correct) data. Parameters ---------- data : array It can be of any shape. The only constraint is that the last dimension should be time. times : 1D array Time instants is seconds. %(baseline_rescale)s mode : 'mean' | 'ratio' | 'logra
(data, times, baseline, mode="mean", copy=True, picks=None, verbose=None)
| 25 | |
| 26 | @verbose |
| 27 | def rescale(data, times, baseline, mode="mean", copy=True, picks=None, verbose=None): |
| 28 | """Rescale (baseline correct) data. |
| 29 | |
| 30 | Parameters |
| 31 | ---------- |
| 32 | data : array |
| 33 | It can be of any shape. The only constraint is that the last |
| 34 | dimension should be time. |
| 35 | times : 1D array |
| 36 | Time instants is seconds. |
| 37 | %(baseline_rescale)s |
| 38 | mode : 'mean' | 'ratio' | 'logratio' | 'percent' | 'zscore' | 'zlogratio' |
| 39 | Perform baseline correction by |
| 40 | |
| 41 | - subtracting the mean of baseline values ('mean') |
| 42 | - dividing by the mean of baseline values ('ratio') |
| 43 | - dividing by the mean of baseline values and taking the log |
| 44 | ('logratio') |
| 45 | - subtracting the mean of baseline values followed by dividing by |
| 46 | the mean of baseline values ('percent') |
| 47 | - subtracting the mean of baseline values and dividing by the |
| 48 | standard deviation of baseline values ('zscore') |
| 49 | - dividing by the mean of baseline values, taking the log, and |
| 50 | dividing by the standard deviation of log baseline values |
| 51 | ('zlogratio') |
| 52 | |
| 53 | copy : bool |
| 54 | Whether to return a new instance or modify in place. |
| 55 | picks : list of int | None |
| 56 | Data to process along the axis=-2 (None, default, processes all). |
| 57 | %(verbose)s |
| 58 | |
| 59 | Returns |
| 60 | ------- |
| 61 | data_scaled: array |
| 62 | Array of same shape as data after rescaling. |
| 63 | """ |
| 64 | if copy: |
| 65 | data = data.copy() |
| 66 | if verbose is not False: |
| 67 | msg = _log_rescale(baseline, mode) |
| 68 | logger.info(msg) |
| 69 | if baseline is None or data.shape[-1] == 0: |
| 70 | return data |
| 71 | |
| 72 | bmin, bmax = baseline |
| 73 | if bmin is None: |
| 74 | imin = 0 |
| 75 | else: |
| 76 | imin = np.where(times >= bmin)[0] |
| 77 | if len(imin) == 0: |
| 78 | raise ValueError( |
| 79 | f"bmin is too large ({bmin}), it exceeds the largest time value" |
| 80 | ) |
| 81 | imin = int(imin[0]) |
| 82 | if bmax is None: |
| 83 | imax = len(times) |
| 84 | else: |