def layer_writer_and_data(request): """Fixture that supplies layer io utilities for tests. Parameters ---------- request : _pytest.fixtures.SubRequest The pytest request object Returns ------- tuple ``(writer, layer_data, extension, reader, Layer)`` - writer: a function that can write layerdata to a path - layer_data: the layerdata tuple for this layer - extension: an appropriate extension for this layer type - reader: a function that can read this layer type from a path and returns a ``(data, meta)`` tuple. - Layer: the Layer class """ if request.param == 'image': data = np.random.rand(20, 20) Layer = Image layer = Image(data) writer = napari_write_image extension = '.tif' def reader(path): return (io.imread(path), {}, 'image') # metadata elif request.param == 'labels': data = np.random.randint(0, 16000, (32, 32), 'uint64') Layer = Labels layer = Labels(data) writer = napari_write_labels extension = '.tif' def reader(path): return (io.imread(path), {}, 'labels') # metadata elif request.param == 'points': data = np.random.rand(20, 2) Layer = Points layer = Points(data) writer = napari_write_points extension = '.csv' reader = partial(io.csv_to_layer_data, require_type='points') elif request.param == 'points-with-properties': data = np.random.rand(20, 2) Layer = Points layer = Points(data, properties={'values': np.random.rand(20)}) writer = napari_write_points extension = '.csv' reader = partial(io.csv_to_layer_data, require_type='points') elif request.param == 'shapes': np.random.seed(0) data = [ np.random.rand(2, 2), np.random.rand(2, 2), np.random.rand(6, 2), np.random.rand(6, 2), np.random.rand(2, 2), ] shape_type = ['ellipse', 'line', 'path', 'polygon', 'rectangle'] Layer = Shapes layer = Shapes(data, shape_type=shape_type) writer = napari_write_shapes extension = '.csv' reader = partial(io.csv_to_layer_data, require_type='shapes') else: return None, None, None, None, None layer_data = layer.as_layer_data_tuple() return writer, layer_data, extension, reader, Layer
def layer_writer_and_data(request): """Fixture that supplies layer io utilities for tests. Parameters ---------- request : _pytest.fixtures.SubRequest The pytest request object Returns ------- tuple ``(writer, layer_data, extension, reader, Layer)`` - writer: a function that can write layerdata to a path - layer_data: the layerdata tuple for this layer - extension: an appropriate extension for this layer type - reader: a function that can read this layer type from a path and returns a ``(data, meta)`` tuple. - Layer: the Layer class """ if request.param == 'image': data = np.random.rand(20, 20) Layer = Image layer = Image(data) writer = napari_write_image extension = '.tif' def reader(path): return ( io.imread(path), {}, # metadata ) elif request.param == 'points': data = np.random.rand(20, 2) Layer = Points layer = Points(data) writer = napari_write_points extension = '.csv' def reader(path): return ( io.read_csv(path)[0][:, 1:3], {}, # metadata ) elif request.param == 'points-with-properties': data = np.random.rand(20, 2) Layer = Points layer = Points(data, properties={'values': np.random.rand(20)}) writer = napari_write_points extension = '.csv' def reader(path): return ( io.read_csv(path)[0][:, 1:3], { 'properties': { io.read_csv(path)[1][3]: io.read_csv(path)[0][:, 3] } }, ) else: return None, None, None, None, None layer_data = layer.as_layer_data_tuple() return writer, layer_data, extension, reader, Layer