Beispiel #1
0
def test_ome_tiff_reader(
    resources_dir,
    filename,
    expected_shape,
    expected_dims,
    select_scene,
):
    # Get file
    f = resources_dir / filename

    # Read file
    img = OmeTiffReader(f, S=select_scene)

    # Check that there are no open file pointers after init
    proc = Process()
    assert str(f) not in [f.path for f in proc.open_files()]

    # Check basics
    # Check that OME Metadata matches the dask data array shape and dims order
    dim_size_getters = {
        Dimensions.Scene: img.size_s,
        Dimensions.Time: img.size_t,
        Dimensions.Channel: img.size_c,
        Dimensions.SpatialZ: img.size_z,
        Dimensions.SpatialY: img.size_y,
        Dimensions.SpatialX: img.size_x,
    }
    for d, getter in dim_size_getters.items():
        if d in expected_dims:
            assert getter() == img.dask_data.shape[img.dims.index(d)]

    assert img.dims == expected_dims
    assert img.is_ome()
    assert img.metadata
    assert img.shape == expected_shape
    assert img.dask_data.shape == expected_shape
    assert img.size(expected_dims) == expected_shape

    # Will error because those dimensions don't exist in the file
    with pytest.raises(exceptions.InvalidDimensionOrderingError):
        assert img.size("ABCDEFG") == expected_shape

    # Check that there are no open file pointers after basics
    assert str(f) not in [f.path for f in proc.open_files()]

    # Check array
    assert isinstance(img.data, np.ndarray)
    assert img.data.shape == expected_shape

    # Check that there are no open file pointers after retrieval
    assert str(f) not in [f.path for f in proc.open_files()]
def test_get_channel_names(resources_dir, filename, scene, expected_channel_names):
    # Get file
    f = resources_dir / filename

    # Read file
    img = OmeTiffReader(f)

    # Check that there are no open file pointers after init
    proc = Process()
    assert str(f) not in [f.path for f in proc.open_files()]

    # Check channel names
    assert img.get_channel_names(scene) == expected_channel_names

    # Check that there are no open file pointers after check
    assert str(f) not in [f.path for f in proc.open_files()]
Beispiel #3
0
def test_ome_tiff_reader(resources_dir, filename, expected_shape,
                         expected_dims, select_scene, expected_chunksize,
                         expected_task_count):
    # Get file
    f = resources_dir / filename

    # Read file
    img = OmeTiffReader(f, S=select_scene)

    # Check that there are no open file pointers after init
    proc = Process()
    assert str(f) not in [f.path for f in proc.open_files()]

    # Check basics
    with Profiler() as prof:
        # Check that OME Metadata matches the dask data array shape and dims order
        dim_size_getters = {
            Dimensions.Scene: img.size_s,
            Dimensions.Time: img.size_t,
            Dimensions.Channel: img.size_c,
            Dimensions.SpatialZ: img.size_z,
            Dimensions.SpatialY: img.size_y,
            Dimensions.SpatialX: img.size_x
        }
        for d, getter in dim_size_getters.items():
            if d in expected_dims:
                assert getter() == img.dask_data.shape[img.dims.index(d)]

        assert img.dims == expected_dims
        assert img.is_ome()
        assert img.metadata
        assert img.dask_data.shape == expected_shape
        assert img.dask_data.chunksize == expected_chunksize
        # Check that basic details don't require task computation
        assert len(prof.results) == 0

    # Check that there are no open file pointers after basics
    assert str(f) not in [f.path for f in proc.open_files()]

    # Check computed type is numpy array, computed shape is expected shape, and task count is expected
    with Profiler() as prof:
        assert isinstance(img.data, np.ndarray)
        assert img.data.shape == expected_shape
        assert len(prof.results) == expected_task_count

    # Check that there are no open file pointers after retrieval
    assert str(f) not in [f.path for f in proc.open_files()]
def test_writerShapeComparison(resources_dir):
    """
    Test to check that OmeTiffWriter saves arrays that are reflexive with OmeTiffReader
    """
    with OmeTiffWriter(resources_dir / filename,
                       overwrite_file=True) as writer:
        writer.save(image)

    output = OmeTiffReader(resources_dir / filename).data

    assert output.shape == image.shape[1:]
def test_size_functions(resources_dir, filename, s, t, c, z, y, x):
    # Get file
    f = resources_dir / filename

    # Init reader
    img = OmeTiffReader(f)

    # Check sizes
    assert img.size_s() == s
    assert img.size_t() == t
    assert img.size_c() == c
    assert img.size_z() == z
    assert img.size_y() == y
    assert img.size_x() == x
def test_dimensionOrder(resources_dir, dims, expected_t, expected_c,
                        expected_z, expected_y, expected_x):
    with OmeTiffWriter(resources_dir / filename,
                       overwrite_file=True) as writer:
        writer.save(image, dimension_order=dims)

    reader = OmeTiffReader(resources_dir / filename)
    output = reader.data
    t = reader.size_t()
    c = reader.size_c()
    z = reader.size_z()
    y = reader.size_y()
    x = reader.size_x()

    os.remove(resources_dir / filename)

    assert output.shape == image.shape[1:]
    assert x == expected_x
    assert y == expected_y
    assert z == expected_z
    assert c == expected_c
    assert t == expected_t