[FieldTrip] Issue with partial artifact rejection in sleep EEG data

Konstantinos Tsilimparis konstantinos.tsilimparis at outlook.com
Fri Jun 28 18:10:39 CEST 2024


Dear Sophie,

"the input is raw data with 14 channels and 1 trial.": this shows that you have continuous (i.e., 1-trial) data (as you would expect for sleep data).

The warning "Original data has trialinfo, using user-specified trialinfo instead" indicates that FieldTrip detected pre-existing trigger information (trialinfo) in your original data. I think this information exists in data_segmented.cfg.trl(:,4). It's important not to change this trialinfo later in your code. What I have experienced is that even if you did not change trialinfo you still receive this warning. In that case, you can just ignore the warning.

"Warning: correcting numerical inaccuracy in the time axes": I encounter this error many times when I use ft_databrowser. Your computer cannot accurately represent floating-point numbers of your time axis in a binary format and leads to this warning. This is not something to worry about.

Cheers,
Konstantinos Tsilimparis


-----Original Message-----
From: fieldtrip <fieldtrip-bounces at science.ru.nl> On Behalf Of fieldtrip-request at science.ru.nl
Sent: Friday, June 28, 2024 12:00 PM
To: fieldtrip at science.ru.nl
Subject: fieldtrip Digest, Vol 163, Issue 20

Send fieldtrip mailing list submissions to
	fieldtrip at science.ru.nl

To subscribe or unsubscribe via the World Wide Web, visit
	https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
or, via email, send a message with subject or body 'help' to
	fieldtrip-request at science.ru.nl

You can reach the person managing the list at
	fieldtrip-owner at science.ru.nl

When replying, please edit your Subject line so it is more specific than "Re: Contents of fieldtrip digest..."


Today's Topics:

   1. 3 post-doc positions and two research technicians posts
      available at University of Birmingham, UK (Ali Mazaheri)
   2. Re: Issue with partial artifact rejection in sleep EEG data
      visualization (Schubert, E.S. (Sophie))
   3. Issue with NaN values using ft_artifact_zvalue
      (Schubert, E.S. (Sophie))


----------------------------------------------------------------------

Message: 1
Date: Thu, 27 Jun 2024 10:25:30 +0000
From: Ali Mazaheri <a.mazaheri at bham.ac.uk>
To: "fieldtrip at science.ru.nl" <fieldtrip at science.ru.nl>
Subject: [FieldTrip] 3 post-doc positions and two research technicians
	posts available at University of Birmingham, UK
Message-ID:
	<LO4P265MB7353712001425CA45E9FA7EBAED72 at LO4P265MB7353.GBRP265.PROD.OUTLOOK.COM>
	
Content-Type: text/plain; charset="utf-8"



Dear all,



I am pleased to announce three post-doc positions available as part of the Wellcome Leap Untangling Addiction Programme that I have been awarded at the University of Birmingham. The project focuses on investigating the neurobiological underpinnings of post-surgical chronic pain and persistent opioid usage. This exciting project involves collaboration among immunologists, machine learners, neuroscientists, and psychologists, who will make up the supervisory team. These positions require expertise in electrophysiology, omics, and machine learning. The positions will start in September 2024 and are full-time, fixed-term contracts up to February 2027.



To find out more about the goal of the project:

https://www.birmingham.ac.uk/news/2024/wellcome-leap-funding-to-develop-screening-tool-for-potential-long-term-opiate-users



To find out more about the Wellcome Leap Untangling Addiction Programme :

https://wellcomeleap.org/ua/



Now the posts:



Electrophysiology:

https://www.jobs.ac.uk/job/DIH547/research-fellow-postdoctoral



Machine Learning:

https://www.jobs.ac.uk/job/DIG808/research-fellow





Omics:

https://www.linkedin.com/jobs/view/research-fellow-in-the-immunology-of-addiction-institute-of-inflammation-and-ageing-104106-grade-7-at-university-of-birmingham-3958194182/?originalSubdomain=uk





In addition to the postdoctoral positions, we are also looking for two research technicians with expertise in immunoassays and EEG. Specific duties for the immunoassay technician will include assistance with setting up and running manual and automated immunoassays, and sample processing for serum, plasma, peripheral blood mononuclear cell (PBMC) isolation, and DNA/RNA isolation. The EEG technician will assist with setting up and collecting EEG data, as well as data interpretation and reporting.



