Closed lippinpauly closed 2 years ago
Hi @lippinpauly, This was something that broke (again) semi-recently and I believe it was from either a release of Cartopy that came out after we had released the fix in the last wrf-python version, or that my cartopy was not up to date when testing the wrf-python release so it wasn't caught then. If you are able to, downgrade your Cartopy to 0.20.0 and that should fix it for the time being. if you are currently on Cartopy 0.20.0 and wrf-python 1.3.3, definitely let me know as this error shouldn't happen with those two versions based on what I have found.
Overall, this is on our radar and hopefully there will be a fix soon!
Thank you very much @michaelavs . It works with the Cartopy-0.20.0 version.
I see the same problem with cartopy in WRF-python.
cartopy 0.20.2 py310hb89acbc_4 conda-forge wrf-python 1.3.3 py310h3254323_0 conda-forge
cart_proj = get_cartopy(slp)
Error message is below
AttributeError Traceback (most recent call last) Input In [30], in <cell line: 2>() 1 # Get the cartopy object and the lat,lon coords ----> 2 cart_proj = get_cartopy(diag) 3 lats, lons = latlon_coords(diag)
File ~/anaconda3/envs/python_env/lib/python3.10/site-packages/wrf/util.py:3523, in get_cartopy(var, wrfin, varname, timeidx, method, squeeze, cache)
3459 def get_cartopy(var=None, wrfin=None, varname=None, timeidx=0, method="cat",
3460 squeeze=True, cache=None):
3461 """Return a :class:cartopy.crs.Projection
subclass for the
3462 map projection.
3463
(...)
3521
3522 """
-> 3523 return _get_proj_obj("cartopy", var, wrfin, varname, timeidx, method,
3524 squeeze, cache)
File ~/anaconda3/envs/python_env/lib/python3.10/site-packages/wrf/util.py:3389, in _get_proj_obj(ob_type, var, wrfin, varname, timeidx, method, squeeze, cache, **kwargs) 3385 wrf_proj, geobnds = _get_wrf_proj_geobnds(var, wrfin, varname, timeidx, 3386 method, squeeze, cache) 3388 if ob_type == "cartopy": -> 3389 proj_obj = wrf_proj.cartopy() 3390 elif ob_type == "basemap": 3391 try:
File ~/anaconda3/envs/python_env/lib/python3.10/site-packages/wrf/projection.py:419, in WrfProj.cartopy(self) 416 if not cartopy_enabled(): 417 raise RuntimeError("'cartopy' is not " 418 "installed or is disabled") --> 419 return self._cartopy()
File ~/anaconda3/envs/python_env/lib/python3.10/site-packages/wrf/projection.py:707, in Mercator._cartopy(self) 704 _cartopy = crs.Mercator(central_longitude=self._stand_lon, 705 globe=self._globe()) 706 else: --> 707 _cartopy = MercatorWithLatTS(central_longitude=self._stand_lon, 708 latitude_true_scale=self._lat_ts, 709 globe=self._globe()) 711 return _cartopy
File ~/anaconda3/envs/python_env/lib/python3.10/site-packages/wrf/projection.py:64, in MercatorWithLatTS.init(self, central_longitude, latitude_true_scale, min_latitude, max_latitude, globe) 61 super(crs.Mercator, self).init(proj4_params, globe=globe) 63 # Calculate limits. ---> 64 limits = self.transform_points( 65 crs.Geodetic(), 66 np.array([-180, 180]) + central_longitude, 67 np.array([min_latitude, max_latitude])) 69 # When using a latitude of true scale, the min/max x-limits get set 70 # to the same value, so make sure the left one is negative 71 xlimits = limits[..., 0]
File ~/anaconda3/envs/python_env/lib/python3.10/site-packages/cartopy/crs.py:408, in CRS.transform_points(self, src_crs, x, y, z, trap) 405 x[to_180] = (((x[to_180] + 180) % 360) - 180) 406 try: 407 result[:, 0], result[:, 1], result[:, 2] = \ --> 408 _safe_pj_transform(src_crs, self, x, y, z, trap=trap) 409 except ProjError as err: 410 msg = str(err).lower()
File ~/anaconda3/envs/python_env/lib/python3.10/site-packages/cartopy/crs.py:50, in _safe_pj_transform(src_crs, tgt_crs, x, y, z, trap) 49 def _safe_pj_transform(src_crs, tgt_crs, x, y, z=None, trap=True): ---> 50 transformer = _get_transformer_from_crs(src_crs, tgt_crs) 51 transformed_coords = transformer.transform(x, y, z, errcheck=trap) 52 if z is None:
File ~/anaconda3/envs/python_env/lib/python3.10/site-packages/cartopy/crs.py:1673, in Mercator.hash(self) 1672 def hash(self): -> 1673 return hash((self.proj4_init, self._x_limits, self._y_limits))
AttributeError: 'MercatorWithLatTS' object has no attribute '_x_limits'
Hi @lippinpauly, This should now be resolved in the most recent version of wrf-python (1.3.4.1). Please let me know if you still run into the problem after updating your version!
@michaelavs Thank you very much to you and your team for the great support. Currently, I am using the older version. However, I will update and let you know if I encounter any problem
Many thanks
Hi all, I am new to wrf-python and I am trying to do the 2021 tutorial. During the plotting of slp (sea level Pressure) variable using wrf_python, I get this error 'MercatorWithLatTS' object has no attribute '_x_limits' over the line (code) cart_proj = get_cartopy(slp)
Any help would be really appreciated
I could see that this issue is discussed and closed recently in #162. However, the solution described in that issue is to update the wrf-python to v1.3.3 and use cartopy >0.20. I am using the recent versions and I still have the same issue.
My installed versions in the wp_env environment
Name Version Build Channel
appdirs 1.4.4 pyh9f0ad1d_0 conda-forge argon2-cffi 21.3.0 pyhd8ed1ab_0 conda-forge argon2-cffi-bindings 21.2.0 py38h294d835_2 conda-forge asttokens 2.0.5 pyhd8ed1ab_0 conda-forge attrs 21.4.0 pyhd8ed1ab_0 conda-forge backcall 0.2.0 pyh9f0ad1d_0 conda-forge backports 1.0 py_2 conda-forge backports.functools_lru_cache 1.6.4 pyhd8ed1ab_0 conda-forge beautifulsoup4 4.11.1 pyha770c72_0 conda-forge bleach 5.0.0 pyhd8ed1ab_0 conda-forge brotlipy 0.7.0 py38h294d835_1004 conda-forge bzip2 1.0.8 h8ffe710_4 conda-forge ca-certificates 2021.10.8 h5b45459_0 conda-forge cartopy 0.20.2 py38hd9cf50b_4 conda-forge certifi 2021.10.8 py38haa244fe_2 conda-forge cffi 1.15.0 py38hd8c33c5_0 conda-forge cftime 1.6.0 py38hbdcd294_1 conda-forge charset-normalizer 2.0.12 pyhd8ed1ab_0 conda-forge colorama 0.4.4 pyh9f0ad1d_0 conda-forge cryptography 36.0.2 py38hb7941b4_1 conda-forge curl 7.82.0 h789b8ee_0 conda-forge cycler 0.11.0 pyhd8ed1ab_0 conda-forge debugpy 1.6.0 py38h885f38d_0 conda-forge decorator 5.1.1 pyhd8ed1ab_0 conda-forge defusedxml 0.7.1 pyhd8ed1ab_0 conda-forge entrypoints 0.4 pyhd8ed1ab_0 conda-forge executing 0.8.3 pyhd8ed1ab_0 conda-forge flit-core 3.7.1 pyhd8ed1ab_0 conda-forge freetype 2.10.4 h546665d_1 conda-forge geographiclib 2.0 pyhd8ed1ab_0 conda-forge geos 3.10.2 h39d44d4_0 conda-forge hdf4 4.2.15 h0e5069d_3 conda-forge hdf5 1.12.1 nompi_h2a0e4a3_104 conda-forge icu 69.1 h0e60522_0 conda-forge idna 3.3 pyhd8ed1ab_0 conda-forge importlib-metadata 4.11.3 py38haa244fe_1 conda-forge importlib_metadata 4.11.3 hd8ed1ab_1 conda-forge importlib_resources 5.7.1 pyhd8ed1ab_0 conda-forge intel-openmp 2022.0.0 h57928b3_3663 conda-forge ipykernel 6.13.0 py38h4317176_0 conda-forge ipython 8.2.0 py38haa244fe_0 conda-forge ipython_genutils 0.2.0 py_1 conda-forge ipywidgets 7.7.0 pyhd8ed1ab_0 conda-forge jbig 2.1 h8d14728_2003 conda-forge jedi 0.18.1 py38haa244fe_1 conda-forge jinja2 3.1.1 pyhd8ed1ab_0 conda-forge jpeg 9e h8ffe710_1 conda-forge jsonschema 4.4.0 pyhd8ed1ab_0 conda-forge jupyter 1.0.0 py38haa244fe_7 conda-forge jupyter_client 7.3.0 pyhd8ed1ab_0 conda-forge jupyter_console 6.4.3 pyhd8ed1ab_0 conda-forge jupyter_core 4.9.2 py38haa244fe_0 conda-forge jupyterlab_pygments 0.2.2 pyhd8ed1ab_0 conda-forge jupyterlab_widgets 1.1.0 pyhd8ed1ab_0 conda-forge kiwisolver 1.4.2 py38hbd9d945_1 conda-forge krb5 1.19.3 h1176d77_0 conda-forge lcms2 2.12 h2a16943_0 conda-forge lerc 3.0 h0e60522_0 conda-forge libblas 3.9.0 14_win64_mkl conda-forge libcblas 3.9.0 14_win64_mkl conda-forge libclang 13.0.1 default_h81446c8_0 conda-forge libcurl 7.82.0 h789b8ee_0 conda-forge libdeflate 1.10 h8ffe710_0 conda-forge libffi 3.4.2 h8ffe710_5 conda-forge liblapack 3.9.0 14_win64_mkl conda-forge libnetcdf 4.8.1 nompi_h1cc8e9d_102 conda-forge libpng 1.6.37 h1d00b33_2 conda-forge libsodium 1.0.18 h8d14728_1 conda-forge libssh2 1.10.0 h680486a_2 conda-forge libtiff 4.3.0 hc4061b1_3 conda-forge libwebp 1.2.2 h57928b3_0 conda-forge libwebp-base 1.2.2 h8ffe710_1 conda-forge libxcb 1.13 hcd874cb_1004 conda-forge libzip 1.8.0 hfed4ece_1 conda-forge libzlib 1.2.11 h8ffe710_1014 conda-forge lz4-c 1.9.3 h8ffe710_1 conda-forge m2w64-gcc-libgfortran 5.3.0 6 conda-forge m2w64-gcc-libs 5.3.0 7 conda-forge m2w64-gcc-libs-core 5.3.0 7 conda-forge m2w64-gmp 6.1.0 2 conda-forge m2w64-libwinpthread-git 5.0.0.4634.697f757 2 conda-forge make 4.3 h3d2af85_1 conda-forge markupsafe 2.1.1 py38h294d835_1 conda-forge matplotlib 3.3.0 1 conda-forge matplotlib-base 3.3.0 py38hfb9ee82_1 conda-forge matplotlib-inline 0.1.3 pyhd8ed1ab_0 conda-forge metpy 1.3.0 pyhd8ed1ab_0 conda-forge mistune 0.8.4 py38h294d835_1005 conda-forge mkl 2022.0.0 h0e2418a_796 conda-forge msys2-conda-epoch 20160418 1 conda-forge nbclient 0.6.0 pyhd8ed1ab_0 conda-forge nbconvert 6.5.0 pyhd8ed1ab_0 conda-forge nbconvert-core 6.5.0 pyhd8ed1ab_0 conda-forge nbconvert-pandoc 6.5.0 pyhd8ed1ab_0 conda-forge nbformat 5.3.0 pyhd8ed1ab_0 conda-forge nest-asyncio 1.5.5 pyhd8ed1ab_0 conda-forge netcdf4 1.5.8 nompi_py38h0500770_101 conda-forge notebook 6.4.11 pyha770c72_0 conda-forge numpy 1.22.3 py38h5ed9b9d_2 conda-forge openjpeg 2.4.0 hb211442_1 conda-forge openssl 1.1.1n h8ffe710_0 conda-forge packaging 21.3 pyhd8ed1ab_0 conda-forge pandas 1.4.2 py38hcc40339_1 conda-forge pandoc 2.18 h57928b3_0 conda-forge pandocfilters 1.5.0 pyhd8ed1ab_0 conda-forge parso 0.8.3 pyhd8ed1ab_0 conda-forge pickleshare 0.7.5 py_1003 conda-forge pillow 9.1.0 py38hd8e0db4_2 conda-forge pint 0.19.2 pyhd8ed1ab_0 conda-forge pip 22.0.4 pyhd8ed1ab_0 conda-forge pooch 1.6.0 pyhd8ed1ab_0 conda-forge proj 9.0.0 h1cfcee9_1 conda-forge prometheus_client 0.14.1 pyhd8ed1ab_0 conda-forge prompt-toolkit 3.0.29 pyha770c72_0 conda-forge prompt_toolkit 3.0.29 hd8ed1ab_0 conda-forge psutil 5.9.0 py38h294d835_1 conda-forge pthread-stubs 0.4 hcd874cb_1001 conda-forge pure_eval 0.2.2 pyhd8ed1ab_0 conda-forge pycparser 2.21 pyhd8ed1ab_0 conda-forge pygments 2.12.0 pyhd8ed1ab_0 conda-forge pyopenssl 22.0.0 pyhd8ed1ab_0 conda-forge pyparsing 3.0.8 pyhd8ed1ab_0 conda-forge pyproj 3.3.1 py38h954eab8_0 conda-forge pyqt 5.12.3 py38haa244fe_8 conda-forge pyqt-impl 5.12.3 py38h885f38d_8 conda-forge pyqt5-sip 4.19.18 py38h885f38d_8 conda-forge pyqtchart 5.12 py38h885f38d_8 conda-forge pyqtwebengine 5.12.1 py38h885f38d_8 conda-forge pyrsistent 0.18.1 py38h294d835_1 conda-forge pyshp 2.2.0 pyhd8ed1ab_0 conda-forge pysocks 1.7.1 py38haa244fe_5 conda-forge python 3.8.13 h9a09f29_0_cpython conda-forge python-dateutil 2.8.2 pyhd8ed1ab_0 conda-forge python-fastjsonschema 2.15.3 pyhd8ed1ab_0 conda-forge python_abi 3.8 2_cp38 conda-forge pytz 2022.1 pyhd8ed1ab_0 conda-forge pywin32 303 py38h294d835_0 conda-forge pywinpty 2.0.5 py38hd3f51b4_1 conda-forge pyzmq 22.3.0 py38h09162b1_2 conda-forge qt 5.12.9 h556501e_6 conda-forge qtconsole 5.3.0 pyhd8ed1ab_0 conda-forge qtconsole-base 5.3.0 pyhd8ed1ab_0 conda-forge qtpy 2.0.1 pyhd8ed1ab_0 conda-forge requests 2.27.1 pyhd8ed1ab_0 conda-forge scipy 1.8.0 py38ha1292f7_1 conda-forge send2trash 1.8.0 pyhd8ed1ab_0 conda-forge setuptools 62.1.0 py38haa244fe_0 conda-forge shapely 1.8.0 py38h1e1a050_6 conda-forge six 1.16.0 pyh6c4a22f_0 conda-forge soupsieve 2.3.1 pyhd8ed1ab_0 conda-forge sqlite 3.38.2 h8ffe710_0 conda-forge stack_data 0.2.0 pyhd8ed1ab_0 conda-forge tbb 2021.5.0 h2d74725_1 conda-forge terminado 0.13.3 py38haa244fe_1 conda-forge tinycss2 1.1.1 pyhd8ed1ab_0 conda-forge tk 8.6.12 h8ffe710_0 conda-forge tornado 6.1 py38h294d835_3 conda-forge traitlets 5.1.1 pyhd8ed1ab_0 conda-forge typing_extensions 4.2.0 pyha770c72_1 conda-forge ucrt 10.0.20348.0 h57928b3_0 conda-forge urllib3 1.26.9 pyhd8ed1ab_0 conda-forge vc 14.2 hb210afc_6 conda-forge vs2015_runtime 14.29.30037 h902a5da_6 conda-forge wcwidth 0.2.5 pyh9f0ad1d_2 conda-forge webencodings 0.5.1 py_1 conda-forge wheel 0.37.1 pyhd8ed1ab_0 conda-forge widgetsnbextension 3.6.0 py38haa244fe_0 conda-forge win_inet_pton 1.1.0 py38haa244fe_4 conda-forge winpty 0.4.3 4 conda-forge wrapt 1.14.0 py38h294d835_1 conda-forge wrf-python 1.3.3 py38ha49ce88_0 conda-forge xarray 2022.3.0 pyhd8ed1ab_0 conda-forge xorg-libxau 1.0.9 hcd874cb_0 conda-forge xorg-libxdmcp 1.1.3 hcd874cb_0 conda-forge xz 5.2.5 h62dcd97_1 conda-forge zeromq 4.3.4 h0e60522_1 conda-forge zipp 3.8.0 pyhd8ed1ab_0 conda-forge zlib 1.2.11 h8ffe710_1014 conda-forge zstd 1.5.2 h6255e5f_0 conda-forge
Error
AttributeError Traceback (most recent call last) Input In [19], in <cell line: 6>() 3 slp = getvar(wrfin, 'slp', timeidx=0) 5 # Extract cartopy object and lat/lon coordinates using get_cartopy and latlon_coords ----> 6 cart_proj = get_cartopy(slp) 7 lats, lons = latlon_coords(slp) 9 # Verify cartopy object and lat/lon coordinates were processed
File ~\miniconda3\envs\wp_env\lib\site-packages\wrf\util.py:3523, in get_cartopy(var, wrfin, varname, timeidx, method, squeeze, cache) 3459 def get_cartopy(var=None, wrfin=None, varname=None, timeidx=0, method="cat", 3460 squeeze=True, cache=None): 3461 """Return a :class:
cartopy.crs.Projection
subclass for the 3462 map projection. 3463 (...) 3521 3522 """ -> 3523 return _get_proj_obj("cartopy", var, wrfin, varname, timeidx, method, 3524 squeeze, cache)File ~\miniconda3\envs\wp_env\lib\site-packages\wrf\util.py:3389, in _get_proj_obj(ob_type, var, wrfin, varname, timeidx, method, squeeze, cache, **kwargs) 3385 wrf_proj, geobnds = _get_wrf_proj_geobnds(var, wrfin, varname, timeidx, 3386 method, squeeze, cache) 3388 if ob_type == "cartopy": -> 3389 proj_obj = wrf_proj.cartopy() 3390 elif ob_type == "basemap": 3391 try:
File ~\miniconda3\envs\wp_env\lib\site-packages\wrf\projection.py:419, in WrfProj.cartopy(self) 416 if not cartopy_enabled(): 417 raise RuntimeError("'cartopy' is not " 418 "installed or is disabled") --> 419 return self._cartopy()
File ~\miniconda3\envs\wp_env\lib\site-packages\wrf\projection.py:707, in Mercator._cartopy(self) 704 _cartopy = crs.Mercator(central_longitude=self._stand_lon, 705 globe=self._globe()) 706 else: --> 707 _cartopy = MercatorWithLatTS(central_longitude=self._stand_lon, 708 latitude_true_scale=self._lat_ts, 709 globe=self._globe()) 711 return _cartopy
File ~\miniconda3\envs\wp_env\lib\site-packages\wrf\projection.py:64, in MercatorWithLatTS.init(self, central_longitude, latitude_true_scale, min_latitude, max_latitude, globe) 61 super(crs.Mercator, self).init(proj4_params, globe=globe) 63 # Calculate limits. ---> 64 limits = self.transform_points( 65 crs.Geodetic(), 66 np.array([-180, 180]) + central_longitude, 67 np.array([min_latitude, max_latitude])) 69 # When using a latitude of true scale, the min/max x-limits get set 70 # to the same value, so make sure the left one is negative 71 xlimits = limits[..., 0]
File ~\miniconda3\envs\wp_env\lib\site-packages\cartopy\crs.py:408, in CRS.transform_points(self, src_crs, x, y, z, trap) 405 x[to_180] = (((x[to_180] + 180) % 360) - 180) 406 try: 407 result[:, 0], result[:, 1], result[:, 2] = \ --> 408 _safe_pj_transform(src_crs, self, x, y, z, trap=trap) 409 except ProjError as err: 410 msg = str(err).lower()
File ~\miniconda3\envs\wp_env\lib\site-packages\cartopy\crs.py:50, in _safe_pj_transform(src_crs, tgt_crs, x, y, z, trap) 49 def _safe_pj_transform(src_crs, tgt_crs, x, y, z=None, trap=True): ---> 50 transformer = _get_transformer_from_crs(src_crs, tgt_crs) 51 transformed_coords = transformer.transform(x, y, z, errcheck=trap) 52 if z is None:
File ~\miniconda3\envs\wp_env\lib\site-packages\cartopy\crs.py:1673, in Mercator.hash(self) 1672 def hash(self): -> 1673 return hash((self.proj4_init, self._x_limits, self._y_limits))
AttributeError: 'MercatorWithLatTS' object has no attribute '_x_limits'