metpy.plots issue with Cartopy Natural Earth - cartopy

I just noticed that when I try to import metpy.plots on NCAR's Cheyenne supercomputer, it loads and works fine when using metpy 0.10.0 (with Cartopy 0.17.0), but I get an error with metpy 0.12.0 or 0.12.1 (with Cartopy 0.18.0b2). This is the error I get:
(NPL) jaredlee#cheyenne3:~> python3
Python 3.6.8 (default, Jun 27 2019, 20:02:05)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import metpy
>>> metpy.__version__
'0.12.1'
>>> import metpy.plots as mpplots
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/glade/work/jaredlee/python/my_npl_clone_20200417/lib/python3.6/site-packages/metpy/plots/__init__.py", line 27, in <module>
from .cartopy_utils import USCOUNTIES, USSTATES
File "/glade/work/jaredlee/python/my_npl_clone_20200417/lib/python3.6/site-packages/metpy/plots/cartopy_utils.py", line 43, in <module>
USCOUNTIES = MetPyMapFeature('us_counties', '20m', facecolor='None', edgecolor='black')
File "/glade/work/jaredlee/python/my_npl_clone_20200417/lib/python3.6/site-packages/metpy/plots/cartopy_utils.py", line 16, in __init__
super().__init__('', name, scale, **kwargs)
File "/glade/work/jaredlee/python/my_npl_clone_20200417/lib/python3.6/site-packages/cartopy/feature/__init__.py", line 264, in __init__
self._validate_scale()
File "/glade/work/jaredlee/python/my_npl_clone_20200417/lib/python3.6/site-packages/cartopy/feature/__init__.py", line 274, in _validate_scale
'Valid scales are "110m", "50m", and "10m".'
ValueError: 20m is not a valid Natural Earth scale. Valid scales are "110m", "50m", and "10m".
>>>
If I manually change cartopy_utils.py in my local copy of metpy so that the USCOUNTIES and USSTATES function calls to MetPyMapFeature use '10m' instead of '20m', then the error goes away. Is this '20m' a bug in cartopy_utils.py? Natural Earth's webpage advertises that it provides data at 1:10m, 1:50m, and 1:110m scales.

MetPy <=0.12.1 is incompatible with CartoPy 0.18. As pointed out by Daryl in his comment, this is an open issue that will hopefully be resolved soon.

Related

cannot import name 'int' from 'numpy'

I was just getting started with PyCharm and python for statistics.
And I got this error:
ImportError: cannot import name 'int' from 'numpy' (/home/tetiana/.local/lib/python3.8/site-packages/numpy/init.py)
Full traceback looks like this:
Traceback (most recent call last):
File "/home/tetiana/forVScode/python/first/first_try.py", line 1, in
from scipy import stats
File "/usr/lib/python3/dist-packages/scipy/stats/init.py", line 379, in
from .stats import *
File "/usr/lib/python3/dist-packages/scipy/stats/stats.py", line 180, in
import scipy.special as special
File "/usr/lib/python3/dist-packages/scipy/special/init.py", line 643, in
from .basic import *
File "/usr/lib/python3/dist-packages/scipy/special/basic.py", line 19, in
from . import orthogonal
File "/usr/lib/python3/dist-packages/scipy/special/orthogonal.py", line 81, in
from numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int,
ImportError: cannot import name 'int' from 'numpy' (/home/tetiana/.local/lib/python3.8/site-packages/numpy/init.py)
Process finished with exit code 1
How can I fix it?
Here is my code:
from scipy import stats
import pandas as pd
state = pd.read_csv('state_murder_rate_test_table.csv')
state['Population'].mean()
stats.trim_mean(state['Population'], 0.1)
state['Population'].median()
I checked whether the Python versions in os and in the project match and they are. I have python 3.8.10 and my os is Ubuntu 20.04
Referring to the current numpy documentation, there exists no type called numpy.int that you can import. I believe that the type you wanna import is numpy.integer or numpy.int_.
The code you provided does not have any statement like: from numpy import int. If you could provide a full traceback error, it'll be easier to see where the error stems from.
I hope this answer will be somewhat useful.

AttributeError: module 'numpy' has no attribute 'float'. Did you mean: 'cfloat'? [duplicate]

