Skip to content

WIP: support for BTI/4D Magnes3600WH data - #385

Closed
dengemann wants to merge 79 commits into
mne-tools:masterfrom
dengemann:bti_bin
Closed

dengemann wants to merge 79 commits into
mne-tools:masterfrom
dengemann:bti_bin

Conversation

@dengemann

Copy link
Copy Markdown
Member

This includes the functions and the class from #248
and binary readers -- disclaimer -- inspired by / refactored from python-megdata, a module hosted by the ynic york group.

Works:

  • reading raw bti data and basic channel info from the so called PDF file
  • reading headshape files

Written, but untested:

  • reading user blocks, coil definitions and transforms from the so called config file

To be done:

@dengemann

Copy link
Copy Markdown
Member Author

... forgot to add to todo:

  • many cosmits, but let's first settle the more general API questions. The result of that will certainly inform @t3on / WIP mne_kit2fiff #366 then.

@dengemann

Copy link
Copy Markdown
Member Author

... almost there. Some dirty padding issue is left which messes up some of the channel names / transforms read from the config file. Also I started organizing the code toward the io API change. As we switch, the new bit submodule, a directory below fife, will move to IO. I will acquire some testdata tomorrow and start with nosetests then, as soon as the missing last bytes unpack correctly. I will probably remove a decent part of the BTI constants, as those arent that constant as I just learned. It turned out that debugging was easier with just the byte jumps and read counts visible. Also, to improve readibility I chose the classical dicitonary style, due to the color scheme implied It helps a lot reading the code which is in big parts nothing but seemingly endless mapping. So the left side has a color different from the right side. I'll let you know as soon as this is ready for review.

@dengemann

Copy link
Copy Markdown
Member Author

Hooray! Debugged the config reading, now I can read in all we need to calibrate the measurement data from short int to float and ale I get the channel transforms. Fiff from binary bti is coming ;-)

@dengemann

Copy link
Copy Markdown
Member Author

Note. Also I included a tiny bti raw file, a config, and a headshape file for unititests. Al are below 1MB. @agramfort that should be ok, shouldn't it?

@dengemann

Copy link
Copy Markdown
Member Author

left to do:

  • improve unit tests and remove debugging helpers
  • test calibrating data to float.
  • test data from non-solaris systems
  • refactor bti.Raw class to handle new input
  • tests comparing mne-python bti-fiff with solaris routine (data and all transforms)

@dengemann

Copy link
Copy Markdown
Member Author

I'm almost there. The raw file nicely constructs from the bti test file. But there is one failing test. On reading the saved tmp fiff the mne.fiff.Raw would throw an exception because nchan is not found.

ERROR: Test conversion to Raw object
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Users/denisaengemann/python/mne-python/mne/fiff/bti/tests/test_bti.py", line 57, in test_raw
    with Raw_(tmp_raw_fname) as r:
  File "/Users/denisaengemann/python/mne-python/mne/utils.py", line 229, in dec
    return function(*args, **kwargs)
  File "/Users/denisaengemann/python/mne-python/mne/fiff/raw.py", line 86, in __init__
    for fname in fnames]
  File "/Users/denisaengemann/python/mne-python/mne/utils.py", line 229, in dec
    return function(*args, **kwargs)
  File "/Users/denisaengemann/python/mne-python/mne/fiff/raw.py", line 158, in _read_raw_file
    info, meas = read_meas_info(fid, tree)
  File "/Users/denisaengemann/python/mne-python/mne/utils.py", line 229, in dec
    return function(*args, **kwargs)
  File "/Users/denisaengemann/python/mne-python/mne/fiff/meas_info.py", line 107, in read_meas_info
    raise ValueError('Number of channels in not defined')
ValueError: Number of channels in not defined

This is weird because info['nchan'] is set and I included two passing assert statemets checking for correspondence of nchan and len(channels) as well as completeness of the raw.info.

@agramfort @mluessi @Eric89GXL do you have an idea what's going on here?

