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