Ejemplo n.º 1
0
def test_stackio_list_iterator():

    metadata = {
        'SizeC': 1,
        'TimeIncrement': 10.0,
        'DimensionOrder': ['C', 'T', 'Z', 'Y', 'X'],
        'SizeT': 4,
        'AcquisitionDate': '2014-03-24T11:25:14',
        'SizeX': 56,
        'SizeY': 48,
        'SizeZ': 4,
        'PhysicalSizeY': 0.065,
        'PhysicalSizeX': 0.065,
        'Shape': (1, 4, 4, 48, 56),
        'PhysicalSizeZ': 1.0
    }

    file_list = data.stack_list()
    stackio = StackIO(image_path_list=file_list, metadata=metadata)
    stack_iter = stackio.list_iterator()

    for n, stack in enumerate(stack_iter()):
        assert stack.shape == (5, 172, 165)
    assert n == 3

    file_list = data.stack_list()
    stackio = StackIO(image_path_list=file_list,
                      metadata=metadata,
                      base_dir=os.path.dirname(file_list[0]))

    assert len(stackio.image_path_list) == 4
def test_cell_boundaries_detector():

    # Fake to only detect the first time stamp
    # to make tests faster

    st = StackIO(data.TC_BF_cells())
    data_iterator = [list(st.image_iterator(position=-3)())[0]]

    metadata = st.metadata
    metadata['SizeT'] = 1

    parameters = {'object_height': 3, 'minimal_area': 160}

    shapes = cell_boundaries_detector(data_iterator,
                                      st.metadata,
                                      show_progress=True,
                                      parameters=parameters)

    real_shapes = np.array([[
        5.529290429042903909e+00, 7.725527184297377836e+00,
        -1.109566958016608318e+00, 1.057975329135689790e+01,
        7.965464600887037783e+00, 0.000000000000000000e+00
    ]])

    assert_array_almost_equal(shapes, real_shapes)
Ejemplo n.º 3
0
def setup():
    global stack_iter
    global metadata
    image_path_list = data.stack_list()

    metadata = {"PhysicalSizeX": 0.42,
                "PhysicalSizeY": 0.42,
                "PhysicalSizeZ": 1.5,
                "TimeIncrement": 3,
                "FileName": '',
                "Shape": [1, 1, 512, 512],
                "DimensionOrder": "TZYX"}

    metadata['FileName'] = image_path_list[0]
    stack_io = StackIO(image_path_list=image_path_list,
                       metadata=metadata)

    im0 = stack_io.get_tif().asarray()
    correct_metadata = {'FileName': os.path.basename(image_path_list[0]),
                        'SizeX': im0.shape[2],
                        'SizeY': im0.shape[1],
                        'SizeZ': im0.shape[0],
                        'SizeT': len(image_path_list),
                        'Shape': (len(image_path_list),
                                  im0.shape[2],
                                  im0.shape[1],
                                  im0.shape[0])}

    stack_io.metadata.update(correct_metadata)
    metadata = stack_io.metadata
    stack_iter = stack_io.list_iterator()
Ejemplo n.º 4
0
def setup():
    global stack_iter
    global metadata
    image_path_list = data.stack_list()

    metadata = {
        "PhysicalSizeX": 0.42,
        "PhysicalSizeY": 0.42,
        "PhysicalSizeZ": 1.5,
        "TimeIncrement": 3,
        "FileName": '',
        "Shape": [1, 1, 512, 512],
        "DimensionOrder": "TZYX"
    }

    metadata['FileName'] = image_path_list[0]
    stack_io = StackIO(image_path_list=image_path_list, metadata=metadata)

    im0 = stack_io.get_tif().asarray()
    correct_metadata = {
        'FileName': os.path.basename(image_path_list[0]),
        'SizeX': im0.shape[2],
        'SizeY': im0.shape[1],
        'SizeZ': im0.shape[0],
        'SizeT': len(image_path_list),
        'Shape':
        (len(image_path_list), im0.shape[2], im0.shape[1], im0.shape[0])
    }

    stack_io.metadata.update(correct_metadata)
    metadata = stack_io.metadata
    stack_iter = stack_io.list_iterator()
Ejemplo n.º 5
0
def test_stackio_get_tif():

    fname = data.CZT_peaks()
    st = StackIO(fname, json_discovery=False, base_dir=os.path.dirname(fname))
    assert st.image_path == fname

    fname = data.CZT_peaks()
    st = StackIO(fname, json_discovery=False)
    assert st.image_path == fname
