Skip to content

Commit e00e512

Browse files
tomflannaghantacaswell
authored andcommitted
Improve the OutOfBounds logic in the integration.
Moves the raising to the gradient steps simplifying the integrator code a bit. Also makes OutOfBounds inherit from IndexError as suggested by tacaswell.
1 parent f924361 commit e00e512

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/matplotlib/streamplot.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ def get_integrator(u, v, dmap, minlength, maxlength, integration_direction):
426426
speed = np.ma.sqrt(u_ax ** 2 + v_ax ** 2)
427427

428428
def forward_time(xi, yi):
429+
if not dmap.grid.within_grid(xi, yi):
430+
raise OutOfBounds
429431
ds_dt = interpgrid(speed, xi, yi)
430432
if ds_dt == 0:
431433
raise TerminateTrajectory()
@@ -480,7 +482,7 @@ def integrate(x0, y0):
480482
return integrate
481483

482484

483-
class OutOfBounds(Exception):
485+
class OutOfBounds(IndexError):
484486
pass
485487

486488

@@ -535,13 +537,11 @@ def _integrate_rk12(x0, y0, dmap, f, maxlength):
535537
else:
536538
raise OutOfBounds
537539

540+
# Compute the two intermediate gradients.
541+
# f should raise OutOfBounds if the locations given are
542+
# outside the grid.
538543
k1x, k1y = f(xi, yi)
539-
540-
if dmap.grid.within_grid(xi + ds * k1x, yi + ds * k1y):
541-
k2x, k2y = f(xi + ds * k1x,
542-
yi + ds * k1y)
543-
else:
544-
raise OutOfBounds
544+
k2x, k2y = f(xi + ds * k1x, yi + ds * k1y)
545545

546546
except OutOfBounds:
547547
# Out of the domain during this step.
@@ -667,7 +667,6 @@ def _gen_starting_points(shape):
667667
x, y = 0, 0
668668
direction = 'right'
669669
for i in range(nx * ny):
670-
671670
yield x, y
672671

673672
if direction == 'right':

0 commit comments

Comments
 (0)