コード例 #1
0
    def test_name_logic(self):
        from jicbioimage.core.io import AutoName

        def no_transform(image):
            return image

        self.assertEqual(AutoName.name(no_transform), '1_no_transform')
        AutoName.directory = os.path.join('/', 'tmp')
        self.assertEqual(AutoName.name(no_transform),
                         os.path.join('/', 'tmp', '2_no_transform'))
コード例 #2
0
    def test_custom_prefix_name_logic(self):
        from jicbioimage.core.io import AutoName
        AutoName.prefix_format = "{:02d}_"

        def no_transform(image):
            return image

        self.assertEqual(AutoName.name(no_transform), '01_no_transform')
コード例 #3
0
    def test_custom_namespace_logic(self):
        from jicbioimage.core.io import AutoName
        AutoName.namespace = "strand1."

        def no_transform(image):
            return image

        self.assertEqual(AutoName.name(no_transform),
                         '1_strand1.no_transform')
コード例 #4
0
ファイル: transform.py プロジェクト: JIC-CSB/jicbioimage.core
    def func_as_transformation(*args, **kwargs):

        # Take copies of the args and kwargs for use in the history.
        # We will need to remove the image from either the kwargs
        # or the args before we use h_args and h_kwargs to create a
        # history event.
        h_args = list(args[:])
        h_kwargs = kwargs.copy()

        # Get the input image, so that we can get the history from it.
        # Also, strip the image for h_args/h_kwargs.
        input_image = kwargs.get("image", None)
        if input_image is None:
            # The image is the first item of args.
            input_image = args[0]
            h_args.pop(0)
        else:
            # The image is in kwargs.
            h_kwargs.pop("image")

        def array_to_str(value):
            if isinstance(value, np.ndarray):
                value = repr(value)
            return value

        h_args = [array_to_str(v) for v in h_args]
        for key, value in h_kwargs.items():
            h_kwargs[key] = array_to_str(value)

        # Get the history from the image.
        history = History()
        if hasattr(input_image, "history"):
            history.extend(input_image.history)

        image = func(*args, **kwargs)
        if not isinstance(image, _BaseImageWithHistory):
            image = Image.from_array(image, log_in_history=False)

        # Update the history of the image.
        image.history = history
        image.history.add_event(func, h_args, h_kwargs)

        if AutoWrite.on:
            fpath = AutoName.name(func)
            image.write(fpath)
        return image
コード例 #5
0
 def test_custom_prefix(self):
     from jicbioimage.core.io import AutoName
     AutoName.prefix_format = "{:02d}_"
     self.assertEqual(AutoName.prefix(), "00_")
コード例 #6
0
 def test_prefix(self):
     from jicbioimage.core.io import AutoName
     self.assertEqual(AutoName.prefix(), "0_")