Esempio n. 1
0
    def map(self,
            dataset: DataSet,
            f,
            roi: np.ndarray = None,
            progress: bool = False) -> BufferWrapper:
        '''
        Create an :class:`AutoUDF` with function :meth:`f` and run it on :code:`dataset`

        Parameters
        ----------

        dataset:
            The dataset to work on
        f:
            Function that accepts a frame as the only parameter. It should return a strongly
            reduced output compared to the size of a frame.
        roi : numpy.ndarray
            region of interest as bool mask over the navigation axes of the dataset
        progress : bool
            Show progress bar

        Returns
        -------

        BufferWrapper : libertem.common.buffers.BufferWrapper
            The result of the UDF. Access the underlying numpy array using the
            :attr:`~libertem.common.buffers.BufferWrapper.data` property.
            Shape and dtype is inferred automatically from :code:`f`.
        '''
        udf = AutoUDF(f=f)
        results = self.run_udf(dataset=dataset,
                               udf=udf,
                               roi=roi,
                               progress=progress)
        return results['result']
Esempio n. 2
0
    def map(self, dataset, f, roi=None):
        '''
        Create an :class:`AutoUDF` with function :meth:`f` and run it on :code:`dataset`

        Parameters
        ----------

        dataset:
            The dataset to work on
        f:
            Function that accepts a frame as the only parameter. It should return a strongly
            reduced output compared to the size of a frame.
        roi : numpy.ndarray
            region of interest as bool mask over the navigation axes of the dataset

        Returns
        -------

        BufferWrapper:
            The result of the UDF. Access the underlying numpy array using the `data` attribute.
            Shape and dtype is inferred automatically from :code:`f`.
        '''
        udf = AutoUDF(f=f)
        results = self.run_udf(dataset=dataset, udf=udf, roi=roi)
        return results['result']
Esempio n. 3
0
File: api.py Progetto: sk1p/LiberTEM
    def map(self,
            dataset: DataSet,
            f,
            roi: np.ndarray = None,
            progress: bool = False,
            corrections: CorrectionSet = None,
            backends=None) -> BufferWrapper:
        '''
        Create an :class:`AutoUDF` with function :meth:`f` and run it on :code:`dataset`

        .. versionchanged:: 0.5.0
            Added the :code:`progress` parameter

        .. versionchanged:: 0.6.0
            Added the :code:`corrections` and :code:`backends` parameter

        Parameters
        ----------

        dataset:
            The dataset to work on
        f:
            Function that accepts a frame as the only parameter. It should return a strongly
            reduced output compared to the size of a frame.
        roi : numpy.ndarray
            region of interest as bool mask over the navigation axes of the dataset
        progress : bool
            Show progress bar
        corrections
            Corrections to apply while running the function. If none are given,
            the corrections that are part of the :code:`DataSet` are used,
            if there are any. See also :ref:`corrections`.
        backends : None or iterable containing 'numpy', 'cupy' and/or 'cuda'
            Restrict the back-end to a subset of the capabilities of the UDF.
            This can be useful for testing hybrid UDFs.

        Returns
        -------

        BufferWrapper : libertem.common.buffers.BufferWrapper
            The result of the UDF. Access the underlying numpy array using the
            :attr:`~libertem.common.buffers.BufferWrapper.data` property.
            Shape and dtype is inferred automatically from :code:`f`.
        '''
        udf = AutoUDF(f=f)
        results: UDFResultDict = self.run_udf(  # type:ignore[assignment]
            dataset=dataset,
            udf=udf,
            roi=roi,
            progress=progress,
            corrections=corrections,
            backends=backends,
        )
        return results['result']
Esempio n. 4
0
        f.create_dataset("data", data=data, chunks=chunks)

    ds = lt_ctx.load("hdf5", path=filename)
    udf = PixelsumUDF()
    res = lt_ctx.run_udf(udf=udf, dataset=ds)['pixelsum']
    assert np.allclose(res, np.sum(data, axis=(2, 3)))


@pytest.fixture(scope='module')
def shared_random_data():
    return _mk_random(size=(16, 16, 256, 256), dtype='float32')


@pytest.mark.parametrize('udf', [
    SumSigUDF(),
    AutoUDF(f=lambda frame: frame.sum()),
])
@pytest.mark.parametrize('chunks', [
    (3, 3, 32, 32),
    (3, 6, 32, 32),
    (3, 4, 32, 32),
    (1, 4, 32, 32),
    (1, 16, 32, 32),
    (3, 3, 256, 256),
    (3, 6, 256, 256),
    (3, 4, 256, 256),
    (1, 4, 256, 256),
    (1, 16, 256, 256),
    (3, 3, 128, 256),
    (3, 6, 128, 256),
    (3, 4, 128, 256),