cartopy
cartopy copied to clipboard
AzimuthalEquidistant Landarea Projection issue in the southern hemisphere
Description
Hi Team,
I have been encountering an issue that may be related to other issues here concerning the accurate plotting of land areas when providing the keywords central_longitude=??
and central_latitude=??
. I attached a working and a failing example. There is no error, but the plotting is weird. I'm running on macOS with a fresh conda
environment with only cartopy
and matplotlib
installed like so:
conda create -n cartopy python matplotlib cartopy
When creating a AzimuthalEquidistant
projection instance using
central_longitude=-66
central_latitude=-25
The land areas fill the entire map:
However, if I use a latitude just slightly closer to the equator the projection is completely fine:
central_longitude=-66
central_latitude=-22
Code to reproduce
Failing example
central_longitude=-66, central_latitude=-25
from cartopy.crs import AzimuthalEquidistant, PlateCarree
import matplotlib.pyplot as plt
import cartopy
fig = plt.figure()
projection = AzimuthalEquidistant(central_longitude=-66, central_latitude=-25)
ax = plt.axes(projection=projection)
ax.set_global()
# only fails for very certain central_longitude=????, central_latitude=????
ax.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='k',
linewidth=0.5, facecolor=(0.8, 0.8, 0.8))
plt.show()
Working as expected example
central_longitude=-66, central_latitude=-22
from cartopy.crs import AzimuthalEquidistant, PlateCarree
import matplotlib.pyplot as plt
import cartopy
fig = plt.figure()
projection = AzimuthalEquidistant(central_longitude=-66, central_latitude=-22)
ax = plt.axes(projection=projection)
ax.set_global()
# only fails for very certain central_longitude=????, central_latitude=????
ax.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='k',
linewidth=0.5, facecolor=(0.8, 0.8, 0.8))
plt.show()
System Summary
Note that anaconda is using python=3.7.x
but the cartopy
environment is using python=3.10.x
.
conda info
active environment : cartopy
active env location : /Users/lucassawade/anaconda3/envs/cartopy
shell level : 1
user config file : /Users/lucassawade/.condarc
populated config files : /Users/lucassawade/.condarc
conda version : 4.12.0
conda-build version : 3.17.8
python version : 3.7.3.final.0
virtual packages : __osx=10.16=0
__unix=0=0
__archspec=1=x86_64
base environment : /Users/lucassawade/anaconda3 (writable)
conda av data dir : /Users/lucassawade/anaconda3/etc/conda
conda av metadata url : None
channel URLs : https://conda.anaconda.org/conda-forge/osx-64
https://conda.anaconda.org/conda-forge/noarch
https://repo.anaconda.com/pkgs/main/osx-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/osx-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /Users/lucassawade/anaconda3/pkgs
/Users/lucassawade/.conda/pkgs
envs directories : /Users/lucassawade/anaconda3/envs
/Users/lucassawade/.conda/envs
platform : osx-64
user-agent : conda/4.12.0 requests/2.23.0 CPython/3.7.3 Darwin/21.2.0 OSX/10.16
UID:GID : 503:20
netrc file : None
offline mode : False
Operating system
macOS=12.1
Cartopy version
cartopy=0.20.2
conda list
# packages in environment at /Users/lucassawade/anaconda3/envs/cartopy:
#
# Name Version Build Channel
brotli 1.0.9 h0d85af4_6 conda-forge
brotli-bin 1.0.9 h0d85af4_6 conda-forge
bzip2 1.0.8 h0d85af4_4 conda-forge
c-ares 1.18.1 h0d85af4_0 conda-forge
ca-certificates 2021.10.8 h033912b_0 conda-forge
cartopy 0.20.2 py310he18ef84_4 conda-forge
certifi 2021.10.8 py310h2ec42d9_1 conda-forge
cycler 0.11.0 pyhd8ed1ab_0 conda-forge
fonttools 4.31.2 py310h1961e1f_0 conda-forge
freetype 2.10.4 h4cff582_1 conda-forge
geos 3.10.2 he49afe7_0 conda-forge
giflib 5.2.1 hbcb3906_2 conda-forge
jbig 2.1 h0d85af4_2003 conda-forge
jpeg 9e h0d85af4_0 conda-forge
kiwisolver 1.4.0 py310h6be76da_0 conda-forge
krb5 1.19.3 hb98e516_0 conda-forge
lcms2 2.12 h577c468_0 conda-forge
lerc 3.0 he49afe7_0 conda-forge
libblas 3.9.0 13_osx64_openblas conda-forge
libbrotlicommon 1.0.9 h0d85af4_6 conda-forge
libbrotlidec 1.0.9 h0d85af4_6 conda-forge
libbrotlienc 1.0.9 h0d85af4_6 conda-forge
libcblas 3.9.0 13_osx64_openblas conda-forge
libcurl 7.82.0 h9dce1e3_0 conda-forge
libcxx 13.0.1 hc203e6f_0 conda-forge
libdeflate 1.10 h0d85af4_0 conda-forge
libedit 3.1.20191231 h0678c8f_2 conda-forge
libev 4.33 haf1e3a3_1 conda-forge
libffi 3.4.2 h0d85af4_5 conda-forge
libgfortran 5.0.0 9_3_0_h6c81a4c_23 conda-forge
libgfortran5 9.3.0 h6c81a4c_23 conda-forge
liblapack 3.9.0 13_osx64_openblas conda-forge
libnghttp2 1.47.0 hca56917_0 conda-forge
libopenblas 0.3.18 openmp_h3351f45_0 conda-forge
libpng 1.6.37 h7cec526_2 conda-forge
libssh2 1.10.0 hd3787cc_2 conda-forge
libtiff 4.3.0 h17f2ce3_3 conda-forge
libwebp 1.2.2 h28dabe5_0 conda-forge
libwebp-base 1.2.2 h0d85af4_1 conda-forge
libxcb 1.13 h0d85af4_1004 conda-forge
libzlib 1.2.11 h6c3fc93_1014 conda-forge
llvm-openmp 13.0.1 hcb1a161_1 conda-forge
lz4-c 1.9.3 he49afe7_1 conda-forge
matplotlib 3.5.1 py310h2ec42d9_0 conda-forge
matplotlib-base 3.5.1 py310hfc59cd6_0 conda-forge
munkres 1.1.4 pyh9f0ad1d_0 conda-forge
ncurses 6.3 he49afe7_0 conda-forge
numpy 1.22.3 py310hb608527_0 conda-forge
openjpeg 2.4.0 h6e7aa92_1 conda-forge
openssl 3.0.2 h6c3fc93_1 conda-forge
packaging 21.3 pyhd8ed1ab_0 conda-forge
pillow 9.0.1 py310h382dc3b_2 conda-forge
pip 22.0.4 pyhd8ed1ab_0 conda-forge
proj 9.0.0 h2364a93_1 conda-forge
pthread-stubs 0.4 hc929b4f_1001 conda-forge
pyparsing 3.0.7 pyhd8ed1ab_0 conda-forge
pyproj 3.3.0 py310h8089d31_2 conda-forge
pyshp 2.2.0 pyhd8ed1ab_0 conda-forge
python 3.10.4 h1cc4136_0_cpython conda-forge
python-dateutil 2.8.2 pyhd8ed1ab_0 conda-forge
python_abi 3.10 2_cp310 conda-forge
readline 8.1 h05e3726_0 conda-forge
scipy 1.8.0 py310h47774c9_1 conda-forge
setuptools 61.2.0 py310h2ec42d9_1 conda-forge
shapely 1.8.0 py310hbb63119_5 conda-forge
six 1.16.0 pyh6c4a22f_0 conda-forge
sqlite 3.37.1 hb516253_0 conda-forge
tk 8.6.12 h5dbffcc_0 conda-forge
tornado 6.1 py310he24745e_2 conda-forge
tzdata 2022a h191b570_0 conda-forge
unicodedata2 14.0.0 py310he24745e_0 conda-forge
wheel 0.37.1 pyhd8ed1ab_0 conda-forge
xorg-libxau 1.0.9 h35c211d_0 conda-forge
xorg-libxdmcp 1.1.3 h35c211d_0 conda-forge
xz 5.2.5 haf1e3a3_1 conda-forge
zlib 1.2.11 h6c3fc93_1014 conda-forge
zstd 1.5.2 h582d3a0_0 conda-forge
pip list
Package Version
--------------- ---------
Cartopy 0.20.2
certifi 2021.10.8
cycler 0.11.0
fonttools 4.31.2
kiwisolver 1.4.0
matplotlib 3.5.1
munkres 1.1.4
numpy 1.22.3
packaging 21.3
Pillow 9.0.1
pip 22.0.4
pyparsing 3.0.7
pyproj 3.3.0
pyshp 2.2.0
python-dateutil 2.8.2
scipy 1.8.0
setuptools 61.2.0
Shapely 1.8.0
six 1.16.0
tornado 6.1
unicodedata2 14.0.0
wheel 0.37.1
I was going to make a new issue for exactly this, but it would be a duplicate so I'll try to poke this one. I've been encountering the same exact thing for quite a while, and it doesn't take the entire globe to show (nor do I have disappearing coastlines as appears to be the case above). It clearly does not have anything to do with the exact projection nor the fact that it's the southern hemisphere, as I get similar plots when using a TransverseMercator in the nothern hemisphere. I have not yet figured out what triggers the land color to fill everything.
The following code:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
def make_map(center_lat, center_lon):
radius_deg = 3
minlat, maxlat = center_lat-radius_deg, center_lat+radius_deg
minlon, maxlon = center_lon-radius_deg, center_lon+radius_deg
tm_proj = ccrs.TransverseMercator(central_longitude=center_lon,
central_latitude=center_lat)
fig, ax = plt.subplots(subplot_kw=dict(projection=tm_proj))
ax.set_extent((minlon, maxlon, minlat, maxlat), crs=ccrs.PlateCarree())
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.STATES)
ax.gridlines(draw_labels=True)
p1_lat, p1_lon = 45.556092, -122.640675 # Portland, OR
p2_lat, p2_lon = 48.422130, -123.357623 # Victoria, BC
make_map(p1_lat, p1_lon)
make_map(p2_lat, p2_lon)
plt.show()
Produces these two plots:
The one centered on Portland looks fine, the one centered on Victoria has "land" everywhere. I've tried changing the order of adding the features but that doesn't work. From my experience in the wild (I've been seeing this for a LONG time in my real-world application), it appears almost random which plots will have land everywhere and which won't.
I'm seeing this in Cartopy 0.22, no differently than in previous versions.
Update - I noticed that I do the coastlines differently in my example, so I probably would have disappearing coastlines if I just relied on the land feature's edges instead of the separate coastline feature. It looks like something isn't closing the shape somewhere, but I couldn't begin to figure out why.
Yeah, takeaway was that somehow through projection the polygon from the continent is closed "the wrong way". But just like you, I wouldn't know where to begin to debug. I gave up on this one after poking a little more.