I am encountering an error in MetPy when following the geocolor satellite imagery tutorial. Specifically, the section entitled "Plot with Cartopy Geostationary Projection". This breakage occurred roughly two weeks ago and functionality has yet to return. Consider the following code:
from xarray import open_dataset
import metpy
data_dir = '.'
color_file = 'OR_ABI-L1b-RadC-M3C01_G16_s20180152002235_e20180152005008_c20180152005054.nc'
c = open_dataset('/'.join([data_dir,color_file]))
dat = c.metpy.parse_cf('Rad')
This block is functionally similar to that provided in the MetPy geocolor satellite tutorial. It worked fine until recently. Now the following error occurs:
Traceback (most recent call last):
File "<stdin>", line 1, in module
File "/usr/local/anaconda3/lib/python3.7/site-packages/metpy/xarray.py", line 191, in parse_cf
from .plots.mapping import CFProjection
File "/usr/local/anaconda3/lib/python3.7/site-packages/metpy/plots/__init__.py", line 13, in module
from .skewt import * # noqa: F403
File "/usr/local/anaconda3/lib/python3.7/site-packages/metpy/plots/skewt.py", line 28, in module
from ..calc import dewpoint, dry_lapse, moist_lapse, vapor_pressure
File "/usr/local/anaconda3/lib/python3.7/site-packages/metpy/calc/__init__.py", line 7, in module
from .cross_sections import * # noqa: F403
File "/usr/local/anaconda3/lib/python3.7/site-packages/metpy/calc/cross_sections.py", line 14, in module
from .tools import first_derivative
File "/usr/local/anaconda3/lib/python3.7/site-packages/metpy/calc/tools.py", line 101, in module
def find_intersections(x, a, b, direction='all'):
File "/usr/local/anaconda3/lib/python3.7/site-packages/pint/registry_helpers.py", line 248, in decorator
% (func.__name__, count_params, len(args))
TypeError: find_intersections takes 4 parameters, but 3 units were passed
What seems to be the problem here? Is there a workaround available?
I think it's an incompatibility between your installed versions of MetPy and Pint. Try making sure you're running the latest versions of those two with:
conda update metpy pint
I should note that MetPy 0.12.0 (currently the latest) is incompatible with xarray 0.15.1. As of this writing, if the above command updates xarray, you'll need to roll it back slightly with:
conda install xarray=0.15.0
We're working on a bugfix release to address this.
Related
import os
import numpy as np
import mne
data_folder = '/Users/sheetal/Desktop/emotions'
data_raw_file = os.path.join(data_folder,"sub-01","eeg","sub-01_task-ImaginedEmotion_eeg.set")
raw = mne.io.read_raw_eeglab(data_raw_file)
OUTPUT
runfile('/Users/sheetal/Desktop/emotions/sub-01/eeg/code1.py', wdir='/Users/sheetal/Desktop/emotions/sub-01/eeg')
Traceback (most recent call last):
File "/Users/sheetal/Desktop/emotions/sub-01/eeg/code1.py", line 15, in <module>
raw = mne.io.read_raw_eeglab(data_raw_file)
File "/Users/sheetal/opt/anaconda3/lib/python3.8/site-packages/mne/io/eeglab/eeglab.py", line 219, in read_raw_eeglab
return RawEEGLAB(input_fname=input_fname, preload=preload,
File "<decorator-gen-222>", line 24, in __init__
File "/Users/sheetal/opt/anaconda3/lib/python3.8/site-packages/mne/io/eeglab/eeglab.py", line 317, in __init__
eeg = _check_load_mat(input_fname, uint16_codec)
File "/Users/sheetal/opt/anaconda3/lib/python3.8/site-packages/mne/io/eeglab/eeglab.py", line 59, in _check_load_mat
eeg = read_mat(fname, uint16_codec=uint16_codec)
File "/Users/sheetal/opt/anaconda3/lib/python3.8/site-packages/mne/externals/pymatreader/pymatreader.py", line 78, in read_mat
raise IOError('The file %s does not exist.' % (filename,))
OSError: The file /Users/sheetal/Desktop/emotions/sub-01/eeg/sub-01_task-ImaginedEmotion_eeg.set does not exist.
I am new to use MNE python package for EEG signal processing and getting error reading .set file
I occasionally encounter this problem.
The .set & corresponding .fdt files are actually there, but unfortunately MNE cannot read those files, resulting in file not found error.
It seemed that the issue is related to the generating files from the EEGLab, which, due to its unstable development, often produce a lot of errors.
Suggestion: re-generating those files from EEGLab.
UPDATE
Currently, I found that my problem is relating to the uncompatible version of EEGLab and Python-MNE.
Previously, I used EEGLab 2019.1 to generate .set files and Python-MNE 0.20.4 to read those files.
Later, EEGLab released the latest version 2021.1 and disable 2019.1 which forced us to use the latest one.
The problems arrive when I used the EEGLab 2021.1 with MNE 0.20.4 which doesn't support the latest version of EEGLab.
Updating MNE to the latest 0.23.4 solves my issue.
After updating scipy, numpy and pandas to the newest versions, I receive the following error whenever I attempt to run my code on a Windows 10 machine with Python 3.7.4:
Traceback (most recent call last):
...
File "Path\To\MyClass.py", line 3, in <module>
import scipy.io as sio
File "Path\To\Anaconda\lib\site-packages\scipy\__init__.py", line 68, in <module>
from ._lib.deprecation import _deprecated
File "Path\To\Anaconda\lib\site-packages\scipy\_lib\__init__.py", line 12, in <module>
from scipy._lib._testutils import PytestTester
ValueError: source code string cannot contain null bytes
This is how the last file looks like:
"""
Module containing private utility functions
===========================================
The ``scipy._lib`` namespace is empty (for now). Tests for all
utilities in submodules of ``_lib`` can be run with::
from scipy import _lib
_lib.test()
"""
from scipy._lib._testutils import PytestTester
test = PytestTester(__name__)
del PytestTester
Am I running into a bug or is my setup broken?
I managed to solve this issue by reinstalling Anaconda. I still don't know the source of the problem though.
I would like to embed python into a C application. Specifically, I would like to use sympy as part of the python portion. To accomplish this I created a clean install of anaconda. Here is a minimal working example that illustrates my problem.
int main()
{
putenv("PYTHONHOME=../anaconda3/bin/python3.7m");
Py_SetPath(L"../:../anaconda3/lib/python3.7:../anaconda3/lib/python3.7/lib-dynload:../anaconda3/lib/python3.7/site-packages:../anaconda3/lib/python3.7/site-packages/aeosa:../anaconda3/lib/python3.7/site-packages/IPython/extensions:../.ipython");
Py_Initialize();
//PyRun_SimpleString("import math\n");
PyRun_SimpleString("import sympy\n");
Py_FinalizeEx();
return (EXIT_SUCCESS)
}
This code compiles fine, but when I attempt to run it I get the following error.
Traceback (most recent call last):
File "../anaconda3/lib/python3.7/site-packages/sympy/__init__.py", line 19, in <module>
import mpmath
File "../anaconda3/lib/python3.7/site-packages/mpmath/__init__.py", line 5, in <module>
from .ctx_fp import FPContext
File "../anaconda3/lib/python3.7/site-packages/mpmath/ctx_fp.py", line 1, in <module>
from .ctx_base import StandardBaseContext
File "../anaconda3/lib/python3.7/site-packages/mpmath/ctx_base.py", line 3, in <module>
from .libmp.backend import xrange
File "../anaconda3/lib/python3.7/site-packages/mpmath/libmp/__init__.py", line 1, in <module>
from .libmpf import (prec_to_dps, dps_to_prec, repr_dps,
File "../anaconda3/lib/python3.7/site-packages/mpmath/libmp/libmpf.py", line 7, in <module>
import math
ImportError: dlopen(../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so, 2): Symbol not found: _PyExc_MemoryError
Referenced from: ../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so
Expected in: flat namespace
in ../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so
Looking at this error it appears that there is an error on "import math". Importing math by itself gives the following error confirming this.
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dlopen(../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so, 2): Symbol not found: _PyExc_MemoryError
Referenced from: ../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so
Expected in: flat namespace
in ../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so
I found several references where similar problems were encountered and discussed (e.g. this, this, this, and this), but the solutions have either not worked, weren't provided, or I didn't fully understand how they might relate to my problem. This solution suggested adding the following line before initialize may help
void*const libpython_handle = dlopen("libpython3.7m.dylib", RTLD_LAZY | RTLD_GLOBAL); // update to my python version
I also tried
void*const libpython_handle = dlopen("../anaconda3/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so", RTLD_LAZY | RTLD_GLOBAL);
as this specifically is (apparently) what's causing the problem. Neither worked. It appears that the problem is related to dependency problems with lib-dynload/* files (discussed here), but thus far I have not been able to find a workaround.
How might I fix this problem?
Edit:
I am using MacOS
I am a new programmer who is picking up python. I recently am trying to learn about importing csv files using numpy.
Here is my code:
import numpy as np
x = np.loadtxt("abcd.py", delimiter = True, unpack = True)
print(x)
The idle returns me with:
>> True
>> Traceback (most recent call last):
>> File "C:/Python34/Scripts/a.py", line 1, in <module>
import numpy as np
>> File "C:\Python34\lib\site-packages\numpy\__init__.py", line 180, in <module>
from . import add_newdocs
>> File "C:\Python34\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
>> File "C:\Python34\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
>> File "C:\Python34\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
>> File "C:\Python34\lib\site-packages\numpy\core\__init__.py", line 14, in <module>
from . import multiarray
>> SystemError: initialization of multiarray raised unreported exception
Why do I get the this system error and how can I remedy it?
I have experienced this problem too. This is cuased by a file named "datetime.py" in the same folder (exactly the same problem confronted by Bruce). Actually "datetime" is an existing python module. However, I do not know why running my own script, e.g. plot.py will invoke my datetime.py file (I have seen the output produced by my datetime.py, and there will be an auto-generated datetime.cpython-36.pyc in the __pycache__ folder).
Although I am not clear about how the error is triggered, after I rename my datetime.py file to other names, I can run the plot.py immediately. Therefore, I suggest you check if there are some files whose name collides with the system modules. (P.S. I use the Visual Studio Code to run python.)
As there is an error at the import line, your installation of numpy is broken in some way. My guess is that you have installed numpy for python2 but are using python3. You should remove numpy and attempt a complete re-install, taking care to pick the correct version.
There are a few oddities in the code:
You are apparently reading a python file, abcd.py, not a csv file. Typically you want to have your data in a csv file.
The delimiter is a string, not a boolean, typically delimiter="," (Documentation)
import numpy as np
x = np.loadtxt("abcd.csv", delimiter = ",", unpack = True)
I am trying to create a standalone application using py2exe that depends on matplotlib and numpy. The code of the application is this:
import numpy as np
import pylab as plt
plt.figure()
a = np.random.random((16,16))
plt.imshow(a,interpolation='nearest')
plt.show()
The setup code for py2exe (modified from http://www.py2exe.org/index.cgi/MatPlotLib) is this:
from distutils.core import setup
import py2exe
import sys
sys.argv.append('py2exe')
opts = {
'py2exe': {"bundle_files" : 3,
"includes" : [ "matplotlib.backends",
"matplotlib.backends.backend_qt4agg",
"pylab", "numpy",
"matplotlib.backends.backend_tkagg"],
'excludes': ['_gtkagg', '_tkagg', '_agg2',
'_cairo', '_cocoaagg',
'_fltkagg', '_gtk', '_gtkcairo', ],
'dll_excludes': ['libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll']
}
}
setup(console=[{"script" : "matplotlib_test.py"}],
zipfile=None,options=opts)
Now, when bundle_files is set = 3 or is absent, all works fine, but the resulting exe cannot be distributed to a machine that is not configured with the same version of Python, etc. If I set bundle_files = 1, it creates a suitably large exe file that must have everything bundled, but it fails to run locally or distributed. In this case, I'm creating everything on a Windows 7 machine with Python 2.6.6 and trying to run locally and on an XP machine with Python 2.6.4 installed.
The errors I get when running on the XP machine seem strange since, without bundling, I get no errors on Win 7. With bundling, Win 7 does not report the traceback information, so I cannot be sure the errors are the same. In any case, here's the error message on XP:
Traceback (most recent call last):
File "matplotlib_test.py", line 2, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "pylab.pyc", line 1, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "matplotlib\__init__.pyc", line 709, in <module>
File "matplotlib\__init__.pyc", line 627, in rc_params
File "matplotlib\__init__.pyc", line 565, in matplotlib_fname
File "matplotlib\__init__.pyc", line 240, in wrapper
File "matplotlib\__init__.pyc", line 439, in _get_configdir
RuntimeError: Failed to create C:\Documents and Settings\mnfienen/.matplotlib; c
onsider setting MPLCONFIGDIR to a writable directory for matplotlib configuratio
n data
Many thanks in advance if anyone can point me in a direction that will fix this!
EDIT 1:
I followed William's advice and fixed the problem with MPLCONFIGDIR, but now get a new error:
:Traceback (most recent call last):
File "matplotlib\__init__.pyc", line 479, in _get_data_path
RuntimeError: Could not find the matplotlib data files
EDIT 2:
I fixed the data files problem by using:
data_files=matplotlib.get_py2exe_datafiles()
This leads to a new error:
Traceback (most recent call last):
File "matplotlib_test.py", line 5, in <module>
import matplotlib.pyplot as plt
File "matplotlib\pyplot.pyc", line 78, in <module>
File "matplotlib\backends\__init__.pyc", line 25, in pylab_setup
ImportError: No module named backend_wxagg
I had the same problem. I think the problem was caused by pylab in matplotlib, py2exe seemed to have trouble finding and getting all the backends associated with pylab.
I got around the problem by changing all my embedded plots to use matplotlib.figure instead of pylab. Here's a simple example on how to make a plot with matplotlib.figure:
import matplotlib.figure as fg
import numpy as np
fig = fg.Figure()
ax = fig.add_subplot(111)
lines = ax.plot(range(10), np.random.randn(10), range(10), np.random.randn(10))
You cannot use fig.show() directly with this, but it can be embedded in GUIs. I used Tkinker:
canvas = FigureCanvasTkAgg(fig, canvas_master)
canvas.show()
Well Misha Fienen, I guess it seems to be failing to write to your user folder, which you probably already knew. Just a stab in the dark but have you tried testing what happens if you follow the advice and change MPLCONFIGDIR to something a bit more basic (eg. "C:\matlibplotcfg\")?
There are two ways of solving the problem.
1.- In your matplotlib.rc file use:
backend : TkAgg
2.- alternatively, in your setup.py "includes" key add:
"matplotlib.backends.backend_wxagg"
both ways produce the test figure in Python 2.6, windows XP