11import math
22
3- import numpy as npy
4- from matplotlib . numerix import npyma as ma
3+ import numpy as np
4+ import numpy . ma as ma
55
66import matplotlib
77rcParams = matplotlib .rcParams
@@ -27,7 +27,7 @@ def __init__(self, round_to=1.0):
2727 self ._round_to = round_to
2828
2929 def __call__ (self , x , pos = None ):
30- degrees = (x / npy .pi ) * 180.0
30+ degrees = (x / np .pi ) * 180.0
3131 degrees = round (degrees / self ._round_to ) * self ._round_to
3232 # \u00b0 : degree symbol
3333 return u"%d\u00b0 " % degrees
@@ -47,8 +47,8 @@ def cla(self):
4747
4848 self .grid (rcParams ['axes.grid' ])
4949
50- Axes .set_xlim (self , - npy .pi , npy .pi )
51- Axes .set_ylim (self , - npy .pi / 2.0 , npy .pi / 2.0 )
50+ Axes .set_xlim (self , - np .pi , np .pi )
51+ Axes .set_ylim (self , - np .pi / 2.0 , np .pi / 2.0 )
5252
5353 def _set_lim_and_transforms (self ):
5454 # A (possibly non-linear) projection on the (already scaled) data
@@ -83,7 +83,7 @@ def _set_lim_and_transforms(self):
8383 Affine2D ().translate (0.0 , - 4.0 )
8484
8585 # This is the transform for latitude ticks.
86- yaxis_stretch = Affine2D ().scale (npy .pi * 2.0 , 1.0 ).translate (- npy .pi , 0.0 )
86+ yaxis_stretch = Affine2D ().scale (np .pi * 2.0 , 1.0 ).translate (- np .pi , 0.0 )
8787 yaxis_space = Affine2D ().scale (1.0 , 1.1 )
8888 self ._yaxis_transform = \
8989 yaxis_stretch + \
@@ -103,8 +103,8 @@ def _set_lim_and_transforms(self):
103103
104104 def _get_affine_transform (self ):
105105 transform = self ._get_core_transform (1 )
106- xscale , _ = transform .transform_point ((npy .pi , 0 ))
107- _ , yscale = transform .transform_point ((0 , npy .pi / 2.0 ))
106+ xscale , _ = transform .transform_point ((np .pi , 0 ))
107+ _ , yscale = transform .transform_point ((0 , np .pi / 2.0 ))
108108 return Affine2D () \
109109 .scale (0.5 / xscale , 0.5 / yscale ) \
110110 .translate (0.5 , 0.5 )
@@ -137,15 +137,15 @@ def set_yscale(self, *args, **kwargs):
137137 set_xscale = set_yscale
138138
139139 def set_xlim (self , * args , ** kwargs ):
140- Axes .set_xlim (self , - npy .pi , npy .pi )
141- Axes .set_ylim (self , - npy .pi / 2.0 , npy .pi / 2.0 )
140+ Axes .set_xlim (self , - np .pi , np .pi )
141+ Axes .set_ylim (self , - np .pi / 2.0 , np .pi / 2.0 )
142142
143143 set_ylim = set_xlim
144144
145145 def format_coord (self , long , lat ):
146146 'return a format string formatting the coordinate'
147- long = long * (180.0 / npy .pi )
148- lat = lat * (180.0 / npy .pi )
147+ long = long * (180.0 / np .pi )
148+ lat = lat * (180.0 / np .pi )
149149 if lat >= 0.0 :
150150 ns = 'N'
151151 else :
@@ -163,7 +163,7 @@ def set_longitude_grid(self, degrees):
163163 number = (360.0 / degrees ) + 1
164164 self .xaxis .set_major_locator (
165165 FixedLocator (
166- npy .linspace (- npy .pi , npy .pi , number , True )[1 :- 1 ]))
166+ np .linspace (- np .pi , np .pi , number , True )[1 :- 1 ]))
167167 self ._logitude_degrees = degrees
168168 self .xaxis .set_major_formatter (self .ThetaFormatter (degrees ))
169169
@@ -174,15 +174,15 @@ def set_latitude_grid(self, degrees):
174174 number = (180.0 / degrees ) + 1
175175 self .yaxis .set_major_locator (
176176 FixedLocator (
177- npy .linspace (- npy .pi / 2.0 , npy .pi / 2.0 , number , True )[1 :- 1 ]))
177+ np .linspace (- np .pi / 2.0 , np .pi / 2.0 , number , True )[1 :- 1 ]))
178178 self ._latitude_degrees = degrees
179179 self .yaxis .set_major_formatter (self .ThetaFormatter (degrees ))
180180
181181 def set_longitude_grid_ends (self , degrees ):
182182 """
183183 Set the latitude(s) at which to stop drawing the longitude grids.
184184 """
185- self ._longitude_cap = degrees * (npy .pi / 180.0 )
185+ self ._longitude_cap = degrees * (np .pi / 180.0 )
186186 self ._xaxis_pretransform \
187187 .clear () \
188188 .scale (1.0 , self ._longitude_cap * 2.0 ) \
@@ -238,19 +238,19 @@ def transform(self, ll):
238238
239239 # Pre-compute some values
240240 half_long = longitude / 2.0
241- cos_latitude = npy .cos (latitude )
241+ cos_latitude = np .cos (latitude )
242242
243- alpha = npy .arccos (cos_latitude * npy .cos (half_long ))
243+ alpha = np .arccos (cos_latitude * np .cos (half_long ))
244244 # Mask this array, or we'll get divide-by-zero errors
245245 alpha = ma .masked_where (alpha == 0.0 , alpha )
246246 # We want unnormalized sinc. numpy.sinc gives us normalized
247247 sinc_alpha = ma .sin (alpha ) / alpha
248248
249- x = (cos_latitude * npy .sin (half_long )) / sinc_alpha
250- y = (npy .sin (latitude ) / sinc_alpha )
249+ x = (cos_latitude * np .sin (half_long )) / sinc_alpha
250+ y = (np .sin (latitude ) / sinc_alpha )
251251 x .set_fill_value (0.0 )
252252 y .set_fill_value (0.0 )
253- return npy .concatenate ((x .filled (), y .filled ()), 1 )
253+ return np .concatenate ((x .filled (), y .filled ()), 1 )
254254 transform .__doc__ = Transform .transform .__doc__
255255
256256 transform_non_affine = transform
@@ -288,7 +288,7 @@ def inverted(self):
288288 inverted .__doc__ = Transform .inverted .__doc__
289289
290290 def __init__ (self , * args , ** kwargs ):
291- self ._longitude_cap = npy .pi / 2.0
291+ self ._longitude_cap = np .pi / 2.0
292292 GeoAxes .__init__ (self , * args , ** kwargs )
293293 self .set_aspect (0.5 , adjustable = 'box' , anchor = 'C' )
294294 self .cla ()
@@ -323,13 +323,13 @@ def transform(self, ll):
323323
324324 # Pre-compute some values
325325 half_long = longitude / 2.0
326- cos_latitude = npy .cos (latitude )
327- sqrt2 = npy .sqrt (2.0 )
326+ cos_latitude = np .cos (latitude )
327+ sqrt2 = np .sqrt (2.0 )
328328
329- alpha = 1.0 + cos_latitude * npy .cos (half_long )
330- x = (2.0 * sqrt2 ) * (cos_latitude * npy .sin (half_long )) / alpha
331- y = (sqrt2 * npy .sin (latitude )) / alpha
332- return npy .concatenate ((x , y ), 1 )
329+ alpha = 1.0 + cos_latitude * np .cos (half_long )
330+ x = (2.0 * sqrt2 ) * (cos_latitude * np .sin (half_long )) / alpha
331+ y = (sqrt2 * np .sin (latitude )) / alpha
332+ return np .concatenate ((x , y ), 1 )
333333 transform .__doc__ = Transform .transform .__doc__
334334
335335 transform_non_affine = transform
@@ -363,18 +363,18 @@ def transform(self, xy):
363363
364364 quarter_x = 0.25 * x
365365 half_y = 0.5 * y
366- z = npy .sqrt (1.0 - quarter_x * quarter_x - half_y * half_y )
367- longitude = 2 * npy .arctan ((z * x ) / (2.0 * (2.0 * z * z - 1.0 )))
368- latitude = npy .arcsin (y * z )
369- return npy .concatenate ((longitude , latitude ), 1 )
366+ z = np .sqrt (1.0 - quarter_x * quarter_x - half_y * half_y )
367+ longitude = 2 * np .arctan ((z * x ) / (2.0 * (2.0 * z * z - 1.0 )))
368+ latitude = np .arcsin (y * z )
369+ return np .concatenate ((longitude , latitude ), 1 )
370370 transform .__doc__ = Transform .transform .__doc__
371371
372372 def inverted (self ):
373373 return HammerAxes .HammerTransform (self ._resolution )
374374 inverted .__doc__ = Transform .inverted .__doc__
375375
376376 def __init__ (self , * args , ** kwargs ):
377- self ._longitude_cap = npy .pi / 2.0
377+ self ._longitude_cap = np .pi / 2.0
378378 GeoAxes .__init__ (self , * args , ** kwargs )
379379 self .set_aspect (0.5 , adjustable = 'box' , anchor = 'C' )
380380 self .cla ()
@@ -407,11 +407,11 @@ def transform(self, ll):
407407 longitude = ll [:, 0 :1 ]
408408 latitude = ll [:, 1 :2 ]
409409
410- aux = 2.0 * npy .arcsin ((2.0 * latitude ) / npy .pi )
411- x = (2.0 * npy .sqrt (2.0 ) * longitude * npy .cos (aux )) / npy .pi
412- y = (npy .sqrt (2.0 ) * npy .sin (aux ))
410+ aux = 2.0 * np .arcsin ((2.0 * latitude ) / np .pi )
411+ x = (2.0 * np .sqrt (2.0 ) * longitude * np .cos (aux )) / np .pi
412+ y = (np .sqrt (2.0 ) * np .sin (aux ))
413413
414- return npy .concatenate ((x , y ), 1 )
414+ return np .concatenate ((x , y ), 1 )
415415 transform .__doc__ = Transform .transform .__doc__
416416
417417 transform_non_affine = transform
@@ -449,7 +449,7 @@ def inverted(self):
449449 inverted .__doc__ = Transform .inverted .__doc__
450450
451451 def __init__ (self , * args , ** kwargs ):
452- self ._longitude_cap = npy .pi / 2.0
452+ self ._longitude_cap = np .pi / 2.0
453453 GeoAxes .__init__ (self , * args , ** kwargs )
454454 self .set_aspect (0.5 , adjustable = 'box' , anchor = 'C' )
455455 self .cla ()
@@ -485,22 +485,22 @@ def transform(self, ll):
485485 latitude = ll [:, 1 :2 ]
486486 clong = self ._center_longitude
487487 clat = self ._center_latitude
488- cos_lat = npy .cos (latitude )
489- sin_lat = npy .sin (latitude )
488+ cos_lat = np .cos (latitude )
489+ sin_lat = np .sin (latitude )
490490 diff_long = longitude - clong
491- cos_diff_long = npy .cos (diff_long )
491+ cos_diff_long = np .cos (diff_long )
492492
493493 inner_k = (1.0 +
494- npy .sin (clat )* sin_lat +
495- npy .cos (clat )* cos_lat * cos_diff_long )
494+ np .sin (clat )* sin_lat +
495+ np .cos (clat )* cos_lat * cos_diff_long )
496496 # Prevent divide-by-zero problems
497- inner_k = npy .where (inner_k == 0.0 , 1e-15 , inner_k )
498- k = npy .sqrt (2.0 / inner_k )
499- x = k * cos_lat * npy .sin (diff_long )
500- y = k * (npy .cos (clat )* sin_lat -
501- npy .sin (clat )* cos_lat * cos_diff_long )
497+ inner_k = np .where (inner_k == 0.0 , 1e-15 , inner_k )
498+ k = np .sqrt (2.0 / inner_k )
499+ x = k * cos_lat * np .sin (diff_long )
500+ y = k * (np .cos (clat )* sin_lat -
501+ np .sin (clat )* cos_lat * cos_diff_long )
502502
503- return npy .concatenate ((x , y ), 1 )
503+ return np .concatenate ((x , y ), 1 )
504504 transform .__doc__ = Transform .transform .__doc__
505505
506506 transform_non_affine = transform
@@ -538,18 +538,18 @@ def transform(self, xy):
538538 y = xy [:, 1 :2 ]
539539 clong = self ._center_longitude
540540 clat = self ._center_latitude
541- p = npy .sqrt (x * x + y * y )
542- p = npy .where (p == 0.0 , 1e-9 , p )
543- c = 2.0 * npy .arcsin (0.5 * p )
544- sin_c = npy .sin (c )
545- cos_c = npy .cos (c )
546-
547- lat = npy .arcsin (cos_c * npy .sin (clat ) +
548- ((y * sin_c * npy .cos (clat )) / p ))
549- long = clong + npy .arctan (
550- (x * sin_c ) / (p * npy .cos (clat )* cos_c - y * npy .sin (clat )* sin_c ))
551-
552- return npy .concatenate ((long , lat ), 1 )
541+ p = np .sqrt (x * x + y * y )
542+ p = np .where (p == 0.0 , 1e-9 , p )
543+ c = 2.0 * np .arcsin (0.5 * p )
544+ sin_c = np .sin (c )
545+ cos_c = np .cos (c )
546+
547+ lat = np .arcsin (cos_c * np .sin (clat ) +
548+ ((y * sin_c * np .cos (clat )) / p ))
549+ long = clong + np .arctan (
550+ (x * sin_c ) / (p * np .cos (clat )* cos_c - y * np .sin (clat )* sin_c ))
551+
552+ return np .concatenate ((long , lat ), 1 )
553553 transform .__doc__ = Transform .transform .__doc__
554554
555555 def inverted (self ):
@@ -560,7 +560,7 @@ def inverted(self):
560560 inverted .__doc__ = Transform .inverted .__doc__
561561
562562 def __init__ (self , * args , ** kwargs ):
563- self ._longitude_cap = npy .pi / 2.0
563+ self ._longitude_cap = np .pi / 2.0
564564 self ._center_longitude = kwargs .pop ("center_longitude" , 0.0 )
565565 self ._center_latitude = kwargs .pop ("center_latitude" , 0.0 )
566566 GeoAxes .__init__ (self , * args , ** kwargs )
0 commit comments