@agramfort

Copy link
Copy Markdown
Member

looking into it now

apparently a first problem is that your info['dig'][k]['r'] is not of length 3 so write_dig_point does not do what it's supposed to do. Also to be consistent with fif files info['dig'][k]['r'].dtype should be np.float32

you also have a problem with write_ch_info. Not sure what yet.

@dengemann

Copy link
Copy Markdown
Member Author

oh, indeed, sth. went wrong with the dig.

@dengemann

Copy link
Copy Markdown
Member Author

yeah, the fiducials are telescoped together in the first dig point's 'r' field. should not be.

@agramfort

Copy link
Copy Markdown
Member

info['chs'][270]['loc'] is None

@agramfort

Copy link
Copy Markdown
Member

appart from that the info seem correct

@dengemann

Copy link
Copy Markdown
Member Author

Yeah, that's a reference channel that apparently has no transform. What to do with this? Can I substitute, e.g. a simply an array of mock loc values? Yes should work

@agramfort

Copy link
Copy Markdown
Member

fill it with np.zeros(12, dtype=np.float32)

@dengemann

Copy link
Copy Markdown
Member Author

@agramfort could you drop some general comment on the style of mne/fiff/bti / the API? Would be helpful for finalizing this one. And thanks for the first aid.

@dengemann

Copy link
Copy Markdown
Member Author

... the 'f4' / 'f8' issue leaves me with the general question how to handle casting, etc. So do we always store 'f4' floats in a riff or is it only for some parts of the info structure?

Comment thread mne/fiff/bti/raw.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref_mag, ref_grad, eog, ext = [count(1) for _ in range(4)]

@agramfort

Copy link
Copy Markdown
Member

it should not matter much as a cast is done when writing but ideally it
should be consistent ie float64 like in fif

On Sun, Jan 20, 2013 at 3:16 PM, Denis A. Engemann <[email protected]

wrote:

@agramfort https://github.com/agramfort could you drop some general
comment on the style of mne/fiff/bti / the API? Would be helpful for
finalizing this one. And thanks for the first aid.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/385#issuecomment-12471173.

Comment thread mne/fiff/bti/raw.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind using a dict here? Bunch can lead to problems eg when pickling.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, was more a debugging thing.

On Sun, Jan 20, 2013 at 3:27 PM, Alexandre Gramfort <
[email protected]> wrote:

In mne/fiff/bti/raw.py:

  • """Read BTi system config file
  • Parameters

  • fname : str
  •    The absolute path to the config file
    
  • Returns

  • cfg : Bunch
  •    A dict like structure including the config blocks found.
    
  • """
  • fid = open(fname, 'rb')
  • cfg = Bunch()

would you mind using a dict here? Bunch can lead to problems eg when
pickling.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/385/files#r2707225.

@agramfort

Copy link
Copy Markdown
Member

let me know when tests pass so we can check coverage + tests for linux

Comment thread mne/fiff/bti/raw.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to pass this ecg_ch and eog_ch, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Wed, Jan 30, 2013 at 12:02 AM, Eric89GXL [email protected]:

In mne/fiff/bti/raw.py:

  •                if 'high_freq' in step:
    
  •                    hp, lp = step['high_freq'], step['low_freq']
    
  •                elif 'hp' in step['process_type']:
    
  •                    hp = step['freq']
    
  •                elif 'lp' in step['process_type']:
    
  •                    lp = step['freq']
    
  •    info['highpass'] = hp
    
  •    info['lowpass'] = lp
    
  •    info['acq_pars'], info['acq_stim'] = None, None
    
  •    info['filename'] = None
    
  •    info['filenames'] = []
    
  •    chs = []
    
  •    ch_names = [ch['name'] for ch in bti_info['chs']]
    
  •    info['ch_names'] = _rename_channels(ch_names)
    

You need to pass this ecg_ch and eog_ch, right?

Oh yes ;-) Thanks!

