[Mne_analysis] Question about copy/inplace operations

Mainak Jas mainakjas at gmail.com
Sun Oct 28 15:39:27 EDT 2018
Search archives:

        External Email - Use Caution        

Hi André,

You should simply do:

freqs = [(1, 5), (5, 10)]
raws = list()for (l_freq, h_freq) in freqs:
    raw_filt = raw.copy()
    raw_filt.filter(l_freq, h_freq)
    raws.append(raw_filt)

No need to hack into any private attributes. I would be surprised if this
does not work. If it doesn’t, I’d suggest trying to reproduce your issue
with MNE sample data (starting from an example) and report back to us with
a minimal example that causes the problem.

Best,
Mainak

On Sun, Oct 28, 2018 at 12:20 PM Andre Sevenius <sevenius.nilsen at gmail.com>
wrote:

>         External Email - Use Caution
>
> Hi all,
> This might seem like an easy question, but I've tried everything.
> I want to test out different filters on the same data, say 1-5hz, 5-10hz,
> etc. So I have a function that implements whatever filters I want from a
> list.  This function returns all instances of raw sent to it, with filters
> applied.
> However, when I use raw.filter - operations happen in place, and when I
> try the next filter (5-10hz), it's applying that to 1-5hz filtered data.
> The same happens if I use mne.filter.filter_data(copy=True).
> The same also happens if I use raw2=raw.copy() or even
> raw2=copy.deepcopy(raw.copy()), before applying filters with either
> raw2.filter or raw2=mne.filter.filter_data. The original raw object also
> gets filtered.
> Preload is set to true, and I've even tried setting raw._data =
> mne.filter.filter_data(copy=True), but it still has retroactive effect!
> Clearly, I must be misunderstanding something here, but how do I make a
> copy of some data/raw object that I can manipulate without having to
> manually use arrays?
>
> my function goes like this:
> def filter(data, params): #data is a raw object
>   temp = copy.deepcopy(data.copy())
>   temp._data=mne.filter.filter_data(temp.get_data(), params, copy=True)
>   return copy.deepcopy(temp)
>
> and I call it by:
> temp = filter(data,params)
>
> Thank you,
> André
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20181028/f82de424/attachment.html 


More information about the Mne_analysis mailing list