Please contact me directly if you would like to inquire about these posts: a.mazaheri at bham.ac.uk<mailto:a.mazaheri at bham.ac.uk>



Ali



Dr Ali Mazaheri
Associate Professor
School of Psychology
Centre for Human Brain Health
University of Birmingham
www.alimazaheri.com


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240627/16012705/attachment-0001.htm>

------------------------------

Message: 2
Date: Thu, 27 Jun 2024 13:37:12 +0000
From: "Schubert, E.S. (Sophie)" <E.S.Schubert at umcutrecht.nl>
To: FieldTrip discussion list <fieldtrip at science.ru.nl>,
	"janmathijs.schoffelen at donders.ru.nl"
	<janmathijs.schoffelen at donders.ru.nl>
Subject: Re: [FieldTrip] Issue with partial artifact rejection in
	sleep EEG data visualization
Message-ID:
	<AM8PR10MB40522441910A21583E4882C0DED72 at AM8PR10MB4052.EURPRD10.PROD.OUTLOOK.COM>
	
Content-Type: text/plain; charset="windows-1252"

Dear Jan-Mathijs,

Thank you for your response and the detailed explanation. I understand your point about the importance of preserving the temporal discontinuity in the data after artifact rejection. Given this, I will focus on working with the artifact-free segments as they are, without attempting to stitch them together for visualization purposes.

I still had a question to the warnings I encountered during artifact rejection using ft_rejectartifact: "the input is raw data with 14 channels and 1 trial. Warning: Original data has trialinfo, using user-specified trialinfo instead. Warning: correcting numerical inaccuracy in the time axes." Could you please help me understand the implications of these warnings? Do they indicate a potential issue that needs to be resolved, or are they more informational and do not affect the integrity of the preprocessing steps?

Thank you in advance!

Kind regards,
Sophie

Van: fieldtrip <fieldtrip-bounces at science.ru.nl> namens Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl>
Datum: dinsdag, 25 juni 2024 om 07:38
Aan: FieldTrip discussion list <fieldtrip at science.ru.nl>
CC: Schoffelen, J.M. (Jan Mathijs) <janmathijs.schoffelen at donders.ru.nl>
Onderwerp: Re: [FieldTrip] Issue with partial artifact rejection in sleep EEG data visualization You don't often get email from fieldtrip at science.ru.nl. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
Hi Sophie,

If I understand the context of your question well, I think that the answer to the question "how to seamlessly visualize the cleaned data after partial artifact rejection?” is: “this is not recommended (and although it may be possible by creatively applying some fieldtrip code in combination with some out-of-the-box matlab, I am not going to tell you how to do it. Het brengt je alleen maar op slechte ideeën)”.

The whole rationale of rejecting the segments of data with artifacts, is to kick them out of the data object altogether, so that they do not contaminate the downstream analysis steps anymore. In doing so, ft_rejectartifact preserves the data’s original time axis, as well as the metadata (trialinfo) pertaining to the individual epochs (e.g. concretely, if an artifact occurs in the middle of an epoch, the given epoch is split into two sub-epochs, each with their own (consistent with the original) time axis, and each with the original epoch’s metadata duplicated). This indeed has consequences for the visualization of the data, because the artifacts appear as gaps. This is explicitly by design. From the context in your message you seem to want to somehow ’stitch together’ the data samples occurring at each side of the gap. Although this may be technically feasible with some matlab voodoo, I would recommend against it. The temporal discontinuity should be preserved for your own sake. If - within a putatively stitched together epoch - neighbouring data samples are derived from different parts of the original data, unwanted side effects will occur in the downstream processing, for instance with filtering, spectral transformation etc.

Best wishes,
Jan-Mathijs





On 24 Jun 2024, at 17:45, Schubert, E.S. (Sophie) via fieldtrip <fieldtrip at science.ru.nl> wrote:


Dear FieldTrip Support Team,

Currently, I am working with sleep EEG data and facing an issue with visualizing artifact-rejected data after employing partial rejection methods.