I think, anyways that's just an interims security measure. On the long run
these arguments will disappear.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/385/files#r2818060.

@larsoner

Copy link
Copy Markdown
Member

Now that I've gone through the code, here are a few issues:

  1. Always using standard file I/O objects. @dengemann I assume you'll give this a shot?
  2. Feasibility of using np.fromstring(). I would like this because it would more closely match what is done in tag.py. However, I noticed that you make extensive use of your read_XXX() functions. What do you think of just having those wrap to using np.fromstring()? They would be mostly one-liners, I think. This could be a good compromise, compared to swapping out all your read_XXX() functions (which would be very time consuming). I don't like having to re-invent a much less torture-tested wheel with the read_XXX() functions unless there is a compelling reason to, which is why I'd rather have the heavy lifting done by np.fromstring() when possible...
  3. Add an example. Can you make a simple example file for people so they can see how easy it is to load a raw file, make epochs from it, and plot them? If the files are too short, you could even just plot the raw traces and/or digitization positions. And then once someone gets around to making an appropriate sample dataset (with dataset importing functions) for this type of data, we could show people the more complex operations (epoching, etc.).

@dengemann

Copy link
Copy Markdown
Member Author

thanks for the in-depth review, Eric! all points should be inside my ballpark ;-)

On 30.01.2013, at 01:03, Eric89GXL [email protected] wrote:

Now that I've gone through the code, here are a few issues:

Always using standard file I/O objects. @dengemann I assume you'll give this a shot?
Feasibility of using np.fromstring(). I would like this because it would more closely match what is done in tag.py. However, I noticed that you make extensive use of your read_XXX() functions. What do you think of just having those wrap to using np.fromstring()? They would be mostly one-liners, I think. This could be a good compromise, compared to swapping out all your read_XXX() functions (which would be very time consuming). I don't like having to re-invent a much less torture-tested wheel with the read_XXX() functions unless there is a compelling reason to, which is why I'd rather have the heavy lifting done by np.fromstring() when possible...
Add an example. Can you make a simple example file for people so they can see how easy it is to load a raw file, make epochs from it, and plot them? If the files are too short, you could even just plot the raw traces and/or digitization positions. And then once someone gets around to making an appropriate sample dataset (with dataset importing functions) for this type of data, we could show people the more complex operations (epoching, etc.).
—
Reply to this email directly or view it on GitHub.

Comment thread mne/fiff/bti/raw.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8, this one's 81 char long.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, you found one ;-)

On 30.01.2013, at 01:39, Eric89GXL [email protected] wrote:

In mne/fiff/bti/raw.py:

  •    info['dev_ctf_t']['trans'] = dev_ctf_t
    
  •    info['ctf_head_t'] = dict()
    
  •    info['ctf_head_t']['from'] = FIFF.FIFFV_MNE_COORD_CTF_HEAD
    
  •    info['ctf_head_t']['to'] = FIFF.FIFFV_COORD_HEAD
    
  •    info['ctf_head_t']['trans'] = ctf_head_t
    
  •    logger.info('Done.')
    
  •    if False:  # reminds us to support this as we go
    
  •        # include digital weights from reference channel
    
  •        comps = info['comps'] = list()
    
  •        weights = bti_info['weights']
    
  •        by_name = lambda x: x[1]
    
  •        chn = dict(ch_mapping)
    
  •        columns = [chn[k] for k in weights['dsp_ch_names']]
    
  •        rows = [chn[k] for k in weights['ch_names']]
    
  •        col_order, col_names = zip(*sorted(enumerate(columns), key=by_name))
    
    PEP8, this one's 81 char long.

—
Reply to this email directly or view it on GitHub.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to beat @agramfort to it :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also see my reviews. the nitpickers united

On 30.01.2013, at 01:42, Eric89GXL [email protected] wrote:

