Skip to content

Commit da57206

Browse files
author
André Böni
committed
+ fix bug no event section
1 parent 93c80e0 commit da57206

File tree

7 files changed

+29
-19
lines changed

7 files changed

+29
-19
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Changelog
33
=========
44

5+
0.2.1
6+
------------------
7+
- Fixed bug for get events when no events entry is present in c3d file
8+
59
0.2.0
610
------------------
711
Breaking changes:

gaitalytics/io.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ def __init__(self, file_path: Path):
139139
self._c3d = ezc3d.c3d(str(file_path))
140140
super().__init__(file_path)
141141

142-
def get_events(self) -> pd.DataFrame:
142+
def get_events(self) -> pd.DataFrame | None:
143143
"""Gets the events from the input file sorted by time.
144144
145145
Returns:
146-
A DataFrame containing the events.
146+
pd.DataFrame A DataFrame containing the events.
147+
None if there are no events in the C3D file.
148+
147149
148-
Raises:
149-
ValueError: If no events are found in the C3D file.
150150
"""
151151
labels = self._get_event_labels()
152152
times = self._get_event_times()
@@ -155,7 +155,7 @@ def get_events(self) -> pd.DataFrame:
155155

156156
# Check if there are any events in the C3D file
157157
if not (labels and times and contexts and icons):
158-
raise ValueError("No events found in the C3D file.")
158+
return None
159159

160160
table = pd.DataFrame(
161161
{
3.41 MB
Binary file not shown.

tests/test_api.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,23 @@ def test_load_config():
3939

4040
def test_load_c3d_trial():
4141
config = api.load_config("./tests/pig_config.yaml")
42-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
42+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
4343
assert len(trial.get_all_data().keys()) == 3
4444
assert trial.events is not None
4545

4646

47+
def test_load_c3d_trial_no_events():
48+
config = api.load_config("./tests/pig_config.yaml")
49+
trial = api.load_c3d_trial("./tests/treadmill_no_events.c3d", config)
50+
assert trial.events is None
51+
52+
4753
def test_detect_events():
4854
config = api.load_config("./tests/pig_config.yaml")
49-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
55+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
5056
event_table = api.detect_events(trial, config, distance=1000)
5157
assert event_table is not None
52-
assert len(event_table) == 4
58+
assert len(event_table) == 5
5359

5460

5561
def test_detect_events_methode():
@@ -61,7 +67,7 @@ def test_detect_events_methode():
6167

6268
def test_check_events():
6369
config = api.load_config("./tests/pig_config.yaml")
64-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
70+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
6571
api.check_events(trial.events)
6672
assert True
6773

@@ -73,15 +79,15 @@ def test_check_events_methode():
7379

7480
def test_write_events(out_path):
7581
config = api.load_config("./tests/pig_config.yaml")
76-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
82+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
7783
event_table = api.detect_events(trial, config, distance=1000)
78-
api.write_events_to_c3d("./tests/test_small.c3d", event_table, out_path)
84+
api.write_events_to_c3d("./tests/treadmill_no_events.c3d", event_table, out_path)
7985
assert True
8086

8187

8288
def test_segment_trial():
8389
config = api.load_config("./tests/pig_config.yaml")
84-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
90+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
8591
segm_trial = api.segment_trial(trial)
8692
assert len(segm_trial.get_all_cycles().keys()) == 2
8793

@@ -100,22 +106,22 @@ def test_segment_trial_method():
100106

101107
def test_time_normalize_trail():
102108
config = api.load_config("./tests/pig_config.yaml")
103-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
109+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
104110
norm_trial = api.time_normalise_trial(trial)
105111
assert norm_trial is not None
106112

107113

108114
def test_time_normalize_cycle_trial():
109115
config = api.load_config("./tests/pig_config.yaml")
110-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
116+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
111117
trial_cycles = api.segment_trial(trial)
112118
norm_trial = api.time_normalise_trial(trial_cycles)
113119
assert norm_trial is not None
114120

115121

116122
def test_time_normalize_trial_frames():
117123
config = api.load_config("./tests/pig_config.yaml")
118-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
124+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
119125
trial_cycles = api.segment_trial(trial)
120126
norm_trial = api.time_normalise_trial(trial_cycles, n_frames=200)
121127
markers = norm_trial.get_cycle("Left", 0).get_data(model.DataCategory.MARKERS)
@@ -124,15 +130,15 @@ def test_time_normalize_trial_frames():
124130

125131
def test_calculate_features():
126132
config = api.load_config("./tests/pig_config.yaml")
127-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
133+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
128134
trial_cycles = api.segment_trial(trial)
129135
features = api.calculate_features(trial_cycles, config)
130-
assert features.shape == (2, 2, 2278)
136+
assert features.shape == (2, 10, 2278)
131137

132138

133139
def test_export_trial(out_folder):
134140
config = api.load_config("./tests/pig_config.yaml")
135-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
141+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
136142
api.export_trial(trial, out_folder)
137143
assert (out_folder / "markers.nc").exists()
138144
assert (out_folder / "analogs.nc").exists()
@@ -141,7 +147,7 @@ def test_export_trial(out_folder):
141147

142148
def test_export_segmented_trial(out_folder):
143149
config = api.load_config("./tests/pig_config.yaml")
144-
trial = api.load_c3d_trial("./tests/test_small.c3d", config)
150+
trial = api.load_c3d_trial("./tests/treadmill_events.c3d", config)
145151
trial_cycles = api.segment_trial(trial)
146152
api.export_trial(trial_cycles, out_folder)
147153
assert (out_folder / "markers.nc").exists()

tests/test_small.c3d

-1.56 MB
Binary file not shown.

tests/treadmill_events.c3d

3.42 MB
Binary file not shown.

tests/treadmill_no_events.c3d

3.41 MB
Binary file not shown.

0 commit comments

Comments
 (0)