@@ -503,13 +503,19 @@ def __init__(self, llcrnrlon=None, llcrnrlat=None,
503
503
if lat_2 is None :
504
504
projparams ['lat_2' ] = lat_1
505
505
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
513
519
elif projection == 'stere' :
514
520
if lat_0 is None or lon_0 is None :
515
521
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):
4068
4074
else :
4069
4075
return corners
4070
4076
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
+
4071
4092
def maskoceans (lonsin ,latsin ,datain ,inlands = True ,resolution = 'l' ,grid = 5 ):
4072
4093
"""
4073
4094
mask data (``datain``), defined on a grid with latitudes ``latsin``
0 commit comments