In mne/fiff/bti/raw.py:

  •    info['dev_ctf_t']['trans'] = dev_ctf_t
    
  •    info['ctf_head_t'] = dict()
    
  •    info['ctf_head_t']['from'] = FIFF.FIFFV_MNE_COORD_CTF_HEAD
    
  •    info['ctf_head_t']['to'] = FIFF.FIFFV_COORD_HEAD
    
  •    info['ctf_head_t']['trans'] = ctf_head_t
    
  •    logger.info('Done.')
    
  •    if False:  # reminds us to support this as we go
    
  •        # include digital weights from reference channel
    
  •        comps = info['comps'] = list()
    
  •        weights = bti_info['weights']
    
  •        by_name = lambda x: x[1]
    
  •        chn = dict(ch_mapping)
    
  •        columns = [chn[k] for k in weights['dsp_ch_names']]
    
  •        rows = [chn[k] for k in weights['ch_names']]
    
  •        col_order, col_names = zip(*sorted(enumerate(columns), key=by_name))
    
    I had to beat @agramfort to it :)

—
Reply to this email directly or view it on GitHub.

@larsoner

Copy link
Copy Markdown
Member

Tests pass over here. Nice work!

@dengemann

Copy link
Copy Markdown
Member Author

Thanks!!

On 30.01.2013, at 01:40, Eric89GXL [email protected] wrote:

Tests pass over here. Nice work!

—
Reply to this email directly or view it on GitHub.

@dengemann

Copy link
Copy Markdown
Member Author

On 30.01.2013, at 01:03, Eric89GXL [email protected] wrote:

Now that I've gone through the code, here are a few issues:

Always using standard file I/O objects. @dengemann I assume you'll give this a shot?
Feasibility of using np.fromstring(). I would like this because it would more closely match what is done in tag.py. However, I noticed that you make extensive use of your read_XXX() functions. What do you think of just having those wrap to using np.fromstring()? They would be mostly one-liners, I think. This could be a good compromise, compared to swapping out all your read_XXX() functions (which would be very time consuming). I don't like having to re-invent a much less torture-tested wheel with the read_XXX() functions unless there is a compelling reason to, which is why I'd rather have the heavy lifting done by np.fromstring() when possible...
Add an example. Can you make a simple example file for people so they can see how easy it is to load a raw file, make epochs from it, and plot them? If the files are too short, you could even just plot the raw traces and/or digitization positions. And then once someone gets around to making an appropriate sample dataset (with dataset importing functions) for this type of data, we could show people the more complex operations (epoching, etc.).

btw. this is definitely planned. Already created an eligible ethically legally unambiguous real sample dataset. It's just that our analogue eeg device broke and still there's no routine available for merging the new digital ecg / eog traces with the megdata. Should not be difficult, but will comsume a few additional hours. Therefore I postponed this..

—
Reply to this email directly or view it on GitHub.

@dengemann dengemann mentioned this pull request Feb 1, 2013
@agramfort

Copy link
Copy Markdown
Member

merged after a crazy rebase to avoid pushed the large files in the history !

awesome work !

@agramfort agramfort closed this Feb 10, 2013
@dengemann

Copy link
Copy Markdown
Member Author

damn it this wasn't ready... many comments put forward by @Eric89GXL were not yet addressed.
Thanks though :-)
Let me append a maintanance PR soon addressing STY issues left.

D

On 10.02.2013, at 18:39, Alexandre Gramfort [email protected] wrote:

merge after a crazy rebase to avoid pushed the large files in the history !

awesome work !

—
Reply to this email directly or view it on GitHub..

@agramfort

Copy link
Copy Markdown
Member

damn it this wasn't ready... many comments put forward by @Eric89GXL were not yet addressed.

Thanks though :-)
Let me append a maintanance PR soon addressing STY issues left.

no release planned and tests passed with a good coverage. I don't feel back :)
and it's putting a bit of pressure :)

@dengemann

Copy link
Copy Markdown
Member Author

Yes, that's reasonable. Actually it's sometimes easier to have minimum working version merged and improve / polish it incrementally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants