Skip to content

Commit 201d059

Browse files
committed
[feat] update api
1 parent c4fdd8c commit 201d059

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
import fastanalysis as fa
3939
4040
tracking = fa.Load("tracking.txt")
41-
keys = fa.keys() # List saved features
42-
fa.saved("output.xlsx", delimiter='\t', keys=["xHead", "yHead", "imageNumber", "id"], ids=None, indexes=None, format="excel") # Saved a list of features for all the frames and all the objects in an excel file.
43-
fa.saved("output.txt", delimiter='\t', keys=None, ids=None, indexes=None, format="excel") # Saved all thefeatures for all the frames and all the objects in an csv file.
41+
keys = fa.keys() # List export features
42+
fa.export("output.xlsx", delimiter='\t', keys=["xHead", "yHead", "imageNumber", "id"], ids=None, indexes=None, format="excel") # Export a list of features for all the frames and all the objects in an excel file.
43+
fa.export("output.txt", delimiter='\t', keys=None, ids=None, indexes=None, format="excel") # Export all thefeatures for all the frames and all the objects in an csv file.
4444
```
4545
Two format are supported: csv and excel.
4646

@@ -54,4 +54,4 @@
5454
plotObj.velocityDistribution(ids=[0, 1], key="Body", pooled=False, subplots=True) # Plot velocity distribution for objects 1 and 0 in 2 subplots
5555
plotObj.velocityDistribution(ids=[0, 1], key="Body", pooled=False, subplots=False) # Plot velocity distribution for objects 1 and 0 in 1 plot
5656
plotObj.velocityDistribution(ids=[0, 1], key="Body", pooled=True) # Plot velocity distribution for objects 1 and 0 pooled in 1 distribution
57-
```
57+
```

fastanalysis/load.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Load:
55
"""Base class to load tracking.txt files"""
66

77
def __init__(self, path):
8-
"""Constructor for Load class.
8+
"""Constructor for the Load tracking object.
99
1010
:param path: Path to the tracking.txt file.
1111
:type path: str
@@ -18,7 +18,7 @@ def __init__(self, path):
1818
raise e
1919

2020
def getDataframe(self):
21-
"""Get the tracking data in a DataFrame.
21+
"""Get the tracking data in a pandas DataFrame format.
2222
2323
:raises Exception: The selected file is empty
2424
:return: Tracking data
@@ -30,7 +30,7 @@ def getDataframe(self):
3030
return self.tracking
3131

3232
def getObjectNumber(self):
33-
"""Get the total number of objects.
33+
"""Get the total number of objects in the tracking file.
3434
3535
:return: [Total number of objects]
3636
:rtype: [int]
@@ -39,7 +39,7 @@ def getObjectNumber(self):
3939
return maxObj
4040

4141
def getObjects(self, ids):
42-
"""Get the data for the objects with ids.
42+
"""Get the tracking data for a list of objects.
4343
4444
:param iD: Id or list of ids of objects.
4545
:type index: list | int
@@ -53,10 +53,10 @@ def getObjects(self, ids):
5353
return objectData
5454

5555
def getFrames(self, indexes):
56-
"""Get the data for the images with number indexes.
56+
"""Get the tracking data for a list of images.
5757
58-
:param index: Index of the image.
59-
:type index: list | int
58+
:param indexes: Indexes of the images.
59+
:type indexes: list | int
6060
:return: Data for the images with indexes.
6161
:rtype: DataFrame
6262
"""
@@ -67,7 +67,7 @@ def getFrames(self, indexes):
6767
return objectData
6868

6969
def getObjectsInFrames(self, ids, indexes):
70-
"""Get the data for objects ids in frames indexes.
70+
"""Get the tracking data for a list of objects in a list of frames.
7171
7272
:param ids: Ids of objects.
7373
:type ids: list | int
@@ -84,7 +84,7 @@ def getObjectsInFrames(self, ids, indexes):
8484
return data
8585

8686
def isObjectsInFrame(self, ids, index):
87-
"""Check if an object id is in a frame index.
87+
"""Check if a list of object is in a frame.
8888
8989
:param ids: Ids of objects.
9090
:type ids: list | int
@@ -109,8 +109,8 @@ def isObjectsInFrame(self, ids, index):
109109
else:
110110
return True
111111

112-
def saved(self, path, delimiter='\t', keys=None, ids=None, indexes=None, fmt="csv"):
113-
"""Check if an object id is in a frame index.
112+
def export(self, path, delimiter='\t', keys=None, ids=None, indexes=None, fmt="csv"):
113+
"""Export the tracking data.
114114
115115
:param path: Path to the saved file.
116116
:type path: str
@@ -135,6 +135,3 @@ def saved(self, path, delimiter='\t', keys=None, ids=None, indexes=None, fmt="cs
135135
tracking.to_csv(path, sep=delimiter, index=False)
136136
elif fmt == "excel":
137137
tracking.to_excel(path, index=False)
138-
139-
140-

fastanalysis/tests/test_load.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,27 @@ def test_export_csv():
5757
reference = pandas.read_csv("tests/tracking.txt", sep='\t')
5858
tracking = load.Load("tests/tracking.txt")
5959

60-
tracking.saved("tests/test.csv")
60+
tracking.export("tests/test.csv")
6161
test = pandas.read_csv("tests/test.csv", sep='\t')
6262
pandas.testing.assert_frame_equal(reference, test)
6363

64-
tracking.saved("tests/test.csv", delimiter=',')
64+
tracking.export("tests/test.csv", delimiter=',')
6565
test = pandas.read_csv("tests/test.csv", sep=',')
6666
pandas.testing.assert_frame_equal(reference, test)
6767

68-
tracking.saved("tests/test.csv", keys=["imageNumber"])
68+
tracking.export("tests/test.csv", keys=["imageNumber"])
6969
test = pandas.read_csv("tests/test.csv", sep='\t')
7070
pandas.testing.assert_frame_equal(reference[["imageNumber"]], test)
7171

72-
tracking.saved("tests/test.csv", indexes=[1])
72+
tracking.export("tests/test.csv", indexes=[1])
7373
test = pandas.read_csv("tests/test.csv", sep='\t')
7474
pandas.testing.assert_frame_equal(reference[reference.imageNumber==1].reset_index(drop=True), test)
7575

76-
tracking.saved("tests/test.csv", ids=[0])
76+
tracking.export("tests/test.csv", ids=[0])
7777
test = pandas.read_csv("tests/test.csv", sep='\t')
7878
pandas.testing.assert_frame_equal(reference[reference.id==0].reset_index(drop=True), test)
7979

80-
tracking.saved("tests/test.csv", ids=[0], indexes=[0])
80+
tracking.export("tests/test.csv", ids=[0], indexes=[0])
8181
test = pandas.read_csv("tests/test.csv", sep='\t')
8282
pandas.testing.assert_frame_equal(reference[(reference.id==0) & (reference.imageNumber==0)].reset_index(drop=True), test)
8383

@@ -86,22 +86,22 @@ def test_export_excel():
8686
reference = pandas.read_csv("tests/tracking.txt", sep='\t')
8787
tracking = load.Load("tests/tracking.txt")
8888

89-
tracking.saved("tests/test.xlsx", fmt="excel")
89+
tracking.export("tests/test.xlsx", fmt="excel")
9090
test = pandas.read_excel("tests/test.xlsx")
9191
pandas.testing.assert_frame_equal(reference, test)
9292

93-
tracking.saved("tests/test.xlsx", keys=["imageNumber"], fmt="excel")
93+
tracking.export("tests/test.xlsx", keys=["imageNumber"], fmt="excel")
9494
test = pandas.read_excel("tests/test.xlsx")
9595
pandas.testing.assert_frame_equal(reference[["imageNumber"]], test)
9696

97-
tracking.saved("tests/test.xlsx", indexes=[1], fmt="excel")
97+
tracking.export("tests/test.xlsx", indexes=[1], fmt="excel")
9898
test = pandas.read_excel("tests/test.xlsx")
9999
pandas.testing.assert_frame_equal(reference[reference.imageNumber==1].reset_index(drop=True), test)
100100

101-
tracking.saved("tests/test.xlsx", ids=[0], fmt="excel")
101+
tracking.export("tests/test.xlsx", ids=[0], fmt="excel")
102102
test = pandas.read_excel("tests/test.xlsx")
103103
pandas.testing.assert_frame_equal(reference[reference.id==0].reset_index(drop=True), test)
104104

105-
tracking.saved("tests/test.xlsx", ids=[0], indexes=[0], fmt="excel")
105+
tracking.export("tests/test.xlsx", ids=[0], indexes=[0], fmt="excel")
106106
test = pandas.read_excel("tests/test.xlsx")
107107
pandas.testing.assert_frame_equal(reference[(reference.id==0) & (reference.imageNumber==0)].reset_index(drop=True), test)

0 commit comments

Comments
 (0)