Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util.plot.get_transformation: special treatment for DEF_CRS #520

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions climada/util/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,18 +740,21 @@ def get_transformation(crs_in):

# projection
try:
if CRS.from_user_input(crs_in) == CRS.from_user_input('EPSG:3395'):
crs_epsg = ccrs.Mercator()
epsg = CRS.from_user_input(crs_in).to_epsg()
if epsg == 3395:
crs = ccrs.Mercator()
elif epsg == 4326: # WSG 84
crs = ccrs.PlateCarree()
else:
crs_epsg = ccrs.epsg(CRS.from_user_input(crs_in).to_epsg())
crs = ccrs.epsg(epsg)
except ValueError:
LOGGER.warning(
"Error parsing coordinate system '%s'. Using projection PlateCarree in plot.", crs_in
)
crs_epsg = ccrs.PlateCarree()
crs = ccrs.PlateCarree()
except requests.exceptions.ConnectionError:
LOGGER.warning('No internet connection. Using projection PlateCarree in plot.')
crs_epsg = ccrs.PlateCarree()
crs = ccrs.PlateCarree()

# units
with warnings.catch_warnings():
Expand All @@ -760,19 +763,19 @@ def get_transformation(crs_in):
# we may safely ignore it.
warnings.simplefilter(action="ignore", category=UserWarning)
try:
units = (crs_epsg.proj4_params.get('units')
units = (crs.proj4_params.get('units')
# As of cartopy 0.20 the proj4_params attribute is {} for CRS from an EPSG number
# (see issue raised https://github.com/SciTools/cartopy/issues/1974
# and longterm discussion on https://github.com/SciTools/cartopy/issues/813).
# In these cases the units can be fetched through the method `to_dict`.
or crs_epsg.to_dict().get('units', '°'))
or crs.to_dict().get('units', '°'))
except AttributeError:
# This happens in setups with cartopy<0.20, where `to_dict` is not defined.
# Officially, we require cartopy>=0.20, but there are still users around that
# can't upgrade due to https://github.com/SciTools/iris/issues/4468
units = '°'

return crs_epsg, units
return crs, units


def multibar_plot(ax, data, colors=None, total_width=0.8, single_width=1,
Expand Down