Skip to content

Commit

Permalink
Tried to fix bugs, but failed
Browse files Browse the repository at this point in the history
edf2asc suddenly gives out a random order for the calibration positions. E.g., calibration point 3 is listed after calibration point 4. That's why I had to change the function _extract_Calibration poisition (as well as _get_calibration_positions). However, now the tests are failing because something is wrong with the lists in lists thingi and also it tries to get the calibration positions also for the testfiles which have none. I thought I specified that within the functions but obviously it doesn't work.
  • Loading branch information
julia-pfarr committed Jun 20, 2024
1 parent 71625b1 commit 7465ba5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
45 changes: 21 additions & 24 deletions eye2bids/edf2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,37 +139,34 @@ def _extract_CalibrationCount(df: pd.DataFrame) -> int:
return len(_calibrations(df))


def _get_calibration_positions(df: pd.DataFrame) -> list[int]:
if _2eyesmode(df) == True:
return (
np.array(df[df[2] == "VALIDATE"][8].str.split(",", expand=True))
.astype(int)
.tolist()
)[::2]
return (
np.array(df[df[2] == "VALIDATE"][8].str.split(",", expand=True))
.astype(int)
.tolist()
)


def _extract_CalibrationPosition(df: pd.DataFrame) -> list[list[int]]:
cal_pos = _get_calibration_positions(df)
cal_num = len(cal_pos) // _extract_CalibrationCount(df)

if _has_validation == False:
CalibrationPosition = []
return CalibrationPosition

else:
cal_df = df[df[2] == "VALIDATE"]#.drop(columns=[2, 3, 4, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17]).reset_index(drop=True)
cal_df[5] = pd.to_numeric(cal_df[5], errors='coerce')
df_sorted = cal_df.sort_values(by=5)

CalibrationPosition: list[list[int]] = []
if _2eyesmode(df) == True:
df_sorted = df_sorted.drop(index=df_sorted.index[::(_extract_CalibrationCount(df) * 2)])

if len(cal_pos) == 0:
return CalibrationPosition
if _extract_CalibrationCount(df) == 1:
CalibrationPosition = np.array((df_sorted[8]).str.split(",", expand=True)).astype(int).tolist()
return CalibrationPosition
else:
CalibrationPosition = []

CalibrationPosition.extend(
cal_pos[i : i + cal_num] for i in range(0, len(cal_pos), cal_num)
)
return CalibrationPosition
for x in df_sorted:
cal_values = np.array((df_sorted[8][::_extract_CalibrationCount(df)]).str.split(",", expand=True)).astype(int).tolist()
CalibrationPosition.append(cal_values)
return CalibrationPosition


def _extract_CalibrationUnit(df: pd.DataFrame) -> str:
if len(_get_calibration_positions(df)) == 0:
if len(_extract_CalibrationPosition(df)) == 0:
return ""

cal_unit = (
Expand Down
8 changes: 2 additions & 6 deletions tests/test_edf2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ def test_extract_CalibrationUnit(folder, expected, eyelink_test_data_dir):
("pitracker", []),
(
"rest",
[
[
[960, 540],
[960, 732],
Expand All @@ -298,14 +297,12 @@ def test_extract_CalibrationUnit(folder, expected, eyelink_test_data_dir):
[1126, 636],
[794, 444],
[960, 348],
]
],
],
),
("satf", []),
("vergence", []),
(
"2eyes",
[
[
[960, 540],
[960, 732],
Expand All @@ -320,8 +317,7 @@ def test_extract_CalibrationUnit(folder, expected, eyelink_test_data_dir):
[1126, 636],
[794, 444],
[960, 348],
]
],
],
),
],
)
Expand Down

0 comments on commit 7465ba5

Please sign in to comment.