This question already has answers here:
How to solve error 'numpy' has no attribute 'float' in Python?
(3 answers)
Closed last month.
I would like to use scikit-optimize's BayesSearchCV and using the following package versions in my environment myEnv:
# Name Version Build Channel
python 3.10.8 h4a9ceb5_0_cpython conda-forge
numpy 1.24.1 pypi_0 pypi
scikit-optimize 0.8.1 pyh9f0ad1d_0 conda-forge
and I am getting the error
AttributeError: module 'numpy' has no attribute 'float'. Did you mean: 'cfloat'?
FYI: The full error message is as follows
Traceback (most recent call last):
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/sklearnex/__main__.py", line 55, in <module>
sys.exit(_main())
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/sklearnex/__main__.py", line 52, in _main
runf(args.name, run_name='__main__')
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 289, in run_path
return _run_module_code(code, init_globals, run_name,
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "bayes_helper.py", line 26, in <module>
from skopt import BayesSearchCV
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/__init__.py", line 44, in <module>
from . import callbacks
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/callbacks.py", line 17, in <module>
from skopt.utils import dump
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/utils.py", line 19, in <module>
from .sampler import Sobol, Lhs, Hammersly, Halton, Grid
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/sampler/__init__.py", line 4, in <module>
from .lhs import Lhs
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/sampler/lhs.py", line 9, in <module>
from ..space import Space, Categorical
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/space/__init__.py", line 5, in <module>
from .space import *
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/space/space.py", line 212, in <module>
class Real(Dimension):
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/space/space.py", line 253, in Real
name=None, dtype=np.float):
File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/numpy/__init__.py", line 284, in __getattr__
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'float'. Did you mean: 'cfloat'?
It seems that there is some compatibility issue between my numpy version and my scikit-optimize version. But I don't find what it is. In the scikit-optimize documentation it just says that NumPy (>= 1.13.3) is required. Which is the case for me. I also tried it with the very latest version of scikit-optimize which is 0.0.9, but I still get this error.
Can anyone help me with solving this issue? I can provide any other package version information if needed.
NumPy abolished types like np.int and np.float, they are deprecated since 1.20, instead standard builtin types int, float or special types like np.int32 should be used.
In short your scikit-optimize and NumPy versions are not compatible.
First you could try to update the package to the newest version of 0.9.
As well can edit that line of code manually in your installation (replace it with float) and test if it works (chance is high).
Else downgrade your numpy to below 1.20. Below 1.24 it still works but will give you a warning

importing pandas, numpy 'module' object has no attribute 'Integral'

I have been working with a script using pandas, numpy, and scikit-learn that worked just fine.
Out of the blue (for sure I did something, but I do not know what) I am getting this error message:
C:\Users\xx\Anaconda3\python.exe
C:/Users/xxxx/create_predictions_2.py
Traceback (most recent call last):
File "C:/Users/xxxx/create_predictions_2.py", line 5, in <module>
import numpy as np
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\__init__.py", line 185, in <module>
from . import add_newdocs
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 9, in <module>
from . import numerictypes as nt
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\core\numerictypes.py", line 968, in <module>
_register_types()
File "C:\Users\xxxx\Anaconda3\lib\site-packages\numpy\core\numerictypes.py", line 965, in _register_types
numbers.Integral.register(integer)
AttributeError: 'module' object has no attribute 'Integral'
Process finished with exit code 1
I am doing the following imports
import numpy as np
import pandas as pd
import xgboost as xgb
import os
from sklearn.preprocessing import LabelEncoder
As you can see, I am using Anaconda on python 3.
Any hints?
i think the issue is due to some jython calls means you tried to create a jython program executed python code in java then without destroying the process you tried to call a python program from python interpreter.

ImportError: No module named 'matplotlib.pyplot'; matplotlib is not a package

