Skip to content

Commit f442857

Browse files
committed
Adding newer version of code
1 parent 7c2ae70 commit f442857

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,19 @@ def __init__(self, llcrnrlon=None, llcrnrlat=None,
503503
if lat_2 is None:
504504
projparams['lat_2'] = lat_1
505505
if not using_corners:
506-
if width is None or height is None:
507-
raise ValueError('must either specify lat/lon values of corners (llcrnrlon,llcrnrlat,ucrnrlon,urcrnrlat) in degrees or width and height in meters')
508-
if lon_0 is None or lat_0 is None:
509-
raise ValueError('must specify lon_0 and lat_0 when using width, height to specify projection region')
510-
llcrnrlon,llcrnrlat,urcrnrlon,urcrnrlat = _choosecorners(width,height,**projparams)
511-
self.llcrnrlon = llcrnrlon; self.llcrnrlat = llcrnrlat
512-
self.urcrnrlon = urcrnrlon; self.urcrnrlat = urcrnrlat
506+
using_cornersxy = (None not in [llcrnrx,llcrnry,urcrnrx,urcrnry])
507+
if using_cornersxy:
508+
llcrnrlon,llcrnrlat,urcrnrlon,urcrnrlat = _choosecornersllur(llcrnrx,llcrnry,urcrnrx,urcrnry,**projparams)
509+
self.llcrnrlon = llcrnrlon; self.llcrnrlat = llcrnrlat
510+
self.urcrnrlon = urcrnrlon; self.urcrnrlat = urcrnrlat
511+
else:
512+
if width is None or height is None:
513+
raise ValueError('must either specify lat/lon values of corners (llcrnrlon,llcrnrlat,ucrnrlon,urcrnrlat) in degrees or width and height in meters')
514+
if lon_0 is None or lat_0 is None:
515+
raise ValueError('must specify lon_0 and lat_0 when using width, height to specify projection region')
516+
llcrnrlon,llcrnrlat,urcrnrlon,urcrnrlat = _choosecorners(width,height,**projparams)
517+
self.llcrnrlon = llcrnrlon; self.llcrnrlat = llcrnrlat
518+
self.urcrnrlon = urcrnrlon; self.urcrnrlat = urcrnrlat
513519
elif projection == 'stere':
514520
if lat_0 is None or lon_0 is None:
515521
raise ValueError('must specify lat_0 and lon_0 for Stereographic basemap (lat_ts is optional)')
@@ -4068,6 +4074,21 @@ def _choosecorners(width,height,**kwargs):
40684074
else:
40694075
return corners
40704076

4077+
def _choosecornersllur(llcrnrx, llcrnry, urcrnrx, urcrnry,**kwargs):
4078+
"""
4079+
private function to determine lat/lon values of projection region corners,
4080+
given width and height of projection region in meters.
4081+
"""
4082+
p = pyproj.Proj(kwargs)
4083+
urcrnrlon, urcrnrlat = p(urcrnrx, urcrnry, inverse=True)
4084+
llcrnrlon, llcrnrlat = p(llcrnrx, llcrnry, inverse=True)
4085+
corners = llcrnrlon,llcrnrlat,urcrnrlon,urcrnrlat
4086+
# test for invalid projection points on output
4087+
if llcrnrlon > 1.e20 or urcrnrlon > 1.e20:
4088+
raise ValueError('width and/or height too large for this projection, try smaller values')
4089+
else:
4090+
return corners
4091+
40714092
def maskoceans(lonsin,latsin,datain,inlands=True,resolution='l',grid=5):
40724093
"""
40734094
mask data (``datain``), defined on a grid with latitudes ``latsin``

0 commit comments

Comments
 (0)