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"), }
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)
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') }
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
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", ), }
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"), }
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)
def get_result_buffers(self): return { 'pixelsum': BufferWrapper( kind="nav", dtype="float32" ) }
def logsum_buffer(): return { 'logsum': BufferWrapper(kind='sig', dtype='float32'), }
def counter_buffers(): return {'counter': BufferWrapper(kind="single", dtype="uint32")}
def make_result_buffers(): return {'std': BufferWrapper(kind="nav", dtype="float32")}
def test_buffer_extra_shape_1(): buffer = BufferWrapper(kind='nav', extra_shape=(2, 3)) assert buffer._extra_shape == (2, 3)
def make_result_buffers(): return { 'intensity': BufferWrapper(kind="nav", dtype="float32"), }
def make_result_buffers(): return {'fou': BufferWrapper(kind="nav", dtype="complex64")}
def my_buffers(): return { 'pixelsum': BufferWrapper( kind="nav", dtype="float32" ) }
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)
def buffer(self, kind, extra_shape=(), dtype="float32"): return BufferWrapper(kind, extra_shape, dtype)
def make_result_buffers(): return { 'x2': BufferWrapper(kind="sig", dtype="float64"), 'x': BufferWrapper(kind="sig", dtype="float64"), }