Ejemplo n.º 6
0
def test_stackio_image_iterator():
    fname = data.CZT_peaks()
    st = StackIO(fname, json_discovery=False)

    arr = st.get_tif().asarray(memmap=True)

    iterator = st.image_iterator(channel_index=0, memmap=True)
    for a in iterator():
        assert a.shape == arr.shape[-2:]

    # Test with channels index

    fname = data.CZT_peaks()
    st = StackIO(fname, json_discovery=False)

    assert_raises(TypeError,
                  st.image_iterator,
                  hannel_index='GFP',
                  memmap=True)

    st.metadata['Channels'] = ['GFP']
    it = st.image_iterator(channel_index='GFP',
                           memmap=False,
                           z_projection=True)
    assert list(it())[0].shape == arr.shape[-2:]
Ejemplo n.º 7
0
def test_peak_detector_no_peaks():

    fname = data.CZT_peaks()
    st = StackIO(fname, json_discovery=False)

    data_iterator = st.image_iterator(channel_index=0)

    parameters = {'w_s': 0.7,
                  'peak_radius': 0.2,
                  'threshold': 300,
                  'max_peaks': 4}

    peaks = peak_detector(data_iterator(),
                          st.metadata,
                          parallel=True,
                          show_progress=False,
                          parameters=parameters)

    assert peaks.empty is True
def test_cell_boundaries_detector_no_shapes():

    # Fake to only detect the first time stamp
    # to make tests faster

    st = StackIO(data.CZT_peaks())
    data_iterator = [list(st.image_iterator(position=-3, channel_index=0)())[0]]

    metadata = st.metadata
    metadata['SizeT'] = 1

    parameters = {'object_height': 1e-6,
                  'minimal_area': 160}

    shapes = cell_boundaries_detector(data_iterator, metadata,
                                      show_progress=True,
                                      parameters=parameters)

    assert shapes.empty is True
def test_cell_boundaries_detector_no_shapes():

    # Fake to only detect the first time stamp
    # to make tests faster

    st = StackIO(data.CZT_peaks())
    data_iterator = [
        list(st.image_iterator(position=-3, channel_index=0)())[0]
    ]

    metadata = st.metadata
    metadata['SizeT'] = 1

    parameters = {'object_height': 1e-6, 'minimal_area': 160}

    shapes = cell_boundaries_detector(data_iterator,
                                      metadata,
                                      show_progress=True,
                                      parameters=parameters)

    assert shapes.empty is True
def test_cell_boundaries_detector():

    # Fake to only detect the first time stamp
    # to make tests faster

    st = StackIO(data.TC_BF_cells())
    data_iterator = [list(st.image_iterator(position=-3)())[0]]

    metadata = st.metadata
    metadata['SizeT'] = 1

    parameters = {'object_height': 3,
                  'minimal_area': 160}

    shapes = cell_boundaries_detector(data_iterator, st.metadata,
                                      show_progress=True,
                                      parameters=parameters)

    real_shapes = np.array([[5.529290429042903909e+00, 7.725527184297377836e+00,
                             -1.109566958016608318e+00, 1.057975329135689790e+01,
                             7.965464600887037783e+00, 0.000000000000000000e+00]])

    assert_array_almost_equal(shapes, real_shapes)
Ejemplo n.º 11
0
def test_stackio_from_objectsio():
    oio = ObjectsIO.from_h5(data.sample_h5_temp())
    st = StackIO.from_objectsio(oio)

    true_metadata = {
        'PysicalSizeY': 0.43,
        'PysicalSizeX': 0.43,
        'PysicalSizeZ': 1.5,
        'TimeIncrement': 3.0,
        'Shape': (512, 512, 23, 5),
        'SizeT': 5,
        'Type': 'unint16',
        'FileName': 'sample.ome.tif',
        'DimensionOrder': 'TZYX',
        'SizeZ': 23,
        'SizeY': 512,
        'SizeX': 512
    }
    guessed_metadata = st.metadata

    assert guessed_metadata == true_metadata
Ejemplo n.º 12
0
def test_stackio_from_tif_file():

    st = StackIO(data.CZT_peaks(), json_discovery=False)

    true_metadata = {
        'SizeC': 1,
        'TimeIncrement': 10.0,
        'DimensionOrder': ['C', 'T', 'Z', 'Y', 'X'],
        'SizeT': 4,
        'AcquisitionDate': '2014-03-24T11:25:14',
        'SizeX': 56,
        'SizeY': 48,
        'SizeZ': 4,
        'PhysicalSizeY': 0.065,
        'PhysicalSizeX': 0.065,
        'Shape': (1, 4, 4, 48, 56),
        'PhysicalSizeZ': 1.0
    }

    guessed_metadata = st.metadata
    guessed_metadata.pop("FileName")

    assert guessed_metadata == true_metadata
Ejemplo n.º 13
0
def test_stackio_get_tif_from_list():
    images_list = data.stack_list()
    st = StackIO(image_path_list=images_list)
    assert st.get_tif_from_list(3).asarray().shape == (5, 172, 165)