Closed honnorat closed 6 years ago
Cartopy 0.17 support latitude_true_scale
in Mercator
, so something like:
if cartopy.__version__ >= '0.17':
class MercatorWithLatTS(ccrs.Mercator):
pass
else:
class MercatorWithLatTS(ccrs.Mercator):
# The old implementation
should work.
Ok, thanks. PR #78 proposes a quick fix to make wrf-python 0.17 usable with cartopy 0.17.
But beyond that, what is the purpose of MercatorWithLatTS
? What does this class do that ccrs.Mercator
doesn't ?
Thanks for the bug report. This was originally written before ccrs.Mercator supported latitude_true_scale. However, there's an additional problem that it fixes. For one of my Mercator test files, the minimum and maximum xlimits get calculated to the same values, which causes a crash when plotting. I'll have to see if this is still an issue before merging the PR. If it is, I'll submit a fix for it and close the PR.
The following example illustrates the problem, and it doesn't look like the new cartopy addresses it:
from cartopy.crs import Mercator, Globe
import numpy as np
stand_lon = np.float32(143.63)
truelat1 = np.float32(39.694)
m = Mercator(central_longitude=stand_lon,
latitude_true_scale=truelat1,
globe=Globe(ellipse=None, semimajor_axis=6370000,
semiminor_axis=6370000.))
print(m._x_limits)
This prints:
(-15398519.86417731, -15398519.864185866)
These values are invalid for plotting.
For reference, if you create the default Mercator, you get:
(-20037508.342789244, 20037508.342789244)
This is why the MercatorWithLatTS has the sign flipping. It looks like this is still needed.
I just looked at your PR, and it should be fine, so I'll go ahead and merge. Thanks!
Using
cartopy 0.17
, it is no longer possible to usewrf.get_cartopy()
on a Mercator grid with non-zero true latitudeThe culprit is https://github.com/SciTools/cartopy/commit/9dce9084b67f30f94d8d878ff508a45f69fecd3b (included in v0.17), where @QuLogic changed internal variable
cartopy.crs.Mercator._xlimits
tocartopy.crs.Mercator._x_limits
. HenceMercatorWithLatTS
is broken since it modifies this internal state.I do not see any clean solution to change
MercatorWithLatTS
while still being compatible withcartopy <= 0.16
andcartopy == 0.17
.