Ejemplo n.º 1
0
    def test_manual_addition_of_ImageCollection_to_DataManager(self):
        # We start off by creating a :class:`jicbioimage.core.io.DataManager`.
        # This takes a backend argument. The backend provides a means to store
        # unpacked image files.
        from jicbioimage.core.io import DataManager, FileBackend
        backend = FileBackend(directory=TMP_DIR)
        data_manager = DataManager(backend=backend)

        # The :func:`jicbioimage.core.image.DataManager.conver` function is be
        # default an instance of the callable
        # :class:`jicbioimage.core.io.BFConvertWrapper` class.
        from jicbioimage.core.io import BFConvertWrapper, _md5_hexdigest_from_file
        self.assertTrue(isinstance(data_manager.convert, BFConvertWrapper))

        # We also need to import an ImageCollection
        from jicbioimage.core.image import ImageCollection

        # If the input file has not already been converted with do so.
        fpath = os.path.join(DATA_DIR, 'z-series.ome.tif')
        self.assertFalse(data_manager.convert.already_converted(fpath))
        if not data_manager.convert.already_converted(fpath):
            path_to_manifest = data_manager.convert(fpath) # unpacks and creates manifests
            self.assertEqual(path_to_manifest, os.path.join(TMP_DIR,
                                                            _md5_hexdigest_from_file(fpath),
                                                            'manifest.json'))
            image_collection = ImageCollection()
            image_collection.parse_manifest(path_to_manifest)
            self.assertEqual(len(image_collection), 5)
            data_manager.append(image_collection)
            self.assertEqual(len(data_manager), 1)
        self.assertTrue(data_manager.convert.already_converted(fpath))
    def test_parse_manifest_raises_runtime_error_if_no_filename(self):
        # Create manifest.json file without fpath.
        manifest_fp = os.path.join(TMP_DIR, 'manifest.json')
        with open(manifest_fp, 'w') as fh:
            json.dump({"nofpath": "/tmp"}, fh)

        from jicbioimage.core.image import ImageCollection
        image_collection = ImageCollection()
        with self.assertRaises(RuntimeError):
            image_collection.parse_manifest(manifest_fp)
Ejemplo n.º 3
0
    def test_parse_manifest_raises_runtime_error_if_no_filename(self):
        # Create manifest.json file without fpath.
        manifest_fp = os.path.join(TMP_DIR, 'manifest.json')
        with open(manifest_fp, 'w') as fh:
            json.dump({"nofpath": "/tmp"}, fh)

        from jicbioimage.core.image import ImageCollection
        image_collection = ImageCollection()
        with self.assertRaises(RuntimeError):
            image_collection.parse_manifest(manifest_fp)
    def test_parse_manifest_raises_backwards_compatible_with_abs_paths(self):
        # Create manifest.json file without fpath.
        manifest_fp = os.path.join(TMP_DIR, 'manifest.json')
        shutil.copy(os.path.join(DATA_DIR, "tjelvar.png"), TMP_DIR)
        abs_im_fpath = os.path.join(TMP_DIR, 'tjelvar.png')
        entry = dict(filename=abs_im_fpath, series=0, channel=0, zslice=0,
                     timepoint=0)
        with open(manifest_fp, 'w') as fh:
            json.dump([entry], fh)

        from jicbioimage.core.image import ImageCollection, Image
        image_collection = ImageCollection()
        image_collection.parse_manifest(manifest_fp)
        im = image_collection[0].image
        expected_im = Image.from_file(abs_im_fpath)
        import numpy as np
        self.assertTrue(np.array_equal(im, expected_im))
Ejemplo n.º 5
0
    def test_parse_manifest_raises_backwards_compatible_with_abs_paths(self):
        # Create manifest.json file without fpath.
        manifest_fp = os.path.join(TMP_DIR, 'manifest.json')
        shutil.copy(os.path.join(DATA_DIR, "tjelvar.png"), TMP_DIR)
        abs_im_fpath = os.path.join(TMP_DIR, 'tjelvar.png')
        entry = dict(filename=abs_im_fpath,
                     series=0,
                     channel=0,
                     zslice=0,
                     timepoint=0)
        with open(manifest_fp, 'w') as fh:
            json.dump([entry], fh)

        from jicbioimage.core.image import ImageCollection, Image
        image_collection = ImageCollection()
        image_collection.parse_manifest(manifest_fp)
        im = image_collection[0].image
        expected_im = Image.from_file(abs_im_fpath)
        import numpy as np
        self.assertTrue(np.array_equal(im, expected_im))