autogaita 1.5.2__py3-none-any.whl → 1.5.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- autogaita-1.5.4.dist-info/METADATA +173 -0
- {autogaita-1.5.2.dist-info → autogaita-1.5.4.dist-info}/RECORD +13 -20
- autogaita-1.5.4.dist-info/top_level.txt +2 -0
- autogaita_backup/common2D_run_and_done_gui.py +414 -0
- autogaita_backup/dlc_1_preparation.py +426 -0
- autogaita_backup/dlc_2_sc_extraction.py +217 -0
- autogaita_backup/dlc_gui.py +359 -0
- autogaita_backup/sleap_1_preparation.py +303 -0
- autogaita_backup/sleap_2_sc_extraction.py +167 -0
- autogaita_backup/sleap_gui.py +359 -0
- autogaita-1.5.2.dist-info/METADATA +0 -40
- autogaita-1.5.2.dist-info/top_level.txt +0 -2
- tests/__init__.py +0 -0
- tests/test_common2D_unit_1_preparation.py +0 -340
- tests/test_common2D_unit_2_sc_extraction.py +0 -367
- tests/test_common2D_unit_3_analysis.py +0 -245
- tests/test_common2D_unit_utils.py +0 -137
- tests/test_dlc_approval.py +0 -110
- tests/test_dlc_unit_1_preparation.py +0 -114
- tests/test_group_approval.py +0 -162
- tests/test_group_unit.py +0 -393
- tests/test_universal3D_approval.py +0 -89
- tests/test_universal3D_unit_1_preparation.py +0 -69
- tests/test_universal3D_unit_2_sc_extraction.py +0 -108
- tests/test_universal3D_unit_3_analysis.py +0 -248
- tests/test_utils.py +0 -442
- {autogaita-1.5.2.dist-info → autogaita-1.5.4.dist-info}/WHEEL +0 -0
- {autogaita-1.5.2.dist-info → autogaita-1.5.4.dist-info}/entry_points.txt +0 -0
- {autogaita-1.5.2.dist-info → autogaita-1.5.4.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
from autogaita.common2D.common2D_1_preparation import (
|
|
2
|
-
move_data_to_folders,
|
|
3
|
-
check_and_expand_cfg,
|
|
4
|
-
check_and_fix_cfg_strings,
|
|
5
|
-
flip_mouse_body,
|
|
6
|
-
some_prep, # note that first input of some_prep is set to "DLC" when not mattering!
|
|
7
|
-
)
|
|
8
|
-
from autogaita.common2D.common2D_utils import extract_info
|
|
9
|
-
import os
|
|
10
|
-
import copy
|
|
11
|
-
import math
|
|
12
|
-
import numpy as np
|
|
13
|
-
import pandas.testing as pdt
|
|
14
|
-
from hypothesis import given, strategies as st, settings, HealthCheck
|
|
15
|
-
import pytest
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# %%.............................. fixtures ..........................................
|
|
19
|
-
# NOTE
|
|
20
|
-
# ----
|
|
21
|
-
# Calling them FIXTURE_extract_... since we have a function called extract_info!
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@pytest.fixture
|
|
25
|
-
def extract_data_using_some_prep(
|
|
26
|
-
fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
27
|
-
):
|
|
28
|
-
data = some_prep(
|
|
29
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
30
|
-
)
|
|
31
|
-
return data
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@pytest.fixture
|
|
35
|
-
def fixture_extract_info(tmp_path):
|
|
36
|
-
info = {}
|
|
37
|
-
info["mouse_num"] = 15
|
|
38
|
-
info["run_num"] = 3
|
|
39
|
-
info["name"] = "ID " + str(info["mouse_num"]) + " - Run " + str(info["run_num"])
|
|
40
|
-
info["results_dir"] = os.path.join(tmp_path, info["name"])
|
|
41
|
-
return info
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@pytest.fixture
|
|
45
|
-
def fixture_extract_folderinfo():
|
|
46
|
-
folderinfo = {}
|
|
47
|
-
folderinfo["root_dir"] = "tests/test_data/dlc_data"
|
|
48
|
-
folderinfo["sctable_filename"] = (
|
|
49
|
-
"correct_annotation_table.xlsx" # has to be an excel file
|
|
50
|
-
)
|
|
51
|
-
folderinfo["data_string"] = "SIMINewOct"
|
|
52
|
-
folderinfo["beam_string"] = "BeamTraining"
|
|
53
|
-
folderinfo["premouse_string"] = "Mouse"
|
|
54
|
-
folderinfo["postmouse_string"] = "25mm"
|
|
55
|
-
folderinfo["prerun_string"] = "run"
|
|
56
|
-
folderinfo["postrun_string"] = "6DLC"
|
|
57
|
-
return folderinfo
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@pytest.fixture
|
|
61
|
-
def fixture_extract_cfg():
|
|
62
|
-
cfg = {}
|
|
63
|
-
cfg["sampling_rate"] = 100
|
|
64
|
-
cfg["subtract_beam"] = True
|
|
65
|
-
cfg["dont_show_plots"] = True
|
|
66
|
-
cfg["convert_to_mm"] = True
|
|
67
|
-
cfg["pixel_to_mm_ratio"] = 3.76
|
|
68
|
-
cfg["x_sc_broken_threshold"] = 200
|
|
69
|
-
cfg["y_sc_broken_threshold"] = 50
|
|
70
|
-
cfg["x_acceleration"] = True
|
|
71
|
-
cfg["angular_acceleration"] = True
|
|
72
|
-
cfg["save_to_xls"] = True
|
|
73
|
-
cfg["bin_num"] = 25
|
|
74
|
-
cfg["plot_SE"] = True
|
|
75
|
-
cfg["standardise_y_at_SC_level"] = False
|
|
76
|
-
cfg["standardise_y_to_a_joint"] = True
|
|
77
|
-
cfg["y_standardisation_joint"] = ["Knee"]
|
|
78
|
-
cfg["plot_joint_number"] = 3
|
|
79
|
-
cfg["color_palette"] = "viridis"
|
|
80
|
-
cfg["legend_outside"] = True
|
|
81
|
-
cfg["invert_y_axis"] = True
|
|
82
|
-
cfg["flip_gait_direction"] = True
|
|
83
|
-
cfg["analyse_average_x"] = True
|
|
84
|
-
cfg["standardise_x_coordinates"] = True
|
|
85
|
-
cfg["x_standardisation_joint"] = ["Hind paw tao"]
|
|
86
|
-
cfg["coordinate_standardisation_xls"] = ""
|
|
87
|
-
cfg["hind_joints"] = ["Hind paw tao", "Ankle", "Knee", "Hip", "Iliac Crest"]
|
|
88
|
-
cfg["fore_joints"] = [
|
|
89
|
-
"Front paw tao ",
|
|
90
|
-
"Wrist ",
|
|
91
|
-
"Elbow ",
|
|
92
|
-
"Lower Shoulder ",
|
|
93
|
-
"Upper Shoulder ",
|
|
94
|
-
]
|
|
95
|
-
cfg["beam_col_left"] = ["BeamLeft"] # BEAM_COL_LEFT & _RIGHT must be lists of len=1
|
|
96
|
-
cfg["beam_col_right"] = ["BeamRight"]
|
|
97
|
-
cfg["beam_hind_jointadd"] = ["Tail base ", "Tail center ", "Tail tip "]
|
|
98
|
-
cfg["beam_fore_jointadd"] = ["Nose ", "Ear base "]
|
|
99
|
-
cfg["angles"] = {
|
|
100
|
-
"name": ["Ankle ", "Knee ", "Hip "],
|
|
101
|
-
"lower_joint": ["Hind paw tao ", "Ankle ", "Knee "],
|
|
102
|
-
"upper_joint": ["Knee ", "Hip ", "Iliac Crest "],
|
|
103
|
-
}
|
|
104
|
-
return cfg
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
# %%.............................. preparation .......................................
|
|
108
|
-
# AN IMPORTANT NOTE ON THESE UNIT TESTS!
|
|
109
|
-
# Calling check_and_expand cfg outside of some_prep with the
|
|
110
|
-
# export_data_using_some_prep fixture leads to the cfg that is returned by
|
|
111
|
-
# check_and_expand to be None since the data var DOES NOT INCLUDE the beam!
|
|
112
|
-
# => We thus set cfg["subtract_beam"] to False prior to calling it (see e.g.the
|
|
113
|
-
# plot_joint test)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def test_move_data_to_folders_smoke_normal(
|
|
117
|
-
fixture_extract_info, fixture_extract_folderinfo
|
|
118
|
-
):
|
|
119
|
-
move_data_to_folders(
|
|
120
|
-
"DLC", ".csv", fixture_extract_info, fixture_extract_folderinfo
|
|
121
|
-
)
|
|
122
|
-
assert len(os.listdir(fixture_extract_info["results_dir"])) == 3
|
|
123
|
-
for file in os.listdir(fixture_extract_info["results_dir"]):
|
|
124
|
-
if file.endswith(".csv"):
|
|
125
|
-
assert (
|
|
126
|
-
(fixture_extract_folderinfo["premouse_string"] in file)
|
|
127
|
-
& (fixture_extract_folderinfo["postmouse_string"] in file)
|
|
128
|
-
& (fixture_extract_folderinfo["prerun_string"] in file)
|
|
129
|
-
& (fixture_extract_folderinfo["postrun_string"] in file)
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
def test_move_data_to_folders_leading_zeros_handled(
|
|
134
|
-
tmp_path, fixture_extract_folderinfo
|
|
135
|
-
):
|
|
136
|
-
# ensure files with leading zeros are moved too
|
|
137
|
-
# => this needs some preparation because I want to test extract_info, too, which is
|
|
138
|
-
# required to output lists in each of its keys because I use it in multiruns to
|
|
139
|
-
# iterate over each idxs which consistute separate runs
|
|
140
|
-
fixture_extract_folderinfo["root_dir"] = (
|
|
141
|
-
"tests/test_data/dlc_data/test_data/leading_zeros/"
|
|
142
|
-
)
|
|
143
|
-
# CARE! function: extract_info for info where we handle leading zeros
|
|
144
|
-
info = extract_info("DLC", fixture_extract_folderinfo)
|
|
145
|
-
for idx in range(len(info["name"])):
|
|
146
|
-
this_info = {}
|
|
147
|
-
# forloop below is borrowed from run_singlerun_in_multirun function
|
|
148
|
-
for keyname in info.keys():
|
|
149
|
-
if "leading_" in keyname:
|
|
150
|
-
if info[keyname][idx] is not False:
|
|
151
|
-
this_info[keyname] = info[keyname][idx]
|
|
152
|
-
else: # pass as is for all other keys
|
|
153
|
-
this_info[keyname] = info[keyname][idx]
|
|
154
|
-
this_info["results_dir"] = tmp_path
|
|
155
|
-
# move_data... creates it, make sure it's not there
|
|
156
|
-
if os.path.exists(this_info["results_dir"]):
|
|
157
|
-
for file in os.listdir(this_info["results_dir"]):
|
|
158
|
-
os.remove(os.path.join(this_info["results_dir"], file))
|
|
159
|
-
os.rmdir(this_info["results_dir"])
|
|
160
|
-
# run with this_info
|
|
161
|
-
move_data_to_folders("DLC", ".csv", this_info, fixture_extract_folderinfo)
|
|
162
|
-
assert len(os.listdir(this_info["results_dir"])) == 2
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
# %%.......................... cfg & string stuff ....................................
|
|
166
|
-
def test_plot_joint_error(
|
|
167
|
-
extract_data_using_some_prep, fixture_extract_cfg, fixture_extract_info
|
|
168
|
-
):
|
|
169
|
-
fixture_extract_cfg["plot_joint_number"] = 2000
|
|
170
|
-
fixture_extract_cfg["subtract_beam"] = False
|
|
171
|
-
check_and_expand_cfg(
|
|
172
|
-
extract_data_using_some_prep, fixture_extract_cfg, fixture_extract_info
|
|
173
|
-
)
|
|
174
|
-
with open(os.path.join(fixture_extract_info["results_dir"], "Issues.txt")) as f:
|
|
175
|
-
content = f.read()
|
|
176
|
-
assert "we can :)" in content
|
|
177
|
-
fixture_extract_cfg = check_and_expand_cfg(
|
|
178
|
-
extract_data_using_some_prep, fixture_extract_cfg, fixture_extract_info
|
|
179
|
-
)
|
|
180
|
-
assert fixture_extract_cfg["plot_joints"] == fixture_extract_cfg["hind_joints"]
|
|
181
|
-
fixture_extract_cfg["plot_joint_number"] = 2
|
|
182
|
-
fixture_extract_cfg = check_and_expand_cfg(
|
|
183
|
-
extract_data_using_some_prep, fixture_extract_cfg, fixture_extract_info
|
|
184
|
-
)
|
|
185
|
-
assert fixture_extract_cfg["plot_joints"] == fixture_extract_cfg["hind_joints"][:2]
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
def test_error_if_no_cfgkey_joints(
|
|
189
|
-
fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
190
|
-
):
|
|
191
|
-
full_cfg = copy.deepcopy(
|
|
192
|
-
fixture_extract_cfg
|
|
193
|
-
) # no referencing here - we need copies!
|
|
194
|
-
for cfg_key in [
|
|
195
|
-
"hind_joints",
|
|
196
|
-
"x_standardisation_joint",
|
|
197
|
-
"y_standardisation_joint",
|
|
198
|
-
]:
|
|
199
|
-
fixture_extract_cfg = copy.deepcopy(full_cfg) # here too!
|
|
200
|
-
fixture_extract_cfg[cfg_key] = ["not_in_data"]
|
|
201
|
-
data = some_prep(
|
|
202
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
203
|
-
)
|
|
204
|
-
with open(os.path.join(fixture_extract_info["results_dir"], "Issues.txt")) as f:
|
|
205
|
-
content = f.read()
|
|
206
|
-
if cfg_key == "hind_joints":
|
|
207
|
-
assert "hind limb joint names" in content
|
|
208
|
-
elif cfg_key == "x_standardisation_joint":
|
|
209
|
-
assert "x-coordinate standardisation joint" in content
|
|
210
|
-
elif cfg_key == "y_standardisation_joint":
|
|
211
|
-
assert "y-coordinate standardisation joint" in content
|
|
212
|
-
assert data is None
|
|
213
|
-
# cannot loop case of x & y joints being broken
|
|
214
|
-
fixture_extract_cfg = copy.deepcopy(full_cfg)
|
|
215
|
-
fixture_extract_cfg["x_standardisation_joint"] = ["not_in_data"]
|
|
216
|
-
fixture_extract_cfg["y_standardisation_joint"] = ["not_in_data"]
|
|
217
|
-
data = some_prep(
|
|
218
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
219
|
-
)
|
|
220
|
-
with open(os.path.join(fixture_extract_info["results_dir"], "Issues.txt")) as f:
|
|
221
|
-
content = f.read()
|
|
222
|
-
assert "x & y-coordinate standardisation joint" in content
|
|
223
|
-
assert data is None
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
@given(test_list=st.lists(st.text(), min_size=1))
|
|
227
|
-
@settings(suppress_health_check=[HealthCheck.function_scoped_fixture])
|
|
228
|
-
def test_removal_of_wrong_strings_from_cfg_key(
|
|
229
|
-
test_list, extract_data_using_some_prep, fixture_extract_cfg, fixture_extract_info
|
|
230
|
-
):
|
|
231
|
-
# the following loop is to account for hypothesis randomly generating strings that
|
|
232
|
-
# actually are data columns (happend for "Knee ")
|
|
233
|
-
for i in range(len(test_list)):
|
|
234
|
-
if test_list[i] + "x" in extract_data_using_some_prep.columns:
|
|
235
|
-
test_list.pop(i)
|
|
236
|
-
cfg_key = "hind_joints" # irrelevant since property testing
|
|
237
|
-
fixture_extract_cfg[cfg_key] = test_list
|
|
238
|
-
test_result = check_and_fix_cfg_strings(
|
|
239
|
-
extract_data_using_some_prep, fixture_extract_cfg, cfg_key, fixture_extract_info
|
|
240
|
-
)
|
|
241
|
-
assert not test_result # empty list is falsey
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
def test_wrong_data_and_beam_strings(
|
|
245
|
-
fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
246
|
-
):
|
|
247
|
-
fixture_extract_folderinfo["beam_string"] = fixture_extract_folderinfo[
|
|
248
|
-
"data_string"
|
|
249
|
-
]
|
|
250
|
-
some_prep(
|
|
251
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
252
|
-
)
|
|
253
|
-
with open(os.path.join(fixture_extract_info["results_dir"], "Issues.txt")) as f:
|
|
254
|
-
content = f.read()
|
|
255
|
-
assert "Your data & baseline (beam) identifiers ([G] in our" in content
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
def test_wrong_postmouse_string(
|
|
259
|
-
fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
260
|
-
):
|
|
261
|
-
fixture_extract_folderinfo["postmouse_string"] = "this_is_a_test"
|
|
262
|
-
some_prep(
|
|
263
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
264
|
-
)
|
|
265
|
-
with open(os.path.join(fixture_extract_info["results_dir"], "Issues.txt")) as f:
|
|
266
|
-
content = f.read()
|
|
267
|
-
assert "Unable to identify ANY RELEVANT FILES for" in content
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
# %%........................... dataframe stuff ......................................
|
|
271
|
-
def test_cols_we_added_to_data(
|
|
272
|
-
fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
273
|
-
):
|
|
274
|
-
data = some_prep(
|
|
275
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
276
|
-
)
|
|
277
|
-
assert (data.columns[0] == "Time") & (data.columns[1] == "Flipped")
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
def test_datas_indexing_and_time_column(
|
|
281
|
-
fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
282
|
-
):
|
|
283
|
-
for fixture_extract_cfg["sampling_rate"] in [50, 500, 5000]:
|
|
284
|
-
data = some_prep(
|
|
285
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
286
|
-
)
|
|
287
|
-
# use isclose here because there are some floating point things going on (eg. 1.
|
|
288
|
-
# 66 and 1.660 for sampling rate of 500)
|
|
289
|
-
assert math.isclose(
|
|
290
|
-
data["Time"].max(),
|
|
291
|
-
(len(data) - 1) / (1 * fixture_extract_cfg["sampling_rate"]),
|
|
292
|
-
rel_tol=1e-9,
|
|
293
|
-
)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
# %%........................... data manipulation ....................................
|
|
297
|
-
def test_global_min_standardisation(
|
|
298
|
-
fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
299
|
-
):
|
|
300
|
-
fixture_extract_cfg["subtract_beam"] = False
|
|
301
|
-
fixture_extract_cfg["standardise_y_to_a_joint"] = False
|
|
302
|
-
data = some_prep(
|
|
303
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
304
|
-
)
|
|
305
|
-
y_cols = [c for c in data.columns if c.endswith(" y")]
|
|
306
|
-
assert data[y_cols].min().min() == 0
|
|
307
|
-
# approach here is find difference between global & standardisation joint minma and
|
|
308
|
-
# see if all y cols' difference is equal to that
|
|
309
|
-
# => this implies that joint-based y-standardisation worked
|
|
310
|
-
global_and_standardisation_joints_y_min_diff = data[
|
|
311
|
-
fixture_extract_cfg["y_standardisation_joint"][0] + " y"
|
|
312
|
-
].min()
|
|
313
|
-
global_min_data = data.copy()
|
|
314
|
-
fixture_extract_cfg["standardise_y_to_a_joint"] = True
|
|
315
|
-
data = some_prep(
|
|
316
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
317
|
-
)
|
|
318
|
-
assert np.allclose( # use np.allclose here because we are comparing arrays
|
|
319
|
-
global_min_data[y_cols],
|
|
320
|
-
data[y_cols] + global_and_standardisation_joints_y_min_diff,
|
|
321
|
-
atol=1e-9,
|
|
322
|
-
)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
def test_flip_mouse_body(
|
|
326
|
-
fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
327
|
-
):
|
|
328
|
-
fixture_extract_cfg["flip_gait_direction"] = False
|
|
329
|
-
test_data = some_prep(
|
|
330
|
-
"DLC", fixture_extract_info, fixture_extract_folderinfo, fixture_extract_cfg
|
|
331
|
-
)
|
|
332
|
-
function_flipped_data = test_data.copy()
|
|
333
|
-
function_flipped_data = flip_mouse_body(test_data, fixture_extract_info)
|
|
334
|
-
x_cols = [col for col in function_flipped_data.columns if col.endswith(" x")]
|
|
335
|
-
global_x_max = max(test_data[x_cols].max())
|
|
336
|
-
for col in x_cols:
|
|
337
|
-
function_flipped_series = function_flipped_data[col]
|
|
338
|
-
function_flipped_series = function_flipped_series.astype(float)
|
|
339
|
-
manually_flipped_series = global_x_max - test_data[col]
|
|
340
|
-
pdt.assert_series_equal(function_flipped_series, manually_flipped_series)
|