|
12 | 12 | from proj import Proj
|
13 | 13 | import matplotlib.numerix as NX
|
14 | 14 | from matplotlib.numerix import ma
|
| 15 | +import numpy as npy |
15 | 16 | from numpy import linspace
|
16 | 17 | from matplotlib.numerix.mlab import squeeze
|
17 | 18 | from matplotlib.cbook import popd, is_scalar
|
|
20 | 21 | # basemap data files now installed in lib/matplotlib/toolkits/basemap/data
|
21 | 22 | basemap_datadir = os.sep.join([os.path.dirname(__file__), 'data'])
|
22 | 23 |
|
23 |
| -__version__ = '0.9.6' |
| 24 | +__version__ = '0.9.7' |
24 | 25 |
|
25 | 26 | # test to see numerix set to use numpy (if not, raise an error)
|
26 | 27 | if NX.which[0] != 'numpy':
|
@@ -2175,13 +2176,33 @@ def transform_vector(self,uin,vin,lons,lats,nx,ny,returnxy=False,checkbounds=Fal
|
2175 | 2176 | uin = interp(uin,lons,lats,lonsout,latsout,checkbounds=checkbounds,order=order,masked=masked)
|
2176 | 2177 | vin = interp(vin,lons,lats,lonsout,latsout,checkbounds=checkbounds,order=order,masked=masked)
|
2177 | 2178 | # 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) |
2185 | 2206 | if returnxy:
|
2186 | 2207 | return uout,vout,x,y
|
2187 | 2208 | else:
|
@@ -2210,12 +2231,35 @@ def rotate_vector(self,uin,vin,lons,lats,returnxy=False):
|
2210 | 2231 | """
|
2211 | 2232 | x, y = self(lons, lats)
|
2212 | 2233 | # 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) |
2219 | 2263 | if returnxy:
|
2220 | 2264 | return uout,vout,x,y
|
2221 | 2265 | else:
|
|
0 commit comments