Exemplo n.º 1
0
    def update(self):
        y = array(self.input.readings_dot)
        from procgraph_mpl import pylab2rgb, pylab

        if max(abs(y)) > 1:
            raise BadInput('I expect an input normalized in the [-1,1] range;'
                           'min,max: %s,%s ' % (min(y), max(y)),
                           self, 'readings_dot')

        f = pylab.figure(frameon=False,
                        figsize=(self.config.width / 100.0,
                                 self.config.height / 100.0))

        R0 = self.config.R0
        amp = self.config.amp

        theta = linspace(0, 2 * math.pi, 300)
        pylab.plot(R0 * cos(theta), R0 * sin(theta), 'k--')

        for group in self.config.groups:
            indices = group['indices']
            indices = range(indices[0], indices[-1] + 1)
            theta_spec = group['theta']
            origin = group.get('origin', [0, 0, 0])
            color = group.get('color', 'b.')

            N = len(indices)

            theta = linspace(theta_spec[0], theta_spec[-1], N)

            group_y = y[indices]

            r = R0 + amp * group_y

            px = cos(theta + origin[2]) * r
            py = sin(theta + origin[2]) * r

            pylab.plot(-py, px, color)

        M = R0 + amp * 1.2
        pylab.axis([-M, M, -M, M])

        # turn off ticks labels, they don't have meaning
        pylab.setp(f.axes[0].get_xticklabels(), visible=False)
        pylab.setp(f.axes[0].get_yticklabels(), visible=False)

        if self.config.title is not None:
            if self.config.title != "":
                pylab.title(self.config.title, fontsize=10)
        else:
            # We don't have a title ---
            t = self.get_input_signals_names()[0]
            pylab.title(t, fontsize=10)

        self.output.image = pylab2rgb(transparent=self.config.transparent)

        pylab.close(f.number)
Exemplo n.º 2
0
    def update(self):

        readings = array(self.input.readings)

        if len(readings.shape) > 1:
            msg = 'Expected flat array, got shape %s' % str(readings.shape)
            raise BadInput(msg, self, 0)

        from procgraph_mpl import pylab, pylab2rgb


        f = pylab.figure(frameon=False,
                        figsize=(self.config.width / 100.0,
                                 self.config.height / 100.0))

        # limit the readings

        bounds = array([0, 0, 0, 0])

        for group in self.config.groups:
            indices = group['indices']
            indices = range(indices[0], indices[-1] + 1)
            theta_spec = group['theta']
            origin = group.get('origin', [0, 0, 0])
            color = group.get('color', 'b.')

            max_readings = group.get('max_readings', self.config.max_readings)
            group_readings = minimum(readings[indices], max_readings)

            N = len(indices)

            theta = linspace(theta_spec[0], theta_spec[-1], N)

            assert len(theta) == len(group_readings)

            x = cos(theta + origin[2]) * group_readings + origin[0]
            y = sin(theta + origin[2]) * group_readings + origin[1]

            valid_flag = group_readings < max_readings
            valid, = nonzero(valid_flag)
            invalid, = nonzero(logical_not(valid_flag))

            pylab.plot(-y[valid], x[valid], color)
            pylab.plot(-y[invalid], x[invalid], 'r.')

            R = max_readings * 1.1
            x_R = R * cos(theta)
            y_R = R * sin(theta)
            group_bounds = array([min(x_R), max(x_R), min(y_R), max(y_R)])
            for i in [1, 3]:
                bounds[i] = maximum(bounds[i], group_bounds[i])
            for i in [0, 2]:
                bounds[i] = minimum(bounds[i], group_bounds[i])

        pylab.axis(bounds)

        if self.config.title is not None:
            if self.config.title != "":
                pylab.title(self.config.title, fontsize=10)
        else:
            # We don't have a title ---
            t = self.get_input_signals_names()[0]
            pylab.title(t, fontsize=10)

        self.output.image = pylab2rgb(transparent=self.config.transparent)
        #tight=True)

        pylab.close(f.number)