From 5828cda743a086e22dace2825f75bccd9c9c398b Mon Sep 17 00:00:00 2001
From: Christian Kento Rasmussen <christian.kento@gmail.com>
Date: Mon, 10 Jun 2024 13:13:22 +0200
Subject: [PATCH] finalized convert function for zarr to tiff

---
 qim3d/io/__init__.py |  1 +
 qim3d/io/convert.py  | 26 +++++---------------------
 2 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/qim3d/io/__init__.py b/qim3d/io/__init__.py
index f97cb7d4..7efd57b8 100644
--- a/qim3d/io/__init__.py
+++ b/qim3d/io/__init__.py
@@ -2,4 +2,5 @@ from .loading import DataLoader, load, ImgExamples
 from .downloader import Downloader
 from .saving import DataSaver, save 
 from .sync import Sync
+from .convert import convert
 from . import logger
\ No newline at end of file
diff --git a/qim3d/io/convert.py b/qim3d/io/convert.py
index dd29d7e2..aa803d8b 100644
--- a/qim3d/io/convert.py
+++ b/qim3d/io/convert.py
@@ -23,13 +23,14 @@ class Convert:
     def convert(self, input_path, output_path):
         # Stringify path in case it is not already a string
         input_path = stringify_path(input_path)
+        output_path = stringify_path(output_path)
 
-        if os.path.isfile(input_path) and os.path.isfile(output_path):
-            match input_path, output_path:
+        if os.path.isfile(input_path):
+            input_ext = os.path.splitext(input_path)[1]
+            output_ext = os.path.splitext(output_path)[1]
+            match input_ext, output_ext:
                 case (".tif", ".zarr"):
                     return self.convert_tif_to_zarr(input_path, output_path)
-                case (".npy", ".zarr"):
-                    return self.convert_npy_to_zarr(input_path, output_path, shape=(64, 64, 64))
                 case (".zarr", ".tif"):
                     return self.convert_zarr_to_tif(input_path, output_path)
                 case _:
@@ -75,23 +76,6 @@ class Convert:
 
         return z
 
-    def convert_npy_to_zarr(self, npy_path, zarr_path, shape, dtype=np.float32, chunks=(64, 64, 64)):
-        """ Convert a numpy file to a zarr file
-
-        Args:
-            npy_path (str): path to the numpy file
-            zarr_path (str): path to the zarr file
-            chunks (tuple, optional): chunk size for the zarr file. Defaults to (64, 64, 64).
-
-        Returns:
-            zarr.core.Array: zarr array containing the data from the numpy file
-        """
-        vol = np.memmap(npy_path, dtype=dtype, mode='r', shape=shape)
-        z = zarr.open(zarr_path, mode='w', shape=vol.shape, chunks=chunks, dtype=vol.dtype)
-        z[:] = vol[:]
-
-        return z
-
     def convert_zarr_to_tif(self, zarr_path, tif_path):
         """ Convert a zarr file to a tiff file
 
-- 
GitLab