示例#1
0
文件: Main.py 项目: jfrelinger/flow
    def BuildColorPanel(self):
        """Select components by color and reassign labels if desired."""
        panel = wx.ScrolledWindow(self, -1, style=wx.VSCROLL)
        color_names = self.model.GetZLabels(self.model.GetCurrentZ(self.group))
        self.cbs = [wx.CheckBox(panel, -1, name) for name in color_names]

        if self.colors is not None:
            maxz = max(self.colors)
            colors = [colormap.floatRgb(i, 0, maxz + 1, i / (maxz + 1)) for i in range(maxz + 1)]

            self.popup = wx.Menu()
            zlabel = self.popup.Append(-1, "Edit label")
            self.popup.Bind(wx.EVT_MENU, self.OnZLabel, zlabel)

            for i, cb in enumerate(self.cbs):
                r, g, b, alpha = colors[i]
                r = int(r * 255)
                g = int(g * 255)
                b = int(b * 255)
                cb.SetValue(True)
                cb.SetBackgroundColour(wx.Colour(r, g, b))
                self.Bind(wx.EVT_CHECKBOX, self.DisableColors, cb)
                cb.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup)

            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.AddMany(self.cbs)
            panel.SetSizer(sizer)
            panel.SetScrollRate(0, 5)
            self.leftPanel.Insert(1, panel, 1, wx.ALL | wx.EXPAND)

        return panel
示例#2
0
文件: Main.py 项目: jfrelinger/flow
    def draw(self):
        alpha = 1.0
        if not hasattr(self, "ms"):
            try:
                self.ms = min(1, 1000.0 / len(self.x))
            except (ZeroDivisionError, TypeError):
                self.ms = 1.0
        if not hasattr(self, "subplot"):
            self.subplot = self.figure.add_subplot(111)
        self.subplot.clear()
        if self.x is not None:
            # sample at most 10000 points for display
            npts = 10000
            if len(self.x) > npts:
                stride = len(self.x) / npts
            else:
                stride = 1

            x = self.x[: npts * stride : stride]
            y = self.y[: npts * stride : stride]

            self.subplot.set_xlabel(self.xlab)
            self.subplot.set_ylabel(self.ylab)
            self.subplot.set_title(self.title)
            if self.scatter.IsChecked():
                # add stuff to color in and out of gate differently
                try:
                    #                 xi = []
                    #                 yi = []
                    #                 xo = []
                    #                 yo = []

                    idx = self.p.PointsInPoly(array([x, y]))
                    xi = x[idx]
                    yi = y[idx]
                    xo = x[~idx]
                    yo = y[~idx]

                    #                 for pt in zip(x, y):
                    #                     if self.p.PointInPoly(pt):
                    #                         xi.append(pt[0])
                    #                         yi.append(pt[1])
                    #                     else:
                    #                         xo.append(pt[0])
                    #                         yo.append(pt[1])
                    self.subplot.plot(xi, yi, "r.", ms=self.ms)
                    self.subplot.plot(xo, yo, "b.", ms=self.ms)
                except AttributeError:
                    # PUT COLOR CODE HERE
                    # ONLY WORKS IF NOT GATING
                    if hasattr(self, "model") and self.Zs is not None and len(self.Zs) == len(self.x):
                        z = array(self.Zs[:], "i")
                        maxz = max(z)
                        self.colors = [colormap.floatRgb(i, 0, maxz + 1, i / (maxz + 1)) for i in range(maxz + 1)]
                        for i in range(maxz + 1):
                            if hasattr(self, "components") and i not in self.components:
                                continue
                            xx = self.x[z == i][: npts * stride : stride]
                            yy = self.y[z == i][: npts * stride : stride]
                            self.subplot.plot(xx, yy, ".", c=self.colors[i], alpha=alpha, ms=self.ms)
                    else:
                        bins = 100
                        z, xedge, yedge = histogram2d(
                            y, x, bins=[bins, bins], range=[(min(y), max(y)), (min(x), max(x))]
                        )

                        # interpolate to get rid of blocky effect
                        # from http://en.wikipedia.org/wiki/Bilinear_interpolation
                        xfrac, xint = modf((x - min(x)) / (max(x) - min(x)) * (bins - 1))
                        yfrac, yint = modf((y - min(y)) / (max(y) - min(y)) * (bins - 1))

                        zvals = zeros(len(xint), "d")
                        for i, (_x, _y, _xf, _yf) in enumerate(zip(xint, yint, xfrac, yfrac)):
                            q11 = z[_y, _x]
                            if _xf:
                                q12 = z[_y, _x + 1]
                            else:
                                q12 = 0
                            if _yf:
                                q21 = z[_y + 1, _x]
                            else:
                                q21 = 0
                            if _xf and _yf:
                                q22 = z[_y + 1, _x + 1]
                            else:
                                q22 = 0

                            zvals[i] = (
                                q11 * (1 - _xf) * (1 - _yf)
                                + q21 * (1 - _xf) * (_yf)
                                + q12 * (_xf) * (1 - _yf)
                                + q22 * (_xf) * (_yf)
                            )

                        try:
                            s = self.subplot.scatter(x, y, alpha=alpha, s=1, c=zvals, edgecolors="none")
                        except LinAlgError, e:
                            print "LinAlgError 533"
                            print e
                            print dir(e)
                            print e.args
                            print e.message
                alpha = alpha - 0.25

            # always put labels on if possible at mean location
            if (not self.ellipse.IsChecked()) and (self.coord1 != self.coord2):
                try:
                    mu = self.parentg.mu_end[:]
                    lvl = 0
                    for i, m in enumerate(mu):
                        lvl += 1
                        if hasattr(self, "components") and i not in self.components:
                            continue
                        xk = m[self.coord1]
                        yk = m[self.coord2]
                        self.subplot.text(
                            xk,
                            yk,
                            str(lvl),
                            fontsize=14,
                            weight="bold",
                            bbox=dict(facecolor="yellow", alpha=0.5),
                            va="center",
                            ha="center",
                        )
                except AttributeError, e:
                    # don't label if error (e.g. no mu_end)
                    pass