Exemplo n.º 1
0
def get_result_buffers_refine():
    return {
        'intensity': BufferWrapper(kind="nav", dtype="float32"),
        'zero': BufferWrapper(kind="nav", extra_shape=(2, ), dtype="float32"),
        'a': BufferWrapper(kind="nav", extra_shape=(2, ), dtype="float32"),
        'b': BufferWrapper(kind="nav", extra_shape=(2, ), dtype="float32"),
    }
Exemplo n.º 2
0
def test_aux_1(lt_ctx):
    data = _mk_random(size=(16, 16, 16, 16), dtype="float32")
    aux_data = BufferWrapper(kind="nav", dtype="float32", extra_shape=(2, ))
    aux_data.set_buffer(_mk_random(size=(16, 16, 2), dtype="float32"))
    dataset = MemoryDataSet(data=data,
                            tileshape=(7, 16, 16),
                            num_partitions=2,
                            sig_dims=2)

    echo_udf = EchoUDF(aux=aux_data)
    res = lt_ctx.run_udf(dataset=dataset, udf=echo_udf)
    assert 'echo' in res
    print(data.shape, res['echo'].data.shape)
    assert np.allclose(res['echo'].raw_data, aux_data.raw_data)
Exemplo n.º 3
0
def batch_buffer():
    """
    Initializes BufferWrapper objects for sum of variances,
    sum of frames, and the number of frames

    Returns
    -------
    A dictionary that maps 'var', 'std', 'mean', 'num_frame', 'sum_frame' to
    the corresponding BufferWrapper objects
    """
    return {
        'var': BufferWrapper(kind='sig', dtype='float32'),
        'num_frame': BufferWrapper(kind='single', dtype='float32'),
        'sum_frame': BufferWrapper(kind='sig', dtype='float32')
    }
Exemplo n.º 4
0
    def aux_data(cls, data, kind, extra_shape=(), dtype="float32"):
        """
        Use this method to create auxiliary data. Auxiliary data should
        have a shape like `(dataset.shape.nav, extra_shape)` and on access,
        an appropriate view will be created. For example, if you access
        aux data in `process_frame`, you will get the auxiliary data for
        the current frame you are processing.

        Example
        -------

        We create a UDF to demonstrate the behavior:

        >>> class MyUDF(UDF):
        ...     def get_result_buffers(self):
        ...         # Result buffer for debug output
        ...         return {'aux_dump': self.buffer(kind='nav', dtype='object')}
        ...
        ...     def process_frame(self, frame):
        ...         # Extract value of aux data for demonstration
        ...         self.results.aux_dump[:] = str(self.params.aux_data[:])
        ...
        >>> # for each frame, provide three values from a sequential series:
        >>> aux1 = MyUDF.aux_data(
        ...     data=np.arange(np.prod(dataset.shape.nav) * 3, dtype=np.float32),
        ...     kind="nav", extra_shape=(3,), dtype="float32"
        ... )
        >>> udf = MyUDF(aux_data=aux1)
        >>> res = ctx.run_udf(dataset=dataset, udf=udf)

        process_frame for frame (0, 7) received a view of aux_data with values [21., 22., 23.]:

        >>> res['aux_dump'].data[0, 7]
        '[21. 22. 23.]'
        """
        buf = BufferWrapper(kind, extra_shape, dtype)
        buf.set_buffer(data)
        return buf
Exemplo n.º 5
0
def get_result_buffers_pass_2(num_disks):
    """
    we 'declare' what kind of result buffers we need, without concrete shapes

    concrete shapes come later, either for partition or whole dataset
    """
    return {
        'centers':
        BufferWrapper(kind="nav", extra_shape=(num_disks, 2), dtype="u2"),
        'refineds':
        BufferWrapper(kind="nav", extra_shape=(num_disks, 2), dtype="float32"),
        'peak_values':
        BufferWrapper(
            kind="nav",
            extra_shape=(num_disks, ),
            dtype="float32",
        ),
        'peak_elevations':
        BufferWrapper(
            kind="nav",
            extra_shape=(num_disks, ),
            dtype="float32",
        ),
    }
Exemplo n.º 6
0
def get_result_buffers_refine(num_disks):
    return {
        'centers':
        BufferWrapper(kind="nav", extra_shape=(num_disks, 2), dtype="u2"),
        'refineds':
        BufferWrapper(kind="nav", extra_shape=(num_disks, 2), dtype="float32"),
        'peak_values':
        BufferWrapper(kind="nav", extra_shape=(num_disks, ), dtype="float32"),
        'peak_elevations':
        BufferWrapper(kind="nav", extra_shape=(num_disks, ), dtype="float32"),
        'zero':
        BufferWrapper(kind="nav", extra_shape=(2, ), dtype="float32"),
        'a':
        BufferWrapper(kind="nav", extra_shape=(2, ), dtype="float32"),
        'b':
        BufferWrapper(kind="nav", extra_shape=(2, ), dtype="float32"),
        'selector':
        BufferWrapper(kind="nav", extra_shape=(num_disks, ), dtype="bool"),
    }
Exemplo n.º 7
0
 def buffer(self, kind, extra_shape=(), dtype="float32", where=None):
     '''
     Use this method to create :class:`~ libertem.common.buffers.BufferWrapper` objects
     in :meth:`get_result_buffers`.
     '''
     return BufferWrapper(kind, extra_shape, dtype, where)
Exemplo n.º 8
0
 def get_result_buffers(self):
     return {
         'pixelsum': BufferWrapper(
             kind="nav", dtype="float32"
         )
     }
Exemplo n.º 9
0
def logsum_buffer():
    return {
        'logsum': BufferWrapper(kind='sig', dtype='float32'),
    }
Exemplo n.º 10
0
 def counter_buffers():
     return {'counter': BufferWrapper(kind="single", dtype="uint32")}
Exemplo n.º 11
0
 def make_result_buffers():
     return {'std': BufferWrapper(kind="nav", dtype="float32")}
Exemplo n.º 12
0
def test_buffer_extra_shape_1():
    buffer = BufferWrapper(kind='nav', extra_shape=(2, 3))
    assert buffer._extra_shape == (2, 3)
Exemplo n.º 13
0
def make_result_buffers():
    return {
        'intensity': BufferWrapper(kind="nav", dtype="float32"),
    }
Exemplo n.º 14
0
 def make_result_buffers():
     return {'fou': BufferWrapper(kind="nav", dtype="complex64")}
Exemplo n.º 15
0
 def my_buffers():
     return {
         'pixelsum': BufferWrapper(
             kind="nav", dtype="float32"
         )
     }
Exemplo n.º 16
0
def test_buffer_extra_shape_2():
    shape_obj = Shape(shape=(12, 13, 14, 15), sig_dims=2)
    buffer = BufferWrapper(kind='nav', extra_shape=shape_obj)
    assert buffer._extra_shape == (12, 13, 14, 15)
Exemplo n.º 17
0
 def buffer(self, kind, extra_shape=(), dtype="float32"):
     return BufferWrapper(kind, extra_shape, dtype)
Exemplo n.º 18
0
 def make_result_buffers():
     return {
         'x2': BufferWrapper(kind="sig", dtype="float64"),
         'x': BufferWrapper(kind="sig", dtype="float64"),
     }