I am trying to use matplotlib for real-time analysis from ECG-signals, but the problem starts even before.
I use the PyCharm IDE, currently working with Python 3.3 and my os is Windows 8.1.
For Matplotlib I downloaded matplotlib and the dependencies (numpy, six, dateutil, pyparsing, pytz) from here (the versions for Python 3.3): http://www.lfd.uci.edu/~gohlke/pythonlibs/ and installed it in the Python33 folder.
Now if I try:
from matplotlib.pyplot import plot, show
plot(range(10))
show()
or:
import pylab
from pylab import *
xAchse=pylab.arange(0,100,1)
yAchse=pylab.array([0]*100)
fig = pylab.figure(1)
ax = fig.add_subplot(111)
ax.grid(True)
ax.set_title("Realtime Waveform Plot")
ax.set_xlabel("Time")
ax.set_ylabel("Amplitude")
ax.axis([0,100,-1.5,1.5])
line1=ax.plot(xAchse,yAchse,'-')
manager = pylab.get_current_fig_manager()
values=[]
values = [0 for x in range(100)]
Ta=0.01
fa=1.0/Ta
fcos=3.5
Konstant=cos(2*pi*fcos*Ta)
T0=1.0
T1=Konstant
def SinwaveformGenerator(arg):
global values,T1,Konstant,T0
#ohmegaCos=arccos(T1)/Ta
#print "fcos=", ohmegaCos/(2*pi), "Hz"
Tnext=((Konstant*T1)*2)-T0
if len(values)%100>70:
values.append(random()*2-1)
else:
values.append(Tnext)
T0=T1
T1=Tnext
def RealtimePloter(arg):
global values
CurrentXAxis=pylab.arange(len(values)-100,len(values),1)
line1[0].set_data(CurrentXAxis,pylab.array(values[-100:]))
ax.axis([CurrentXAxis.min(),CurrentXAxis.max(),-1.5,1.5])
manager.canvas.draw()
#manager.show()
timer = fig.canvas.new_timer(interval=20)
timer.add_callback(RealtimePloter, ())
timer2 = fig.canvas.new_timer(interval=20)
timer2.add_callback(SinwaveformGenerator, ())
timer.start()
timer2.start()
pylab.show()
For a smal test, I get two different Error's. For the first one it is the following:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1519, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute __path__
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Timo/PycharmProjects/GUI_test/matplotlib.py", line 1, in <module>
from matplotlib.pyplot import plot, show
File "C:\Users\Timo\PycharmProjects\GUI_test\matplotlib.py", line 1, in <module>
from matplotlib.pyplot import plot, show
ImportError: No module named 'matplotlib.pyplot'; matplotlib is not a package
And for the second bigger example it is this:
Traceback (most recent call last):
File "C:/Users/Timo/PycharmProjects/GUI_test/matplotlib.py", line 1, in <module>
import pylab
File "C:\Python33\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Users\Timo\PycharmProjects\GUI_test\matplotlib.py", line 4, in <module>
xAchse=pylab.arange(0,100,1)
AttributeError: 'module' object has no attribute 'arange'
Afterwards I changed the imports to the ones Pycharm wanted me to use. from matplotlib import pylab but this only resulted in an ImportError. cannot import pylab
The funny thing is, if I run these small tests in the Python Console it works just fine, so my guess is that it has something to do with PyCharm...
I also tried to add the exact path from the matplotlib to the Path variable but that resulted in another Error.
Your current project folder C:/Users/Timo/PycharmProjects/GUI_test/matplotlib.py contains matplotlib.py which causes this issue. Change the filename to anything else, which is not a name of a python package.

error importing numpy

I have strange error, when I try to import numpy:
Traceback (most recent call last):
File "/home/timo/malltul/mafet/src/mafet/core/pattern.py", line 7, in <module>
import numpy as np
File "/usr/lib/python2.6/dist-packages/numpy/__init__.py", line 147, in <module>
import ma
File "/usr/lib/python2.6/dist-packages/numpy/ma/__init__.py", line 44, in <module>
import core
File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 4850, in <module>
all = _frommethod('all')
File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 4824, in __init__
self.__doc__ = self.getdoc()
File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 4830, in getdoc
signature = self.__name__ + get_object_signature(meth)
File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 109, in get_object_signature
import inspect
File "/usr/lib/python2.6/inspect.py", line 39, in <module>
import tokenize
File "/usr/lib/python2.6/tokenize.py", line 38, in <module>
COMMENT = N_TOKENS
NameError: name 'N_TOKENS' is not defined
It seems that the cause of the problem is that my script is in my own package named core and whenever I try to import numpy there, I get the error. Importing works fine elsewhere.
The only solution I've got this far is to rename my 'core' package to something else. Why does this matter? Am I doing something wrong?
I'm using Python2.6 on Ubuntu 10.14 . Numpy version is 1.3.0 .
EDIT: Actually renaming my package does not fix it. Renaming token.py in my package fixes it. Sorry for the error.
I doubt this has anything to do with your core module or with numpy.
From the stack trace, it would appear that the problem is with the tokenize module, which is part of Python, not part of numpy. Tokenize does from token import * and then uses N_TOKENS that's defined in token.py.
First of all, I'd check that there's no stray module called token on your PYTHONPATH:
>>> import token
>>> token.__file__
'/usr/lib/python2.6/token.pyc'
If this picks up the above file yet you still get the problem, I'd suggest reinstalling Python.