I have developed a custom script to define trials, which reads PSG signals from an EDF file and event annotations from a CSV file. This script calculates trial segments (trl) by specifying start and end points relative to event times, ensuring that each trial fits within the dataset's limits. The trl matrix records the start and end samples of each trial, along with its offset and associated event value. This precise trial definition is crucial for subsequent data analysis steps, including artifact rejection and sleep stage classification.

For artifact detection, I utilize automatic methods within FieldTrip to partially reject artifacts based on segments, specifically targeting EOG and EMG artifacts.The eog_artifacts.EOG_eye and combined_muscle_artifacts structures contain pairs of sample indices indicating the start and end of detected artifact segments, highlighting where artifacts were identified during the detection process.

I am able to visualize marked artifacts using the following code snippet:

%% Visualization of the signal with marked artifacts

cfg = [];

cfg.channel = 'all'; % All channels

cfg.viewmode = 'vertical'; % Or 'butterfly', depending on preference

cfg.artfctdef.eog.artifact = eog_artifacts_high.EOG_eye;

cfg.artfctdef.muscle.artifact = combined_muscle_artifacts;

ft_databrowser(cfg, data_segmented);

Here is a simplified version of the code snippet I use to reject artifact segments:

%% Reject artifacts partially within trials

cfg = [];

cfg.artfctdef.reject = 'partial'; % Partial rejection within trials

cfg.artfctdef.eog.artifact = eog_artifacts.EOG_eye; % EOG artifacts

cfg.artfctdef.muscle.artifact = combined_muscle_artifacts; % Combined muscle artifacts



data_clean_artifactfree = ft_rejectartifact(cfg, data_segmented);



cfg = [];

cfg.channel = 'all'; % All channels

cfg.viewmode = 'vertical'; % Visualization mode

ft_databrowser(cfg, data_clean_artifactfree);

During artifact rejection using ft_rejectartifact, I encounter the following warning messages: "The input is raw data with 14 channels and 1 trial. Warning: Original data has trialinfo, using user-specified trialinfo instead. Warning: correcting numerical inaccuracy in the time axes". Despite these warnings, the artifact rejection process completes successfully. However, when attempting to visualize the cleaned data (second part of the code), I observe fragmented signals where rejected artifact segments are displayed as white spaces, indicating signal removal. This fragmentation makes it challenging to assess the artifact-free data as a continuous signal and to detect any discontinuities or abrupt transitions in the data.

Ultimately, my objective is to use ft_redefinetrial to concatenate segments and visualize the entire continuous signal (while preserving the event markers – so that the information about the sleep stages is still accessible). Could you please provide guidance on how to seamlessly visualize the cleaned data after partial artifact rejection? Specifically, I would appreciate insights into any additional parameters or configurations that might be necessary to achieve a continuous visualization of the artifact-free EEG signal, ensuring proper data handling and analysis.

Thank you in advance for your assistance.

Best regards,

Sophie Schubert

________________________________

De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht ontvangt, wordt u verzocht de inhoud niet te gebruiken en de afzender direct te informeren door het bericht te retourneren. Het Universitair Medisch Centrum Utrecht is een publiekrechtelijke rechtspersoon in de zin van de W.H.W. (Wet Hoger Onderwijs en Wetenschappelijk Onderzoek) en staat geregistreerd bij de Kamer van Koophandel voor Midden-Nederland onder nr. 30244197.

Denk s.v.p aan het milieu voor u deze e-mail afdrukt.

________________________________

This message may contain confidential information and is intended exclusively for the addressee. If you receive this message unintentionally, please do not use the contents but notify the sender immediately by return e-mail. University Medical Center Utrecht is a legal person by public law and is registered at the Chamber of Commerce for Midden-Nederland under no. 30244197.

Please consider the environment before printing this e-mail.
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240627/f20f07df/attachment-0001.htm>

------------------------------

Message: 3
Date: Thu, 27 Jun 2024 13:53:08 +0000
From: "Schubert, E.S. (Sophie)" <E.S.Schubert at umcutrecht.nl>
To: "fieldtrip at science.ru.nl" <fieldtrip at science.ru.nl>
Subject: [FieldTrip] Issue with NaN values using ft_artifact_zvalue
Message-ID:
	<AM8PR10MB405238A7D5CC39CE8A0F7C1EDED72 at AM8PR10MB4052.EURPRD10.PROD.OUTLOOK.COM>
	
Content-Type: text/plain; charset="utf-8"

