Beispiel #1
0
    def add_data(self, channel_group, data_dict, scan_type='scan1D', scan_shape = [], title='', enlargeable=False, init=False, add_scan_dim=False):

        shape, dimension, size = utils.get_data_dimension(data_dict['data'])
        data_array = self.add_array(channel_group, 'Data', 'data', array_type=np.float,
            title=title, data_shape=shape,enlargeable=enlargeable, data_dimension = dimension, scan_type=scan_type,
            scan_shape = scan_shape,
            array_to_save=data_dict['data'],
            init = init, add_scan_dim = add_scan_dim)

        if 'x_axis' in data_dict:
            if not isinstance(data_dict['x_axis'], dict):
                array_to_save = data_dict['x_axis']
                tmp_dict = dict(label='', units='')
            else:
                tmp_dict = copy.deepcopy(data_dict['x_axis'])
                array_to_save = tmp_dict.pop('data')

            array = self.add_array(channel_group, 'x_axis', 'axis',
                   array_type=np.float,array_to_save=array_to_save,
                            enlargeable=False, data_dimension='1D', metadata=tmp_dict)

        if 'y_axis' in data_dict:
            if not isinstance(data_dict['y_axis'], dict):
                array_to_save = data_dict['y_axis']
                tmp_dict = dict(label='', units='')
            else:
                tmp_dict = copy.deepcopy(data_dict['y_axis'])
                array_to_save = tmp_dict.pop('data')

            array = self.add_array(channel_group, 'y_axis', 'axis',
                    array_type=np.float, array_to_save=array_to_save,
                    enlargeable=False, data_dimension='1D', metadata=tmp_dict)
        return data_array
Beispiel #2
0
def test_get_data_dimension():
    shapes = [(), (1, ), (10, ), (5, 5)]
    scan_types = ['scan1D', 'scan2D']
    remove = [False, True]
    for shape in shapes:
        for scan in scan_types:
            for rem in remove:
                arr = np.ones((shape))
                size = arr.size
                dim = len(arr.shape)
                if dim == 1 and size == 1:
                    dim = 0
                if rem:
                    if scan.lower() == 'scan1d':
                        dim -= 1
                    if scan.lower() == 'scan2d':
                        dim -= 2
                assert utils.get_data_dimension(
                    arr, scan, rem) == (shape, '{:d}D'.format(dim), size)
Beispiel #3
0
def test_get_data_dimension():
    shapes = [(), (1, ), (10, ), (5, 5), (2, 2, 2)]
    scan_types = ['scan1D', 'scan2D', 'scanND']
    remove = [False, True]
    for shape in shapes:
        for scan in scan_types:
            for rem in remove:
                arr = np.ones(shape)
                size = arr.size
                dim = len(arr.shape)
                if dim == 1 and size == 1:
                    dim = 0
                if rem:
                    if scan.lower() == 'scan1d':
                        dim -= 1
                    if scan.lower() == 'scan2d':
                        dim -= 2
                else:
                    if dim > 2:
                        dim = 'N'
                assert utils.get_data_dimension(arr, scan,
                                                rem) == (shape, f'{dim}D',
                                                         size)