def gate(self, fcm, chan=None, name=None, _full=False): """ return gated region """ if chan is None: chan = self.chan if name is None: if self.name is not '': name = self.name else: name = '' if name is not "" and len(name) != 4: raise ValueError( 'name must be empty or contain 4 items: name is %s' % str(name)) # I (+,+), II (-,+), III (-,-), and IV (+,-) x = fcm.view()[:, chan[0]] y = fcm.view()[:, chan[1]] quad = {} quad[1] = (x > self.vert[0]) & (y > self.vert[1]) # (+,+) quad[2] = (x < self.vert[0]) & (y > self.vert[1]) # (-,+) quad[3] = (x < self.vert[0]) & (y < self.vert[1]) # (-,-) quad[4] = (x > self.vert[0]) & (y < self.vert[1]) # (+,-) root = fcm.get_cur_node() cname = root.name if name is "": name = ["q%d" % i for i in quad.keys()] if _full: nodes = [] for i in quad.keys(): if not self.allow_empty: if True in quad[i]: fcm.tree.visit(cname) node = GatingNode(name[i - 1], root, quad[i]) fcm.add_view(node) if _full: nodes.append(node) else: fcm.tree.visit(cname) node = GatingNode(name[i - 1], root, quad[i]) fcm.add_view(node) if _full: nodes.append(node) if _full: return nodes else: return fcm
def gate(self, fcm, chan=None, op=None, name=None): """ return all events greater (or less) than a threshold allowed op are 'g' (greater) or 'l' (less) """ if chan is None: chan = self.chan x = fcm.view()[:, chan] if op is None: op = self.op if op == 'g': idxs = numpy.greater(x, self.vert) elif op == 'l': idxs = numpy.less(x, self.vert) else: raise ValueError('op should be "g" or "l", received "%s"' % str(op)) if name is None: name = self.name node = GatingNode(name, fcm.get_cur_node(), idxs) fcm.add_view(node) return fcm
def gate(self, fcm, chan=None, invert=False, name=None): """ return gated region of FCM data """ if chan is None: chan = self.chan if isinstance(chan, tuple): chan = list(chan) for i, j in enumerate(chan): if isinstance(j, str): chan[i] = fcm.name_to_index(j)[0] if name is None: name = self.name idxs = points_in_poly(self.vert, fcm.view()[:, chan]) # matplotlib has points in poly routine in C # no faster than our numpy version # idxs = points_inside_poly(fcm.view()[:, chan], self.vert) if invert: idxs = numpy.invert(idxs) node = GatingNode(name, fcm.get_cur_node(), idxs) fcm.add_view(node) return fcm
def gate(self, fcm, chan=None, name=None): """ return interval region. """ if chan is None: chan = self.chan if name is None: name = self.name assert (len(self.chan) == 1) assert (len(self.vert) == 2) assert (self.vert[1] >= self.vert[0]) x = fcm.view()[:, chan[0]] idxs = numpy.logical_and(x > self.vert[0], x < self.vert[1]) node = GatingNode(name, fcm.get_cur_node(), idxs) fcm.add_view(node) return fcm