Exemple #1
0
    def init_dataset(self):
        data_path = os.path.join(self.test_folder, "data.h5")
        data_key = "data"
        with open_file(data_path, "a") as f:
            f.create_dataset(data_key, data=np.random.rand(*self.shape))

        tmp_folder = os.path.join(self.test_folder, "tmp-init")

        raw_name = "test-raw"
        scales = [[2, 2, 2]]
        add_image(data_path, data_key, self.root, self.dataset_name, raw_name,
                  resolution=(1, 1, 1), chunks=(64, 64, 64), scale_factors=scales,
                  tmp_folder=tmp_folder, target="local", max_jobs=self.max_jobs)
Exemple #2
0
    def init_dataset(self):
        data_path = os.path.join(self.test_folder, "data.h5")
        data_key = "data"
        with open_file(data_path, "a") as f:
            f.create_dataset(data_key, data=np.random.rand(*self.shape))

        seg_path = os.path.join(self.test_folder, "seg.h5")
        with open_file(seg_path, "a") as f:
            f.create_dataset(data_key,
                             data=np.random.randint(0, 100, size=self.shape))

        scales = [[2, 2, 2]]
        max_jobs = min(4, mp.cpu_count())

        tmp_folder = os.path.join(self.test_folder, "tmp-init-raw")
        mobie.add_image(data_path,
                        data_key,
                        self.root,
                        self.dataset_name,
                        self.raw_name,
                        resolution=(1, 1, 1),
                        chunks=self.chunks,
                        scale_factors=scales,
                        tmp_folder=tmp_folder,
                        max_jobs=max_jobs)

        tmp_folder = os.path.join(self.test_folder, "tmp-init-seg")
        mobie.add_segmentation(seg_path,
                               data_key,
                               self.root,
                               self.dataset_name,
                               self.seg_name,
                               resolution=(1, 1, 1),
                               chunks=self.chunks,
                               scale_factors=scales,
                               tmp_folder=tmp_folder,
                               max_jobs=max_jobs)

        display_settings = [
            mobie.metadata.get_image_display("image-group-0", [self.raw_name]),
            mobie.metadata.get_segmentation_display("segmentation-group-1",
                                                    [self.seg_name]),
        ]
        source_transforms = [
            mobie.metadata.get_affine_source_transform(
                [self.raw_name, self.seg_name], np.random.rand(12))
        ]
        mobie.create_view(os.path.join(self.root, self.dataset_name),
                          "my-view", [[self.raw_name], [self.seg_name]],
                          display_settings=display_settings,
                          source_transforms=source_transforms)
Exemple #3
0
    def test_add_image_with_dataset(self):
        self.init_dataset()
        dataset_folder = os.path.join(self.root, self.dataset_name)
        im_name = "extra-im"

        tmp_folder = os.path.join(self.test_folder, "tmp-im")

        scales = [[2, 2, 2]]
        add_image(self.im_path, self.im_key,
                  self.root, self.dataset_name, im_name,
                  resolution=(1, 1, 1), scale_factors=scales,
                  chunks=(64, 64, 64), tmp_folder=tmp_folder,
                  target="local", max_jobs=self.max_jobs)
        self.check_data(dataset_folder, im_name)
Exemple #4
0
    def test_init_from_tif(self):
        shape = (32, 128, 128)

        im_folder = os.path.join(self.test_folder, "im-stack")
        self.make_tif_data(im_folder, shape)

        dataset_name = "test"
        raw_name = "test-raw"
        scales = [[1, 2, 2], [1, 2, 2], [2, 2, 2]]
        add_image(im_folder, "*.tif", self.root, dataset_name, raw_name,
                  resolution=(0.25, 1, 1), chunks=(16, 64, 64),
                  scale_factors=scales, tmp_folder=self.tmp_folder,
                  target="local", max_jobs=self.max_jobs)

        self.check_dataset(os.path.join(self.root, dataset_name), shape, raw_name)
Exemple #5
0
    def init_h5_dataset(
        self, dataset_name, raw_name, shape, file_format="bdv.n5", func=None, int_to_uint=False
    ):

        data_path = os.path.join(self.test_folder, "data.h5")
        data_key = "data"
        self.make_hdf5_data(data_path, data_key, shape, func)

        n_jobs = 1 if file_format == "bdv.hdf5" else self.max_jobs
        scales = [[2, 2, 2], [2, 2, 2], [2, 2, 2]]
        add_image(data_path, data_key, self.root, dataset_name, raw_name,
                  resolution=(1, 1, 1), chunks=(32, 32, 32),
                  scale_factors=scales,
                  tmp_folder=self.tmp_folder,
                  file_format=file_format,
                  target="local", max_jobs=n_jobs,
                  int_to_uint=int_to_uint)
Exemple #6
0
    def init_dataset(self):
        data_path = os.path.join(self.test_folder, 'data.h5')
        data_key = 'data'
        with open_file(data_path, 'a') as f:
            f.create_dataset(data_key, data=np.random.rand(*self.shape))

        tmp_folder = os.path.join(self.test_folder, 'tmp-init')

        raw_name = 'test-raw'
        scales = [[2, 2, 2]]
        add_image(data_path,
                  data_key,
                  self.root,
                  self.dataset_name,
                  raw_name,
                  resolution=(1, 1, 1),
                  chunks=(64, 64, 64),
                  scale_factors=scales,
                  tmp_folder=tmp_folder)
