Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with blink preprocessing #20

Open
acooperr1 opened this issue May 17, 2024 · 0 comments
Open

Issues with blink preprocessing #20

acooperr1 opened this issue May 17, 2024 · 0 comments

Comments

@acooperr1
Copy link

acooperr1 commented May 17, 2024

Hi there, I am new to analyzing pupil data and am running into issues in the preprocessing of the data. Specifically, I am having difficulty properly detecting blinks in my data. I have tried a lot of of combinations and haven't found any of them to be completely accurate for all of my subjects.

Below is my script:

#! /usr/bin/env python3
import sys
import os
import pypillometry as pp
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

#File containing a list of subjs
input_file = "/Users/acoop/Dropbox/2023-fMRI/scripts/subj_list.txt"

#create lists to store subjects and scan numbers
subjects = []
scan_numbers = []

# Open the input file
with open(input_file, "r") as file:
    # Loop over each line in the file
    for line in file:
        # get subj name and scan number
        subj, scan_num = line.split()
        subjects.append(subj)
        scan_numbers.append(scan_num)

#create a pdf file to save plots 
pdf_file = "/Users/acoop/Desktop/subj_plots.pdf"

#create a PDF object 
pdf = PdfPages(pdf_file)

for subj, scan_num in zip(subjects, scan_numbers):
# Set data directories
    edf_dir = f"/Users/acoop/Dropbox/2023-fMRI/ParticipantFiles/{subj}/Oddball/{scan_num}"

# Loop through each file in the folder
    for filename in os.listdir(edf_dir):
    # Check if the file ends with .EDF
        if filename.endswith(".EDF"):
            prefix = filename

            # declare file name 
            pd_file = os.path.join(edf_dir, f"{prefix}.pd")
            print(f"Directories it's pulling from: {pd_file}")

#load picklefile, apply a 3Hz low-pass filter to it, downsample the signal to 50 Hz, detect blinks in the signal and merge short, successive blinks together. Store it all in object d
            d=pp.PupilData.from_file(pd_file)\
               .blinks_detect()\
               .blinks_merge()\
               .lowpass_filter(3)\
               .downsample(50)

            default = d.get_erpd("default", "DEFAULT_CUE")
            oddball = d.get_erpd("oddball", "ODDBALL_CUE")

            plt.figure(figsize=(15, 5))
            d.plot()
            # Add title with subject and scan number
            plt.title(f"Subject: {subj}, Scan Number: {scan_num}")
            pdf.savefig(plt.gcf())
            plt.close()

#get summary of the dataset and the operations applied to it 
            print(d)
#return information in the form of a dict
            d.summary()

pdf.close()
print(f"All plots have been saved to {pdf_file}")

Here are some of the various preprocessing options I've tried:

For .blinks_detect:
-min_duration=10
-min_offset_len=2
-min_onset_len=3
-vel_onset=-5
-vel_offset=5

For .blinks_merge:

  • distance=130

For .lowpass_filter:
-3
-cutoff=5
-5

for .downsample:
-50
-100

Each time I have run this script with the various different options it has incorrectly identified the blinks by either identifying too many or not identifying all of them. I have also been unable to interpolate all of my subjects and run into errors after the first subject. The interpolate command I have been using is: d = d.blinks_interp_mahot()

Here are some plots of the preprocessed blink data with the default parameters set:

Screenshot 2024-05-16 at 5 22 35 PM Screenshot 2024-05-16 at 5 22 57 PM Screenshot 2024-05-16 at 5 23 18 PM

If you have any guesses on what the issue could be, please let me know, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant