neurofractal / analyse_OPMEG

Nic & Rob's lair of scripts to analyse OPM data, using the Fieldtrip toolbox
https://neurofractal.github.io/analyse_OPMEG/
MIT License
9 stars 1 forks source link

Implement FT wrapper for MFC #33

Closed neurofractal closed 2 years ago

neurofractal commented 3 years ago

https://github.com/tierneytim/OPM/blob/master/spm_opm_mfc.m

neurofractal commented 3 years ago

Various issues to solve:

  1. Why the hell is SPM still complaining about grad units in fT?
  2. Inputs for bad channels to be passed onto SPM
  3. Better handling of paths for adding + removing SPM
neurofractal commented 3 years ago

Also something to check in future: FT to SPM conversion has been modified by using:

datafile = file_array(fullfile(D.path, fnamedat), [Nchannels Nsamples], ‘float64-le’);
tierneytim commented 3 years ago
  1. I think grad units should be T despite the chan units being fT. You'll need to confirm with Vladimir as errors here could really upset forward models.

and on the extra point why the modification for 'float64-le'? The OPM data only has 16-20 bits of precision. 64-bit seems like overkill unless there is a good reason.

neurofractal commented 3 years ago

Hey @tierneytim - cheers 👍.

  1. Do you know why that would be?

and on the extra point why the modification for 'float64-le'? The OPM data only has 16-20 bits of precision. 64-bit seems like overkill unless there is a good reason.

So I ran into problems when downsampling the data in FT (to 600Hz) before passing onto SPM. Any ideas? I shall investigate further...

tierneytim commented 3 years ago
  1. I don't fully understand myself but fieldtrip handles forward model-y stuff and fieldtrip wants T. Therefore grad is T. But confirm with Vladimir.

On precision, this is most likely a problem with the resampler and not the data. Therefore keep the data as 32-bit. I would also strongly advise against using the default resampler as it is inappropriate for our OPM data. I've nearly finished writing a generic downsampler that is more suitable for our needs and so this problem will vanish soon enough. If you really need to use it, just use the spm_eeg_downsample and then convert to fieldtrip. Then if you still have bugs report to myself/Vladimir.

georgeoneill commented 3 years ago

@neurofractal am I right in thinking that the errors you describe come from comparing the FT object after downsampling with the SPM object when you use a ft2spm function? As I think the downsampler is the red herring here.

neurofractal commented 3 years ago

@georgeoneill don't think so:

FT --> SPM --> FT the data is identical before and after Downsample --> FT --> SPM --> FT the data is not identical before and after

tierneytim commented 3 years ago

by 'data' you mean the raw field values?

what do you mean by identical? what is your tolerance here for identical? what datasets are being compared for equality? by how much do they differ?

georgeoneill commented 3 years ago

Okay I think I understand the problem. Can you check the data types before and after the downsampling?

tierneytim commented 3 years ago

Yeah, I think fieldtrip is doing a cast to double so hopefully the error is just the difference between single and double precision...

georgeoneill commented 3 years ago

I agree. Which would explain why setting the file array datatype to double means you are no loger getting 'data' errors. I think @tierneytim's advice of trying to downsample in SPM rather than fieldtrip (which should respect datatypes) is a reasonable stopgap for the time being, as hard-coding SPM to always cast to double going forward might cause more headaches later.

neurofractal commented 3 years ago

Thanks both - sounds like a plan. @tierneytim when you get the downsampler working please do let me know :)

tierneytim commented 3 years ago

@neurofractal, I don't think the downsampling should be included in the mfc wrapper. They should be two separate stages in an analysis script (if it is to be used at all). The mean-field correction should run very quickly on any dataset. The user can specify the maximum memory usage so downsampling should not be necessary. Unless you have a reason for this?

Also, spm_eeg_downsample should have the trigNN flag set to 1 if it is used on OPM data

neurofractal commented 3 years ago

Also, spm_eeg_downsample should have the trigNN flag set to 1 if it is used on OPM data

Aah thanks 👍

Unless you have a reason for this?

Not particularly, other than saving me time when messing about with data. I'm not going to spend too long on making this perfect, given we will make a fully FT version of the code when the SPM version is stable.

tierneytim commented 3 years ago

I'm curious, how much time is saved for spm_opm_mfc? For me, it's always faster to directly run it rather then downsample and run.