A :class:`cartopy.crs.Mercator` subclass that adds support for a latitude of true scale parameter. See Also: :class:`cartopy.crs.Mercator`
| 21 | |
| 22 | if cartopy_enabled(): |
| 23 | class MercatorWithLatTS(crs.Mercator): |
| 24 | """A :class:`cartopy.crs.Mercator` subclass that adds support for |
| 25 | a latitude of true scale parameter. |
| 26 | |
| 27 | See Also: |
| 28 | |
| 29 | :class:`cartopy.crs.Mercator` |
| 30 | |
| 31 | """ |
| 32 | def __init__(self, central_longitude=0.0, |
| 33 | latitude_true_scale=0.0, |
| 34 | min_latitude=-80.0, |
| 35 | max_latitude=84.0, |
| 36 | globe=None): |
| 37 | """Initialize a :class:`wrf.MercatorWithLatTS` object. |
| 38 | |
| 39 | Args: |
| 40 | |
| 41 | central_longitude (:obj:`float`, optional): The central |
| 42 | longitude. Default is 0.0. |
| 43 | |
| 44 | latitude_true_scale (:obj:`float`, optional): The latitude |
| 45 | of true scale. Default is 0.0. |
| 46 | |
| 47 | min_latitude (:obj:`float`, optional): The maximum southerly |
| 48 | extent of the projection. Default is -80.0. |
| 49 | |
| 50 | max_latitude (:obj:`float`, optional): The maximum northerly |
| 51 | extent of the projection. Default is 84.0. |
| 52 | |
| 53 | globe (:class:`cartopy.crs.Globe`, optional): A globe object. |
| 54 | If omitted, a default globe is created. |
| 55 | |
| 56 | """ |
| 57 | proj4_params = [("proj", "merc"), |
| 58 | ("lon_0", central_longitude), |
| 59 | ("lat_ts", latitude_true_scale), |
| 60 | ("k", 1), |
| 61 | ("units", "m")] |
| 62 | super(crs.Mercator, self).__init__(proj4_params, globe=globe) |
| 63 | |
| 64 | # Need to have x/y limits defined for the initial hash which |
| 65 | # gets used within transform_points for caching |
| 66 | self._x_limits = self._y_limits = None |
| 67 | |
| 68 | # Calculate limits. |
| 69 | limits = self.transform_points( |
| 70 | crs.Geodetic(), |
| 71 | np.array([-180, 180]) + central_longitude, |
| 72 | np.array([min_latitude, max_latitude])) |
| 73 | |
| 74 | # When using a latitude of true scale, the min/max x-limits get set |
| 75 | # to the same value, so make sure the left one is negative |
| 76 | xlimits = limits[..., 0] |
| 77 | |
| 78 | if math.fabs(xlimits[0] - xlimits[1]) < 1e-6: |
| 79 | if xlimits[0] < 0: |
| 80 | xlimits[1] = -xlimits[1] |