@@ -319,21 +319,49 @@ def __call__(self, direction, factor, values): # hour
319319
320320
321321class ExtremeFinderCycle (ExtremeFinderSimple ):
322- """
323- When there is a cycle, e.g., longitude goes from 0-360.
324- """
322+ # docstring inherited
323+
325324 def __init__ (self , nx , ny ,
326325 lon_cycle = 360. , lat_cycle = None ,
327326 lon_minmax = None , lat_minmax = (- 90 , 90 )):
327+ """
328+ This subclass handles the case where one or both coordinates should be
329+ taken modulo 360, or be restricted to not exceed a specific range.
330+
331+ Parameters
332+ ----------
333+ nx, ny : int
334+ The number of samples in each direction.
335+
336+ lon_cycle, lat_cycle : 360 or None
337+ If not None, values in the corresponding direction are taken modulo
338+ *lon_cycle* or *lat_cycle*; in theory this can be any number but
339+ the implementation actually assumes that it is 360 (if not None);
340+ other values give nonsensical results.
341+
342+ This is done by "unwrapping" the transformed grid coordinates so
343+ that jumps are less than a half-cycle; then normalizing the span to
344+ no more than a full cycle.
345+
346+ For example, if values are in the union of the [0, 2] and
347+ [358, 360] intervals (typically, angles measured modulo 360), the
348+ values in the second interval are normalized to [-2, 0] instead so
349+ that the values now cover [-2, 2]. If values are in a range of
350+ [5, 1000], this gets normalized to [5, 365].
351+
352+ lon_minmax, lat_minmax : (float, float) or None
353+ If not None, the computed bounding box is clipped to the given
354+ range in the corresponding direction.
355+ """
328356 self .nx , self .ny = nx , ny
329357 self .lon_cycle , self .lat_cycle = lon_cycle , lat_cycle
330358 self .lon_minmax = lon_minmax
331359 self .lat_minmax = lat_minmax
332360
333361 def __call__ (self , transform_xy , x1 , y1 , x2 , y2 ):
334362 # docstring inherited
335- x_ , y_ = np .linspace ( x1 , x2 , self . nx ), np . linspace ( y1 , y2 , self . ny )
336- x , y = np .meshgrid ( x_ , y_ )
363+ x , y = np .meshgrid (
364+ np . linspace ( x1 , x2 , self . nx ), np .linspace ( y1 , y2 , self . ny ) )
337365 lon , lat = transform_xy (np .ravel (x ), np .ravel (y ))
338366
339367 # iron out jumps, but algorithm should be improved.
@@ -353,13 +381,6 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
353381 lon_min , lon_max = np .nanmin (lon ), np .nanmax (lon )
354382 lat_min , lat_max = np .nanmin (lat ), np .nanmax (lat )
355383
356- lon_min , lon_max , lat_min , lat_max = \
357- self ._adjust_extremes (lon_min , lon_max , lat_min , lat_max )
358-
359- return lon_min , lon_max , lat_min , lat_max
360-
361- def _adjust_extremes (self , lon_min , lon_max , lat_min , lat_max ):
362-
363384 lon_min , lon_max , lat_min , lat_max = \
364385 self ._add_pad (lon_min , lon_max , lat_min , lat_max )
365386
0 commit comments