Skip to content

Commit

Permalink
merge origin/main
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-pfarr committed Nov 10, 2023
2 parents 757667e + cd7b611 commit 6699402
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion eye2bids/edf2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,17 @@ def edf2bids(
# Samples to eyetrack.tsv
samples_asc_file = _convert_edf_to_asc_samples(input_file)
eyetrack_tsv = _samples_to_data_frame(samples_asc_file)
# strip blankspcace and convert empty cells to nan
eyetrack_tsv = eyetrack_tsv.applymap(lambda x: x.strip() if isinstance(x, str) else x)
eyetrack_tsv = eyetrack_tsv.replace(".", np.nan, regex=False)

output_filename = generate_output_filename(
output_dir=output_dir, input_file=input_file, suffix="_eyetrack", extension="tsv"
)
with open(output_filename, "w") as outfile:
eyetrack_tsv.to_csv(outfile, sep="\t", index=False, compression="gzip")
eyetrack_tsv.to_csv(
outfile, sep="\t", index=False, compression="gzip", na_rep="n/a"
)
e2b_log.info(f"file generated: {output_filename}")


Expand Down
24 changes: 24 additions & 0 deletions tests/test_edf2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from pathlib import Path

import pandas as pd
import pytest

from eye2bids.edf2bids import (
Expand Down Expand Up @@ -64,6 +65,29 @@ def test_edf_end_to_end(metadata_file, eyelink_test_data_dir):
assert eyetrack["SamplingFrequency"] == 500
assert eyetrack["RecordedEye"] == "Right"

expected_events_sidecar = output_dir / f"{input_file.stem}_eyetrack.tsv"
assert expected_events_sidecar.exists()


@pytest.mark.skipif(not _check_edf2asc_present(), reason="edf2asc missing")
def test_edf_nan_in_tsv(eyelink_test_data_dir):
"""Check that dots '.' are converted to NaN in the tsv file."""
input_dir = eyelink_test_data_dir / "emg"
input_file = edf_test_files(input_dir=input_dir)[0]

output_dir = data_dir() / "output"
output_dir.mkdir(exist_ok=True)

edf2bids(
input_file=input_file,
output_dir=output_dir,
)

expected_events_sidecar = output_dir / f"{input_file.stem}_eyetrack.tsv"
df = pd.read_csv(expected_events_sidecar, sep="\t")
count = sum(i == "." for i in df["eye1_x_coordinate"])
assert count == 0


@pytest.mark.parametrize(
"folder, expected",
Expand Down

0 comments on commit 6699402

Please sign in to comment.