[mne-python] strange behavior of raw.save()

Hi all,

on saving a raw file using the instance method save() I get the
following error message.

http://pastebin.com/g66H4svV

After that the file is not readable anymore ( the same error message
will appear as Raw.__init__() is called. )

If I use an alternative file name this does not happen.

a) what is the reason for that / what does it actually tell, and

b) shouldn't that rather throw an exception than messing up the original file?

Cheers,
Denis

Hi Denis,

Are you by any chance saving the raw file to the same file from where
you read it? I.e., something like

raw = Raw('test_raw.fif')
..
raw.save('test_raw.fif')

Unless you use preload=True, this won't work since raw.save() will read
from the file and at the same time overwrite it. We should add a check
such that it throws and exception with a explanatory error message if
one tries to do this.

Martin

Thanks Martin,

that must be it.
I actually I was testing a new command line tool of mine for mass riff
export / augmentation / conversion
And in one of the use cases I simply wanted to change the info
structure without loading the data.
So this means I can either preload the data or work around it by e.g.
iterative renaming.

To prevent users from tnings like that one could add something like

raw.save(fname)

(...)

if fname == self.raw.info['filename'] and not self.preload:
    raise ValueError("Invalid operation "
                            "Either load data or use alternative file name")

Wdyt?

Cheers,
Denis

2012/9/8 Martin Luessi <mluessi at nmr.mgh.harvard.edu>:

Ok, I tried the following:

I added

if fname == self.info['filename'] and not hasattr(self,'_data'):
            raise ValueError('Invalid operation. Either read data with preload '
                                    'option or use alternative file name')

to Raw.save

Hower, in case the data is preloaded the file still breaks...

2012/9/8 Denis-Alexander Engemann <d.engemann at fz-juelich.de>:

Ok. self._preload

2012/9/9 Denis-Alexander Engemann <d.engemann at fz-juelich.de>:

Ok, self._data == True or self._preodaded == True does not make a difference.

Is it at all possible to write make a ras.save using the identical fid?
Otherwise we should just add:

if fname == self.info['filename']:
            raise RuntimeError('Invalid operation. Use an alternative
file name')

2012/9/9 Denis-Alexander Engemann <d.engemann at fz-juelich.de>