Dear FieldTrip Support Team,
I am writing to seek assistance with an issue I am encountering while using the ft_artifact_zvalue function in FieldTrip for artifact rejection. Despite my data containing no NaN values initially, I receive an error during the bandpass filtering process indicating that the input is expected to be finite.
Here is a detailed description of the problem:
searching for artifacts in 2 channels
Warning: data contains NaNs, not all processing methods are robust to NaNs, so the NaNs might spread
Warning: data contains NaN values
Error using filtfilt>efiltfilt
Error using filtfilt
Expected input to be finite.

Error in filtfilt (line 102)
        y = efiltfilt(b,a,x);

Error in filter_with_correction (line 73)
    filt = filtfilt(B, A, dat')';

Error in ft_preproc_bandpassfilter (line 300)
    filt = filter_with_correction(B,A,dat,dir,usefftfilt);

Error in preproc (line 405)
if strcmp(cfg.bpfilter, 'yes'),     dat = ft_preproc_bandpassfilter(dat, fsample, cfg.bpfreq, cfg.bpfiltord, cfg.bpfilttype, cfg.bpfiltdir, cfg.bpinstabilityfix, cfg.bpfiltdf, cfg.bpfiltwintype, cfg.bpfiltdev, cfg.plotfiltresp, cfg.usefftfilt); end

Error in ft_artifact_zvalue (line 315)
  thisdat = preproc(thisdat, cfg.artfctdef.zvalue.channel, offset2time(0, hdr.Fs, size(thisdat,2)), cfg.artfctdef.zvalue, fltpadding, fltpadding); The code that I use:
frontalEye = {'EOG LOC-A2', 'EOG ROC-A2'}; % for artifact rejection cfg = []; cfg.artfctdef.zvalue.channel = frontalEye; cfg.artfctdef.zvalue.cutoff = 2.5; cfg.artfctdef.zvalue.trlpadding = 0; cfg.artfctdef.zvalue.artpadding = 0.4; cfg.artfctdef.zvalue.fltpadding = 0.1; cfg.artfctdef.zvalue.bpfilter = 'yes'; cfg.artfctdef.zvalue.bpfreq = [0.5 2]; cfg.artfctdef.zvalue.bpfiltord = 4; cfg.artfctdef.zvalue.bpfilttype = 'but'; cfg.artfctdef.zvalue.hilbert = 'yes'; cfg.artfctdef.zvalue.interactive = 'no'; [cfg, artifact_EOG_eye] = ft_artifact_zvalue(cfg, data_segmented); Important notes:

  1.  I have checked and verified that the data does not contain any NaN values before the filtering process.
  2.  I have tried different configurations, including setting the padding to 0, which prevents the error It appears that NaN values are being introduced during the filtering process, but I am unable to determine the cause. I understand that the filterpadding specifies how much extra data around each trial's segment is read from the file. This extra data (padding) is used to mitigate edge artifacts that can occur after applying filters to the data. However, given the encountered error, I am uncertain if I am utilizing this function correctly. Could you please provide guidance on how to resolve this issue?
Thank you for your support!
Kind regards,
Sophie Schubert


------------------------------------------------------------------------------

De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht ontvangt, wordt u verzocht de inhoud niet te gebruiken en de afzender direct te informeren door het bericht te retourneren. Het Universitair Medisch Centrum Utrecht is een publiekrechtelijke rechtspersoon in de zin van de W.H.W.
(Wet Hoger Onderwijs en Wetenschappelijk Onderzoek) en staat geregistreerd bij de Kamer van Koophandel voor Midden-Nederland onder nr. 30244197.

Denk s.v.p aan het milieu voor u deze e-mail afdrukt.

------------------------------------------------------------------------------

This message may contain confidential information and is intended exclusively for the addressee. If you receive this message unintentionally, please do not use the contents but notify the sender immediately by return e-mail. University Medical Center Utrecht is a legal person by public law and is registered at the Chamber of Commerce for Midden-Nederland under no. 30244197.

Please consider the environment before printing this e-mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240627/3f6e5105/attachment-0001.htm>

------------------------------

Subject: Digest Footer

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202


------------------------------

End of fieldtrip Digest, Vol 163, Issue 20
******************************************



More information about the fieldtrip mailing list