From 19e7b69a3ca9aadd5cd929d606ba1e9f6580da5a Mon Sep 17 00:00:00 2001
From: Zhichao Zhang <zhichao.zhang@stud.tu-darmstadt.de>
Date: Tue, 6 Sep 2022 10:00:10 +0200
Subject: [PATCH] change docstring for documentation

---
 pykkn/dataset.py       | 10 ----------
 pykkn/dataset_image.py |  2 +-
 pykkn/dataset_video.py |  6 +-----
 pykkn/parameter.py     |  2 +-
 pykkn/storage.py       | 35 ++++++++++++++++++++++++++++++-----
 5 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/pykkn/dataset.py b/pykkn/dataset.py
index e209592..3103317 100644
--- a/pykkn/dataset.py
+++ b/pykkn/dataset.py
@@ -17,9 +17,6 @@ class Dataset(Storage):
     dataset.data = np.double(1) \n
     dataset.attrs['samplerate'] = 1000 \n
     dataset.attrs['timestamp'] = '2022-06-12 10:39:11' \n
-    dataset.set_storage_path('test/test_ut_ds.h5') \n
-    dataset.store() \n
-
     """
 
     def __init__(self, name: str):
@@ -35,10 +32,3 @@ class Dataset(Storage):
         # the format of time stamp should be "YYYY-MM-DD HH:mm:ss"
         self.attrs["timestamp"] = "-"
         self.attrs["samplerate"] = np.double(1)
-
-
-if __name__ == "__main__":
-    d = Dataset("abc")
-    d.data = 1
-    d.set_storage_path("tests/test_results/path_test.h5")
-    d.store(format="json")
diff --git a/pykkn/dataset_image.py b/pykkn/dataset_image.py
index c63c660..26aea74 100644
--- a/pykkn/dataset_image.py
+++ b/pykkn/dataset_image.py
@@ -20,7 +20,7 @@ class Dataset_Image(Storage):
     Examples
     ---------
     ataset1 = Dataset_Image('image_dataset_1') \n
-    dataset1.data = "/test/test_rig_1.jpg"
+    dataset1.data = "test_rig_1.jpg"
     """
 
     def __init__(self, name: str):
diff --git a/pykkn/dataset_video.py b/pykkn/dataset_video.py
index 732073a..a68c2f6 100644
--- a/pykkn/dataset_video.py
+++ b/pykkn/dataset_video.py
@@ -16,13 +16,9 @@ class Dataset_Video(Storage):
     Examples
     --------
     dataset1 = Dataset_Video('video_dataset_1') \n
-    ataset1.data = "test_meeting_recording.mp4"   \n
     dataset1.data = "test_meeting_recording.mp4"    \n
     dataset1.attrs['timestamp'] = '2022-06-13 11:22:11' \n
-
-    dataset1.set_storage_path('test/test_ut_video.h5')  \n
-
-    dataset1.store()    \n
+    dataset1.set_storage_path('test_ut_video.h5')  \n
     """
 
     def __init__(self, name: str):
diff --git a/pykkn/parameter.py b/pykkn/parameter.py
index 70be443..776d777 100644
--- a/pykkn/parameter.py
+++ b/pykkn/parameter.py
@@ -14,7 +14,7 @@ class Parameter(Storage):
     Examples
     --------
     para1 = Parameter('para1') \n
-    para1.attrs['value'] = 1
+    para1.attrs['value'] = 1 \n
     para1.attrs['units'] = 'cm' \n
     para1.attrs['variable'] = '-' \n
     para1.attrs['origin'] = 'this'
diff --git a/pykkn/storage.py b/pykkn/storage.py
index b9f651f..1494b7e 100644
--- a/pykkn/storage.py
+++ b/pykkn/storage.py
@@ -35,15 +35,22 @@ class Storage:
         Parameters
         ----------
         path : str
-            _description_
+            the storage path you want to store the result file,
+            have to end with .h5
         """
         self.storage_path = Path(path)
 
-    def is_overwritable(self):
-        return self.storage_path.exists()
+    # def is_overwritable(self):
+    #     return self.storage_path.exists()
 
-    def store_HDF5(self, root=None):
+    def store_HDF5(self, root=h5py.File):
+        '''sub-method of store() for HDF5 output
 
+        Parameters
+        ----------
+        root : h5py.File, optional
+            the root of file object
+        '''
         # make a new HDF5 file if this is a root
         if root is None:
             root = h5py.File(self.storage_path, "w")
@@ -96,8 +103,14 @@ class Storage:
                     for i in eval(attr):
                         i.store_HDF5(root=s_grp)
 
-    def store_json(self, root=None):
+    def store_json(self, root=dict):
+        '''sub-method of store() for JSON output
 
+        Parameters
+        ----------
+        root : dict, optional
+            the root of dict object
+        '''
         if root is None:
             root = {}
 
@@ -170,7 +183,15 @@ class Storage:
             return root
 
     def store(self, format=None, root=None):
+        '''store the pykkn structure into HDF5 or JSON
 
+        Parameters
+        ----------
+        format : str, optional
+           the target format, by default is HDF5, can be specified as json
+        root : h5py.File or dict, optional
+            the root of h5py.File or dict object
+        '''
         if format is None:
             if self.storage_path is None:
                 # set the file saving path if it does not exist
@@ -289,10 +310,12 @@ class Storage:
 
     def encode(self, object: Any) -> str:
         """encode anything as a string
+
         Parameters:
         ----------
         object: Any
             an object which can be an instance of any class
+
         Returns:
         --------
         object_string: str
@@ -306,10 +329,12 @@ class Storage:
 
     def decode(self, object_string: str) -> object:
         """decode a string as its original form
+
         Parameters:
         -----------
         object_string: str
             an encoded string
+
         Returns:
         --------
         object: object
-- 
GitLab