Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c740e6

Browse files
author
Jeff Whitaker
committed
numpification and fixes for rotate_vector (EF)
svn path=/trunk/toolkits/basemap/; revision=4042
1 parent eaa3711 commit 1c740e6

File tree

3 files changed

+63
-15
lines changed

3 files changed

+63
-15
lines changed

Changelog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
version 0.9.7 (not yet released)
2+
* fix rotate_vector so it works in S. Hem and for non-orthogonal
3+
grids (EF)
4+
* numpification (EF)
15
version 0.9.6 (svn revision 3888)
26
* fix addcyclic function so it handles masked arrays.
37
* labelling of meridians and parallels now works with

lib/matplotlib/toolkits/basemap/basemap.py

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from proj import Proj
1313
import matplotlib.numerix as NX
1414
from matplotlib.numerix import ma
15+
import numpy as npy
1516
from numpy import linspace
1617
from matplotlib.numerix.mlab import squeeze
1718
from matplotlib.cbook import popd, is_scalar
@@ -20,7 +21,7 @@
2021
# basemap data files now installed in lib/matplotlib/toolkits/basemap/data
2122
basemap_datadir = os.sep.join([os.path.dirname(__file__), 'data'])
2223

23-
__version__ = '0.9.6'
24+
__version__ = '0.9.7'
2425

2526
# test to see numerix set to use numpy (if not, raise an error)
2627
if NX.which[0] != 'numpy':
@@ -2175,13 +2176,33 @@ def transform_vector(self,uin,vin,lons,lats,nx,ny,returnxy=False,checkbounds=Fal
21752176
uin = interp(uin,lons,lats,lonsout,latsout,checkbounds=checkbounds,order=order,masked=masked)
21762177
vin = interp(vin,lons,lats,lonsout,latsout,checkbounds=checkbounds,order=order,masked=masked)
21772178
# rotate from geographic to map coordinates.
2178-
delta = 0.1 # increment in latitude used to estimate derivatives.
2179-
xn,yn = self(lonsout,NX.where(latsout+delta<90.,latsout+delta,latsout-delta))
2180-
# northangle is the angle between true north and the y axis.
2181-
northangle = NX.where(lats+delta<90, NX.arctan2(xn-x, yn-y),
2182-
NX.arctan2(x-xn, y-yn))
2183-
uout = uin*NX.cos(northangle) + vin*NX.sin(northangle)
2184-
vout = vin*NX.cos(northangle) - uin*NX.sin(northangle)
2179+
if ma.isMaskedArray(uin):
2180+
mask = ma.getmaskarray(uin)
2181+
uin = uin.filled(1)
2182+
vin = vin.filled(1)
2183+
masked = True # override kwarg with reality
2184+
uvc = uin + 1j*vin
2185+
uvmag = npy.abs(uvc)
2186+
delta = 0.1 # increment in longitude
2187+
dlon = delta*uin/uvmag
2188+
dlat = delta*(vin/uvmag)*npy.cos(latsout*npy.pi/180.0)
2189+
farnorth = latsout+dlat >= 90.0
2190+
somenorth = farnorth.any()
2191+
if somenorth:
2192+
dlon[farnorth] *= -1.0
2193+
dlat[farnorth] *= -1.0
2194+
lon1 = lonsout + dlon
2195+
lat1 = latsout + dlat
2196+
xn, yn = self(lon1, lat1)
2197+
vecangle = npy.arctan2(yn-y, xn-x)
2198+
if somenorth:
2199+
vecangle[farnorth] += npy.pi
2200+
uvcout = uvmag * npy.exp(1j*vecangle)
2201+
uout = uvcout.real
2202+
vout = uvcout.imag
2203+
if masked:
2204+
uout = ma.array(uout, mask=mask)
2205+
vout = ma.array(vout, mask=mask)
21852206
if returnxy:
21862207
return uout,vout,x,y
21872208
else:
@@ -2210,12 +2231,35 @@ def rotate_vector(self,uin,vin,lons,lats,returnxy=False):
22102231
"""
22112232
x, y = self(lons, lats)
22122233
# rotate from geographic to map coordinates.
2213-
delta = 0.1 # increment in latitude used to estimate derivatives.
2214-
xn,yn = self(lons,NX.where(lats+delta<90.,lats+delta,lats-delta))
2215-
northangle = NX.where(lats+delta<90, NX.arctan2(xn-x, yn-y),
2216-
NX.arctan2(x-xn, y-yn))
2217-
uout = uin*NX.cos(northangle) + vin*NX.sin(northangle)
2218-
vout = vin*NX.cos(northangle) - uin*NX.sin(northangle)
2234+
if ma.isMaskedArray(uin):
2235+
mask = ma.getmaskarray(uin)
2236+
masked = True
2237+
uin = uin.filled(1)
2238+
vin = vin.filled(1)
2239+
else:
2240+
masked = False
2241+
uvc = uin + 1j*vin
2242+
uvmag = npy.abs(uvc)
2243+
delta = 0.1 # increment in longitude
2244+
dlon = delta*uin/uvmag
2245+
dlat = delta*(vin/uvmag)*npy.cos(lats*npy.pi/180.0)
2246+
farnorth = lats+dlat >= 90.0
2247+
somenorth = farnorth.any()
2248+
if somenorth:
2249+
dlon[farnorth] *= -1.0
2250+
dlat[farnorth] *= -1.0
2251+
lon1 = lons + dlon
2252+
lat1 = lats + dlat
2253+
xn, yn = self(lon1, lat1)
2254+
vecangle = npy.arctan2(yn-y, xn-x)
2255+
if somenorth:
2256+
vecangle[farnorth] += npy.pi
2257+
uvcout = uvmag * npy.exp(1j*vecangle)
2258+
uout = uvcout.real
2259+
vout = uvcout.imag
2260+
if masked:
2261+
uout = ma.array(uout, mask=mask)
2262+
vout = ma.array(vout, mask=mask)
22192263
if returnxy:
22202264
return uout,vout,x,y
22212265
else:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def dbf_macros():
8888
package_data = {'matplotlib.toolkits.basemap':pyproj_datafiles+basemap_datafiles}
8989
setup(
9090
name = "basemap",
91-
version = "0.9.6",
91+
version = "0.9.7",
9292
description = "Plot data on map projections with matplotlib",
9393
long_description = """
9494
An add-on toolkit for matplotlib that lets you plot data

0 commit comments

Comments
 (0)