Beispiel #1
0
    def _update_cb(self, sender, ins_param, val):
        if ins_param not in self._watch:
            return

        info = self._watch[ins_param]
        ins = info['instrument']
        param = info['parameter']
        strval = qt.format_parameter_value(info['options'], val)
        self._tree_model.set(info['iter'], 2, strval)

        if not info.get('graph', False):
            return

        cols = self._get_ncols(info, val)
        plotname = 'watch_%s.%s' % (ins.get_name(), param)

        # Create temp file and setup plotting
        if 'tempfile' not in info:
            info['tempfile'] = temp.File(mode='w')

            cmd = 'qt.plot_file("%s", name="%s", clear=True)' % (
                info['tempfile'].name, plotname)
            qt.cmd(cmd, callback=lambda *x: True)
            for i in range(cols - 2):
                cmd = 'qt.plot_file("%s", name="%s", valdim=%d)' % (
                    info['tempfile'].name, plotname, i + 2)
                qt.cmd(cmd, callback=lambda *x: True)
        else:
            info['tempfile'].reopen()

        # Allocate array, fill xs and ys with first point, shift otherwise
        if 'data' not in info or info['data'] is None:
            d = np.ones([info['points'], cols])
            info['data'] = d
            r = self._get_row(info, val)
            for i in range(cols):
                d[:, i] = r[i]
        else:
            info['data'][:-1, :] = info['data'][1:, :]

        r = self._get_row(info, val, prevrow=info['data'][-2, :])
        info['data'][-1, :] = r

        np.savetxt(info['tempfile'].get_file(), info['data'])
        info['tempfile'].close()
        cmd = 'qt.plots["%s"].update()' % (plotname, )
        qt.cmd(cmd)
    def _update_cb(self, sender, ins_param, val):
        if ins_param not in self._watch:
            return

        info = self._watch[ins_param]
        ins = info['instrument']
        param = info['parameter']
        strval = qt.format_parameter_value(info['options'], val)
        self._tree_model.set(info['iter'], 2, strval)

        if not info.get('graph', False):
            return

        plotname = 'watch_%s.%s' % (ins.get_name(), param)
        if 'data' not in info or info['data'] is None:
            cols = self._get_ncols(info, val)
            d = np.zeros([info['points'], cols], dtype=np.float)
            r = self._get_row(info, val)
            d[0, :] = self._get_row(info, val)
            info['data'] = d
            info['tempfile'] = temp.File(mode='w')

            cmd = 'qt.plot_file("%s", name="%s", clear=True)' % (
                info['tempfile'].name, plotname)
            qt.cmd(cmd, callback=lambda *x: do_print(x))
            for i in range(cols - 2):
                cmd = 'qt.plot_file("%s", name="%s", valdim=%d)' % (
                    info['tempfile'].name, plotname, i + 2)
                qt.cmd(cmd, callback=lambda *x: do_print(x))

        else:
            info['tempfile'].reopen()

        info['data'][0:-1, :] = info['data'][1:, :]
        r = self._get_row(info, val, prevrow=info['data'][-2, :])
        info['data'][-1, :] = self._get_row(info,
                                            val,
                                            prevrow=info['data'][-2, :])
        np.savetxt(info['tempfile'].get_file(), info['data'])
        info['tempfile'].close()
        cmd = 'qt.plots["%s"].update()' % (plotname, )
        qt.cmd(cmd)
Beispiel #3
0
    def create_tempfile(self, path=None):
        '''
        Create a temporary file, optionally called <path>.
        '''

        if self._temp_binary:
            mode = 'wb'
        else:
            mode = 'w'
        self._file = temp.File(path, mode=mode, binary=self._temp_binary)
        try:
            if self._temp_binary:
                ret = self._write_binary()
            else:
                self._write_data()

            self._dir, self._filename = os.path.split(self._file.name)
            self._file.close()
            self._tempfile = True
        except Exception, e:
            logging.warning('Error creating temporary file: %s', e)
            self._dir = ''
            self._filename = ''
            self._tempfile = False