diff --git a/eye2bids/_base.py b/eye2bids/_base.py index f32cd3b..4739855 100644 --- a/eye2bids/_base.py +++ b/eye2bids/_base.py @@ -78,10 +78,12 @@ class BasePhysioJson(dict[str, Any]): input_file: Path has_validation: bool two_eyes: bool + has_calibration: bool def __init__(self, manufacturer: str, metadata: dict[str, Any] | None = None) -> None: self["Manufacturer"] = manufacturer + self["PhysioType"] = "eyetrack" self["Columns"] = ["x_coordinate", "y_coordinate", "pupil_size", "timestamp"] self["timestamp"] = { diff --git a/eye2bids/edf2bids.py b/eye2bids/edf2bids.py index 5a2ccb0..c34bfec 100644 --- a/eye2bids/edf2bids.py +++ b/eye2bids/edf2bids.py @@ -128,6 +128,10 @@ def _calibrations(df: pd.DataFrame) -> pd.DataFrame: return df[df[3] == "CALIBRATION"] +def _has_calibration(df: pd.DataFrame) -> bool: + return not _calibrations(df).empty + + def _extract_CalibrationType(df: pd.DataFrame) -> list[int]: return _calibrations(df).iloc[0:1, 2:3].to_string(header=False, index=False) @@ -422,16 +426,19 @@ def generate_physio_json( base_json.input_file = input_file base_json.has_validation = _has_validation(df_ms_reduced) base_json.two_eyes = _2eyesmode(df_ms_reduced) + base_json.has_calibration = _has_calibration(df_ms_reduced) base_json["ManufacturersModelName"] = _extract_ManufacturersModelName(events) base_json["DeviceSerialNumber"] = _extract_DeviceSerialNumber(events) - base_json["EyeTrackingMethod"] = _extract_EyeTrackingMethod(events) base_json["PupilFitMethod"] = _extract_PupilFitMethod(df_ms_reduced) base_json["SamplingFrequency"] = _extract_SamplingFrequency(df_ms_reduced) base_json["StartTime"] = _extract_StartTime(events) base_json["StopTime"] = _extract_StopTime(events) + if base_json.has_calibration: + base_json["EyeTrackingMethod"] = _extract_EyeTrackingMethod(events) + if base_json.two_eyes: metadata_eye1: dict[str, str | list[str] | list[float]] = { "RecordedEye": (_extract_RecordedEye(df_ms_reduced)[0]), diff --git a/tests/test_edf2bids.py b/tests/test_edf2bids.py index a753aa8..0c1abae 100644 --- a/tests/test_edf2bids.py +++ b/tests/test_edf2bids.py @@ -273,7 +273,7 @@ def test_extract_CalibrationUnit(folder, expected, eyelink_test_data_dir): [1126, 636], [794, 444], [960, 348], - ] + ], ], ), (