Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        '''
        Create data object. There are three different uses:
        1) create an empty data object for use in a measurement
        2) create a data object and fill immediately with a numpy array
        3) create a data object from an existing data file

        All inputs are optional.
        The 'name' input is used in an internal list (accessable through
        qt.data). If omitted, a name will be auto generated.
        This 'name' will also be used later to auto generate a filename
        when calling 'create_file()' (if that is called without options).
        The input 'filename' here is only used for loading an existing file.

        args input:
            filename (string), set the filename to load.
            data (numpy.array), array to construct data object for

        kwargs input:
            name (string), default will be 'data<n>'
            infile (bool), default True
            inmem (bool), default False if no file specified, True otherwise
            tempfile (bool), default False. If True create a temporary file
                for the data.
            binary (bool), default True. Whether tempfile should be binary.
        '''

        # Init SharedGObject a bit lower

        name = kwargs.get('name', '')
        infile = kwargs.get('infile', True)
        inmem = kwargs.get('inmem', False)

        self._inmem = inmem
        self._tempfile = kwargs.get('tempfile', False)
        self._temp_binary = kwargs.get('binary', True)
        self._options = kwargs
        self._file = None
        self._stop_req_hid = None

        # Dimension info
        self._dimensions = []
        self._block_sizes = []
        self._loopdims = None
        self._loopshape = None
        self._complete = False
        self._reshaped_data = None

        # Number of coordinate dimensions
        self._ncoordinates = 0

        # Number of value dimensions
        self._nvalues = 0

        # Number of data points
        self._npoints = 0
        self._npoints_last_block = 0
        self._npoints_max_block = 0

        self._comment = []
        self._localtime = time.localtime()
        self._timestamp = time.asctime(self._localtime)
        self._timemark = time.strftime('%H%M%S', self._localtime)
        self._datemark = time.strftime('%Y%m%d', self._localtime)

        # FIXME: the name generation here is a bit nasty
        name = Data._data_list.new_item_name(self, name)
        self._name = name

        SharedGObject.__init__(self,
                               'data_%s' % name,
                               replace=True,
                               idle_emit=True)

        data = get_arg_type(args, kwargs, (numpy.ndarray, list, tuple), 'data')
        if data is not None:
            self.set_data(data)
        else:
            self._data = numpy.array([])
            self._infile = infile

        filepath = get_arg_type(args, kwargs, types.StringType, 'filepath')
        if self._tempfile:
            self.create_tempfile(filepath)
        elif filepath is not None and filepath != '':
            if 'inmem' not in kwargs:
                inmem = True
            self.set_filepath(filepath, inmem)
            self._infile = True
        else:
            self._dir = ''
            self._filename = ''
            self._infile = infile

        # Don't hold references to temporary data files
        if not self._tempfile:
            Data._data_list.add(name, self)
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        '''
        Create data object. There are three different uses:
        1) create an empty data object for use in a measurement
        2) create a data object and fill immediately with a numpy array
        3) create a data object from an existing data file

        All inputs are optional.
        The 'name' input is used in an internal list (accessable through
        qt.data). If omitted, a name will be auto generated.
        This 'name' will also be used later to auto generate a filename
        when calling 'create_file()' (if that is called without options).
        The input 'filename' here is only used for loading an existing file.

        args input:
            filename (string), set the filename to load.
            data (numpy.array), array to construct data object for

        kwargs input:
            name (string), default will be 'data<n>'
            infile (bool), default True
            inmem (bool), default False if no file specified, True otherwise
            tempfile (bool), default False. If True create a temporary file
                for the data.
            binary (bool), default True. Whether tempfile should be binary.
        '''

        # Init SharedGObject a bit lower

        name = kwargs.get('name', '')
        infile = kwargs.get('infile', True)
        inmem = kwargs.get('inmem', False)

        self._inmem = inmem
        self._tempfile = kwargs.get('tempfile', False)
        self._temp_binary = kwargs.get('binary', True)
        self._options = kwargs
        self._file = None
        self._stop_req_hid = None

        # Dimension info
        self._dimensions = []
        self._block_sizes = []
        self._loopdims = None
        self._loopshape = None
        self._complete = False
        self._reshaped_data = None

        # Number of coordinate dimensions
        self._ncoordinates = 0

        # Number of value dimensions
        self._nvalues = 0

        # Number of data points
        self._npoints = 0
        self._npoints_last_block = 0
        self._npoints_max_block = 0

        self._comment = []
        self._localtime = time.localtime()
        self._timestamp = time.asctime(self._localtime)
        self._timemark = time.strftime('%H%M%S', self._localtime)
        self._datemark = time.strftime('%Y%m%d', self._localtime)

        # FIXME: the name generation here is a bit nasty
        name = Data._data_list.new_item_name(self, name)
        self._name = name

        SharedGObject.__init__(self, 'data_%s' % name,
            replace=True, idle_emit=True)

        data = get_arg_type(args, kwargs,
                (numpy.ndarray, list, tuple),
                'data')
        if data is not None:
            self.set_data(data)
        else:
            self._data = numpy.array([])
            self._infile = infile

        filepath = get_arg_type(args, kwargs, types.StringType, 'filepath')
        if self._tempfile:
            self.create_tempfile(filepath)
        elif filepath is not None and filepath != '':
            if 'inmem' not in kwargs:
                inmem = True
            self.set_filepath(filepath, inmem)
            self._infile = True
        else:
            self._dir = ''
            self._filename = ''
            self._infile = infile

        # Don't hold references to temporary data files
        if not self._tempfile:
            Data._data_list.add(name, self)