Example #1
0
    def ct(self, seconds=None, scalers=[]):
        if not scalers:
            scalers = self.scalers

        if scalers is None or len(scalers) == 0:
            logging.error('Scaler list undefined (see %%config ECLIScaler.scalers)')
            return

        if seconds is None:
            seconds = self.default_count_time

        for scaler in scalers:
            if self.show_timestamp:
                print(' %s' % util.timestamp_string())
                print()

            dev = self._get_device(scaler)
            table = self.scaler_counts_table(dev, seconds)
            table.print_()
Example #2
0
    def single_step(self, scan=None, grid_point=(), point=0, array_idx=0,
                    **kwargs):
        """
        Callback: called after every single point in a stepscan
        """
        self._last_point = point
        data = [c.buff[array_idx] for c in scan.counters]

        def format_data(d):
            try:
                if isinstance(d, np.ndarray):
                    #return str(list(d[:10]))
                    return '-'
                else:
                    if int(d) == float(d):
                        return '%d' % int(d)
                    else:
                        return self.format_string % d
            except Exception as ex:
                return str(d)

        def grid_string(point, dimensions, delim=','):
            ret = []
            for pt, dim in zip(point, dimensions):
                dlen = len(str(dim))
                dformat = '%%.%dd' % (dlen, )
                ret.append(dformat % pt)
            return delim.join(ret)

        ndim = scan.ecli_info['ndim']
        dims = scan.ecli_info['dimensions']
        if ndim > 1 and self.show_grid_point:
            point_str = grid_string(grid_point, dims)
        else:
            point_str = u'%d' % point

        data_str = [point_str]

        # Get the posix timestamp
        ts = scan.get_timestamp(array_idx)

        # Convert it into a readable format
        ts = util.timestamp_string(ts)

        data_str.append(ts)
        data_str.extend([format_data(d) for d in data])

        header_widths = self._header_widths  # modified in-place

        # Ensure that none of the columns have changed size (such that
        # a printed value would be longer than its header field)
        longer_indices = [i for i, len_, value
                          in (izip(itertools.count(), header_widths, data_str))
                          if len(value) > len_]

        lengths_changed = False
        for index in longer_indices:
            header_widths[index] = len(data_str[index]) + 2
            lengths_changed = True

        # Re-print out the header if necessary
        if lengths_changed or (point % self.reprint_points) == 0:
            if point == 0 or self.reprint_headers:
                if self.blank_before_headers:
                    print(u'', file=self.outfile)
                self._print_headers(header_widths)

        # Right justify all of the values, and print them out
        data_str = [value.rjust(len_)
                    for len_, value in zip(header_widths, data_str)]
        print(u' '.join(data_str), file=self.outfile)