question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set non-UTC timezone

See original GitHub issue

Describe the bug

There seems to be no obvious way to set utc_offset in the Info object. Setting it directly prints a warning and threatens with an error after the next release. The function set_meas_date only accepts UTC datetime objects.

Steps to reproduce

>>> import mne
>>> mne.__version__
'0.24.0'
>>> info = mne.create_info([''], 1)
>>> info['utc_offset'] = '+02:00'
<stdin>:1: DeprecationWarning: utc_offset cannot be set directly. This warning will turn into an error after 0.24
>>> recording = mne.io.RawArray([[]],info)
Creating RawArray with float64 data, n_channels=1, n_times=0
    Range : 0 ... -1 =      0.000 ...    -1.000 secs
Ready.
>>> from datetime import datetime, timezone, timedelta
>>> date = datetime.now().replace(tzinfo=timezone(timedelta(hours=2), 'Europe/Berlin'))
>>> recording.set_meas_date(date)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.8/site-packages/mne/channels/channels.py", line 654, in set_meas_date
    meas_date = _handle_meas_date(meas_date)
  File "/opt/conda/lib/python3.8/site-packages/mne/annotations.py", line 690, in _handle_meas_date
    _check_dt(meas_date)  # run checks
  File "/opt/conda/lib/python3.8/site-packages/mne/utils/numerics.py", line 1029, in _check_dt
    raise ValueError('Date must be datetime object in UTC: %r' % (dt,))
ValueError: Date must be datetime object in UTC: datetime.datetime(2021, 11, 4, 11, 50, 49, 834556, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200), 'Europe/Berlin'))

Expected results

Either utc_offset should be writable or set_meas_date should accept non-UTC datetime objects and set meas_date (after conversion) and utc_offset accordingly.

Actual results

See above.

Additional information

`mne.sys_info()`
Platform:       Linux-5.10.75-flatcar-x86_64-with-glibc2.10
Python:         3.8.10 | packaged by conda-forge | (default, May 11 2021, 07:01:05)  [GCC 9.3.0]
Executable:     /opt/conda/bin/python
CPU:            x86_64: 32 cores
Memory:         Unavailable (requires "psutil" package)
mne:            0.24.0
numpy:          1.21.0 {blas=openblas, lapack=openblas}
scipy:          1.7.1
matplotlib:     3.4.3 {backend=agg}

sklearn:        1.0.1
numba:          Not found
nibabel:        Not found
nilearn:        Not found
dipy:           Not found
cupy:           Not found
pandas:         1.3.4
mayavi:         Not found
pyvista:        Not found
pyvistaqt:      Not found
ipyvtklink:     Not found
vtk:            Not found
PyQt5:          Not found
ipympl:         Not found
mne_qt_browser: Not found

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
heilerichcommented, Nov 5, 2021

@sappelhoff I guess you are right, it is not a violation of the standard. I would still argue, that at least giving users the option to write dates in local time (which the standard allows), but that discussion is probably better suited for the MNE-BIDS repository.

Regarding MNE itself, if everyone is in favor I will see if I can find some time to implement the changes proposed by @larsoner https://github.com/mne-tools/mne-python/issues/9953#issuecomment-961158494

1reaction
hoechenbergercommented, Nov 5, 2021
  • no timezone indicator
  • a UTC timezone indicator (Z)

Best. Standard. Ever. 🙈🙈🙈

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot change timezone in Windows 10 - Microsoft Community
I cannot change the timezone in Windows10. It's stuck in Pacific Standard Time. I select Eastern Standard Time and it reverts back to...
Read more >
How to initialize a JavaScript Date to a particular time zone
As far as I know, I can either set the UTC time or local time. But, how do I set time in another...
Read more >
Can't create a non-UTC Date object to call .getTime() on
This API retrieves data from a system (not in my control) that is based in the America/Las_Angeles timezone. I have tried for hours...
Read more >
Nutanix Files - FSVM default hardware clock timezone (UTC)
... clock time zone set to anything other than UTC, it will fail to ... hardware clock timezone is set to non-UTC value,...
Read more >
Date and Time Handling | Npgsql Documentation
Starting with 6.0, Npgsql maps UTC DateTime to timestamp with time zone , and ... without time zone ; trying to send a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found