Skip to content

Commit d6a38a0

Browse files
committed
[feat] add selection by keys
1 parent f6d3daa commit d6a38a0

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
```
1010
git clone https://github.com/FastTrackOrg/FastAnalysis.git
1111
cd FastAnalysis
12-
pip install fastanalysis
12+
pip install .
1313
```
1414

1515
## Development

fastanalysis/load.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ def getDataframe(self):
2929
else:
3030
return self.tracking
3131

32+
def getKeys(self):
33+
"""Get the list of keys of the tracking data.
34+
35+
:return: Keys
36+
:rtype: List
37+
"""
38+
return self.tracking.keys().tolist()
39+
40+
def getDataKeys(self, keys):
41+
"""Get the tracking data in a pandas DataFrame format.
42+
43+
:raises Exception: The selected file is empty
44+
:return: Tracking data
45+
:rtype: DataFrame
46+
"""
47+
if isinstance(keys, list):
48+
data = self.tracking[keys]
49+
else:
50+
data = self.tracking[[keys]]
51+
return data
52+
3253
def getObjectNumber(self):
3354
"""Get the total number of objects in the tracking file.
3455

fastanalysis/tests/test_load.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,18 @@ def test_object_number():
1919
"""Test number of objects."""
2020
objectNumber = load.Load("tests/tracking.txt").getObjectNumber()
2121
assert objectNumber == 207
22-
22+
23+
def test_get_keys():
24+
"""Test get list of keys."""
25+
keys = load.Load("tests/tracking.txt").getKeys()
26+
assert keys == ["xHead", "yHead", "tHead", "xTail", "yTail", "tTail", "xBody", "yBody", "tBody", "curvature", "areaBody", "perimeterBody", "headMajorAxisLength", "headMinorAxisLength", "headExcentricity", "tailMajorAxisLength", "tailMinorAxisLength", "tailExcentricity", "bodyMajorAxisLength", "bodyMinorAxisLength", "bodyExcentricity", "imageNumber", "id"]
27+
28+
def test_data_keys():
29+
"""Test get data from list of keys."""
30+
reference = pandas.read_csv("tests/tracking.txt", sep='\t')
31+
pandas.testing.assert_frame_equal(load.Load("tests/tracking.txt").getDataKeys(["yHead", "tHead"]), reference[["yHead", "tHead"]])
32+
pandas.testing.assert_frame_equal(load.Load("tests/tracking.txt").getDataKeys("yHead"), reference[["yHead"]])
33+
2334
def test_get_objects():
2435
"""Test get the data for an object"""
2536
reference = pandas.read_csv("tests/tracking.txt", sep='\t')

0 commit comments

Comments
 (0)