def create_h5(array: Array5D, axiskeys_style: str, chunk_shape: Optional[Shape5D] = None, axiskeys: str = "xyztc"): raw_chunk_shape = (chunk_shape or Shape5D() * 2).clamped(maximum=array.shape).to_tuple(axiskeys) path = tempfile.mkstemp()[1] + ".h5" f = h5py.File(path, "w") ds = f.create_dataset("data", chunks=raw_chunk_shape, data=array.raw(axiskeys)) if axiskeys_style == "dims": for key, dim in zip(axiskeys, ds.dims): dim.label = key elif axiskeys_style == "vigra": type_flags = {"x": 2, "y": 2, "z": 2, "t": 2, "c": 1} axistags = [{"key": key, "typeflags": type_flags[key], "resolution": 0, "description": ""} for key in axiskeys] ds.attrs["axistags"] = json.dumps({"axes": axistags}) else: raise Exception(f"Bad axiskeys_style: {axiskeys_style}") return PurePosixPath(path)
def encode(self, data: Array5D) -> bytes: return data.raw("xyzc").tobytes("F")
def create_png(array: Array5D) -> PurePosixPath: png_path = tempfile.mkstemp()[1] + ".png" skimage.io.imsave(png_path, array.raw("yxc")) return PurePosixPath(png_path)
def from_array5d(data: Array5D, labels: Optional[Set[int]] = None) -> "ConnectedComponents": return ConnectedComponents( data.raw(Point5D.LABELS), axiskeys=Point5D.LABELS, location=data.location, labels=labels )