Ejemplo n.º 1
0
def test_roi_2(random_hdf5, lt_ctx, mnp):
    ds = H5DataSet(
        path=random_hdf5.filename,
        ds_path="data",
        tileshape=(1, 4, 16, 16),
        min_num_partitions=mnp,
    )
    ds = ds.initialize(lt_ctx.executor)

    roi = {
        "shape": "disk",
        "cx": 2,
        "cy": 2,
        "r": 1,
    }
    analysis = SumAnalysis(dataset=ds, parameters={
        "roi": roi,
    })

    print(analysis.get_roi())

    results = lt_ctx.run(analysis)

    # let's draw a circle!
    mask = np.full((5, 5), False)
    mask[1, 2] = True
    mask[2, 1:4] = True
    mask[3, 2] = True

    print(mask)

    assert mask.shape == (5, 5)
    assert mask.dtype == np.bool

    reader = ds.get_reader()
    with reader.get_h5ds() as h5ds:
        data = np.array(h5ds)

        # applying the mask flattens the first two dimensions, so we
        # only sum over axis 0 here:
        expected = data[mask, ...].sum(axis=(0, ))

        assert expected.shape == (16, 16)
        assert results.intensity.raw_data.shape == (16, 16)

        # is not equal to results without mask:
        assert not np.allclose(results.intensity.raw_data,
                               data.sum(axis=(0, 1)))
        # ... but rather like `expected`:
        assert np.allclose(results.intensity.raw_data, expected)
Ejemplo n.º 2
0
def test_sum_zero_roi(lt_ctx):
    data = _mk_random(size=(16, 16, 16, 16), dtype='<u2')
    dataset = MemoryDataSet(data=data, tileshape=(2, 16, 16), num_partitions=32)

    roi = {
        "shape": "disk",
        "cx": -1,
        "cy": -1,
        "r": 0,
    }
    analysis = SumAnalysis(dataset=dataset, parameters={
        "roi": roi,
    })

    results = lt_ctx.run(analysis)

    mask = masks.circular(roi["cx"], roi["cy"], 16, 16, roi["r"])
    assert mask.shape == (16, 16)
    assert np.count_nonzero(mask) == 0
    assert mask.dtype == np.bool

    # applying the mask flattens the first two dimensions, so we
    # only sum over axis 0 here:
    expected = data[mask, ...].sum(axis=(0,))

    assert expected.shape == (16, 16)
    assert results['intensity'].raw_data.shape == (16, 16)

    # is not equal to results without mask:
    assert not np.allclose(results['intensity'].raw_data, data.sum(axis=(0, 1)))
    # ... but rather like `expected`:
    assert np.allclose(results['intensity'].raw_data, expected)
Ejemplo n.º 3
0
def test_dist_process(default_frms6, dist_ctx):
    roi = {
        "shape": "disk",
        "cx": 5,
        "cy": 6,
        "r": 7,
    }
    analysis = SumAnalysis(dataset=default_frms6, parameters={"roi": roi})
    dist_ctx.run(analysis)
Ejemplo n.º 4
0
    def create_sum_analysis(self, dataset):
        """
        Sum of all signal elements

        Parameters
        ----------
        dataset
            the dataset to work on
        """
        return SumAnalysis(dataset=dataset, parameters={})
Ejemplo n.º 5
0
def test_sum_analysis(default_frms6, lt_ctx):
    roi = {
        "shape": "disk",
        "cx": 5,
        "cy": 6,
        "r": 7,
    }
    analysis = SumAnalysis(dataset=default_frms6, parameters={
        "roi": roi,
    })
    # not checking result yet, just making sure it doesn't crash:
    lt_ctx.run(analysis)
Ejemplo n.º 6
0
    def create_sum_analysis(self, dataset) -> SumAnalysis:
        """
        Create an Analysis that sums all signal elements along the navigation
        dimension, preserving the signal dimension.

        Parameters
        ----------
        dataset
            the dataset to work on

        Returns
        -------
        SumAnalysis : libertem.analysis.base.Analysis
            When run by the Context, this Analysis generates a
            :class:`libertem.analysis.sum.SumResultSet`.
        """
        return SumAnalysis(dataset=dataset, parameters={})