Skip to content
Snippets Groups Projects
Commit 19e7b69a authored by Zhang, Zhichao's avatar Zhang, Zhichao
Browse files

change docstring for documentation

parent 7f060014
No related branches found
No related tags found
No related merge requests found
......@@ -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")
......@@ -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):
......
......@@ -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):
......
......@@ -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'
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment