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