PyMNE for julia

Hi. I am trying to import raw EEG data in the .cnt format to julia. I have downloaded PyMNE (the Python MNE package for julia) and I am trying with the PyMNE.io.read_raw_cnt function. I run:

PyMNE.io.read_raw_cnt(“C:\Users\skaar\Desktop\Osnabruck\EEG_AAT_SUB023.cnt”)

And I get the following error:

ERROR: Python: UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 0: ordinal not in range(128)
Python stacktrace:
[1] read_str
@ mne.io.utils C:\Users\skaar.julia\environments\v1.7.CondaPkg\env\lib\site-packages\mne\io\utils.py:244
[2] get_cnt_info
@ mne.io.cnt.cnt C:\Users\skaar.julia\environments\v1.7.CondaPkg\env\lib\site-packages\mne\io\cnt\cnt.py:176
[3] init
@ mne.io.cnt.cnt C:\Users\skaar.julia\environments\v1.7.CondaPkg\env\lib\site-packages\mne\io\cnt\cnt.py:388
[4] read_raw_cnt
@ mne.io.cnt.cnt C:\Users\skaar.julia\environments\v1.7.CondaPkg\env\lib\site-packages\mne\io\cnt\cnt.py:163
Stacktrace:
[1] pythrow()
@ PythonCall C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\err.jl:94
[2] errcheck
@ C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\err.jl:10 [inlined]
[3] pycallargs
@ C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\abstract\object.jl:210 [inlined]
[4] pycall(f::Py, args::String; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ PythonCall C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\abstract\object.jl:228
[5] pycall
@ C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\abstract\object.jl:218 [inlined]
[6] #
#11
@ C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\Py.jl:352 [inlined]
[7] (::Py)(args::String)
@ PythonCall C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\Py.jl:352
[8] top-level scope
@ REPL[8]:1

Any idea how to solve this unicode error for importing a .cnt file with a python package?

Thank you,
Sofie

Could you try to find whether the error has something to do with the Julia wrapper or if it is purely an issue in the python package? Does the python package on its own cause the same problem? If that is the case, you should probably ask the package authors (on a github issue maybe).

Two minor notes:

  • wrapping your code examples in backticks formats them like code and makes it much easier to read
  • pasting the complete backtraces, not just the first line of the error message makes it much easier to see where the error is
1 Like

I think the error is in the Python package and not the julia wrapper. A website says The Python “UnicodeDecodeError: ‘ascii’ codec can’t decode byte in position” occurs when we use the ascii codec to decode bytes that were encoded using a different codec. To solve the error, specify the correct encoding, e.g. utf-8.. The encoding in python is specified with encoding argument:

PyMNE.io.read_raw_cnt(“C:\Users\skaar\Desktop\Osnabrück\EEG_AAT_SUB023.cnt”, encoding=“utf-8”)

But that does not work in julia:

ERROR: Python: TypeError: read_raw_cnt() got an unexpected keyword argument ‘encoding’
Python stacktrace: none
Stacktrace:
[1] pythrow()
@ PythonCall C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\err.jl:94
[2] errcheck
@ C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\err.jl:10 [inlined]
[3] pycallargs
@ C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\abstract\object.jl:211 [inlined]
[4] pycall(f::Py, args::String; kwargs::Base.Pairs{Symbol, String, Tuple{Symbol}, NamedTuple{(:encoding,), Tuple{String}}})
@ PythonCall C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\abstract\object.jl:222
[5] #_#11
@ C:\Users\skaar.julia\packages\PythonCall\3GRYN\src\Py.jl:352 [inlined]
[6] top-level scope
@ REPL[6]:1

Any idea how to specify encoding in julia?

If you can run the python package on its own (without julia) in order to verify that the issue is with the python package, then it would be best to ask the folks that develop the package about it.

In python you can indeed specify encoding when processing strings, but that is for a select few built-in operations. The encoding keyword argument is not some language feature that is available everywhere: it is just a function argument that might exists if the person writing the function decides to use is as a name for one of the function arguments - just like any other function argument.

Check this post on a couple of pointers on how to use Markdown when posting code and error messages (makes it a bit easier to read and comment about it on most platforms like discourse or github) Please read: make it easier to help you