How to edit time attribute in a raw object

External Email - Use Caution

Hi all
I posted this question in stackoverflow but seems MNE community is not
active there, hence I searched for MNE mailing list and joined it.
I use MNE for analysis of both rat and human EEG recordings. The system
we have for rat EEG is from a company called NeuroNexus, and they have
their own Matlab script to convert the EEG recordings and the time
stamps into mat files. And then I import them in python and use MNE to
analyse and visualise them. This means I have to establish my EEG raw
objects from the scratch and save them to file, which I can do. But a
seemingly trivial thing that I have not managed to find out how to do is
to incorporate the time array into the EEG raw object. When I create and
save the EEG raw object, it automatically set the initial time to 0, but
my initial recording time is not 0 and I need to offset that. It is
important to correct this, because the time stamps of EEG and
behavioural data should match.
Simply typing |raw.times = new_array| leads to |AttributeError: can't
set attribute. ||This should be a very simple thing to do, but I have
not been able to find it although I have looked into the documentation.
So, I thought to ask it in here and if it is not really possible, then
dig into the source code to fix it myself. Thanks in advance.
Regards,
Vahid

External Email - Use Caution

The time in the raw recordings (the Raw object) are assumed to be
arbitrary and just a measure of time elapsed since the beginning of the
recording, so there's not really a way to set or manipulate them. Why do
you need absolute time here? Are you concatenating Raw objects?

Best,
Phillip

An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20191104/9abe7c08/attachment-0001.html

External Email - Use Caution

If the time of recording start is properly encoded in the file and read by
MNE (which is hopefully the case), then you should be able to use it. You
can manually convert from relative (starting from zero) to absolute time by
looking at `raw.info['meas_date']` and `raw.first_samp`. But the eaiser
thing to do would be to construct an Annotations
<https://mne.tools/stable/generated/mne.Annotations.html> class with your
behavioral/pupil events (in whatever starting time frame you prefer), then
set `raw.annotations = my_annotations`, which should convert it to the raw
object's time reference in `raw.info['meas_date']`. Check out the
Annotations tutorials -- such as this one
<https://mne.tools/dev/auto_tutorials/raw/plot_30_annotate_raw.html#creating-annotations-programmatically>
-- and if it's not clear from them how to do it, we should improve the
documentation.

We do not allow modifying the `raw.times` attribute intentionally. A lot of
downstream code (e.g., epoching) would break, loudly or (worse) silently,
in unexpected and unpredictable if users could do this.

Eric

External Email - Use Caution

Eric

Can we directly modify the ` <http://raw.info> raw.info['meas_date']` value without creating an annotation ?

How ?

Thank you in advance

External Email - Use Caution

Why do you need to modify it? Was it incorrectly recorded in the file, or
incorrectly read by MNE?

In principle yes we could add something to MNE to allow setting this in
cases where it is for some reason incorrect. I've made an MNE-Python issue
about it here:

https://github.com/mne-tools/mne-python/issues/7037

Eric

External Email - Use Caution

Eric

I am creating a raw object (RawArray function) and epoch from a numpy array imported from a third party software, so the absolute time is lost.

This is why I would like to add it to `raw.info['meas_date']`, or do you really recommend to use annotations ?

Thank you for your answer

External Email - Use Caution

This is why I would like to add it to `raw.info['meas_date']`, or do you
really recommend to use annotations ?

In this case it would probably make sense to be able to set
`raw.info['meas_date']`.
Let's figure out how to implement it in MNE tools for MEG and EEG data analysis · GitHub
mne-python/issues/7037.

Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20191112/23a81d3b/attachment.html