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.
@@ -1,137 +0,0 @@
1
- import pytest
2
- from autogaita.common2D.common2D_utils import extract_info, find_number
3
- import os
4
- import pytest
5
-
6
-
7
- # %%.............................. fixtures ..........................................
8
- # => CALL FIXTURES _fixture SINCE WE HAVE A FUNCTION CALLED extract_info!
9
- @pytest.fixture
10
- def fixture_extract_info(tmp_path):
11
- info = {}
12
- info["mouse_num"] = 15
13
- info["run_num"] = 3
14
- info["name"] = "ID " + str(info["mouse_num"]) + " - Run " + str(info["run_num"])
15
- info["results_dir"] = os.path.join(tmp_path, info["name"])
16
- return info
17
-
18
-
19
- @pytest.fixture
20
- def fixture_extract_folderinfo():
21
- folderinfo = {}
22
- folderinfo["root_dir"] = "tests/test_data/dlc_data"
23
- folderinfo["sctable_filename"] = (
24
- "correct_annotation_table.xlsx" # has to be an excel file
25
- )
26
- folderinfo["data_string"] = "SIMINewOct"
27
- folderinfo["beam_string"] = "BeamTraining"
28
- folderinfo["premouse_string"] = "Mouse"
29
- folderinfo["postmouse_string"] = "_25mm"
30
- folderinfo["prerun_string"] = "run"
31
- folderinfo["postrun_string"] = "-6DLC"
32
- return folderinfo
33
-
34
-
35
- @pytest.fixture
36
- def fixture_extract_cfg():
37
- cfg = {}
38
- cfg["sampling_rate"] = 100
39
- cfg["subtract_beam"] = True
40
- cfg["dont_show_plots"] = True
41
- cfg["convert_to_mm"] = True
42
- cfg["pixel_to_mm_ratio"] = 3.76
43
- cfg["x_sc_broken_threshold"] = 200
44
- cfg["y_sc_broken_threshold"] = 50
45
- cfg["x_acceleration"] = True
46
- cfg["angular_acceleration"] = True
47
- cfg["save_to_xls"] = True
48
- cfg["bin_num"] = 25
49
- cfg["plot_SE"] = True
50
- cfg["standardise_y_at_SC_level"] = False
51
- cfg["standardise_y_to_a_joint"] = True
52
- cfg["y_standardisation_joint"] = ["Knee"]
53
- cfg["plot_joint_number"] = 3
54
- cfg["color_palette"] = "viridis"
55
- cfg["legend_outside"] = True
56
- cfg["invert_y_axis"] = True
57
- cfg["flip_gait_direction"] = True
58
- cfg["analyse_average_x"] = True
59
- cfg["standardise_x_coordinates"] = True
60
- cfg["x_standardisation_joint"] = ["Hind paw tao"]
61
- cfg["coordinate_standardisation_xls"] = ""
62
- cfg["hind_joints"] = ["Hind paw tao", "Ankle", "Knee", "Hip", "Iliac Crest"]
63
- cfg["fore_joints"] = [
64
- "Front paw tao ",
65
- "Wrist ",
66
- "Elbow ",
67
- "Lower Shoulder ",
68
- "Upper Shoulder ",
69
- ]
70
- cfg["beam_col_left"] = ["BeamLeft"] # BEAM_COL_LEFT & _RIGHT must be lists of len=1
71
- cfg["beam_col_right"] = ["BeamRight"]
72
- cfg["beam_hind_jointadd"] = ["Tail base ", "Tail center ", "Tail tip "]
73
- cfg["beam_fore_jointadd"] = ["Nose ", "Ear base "]
74
- cfg["angles"] = {
75
- "name": ["Ankle ", "Knee ", "Hip "],
76
- "lower_joint": ["Hind paw tao ", "Ankle ", "Knee "],
77
- "upper_joint": ["Knee ", "Hip ", "Iliac Crest "],
78
- }
79
- return cfg
80
-
81
-
82
- # %%.............................. tests ..........................................
83
- # 1) Test extract_info function
84
- def test_extract_info_function(fixture_extract_folderinfo):
85
- # => IT IS CORRECT THAT EXTRACT_INFO RETURNS lists of integers!
86
- # a. smoke test standard case
87
- info = extract_info("DLC", fixture_extract_folderinfo)
88
- assert info["mouse_num"] == [15]
89
- assert info["run_num"] == [3]
90
- # b. test that underscores/hyphens are added
91
- folderinfo = fixture_extract_folderinfo
92
- folderinfo["postmouse_string"] = "25mm"
93
- folderinfo["postrun_string"] = "6DLC"
94
- info = extract_info("DLC", folderinfo)
95
- assert info["mouse_num"] == [15]
96
- assert info["run_num"] == [3]
97
- # c. test that leading zeros are removed
98
- folderinfo["root_dir"] = "tests/test_data/dlc_data/test_data/leading_zeros/"
99
- info = extract_info("DLC", folderinfo)
100
- assert info["mouse_num"] == [12, 12]
101
- # order of this might break in some test env
102
- assert info["run_num"] == [4, 3]
103
- assert info["leading_mouse_num_zeros"] == [False, False]
104
- assert info["leading_run_num_zeros"] == ["00", False]
105
-
106
-
107
- # 2) Test find number function - also for leading zeros
108
- def test_find_number_valid_case():
109
- fullstring = "Mouse1_Run002"
110
- prestring = "Mouse"
111
- poststring = "_Run"
112
- result = find_number(fullstring, prestring, poststring)
113
- assert result == (1, False)
114
-
115
-
116
- def test_find_number_prestring_not_found():
117
- fullstring = "Mouse001_Run002"
118
- prestring = "Cat"
119
- poststring = "_Run"
120
- with pytest.raises(ValueError):
121
- find_number(fullstring, prestring, poststring)
122
-
123
-
124
- def test_find_number_poststring_not_found():
125
- fullstring = "Mouse001_Run002"
126
- prestring = "Mouse"
127
- poststring = "_Walk"
128
- with pytest.raises(ValueError):
129
- find_number(fullstring, prestring, poststring)
130
-
131
-
132
- def test_find_number_leading_zeros():
133
- fullstring = "Mouse001Run002"
134
- prestring = "Mouse"
135
- poststring = "Run"
136
- result = find_number(fullstring, prestring, poststring)
137
- assert result == (1, "00")
@@ -1,110 +0,0 @@
1
- from autogaita.resources.utils import try_to_run_gaita
2
- import pandas as pd
3
- import pandas.testing as pdt
4
- import os
5
- import pytest
6
-
7
- # ............................ DLC APPROVAL TESTS STRUCTURE ..........................
8
- # 1. Run 4 pytest fixtures in preparation
9
- # 2. Run autogaita.dlc for ID 15 - Run 3 (with the cfg used there)
10
- # 3. Load the "Average Stepcycles".xlsx file from the repo and compare for
11
- # equivalence to average_data
12
- # 4. Do the same for "Standard Devs. Stepcycle.xlsx" and std_data
13
- # 5. Pass the test if the two df-pairs are equal
14
-
15
-
16
- # ............................... PREPARE - FOUR FIXTURES ...........................
17
-
18
-
19
- @pytest.fixture
20
- def extract_true_dir():
21
- return "tests/test_data/dlc_data/true_data/"
22
-
23
-
24
- @pytest.fixture
25
- def extract_info(tmp_path):
26
- info = {}
27
- info["mouse_num"] = 12
28
- info["run_num"] = 3
29
- info["name"] = "ID " + str(info["mouse_num"]) + " - Run " + str(info["run_num"])
30
- info["results_dir"] = os.path.join(tmp_path, info["name"])
31
- return info
32
-
33
-
34
- @pytest.fixture
35
- def extract_folderinfo():
36
- folderinfo = {}
37
- folderinfo["root_dir"] = "tests/test_data/dlc_data/test_data/"
38
- folderinfo["sctable_filename"] = "correct_annotation_table.xlsx"
39
- folderinfo["data_string"] = "SIMINewOct"
40
- folderinfo["beam_string"] = "BeamTraining"
41
- folderinfo["premouse_string"] = "Mouse"
42
- folderinfo["postmouse_string"] = "25mm"
43
- folderinfo["prerun_string"] = "run"
44
- folderinfo["postrun_string"] = "6DLC"
45
- return folderinfo
46
-
47
-
48
- @pytest.fixture
49
- def extract_cfg():
50
- cfg = {}
51
- cfg["sampling_rate"] = 100
52
- cfg["subtract_beam"] = True
53
- cfg["dont_show_plots"] = True
54
- cfg["convert_to_mm"] = True
55
- cfg["pixel_to_mm_ratio"] = 3.76
56
- cfg["x_sc_broken_threshold"] = 200
57
- cfg["y_sc_broken_threshold"] = 50
58
- cfg["x_acceleration"] = True
59
- cfg["angular_acceleration"] = True
60
- cfg["save_to_xls"] = True
61
- cfg["bin_num"] = 25
62
- cfg["plot_SE"] = True
63
- cfg["standardise_y_at_SC_level"] = False
64
- cfg["standardise_y_to_a_joint"] = True
65
- cfg["y_standardisation_joint"] = ["Knee"]
66
- cfg["plot_joint_number"] = 3
67
- cfg["color_palette"] = "viridis"
68
- cfg["legend_outside"] = True
69
- cfg["invert_y_axis"] = True
70
- cfg["flip_gait_direction"] = True
71
- cfg["analyse_average_x"] = True
72
- cfg["standardise_x_coordinates"] = True
73
- cfg["x_standardisation_joint"] = ["Hind paw tao"]
74
- cfg["coordinate_standardisation_xls"] = ""
75
- cfg["hind_joints"] = ["Hind paw tao", "Ankle", "Knee", "Hip", "Iliac Crest"]
76
- cfg["fore_joints"] = [
77
- "Front paw tao ",
78
- "Wrist ",
79
- "Elbow ",
80
- "Lower Shoulder ",
81
- "Upper Shoulder ",
82
- ]
83
- cfg["beam_col_left"] = ["BeamLeft"] # BEAM_COL_LEFT & _RIGHT must be lists of len=1
84
- cfg["beam_col_right"] = ["BeamRight"]
85
- cfg["beam_hind_jointadd"] = ["Tail base ", "Tail center ", "Tail tip "]
86
- cfg["beam_fore_jointadd"] = ["Nose ", "Ear base "]
87
- cfg["angles"] = {
88
- "name": ["Ankle ", "Knee ", "Hip "],
89
- "lower_joint": ["Hind paw tao ", "Ankle ", "Knee "],
90
- "upper_joint": ["Knee ", "Hip ", "Iliac Crest "],
91
- }
92
- return cfg
93
-
94
-
95
- # .............................. RUN - ONE APPROVAL TESTS ............................
96
-
97
-
98
- @pytest.mark.slow
99
- def test_dlc_approval_average_df(
100
- extract_true_dir, extract_info, extract_folderinfo, extract_cfg
101
- ):
102
- # run
103
- try_to_run_gaita("DLC", extract_info, extract_folderinfo, extract_cfg, False)
104
- for true_df_file in os.listdir(extract_true_dir):
105
- if true_df_file.endswith(".xlsx"):
106
- true_df = pd.read_excel(os.path.join(extract_true_dir, true_df_file))
107
- test_df = pd.read_excel(
108
- os.path.join(extract_info["results_dir"], true_df_file)
109
- )
110
- pdt.assert_frame_equal(test_df, true_df)
@@ -1,114 +0,0 @@
1
- from autogaita.common2D.common2D_1_preparation import (
2
- some_prep,
3
- move_data_to_folders,
4
- check_gait_direction,
5
- )
6
- import os
7
- import pandas as pd
8
- import pytest
9
-
10
-
11
- # %%................................ fixtures ........................................
12
- @pytest.fixture
13
- def extract_data_using_some_prep(extract_info, extract_folderinfo, extract_cfg):
14
- data = some_prep("DLC", extract_info, extract_folderinfo, extract_cfg)
15
- return data
16
-
17
-
18
- @pytest.fixture
19
- def extract_info(tmp_path):
20
- info = {}
21
- info["mouse_num"] = 15
22
- info["run_num"] = 3
23
- info["name"] = "ID " + str(info["mouse_num"]) + " - Run " + str(info["run_num"])
24
- info["results_dir"] = os.path.join(tmp_path, info["name"])
25
- return info
26
-
27
-
28
- @pytest.fixture
29
- def extract_folderinfo():
30
- folderinfo = {}
31
- folderinfo["root_dir"] = "tests/test_data/dlc_data"
32
- folderinfo["sctable_filename"] = (
33
- "correct_annotation_table.xlsx" # has to be an excel file
34
- )
35
- folderinfo["data_string"] = "SIMINewOct"
36
- folderinfo["beam_string"] = "BeamTraining"
37
- folderinfo["premouse_string"] = "Mouse"
38
- folderinfo["postmouse_string"] = "25mm"
39
- folderinfo["prerun_string"] = "run"
40
- folderinfo["postrun_string"] = "6DLC"
41
- return folderinfo
42
-
43
-
44
- @pytest.fixture
45
- def extract_cfg():
46
- cfg = {}
47
- cfg["sampling_rate"] = 100
48
- cfg["subtract_beam"] = True
49
- cfg["dont_show_plots"] = True
50
- cfg["convert_to_mm"] = True
51
- cfg["pixel_to_mm_ratio"] = 3.76
52
- cfg["x_sc_broken_threshold"] = 200
53
- cfg["y_sc_broken_threshold"] = 50
54
- cfg["x_acceleration"] = True
55
- cfg["angular_acceleration"] = True
56
- cfg["save_to_xls"] = True
57
- cfg["bin_num"] = 25
58
- cfg["plot_SE"] = True
59
- cfg["standardise_y_at_SC_level"] = False
60
- cfg["standardise_y_to_a_joint"] = True
61
- cfg["y_standardisation_joint"] = ["Knee"]
62
- cfg["plot_joint_number"] = 3
63
- cfg["color_palette"] = "viridis"
64
- cfg["legend_outside"] = True
65
- cfg["invert_y_axis"] = True
66
- cfg["flip_gait_direction"] = True
67
- cfg["analyse_average_x"] = True
68
- cfg["standardise_x_coordinates"] = True
69
- cfg["x_standardisation_joint"] = ["Hind paw tao"]
70
- cfg["coordinate_standardisation_xls"] = ""
71
- cfg["hind_joints"] = ["Hind paw tao", "Ankle", "Knee", "Hip", "Iliac Crest"]
72
- cfg["fore_joints"] = [
73
- "Front paw tao ",
74
- "Wrist ",
75
- "Elbow ",
76
- "Lower Shoulder ",
77
- "Upper Shoulder ",
78
- ]
79
- cfg["beam_col_left"] = ["BeamLeft"] # BEAM_COL_LEFT & _RIGHT must be lists of len=1
80
- cfg["beam_col_right"] = ["BeamRight"]
81
- cfg["beam_hind_jointadd"] = ["Tail base ", "Tail center ", "Tail tip "]
82
- cfg["beam_fore_jointadd"] = ["Nose ", "Ear base "]
83
- cfg["angles"] = {
84
- "name": ["Ankle ", "Knee ", "Hip "],
85
- "lower_joint": ["Hind paw tao ", "Ankle ", "Knee "],
86
- "upper_joint": ["Knee ", "Hip ", "Iliac Crest "],
87
- }
88
- return cfg
89
-
90
-
91
- # %%.............................. preparation .......................................
92
- def test_check_gait_direction(extract_data_using_some_prep, extract_cfg, extract_info):
93
- direction_joint = extract_cfg["direction_joint"]
94
- flip_gait_direction = True # 1) test broken DLC data (empty)
95
- broken_data = pd.DataFrame(data=None, columns=extract_data_using_some_prep.columns)
96
- check_gait_direction(
97
- "DLC", broken_data, direction_joint, flip_gait_direction, extract_info
98
- )
99
- with open(os.path.join(extract_info["results_dir"], "Issues.txt")) as f:
100
- content = f.read()
101
- assert "Unable to determine gait direction!" in content
102
- flip_this_data = pd.DataFrame(
103
- data=None, columns=extract_data_using_some_prep.columns
104
- ) # 2) test data that has to be flipped
105
- data_len = 20
106
- flip_this_data[direction_joint + "likelihood"] = [0.99] * data_len
107
- first_half = [10] * int((data_len / 2))
108
- second_half = [-10] * int((data_len / 2))
109
- x_coords = first_half + second_half
110
- flip_this_data[direction_joint + "x"] = x_coords
111
- flip_this_data = check_gait_direction(
112
- "DLC", flip_this_data, direction_joint, flip_gait_direction, extract_info
113
- )
114
- assert flip_this_data["Flipped"][0] == True
@@ -1,162 +0,0 @@
1
- from autogaita import group
2
- from autogaita.group.group_constants import STATS_TXT_FILENAME
3
- from autogaita.resources.constants import CONFIG_JSON_FILENAME
4
- import pandas as pd
5
- import pandas.testing as pdt
6
- import filecmp
7
- import os
8
- import shutil
9
- import pdb
10
- import pytest
11
-
12
- # ........................... GROUP APPROVAL TESTS STRUCTURE .........................
13
- # 1. Run autogaita.group for example group (3 beams) data (with the cfg used there)
14
- # store results in a temporary path using tmp_path input.
15
- # 2. Load the "Grand Average Stepcycles".xlsx & "Grand Standard Devs. Stepcycle.xlsx"
16
- # files from the repo (TRUE PATH) - test for equivalence with TEST PATH
17
- # 3. Then test if PCA XLS file is equal
18
- # 4. Finally test if Stats.txt files are equal
19
-
20
- # A Note
21
- # ------
22
- # We don't test the cluster extent test in an automated way.
23
- # We have results of simulations that ran for over a week in our preprint.
24
- # If the cluster extent test should change for some reason - re-run those simulations.
25
-
26
-
27
- # ............................... PREPARE - THREE FIXTURES ..........................
28
-
29
-
30
- @pytest.fixture
31
- def extract_true_dir():
32
- return "example data/group/"
33
-
34
-
35
- @pytest.fixture
36
- def extract_folderinfo(tmp_path):
37
- folderinfo = {}
38
- folderinfo["group_names"] = ["5 mm", "12 mm", "25 mm"]
39
- folderinfo["group_dirs"] = [
40
- "example data/5mm/Results/",
41
- "example data/12mm/Results/",
42
- "example data/25mm/Results/",
43
- ]
44
- folderinfo["results_dir"] = tmp_path
45
- folderinfo["load_dir"] = ""
46
- return folderinfo
47
-
48
-
49
- @pytest.fixture
50
- def extract_cfg():
51
- cfg = {}
52
- cfg["do_permtest"] = False
53
- cfg["do_anova"] = True
54
- cfg["permutation_number"] = 100
55
- cfg["PCA_n_components"] = 3
56
- cfg["PCA_custom_scatter_PCs"] = ""
57
- cfg["PCA_save_3D_video"] = False
58
- cfg["PCA_bins"] = ""
59
- cfg["stats_threshold"] = 0.05
60
- cfg["plot_SE"] = False
61
- cfg["color_palette"] = "viridis"
62
- cfg["dont_show_plots"] = True
63
- cfg["legend_outside"] = True
64
- cfg["which_leg"] = "left"
65
- cfg["anova_design"] = "RM ANOVA"
66
- cfg["permutation_number"] = 100
67
- # NOTE - PCA & stats lists MUST be kept in this order
68
- # (otherwise PCA.Info & Stats.txt wont be equivalent to TRUE_DATA's)
69
- # => it's this order because it resulted from group_gui input (and thus corresponds to the checkbox-order of the features window)
70
- cfg["PCA_variables"] = [
71
- "Knee y",
72
- "Ankle y",
73
- "Hind paw tao y",
74
- "Ankle Angle",
75
- "Knee Angle",
76
- "Hip Angle",
77
- ]
78
- cfg["stats_variables"] = cfg["PCA_variables"]
79
- return cfg
80
-
81
-
82
- # .............................. RUN - ONE APPROVAL TEST .............................
83
-
84
-
85
- @pytest.mark.filterwarnings("ignore:Epsilon values")
86
- @pytest.mark.slow
87
- def test_group_approval(extract_true_dir, extract_folderinfo, extract_cfg):
88
-
89
- # ........................... 1) RUN GROUP GAITA .................................
90
- group(extract_folderinfo, extract_cfg)
91
-
92
- # ...................... 2) TEST EQUIVALENCE OF GROUP DFs ........................
93
- # load true dfs from xlsx files
94
- true_av_df = pd.read_excel(
95
- os.path.join(extract_true_dir, "25 mm - Grand Average Group Stepcycles.xlsx")
96
- )
97
- true_std_df = pd.read_excel(
98
- os.path.join(
99
- extract_true_dir, "25 mm - Grand Standard Deviation Group Stepcycles.xlsx"
100
- )
101
- )
102
- test_av_df = pd.read_excel(
103
- os.path.join(
104
- extract_folderinfo["results_dir"],
105
- "25 mm - Grand Average Group Stepcycles.xlsx",
106
- )
107
- )
108
- test_std_df = pd.read_excel(
109
- os.path.join(
110
- extract_folderinfo["results_dir"],
111
- "25 mm - Grand Standard Deviation Group Stepcycles.xlsx",
112
- )
113
- )
114
- # finally assert equivalence of df-pairs
115
- pdt.assert_frame_equal(test_av_df, true_av_df)
116
- pdt.assert_frame_equal(test_std_df, true_std_df)
117
-
118
- # ....................... 3) TEST EQUIVALENCE OF PCA DFs .........................
119
- # => okay so the equivalence test fails for ID INFO.xlsx on CI but passes locally.
120
- # => it is due to the rows of the ID INFO.xlsx being in a different order
121
- # => I guess due to how git-actions' os lists the files in the folder or something
122
- # => the workaround here uses a env-variable that is set in the CI workflow file
123
- if os.getenv("CI") == "true":
124
- pca_filenames = ["PCA Info.xlsx", "PCA Feature Summary.xlsx"]
125
- else:
126
- pca_filenames = [
127
- "PCA Feature Summary.xlsx",
128
- "PCA ID Info.xlsx",
129
- "PCA Info.xlsx",
130
- ]
131
- for filename in pca_filenames:
132
- true_pca_df = pd.read_excel(os.path.join(extract_true_dir, filename))
133
- test_pca_df = pd.read_excel(
134
- os.path.join(extract_folderinfo["results_dir"], filename)
135
- )
136
- pdt.assert_frame_equal(test_pca_df, true_pca_df)
137
-
138
- # ................... 4) TEST EQUIVALENCE OF STATS.TXT & DFs .....................
139
- shallow = False # if True compares only the metadata, not the contents!
140
- match, _, _ = filecmp.cmpfiles( # Summary Stats.txt file
141
- extract_true_dir,
142
- extract_folderinfo["results_dir"],
143
- [STATS_TXT_FILENAME],
144
- shallow,
145
- )
146
- assert match == [STATS_TXT_FILENAME]
147
- for version_number in ["1", "2"]: # Two Tukeys Results Excel Files
148
- filename = f"Stats Multiple Comparison - Version {version_number}.xlsx"
149
- true_stats_df = pd.read_excel(os.path.join(extract_true_dir, filename))
150
- test_stats_df = pd.read_excel(
151
- os.path.join(extract_folderinfo["results_dir"], filename)
152
- )
153
- pdt.assert_frame_equal(test_stats_df, true_stats_df)
154
-
155
- # ...................... 5) TEST EQUIVALENCE OF CONFIG.JSON ......................
156
- match, _, _ = filecmp.cmpfiles(
157
- extract_true_dir,
158
- extract_folderinfo["results_dir"],
159
- [CONFIG_JSON_FILENAME],
160
- shallow,
161
- )
162
- assert match == [CONFIG_JSON_FILENAME]