Exemplo n.º 1
0
    def add_array(self,
                  where,
                  name,
                  data_type,
                  data_shape=(1, ),
                  data_dimension='0D',
                  scan_type='',
                  scan_shape=[],
                  title='',
                  array_to_save=None,
                  array_type=np.float,
                  enlargeable=False,
                  metadata=dict([]),
                  init=False,
                  add_scan_dim=False):

        if data_dimension not in data_dimensions:
            raise Exception('Invalid data dimension')
        if data_type not in data_types:
            raise Exception('Invalid data type')
        if scan_type != '':
            scan_type = utils.uncapitalize(scan_type)
        if scan_type not in scan_types:
            raise Exception('Invalid scan type')
        if enlargeable:
            shape = [0]
            if data_shape != (1, ):
                shape.extend(data_shape)
            shape = tuple(shape)
            array = self.h5_file.create_earray(where,
                                               utils.capitalize(name),
                                               tables.Atom.from_dtype(
                                                   np.dtype(array_type)),
                                               shape=shape,
                                               title=title,
                                               filters=self.filters)
            array._v_attrs['shape'] = shape
        else:
            if add_scan_dim:  #means it is an array initialization to zero
                shape = scan_shape[:]
                shape.extend(data_shape)
                if init or array_to_save is None:
                    array_to_save = np.zeros(shape)

            array = self.h5_file.create_carray(where,
                                               utils.capitalize(name),
                                               obj=array_to_save,
                                               title=title,
                                               filters=self.filters)
            array._v_attrs['shape'] = array_to_save.shape

        array._v_attrs['type'] = data_type
        array._v_attrs['data_dimension'] = data_dimension
        array._v_attrs['scan_type'] = scan_type

        for metadat in metadata:
            array._v_attrs[metadat] = metadata[metadat]
        return array
Exemplo n.º 2
0
 def test_uncapitalize(self):
     string = 'ABCDef'
     assert utils.uncapitalize(string) == 'aBCDef'
     assert utils.uncapitalize(string, 3) == 'abcDef'