Exemple #7
0
    def setUp(self):
        os.makedirs(self.tmp_folder, exist_ok=True)
        data_path = os.path.join(self.tmp_folder, "data.h5")
        data_key = "data"
        shape = (64, 64, 64)
        with open_file(data_path, "a") as f:
            f.create_dataset(data_key, data=np.random.rand(*shape))

        scales = [[2, 2, 2]]
        max_jobs = min(4, mp.cpu_count())

        tmp_folder = os.path.join(self.tmp_folder, "tmp-init-raw")
        mobie.add_image(data_path,
                        data_key,
                        self.data_folder,
                        "test-ds",
                        "raw",
                        resolution=(1, 1, 1),
                        chunks=(32, 32, 32),
                        scale_factors=scales,
                        tmp_folder=tmp_folder,
                        max_jobs=max_jobs)
Exemple #8
0
    def init_ds(self):
        import h5py
        from mobie import add_image
        os.makedirs(self.root, exist_ok=True)
        path = os.path.join(self.root, "data.h5")
        with h5py.File(path, "w") as f:
            f.create_dataset("data", data=np.random.rand(2, 64, 64))

        sources = []
        for ii in range(4):
            im_name = f"image-{ii}"
            add_image(path,
                      "data",
                      self.root,
                      "ds",
                      im_name,
                      resolution=(1, 1, 1),
                      scale_factors=[[2, 2, 2]],
                      chunks=(1, 32, 32),
                      tmp_folder=os.path.join(self.root, f"tmp-{ii}"),
                      max_jobs=min(4, multiprocessing.cpu_count()))
            sources.append(im_name)
        return sources
Exemple #9
0
 def setUp(self):
     os.makedirs(self.root)
     in_key = "data"
     resolution = (1.0, 1.0, 1.0)
     scale_factors = [[2, 2, 2]]
     chunks = (32, 32, 32)
     max_jobs = min(4, mp.cpu_count())
     for view_id in range(self.n_views):
         view_name = f"view-{view_id}"
         in_path = f"{self.root}/data-{view_id}.h5"
         with h5py.File(in_path, "w") as f:
             f.create_dataset(in_key, data=np.random.rand(64, 64, 64))
         tmp_folder = os.path.join(self.tmp_root, f"view-{view_id}")
         mobie.add_image(in_path,
                         in_key,
                         self.root,
                         self.ds_name,
                         view_name,
                         resolution,
                         scale_factors,
                         chunks,
                         tmp_folder=tmp_folder,
                         max_jobs=max_jobs)
Exemple #10
0
input_file = os.path.join(example_input_data, 'em_overview.tif')

# This is the name that will be given to the image source in mobie.
raw_name = 'em-raw'
unit = 'nanometer'
resolution = (1., 10., 10.)
chunks = (1, 512, 512)
scale_factors = 4 * [[1, 2, 2]]

mobie.add_image(
    input_path=input_file,
    input_key='',  # the input is a single tif image, so we leave input_key blank
    root=mobie_project_folder,
    dataset_name=dataset_name,
    image_name=raw_name,
    resolution=resolution,
    chunks=chunks,
    scale_factors=scale_factors,
    is_default_dataset=True,  # mark this dataset as the default dataset that will be loaded by mobie
    target=target,
    max_jobs=max_jobs,
    unit=unit
)

tomo_names = ['27_tomogram.tif', '29_tomogram.tif']
unit = 'nanometer'
resolution = [5., 5., 5.]
chunks = (32, 128, 128)
scale_factors = [[1, 2, 2], [1, 2, 2],
                 [1, 2, 2], [1, 2, 2],
                 [2, 2, 2]]
Exemple #11
0
    def init_dataset(self):
        data_path = os.path.join(self.test_folder, "data.h5")
        data_key = "data"
        with open_file(data_path, "a") as f:
            f.create_dataset(data_key, data=np.random.rand(*self.shape))

        seg_path = os.path.join(self.test_folder, "seg.h5")
        with open_file(seg_path, "a") as f:
            f.create_dataset(data_key,
                             data=np.random.randint(0, 100, size=self.shape))

        scales = [[2, 2, 2]]
        max_jobs = min(4, mp.cpu_count())

        tmp_folder = os.path.join(self.test_folder, "tmp-init-raw")
        mobie.add_image(data_path,
                        data_key,
                        self.root,
                        self.dataset_name,
                        self.raw_name,
                        resolution=(1, 1, 1),
                        chunks=self.chunks,
                        scale_factors=scales,
                        tmp_folder=tmp_folder,
                        max_jobs=max_jobs)

        tmp_folder = os.path.join(self.test_folder, "tmp-init-extra")
        mobie.add_image(data_path,
                        data_key,
                        self.root,
                        self.dataset_name,
                        self.extra_name,
                        resolution=(1, 1, 1),
                        chunks=self.chunks,
                        scale_factors=scales,
                        tmp_folder=tmp_folder,
                        max_jobs=max_jobs)

        tmp_folder = os.path.join(self.test_folder, "tmp-init-seg")
        mobie.add_segmentation(seg_path,
                               data_key,
                               self.root,
                               self.dataset_name,
                               self.seg_name,
                               resolution=(1, 1, 1),
                               chunks=self.chunks,
                               scale_factors=scales,
                               tmp_folder=tmp_folder,
                               max_jobs=max_jobs)

        tmp_folder = os.path.join(self.test_folder, "tmp-init-extra_seg")
        mobie.add_segmentation(seg_path,
                               data_key,
                               self.root,
                               self.dataset_name,
                               self.extra_seg_name,
                               resolution=(1, 1, 1),
                               chunks=self.chunks,
                               scale_factors=scales,
                               tmp_folder=tmp_folder,
                               max_jobs=max_jobs)