def samplesToMins(self, indices): if isinstance(indices, slice): r = (arr([indices.start, indices.stop]) / self.Fs) / 60.0 r = slice(r[0], r[1]) else: r = (arr(indices) / self.Fs) / 60.0 return r
def savepeaks(self): if self.algmode == 'LOAD': log('skipping savepeaks for ' + str(self) + ' because data was loaded from file') # return False # obsolete stuff # if 'heartbeatevents_py' in self.peakfile.load().keys(): # del self.peakfile['heartbeatevents_py'] # del self.peakfile['heartbeatevents_mat'] export = { 'latency': arr(self.rPeaks) + 1, 'type': ['ECG' for _ in itr(self.rPeaks)], 'urevent': [i + 1 for i in itr(self.rPeaks)] } self.peakfile[self.alg.name()] = { 'alg': { 'name': self.alg.__class__.__name__, 'version': self.alg.version, 'tag': self.alg.versions()[self.alg.version] }, 'py': arr(self.rPeaks), 'mat': arr(self.rPeaks) + 1, 'heartbeatevents': export } self.peakfile['heartbeatevents'] = export return True
def __getitem__(self, item): if isinstance(item, tuple) and isinstance(item[0], Class): return self.data[ np.where(arr(self.ground_truth) == item[0], True, False), np.where(arr(self.ground_truth) == item[1], True, False) ] else: return super().__getitem__(item)
def times(self, indices=None): # seconds if indices is None: indices = self.rawslice if not isinstance(indices, slice): if len(indices) == 0: return arr() t = self._times[slice(min(indices), max(indices) + 1)] indices = arr(indices) - min(indices) t = t[indices] else: t = self._times[indices] return t
def _times(self): indices = self.rawslice if not isinstance(indices, slice): if len(indices) == 0: return arr() t = self.raw.times(slice(min(indices), max(indices) + 1)) indices = arr(indices) - min(indices) t = t[indices] else: t = self.raw.times(indices) return t
def append(self, exp_data, indices, is_GNET=False): if self.dims == 1: row = exp_data.y if is_GNET: row = np.mean(np.reshape(arr(row), (-1, 3)), axis=1).tolist() self.data = vert(self.data, row) elif self.dims == 2: data = arr(exp_data.data) if self.is_table: data = arr(exp_data.data, dtype=np.object) self.row_headers = make2d(data[:, 0]).T self.col_headers = make2d(data[0, :]) data = arr(data[1:, 1:], dtype=float) self.data = lay(self.data, data)
def sort_by_class_name(self): assert self.ground_truth is not None zipped = sort_human(zip(self.data.tolist(), self.ground_truth), keyparam=lambda p: p[1].name) templist = self.ground_truth = [] for z in zipped: templist.append(z[0]) self.ground_truth.append(z[1]) self.data = arr(templist)
def nandiv(a, v): r = arr() for i in itr(a): if isnan(a[i]): r = append(r, None) else: r = append(r, a[i] / v) return r
def nanstd(lll): # l = list(filter(lambda x: not isnan(x),l)) lll = arr(lll) lll = lll[np.invert(isnan(lll))] if len(lll) > 0: # tolist needed because dtype is obj sometimes for some reason ???? lll = lll[np.invert(isinf(lll.tolist()))] rr = safestd(lll) return rr
def prep_ys(y_true, y_pred): if not isinstance(y_true, mparray): y_true = y_true.numpy() y_true = y_true[:, 0] if not isinstance(y_pred, mparray): y_pred = y_pred.numpy() y_pred = y_pred[:, 0:nnstate.num_pred_classes()] y_pred = arr(list(map(maxindex, y_pred))) return y_true, y_pred
def difffun(lamb, ar): newlist = arrayfun(lamb, ar) diffs = arr() for idx, e in enumerate(newlist): if idx == 0: last_e = e continue # noinspection PyUnboundLocalVariable diffs += e - last_e last_e = e return diffs
def names(self, keepExtension=True): nams = [] path = self.abspath while path != '/' and len(path) > 0: head, tail = os.path.split(path) if '.' in tail and keepExtension is False: tail = tail.split('.')[0] nams.append(tail) # if head == '/': break path = File(head).abspath return arr(list(reversed(nams)))
def nanmean(lll): if ndims(lll) > 2: err('no ready') elif ndims(lll) == 2: rrr = arr() for i in range(0, lll.shape[1]): colu = list(filter(lambda x: not isnan(x), lll[:, i])) rrr += safemean(colu) else: # 1-d lll = list(filter(lambda x: not isnan(x), lll)) rrr = safemean(lll) # noinspection PyUnboundLocalVariable return rrr