@@ -140,8 +140,8 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
140
140
u = np .ma .masked_invalid (u )
141
141
v = np .ma .masked_invalid (v )
142
142
143
- integrate = get_integrator (u , v , dmap , minlength , maxlength ,
144
- integration_direction )
143
+ integrate = _get_integrator (u , v , dmap , minlength , maxlength ,
144
+ integration_direction )
145
145
146
146
trajectories = []
147
147
if start_points is None :
@@ -176,18 +176,14 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
176
176
if use_multicolor_lines :
177
177
if norm is None :
178
178
norm = mcolors .Normalize (color .min (), color .max ())
179
- if cmap is None :
180
- cmap = cm .get_cmap (matplotlib .rcParams ['image.cmap' ])
181
- else :
182
- cmap = cm .get_cmap (cmap )
179
+ cmap = cm .get_cmap (cmap )
183
180
184
181
streamlines = []
185
182
arrows = []
186
183
for t in trajectories :
187
- tgx = np .array (t [0 ])
188
- tgy = np .array (t [1 ])
184
+ tgx , tgy = t .T
189
185
# Rescale from grid-coordinates to data-coordinates.
190
- tx , ty = dmap .grid2data (* np . array ( t ) )
186
+ tx , ty = dmap .grid2data (tgx , tgy )
191
187
tx += grid .x_origin
192
188
ty += grid .y_origin
193
189
@@ -427,7 +423,7 @@ class TerminateTrajectory(Exception):
427
423
# Integrator definitions
428
424
# =======================
429
425
430
- def get_integrator (u , v , dmap , minlength , maxlength , integration_direction ):
426
+ def _get_integrator (u , v , dmap , minlength , maxlength , integration_direction ):
431
427
432
428
# rescale velocity onto grid-coordinates for integrations.
433
429
u , v = dmap .data2grid (u , v )
@@ -454,7 +450,7 @@ def backward_time(xi, yi):
454
450
455
451
def integrate (x0 , y0 ):
456
452
"""
457
- Return x, y grid-coordinates of trajectory based on starting point.
453
+ Return (N, 2) grid-coordinates of trajectory based on starting point.
458
454
459
455
Integrate both forward and backward in time from starting point in
460
456
grid coordinates.
@@ -464,37 +460,41 @@ def integrate(x0, y0):
464
460
resulting trajectory is None if it is shorter than `minlength`.
465
461
"""
466
462
467
- stotal , x_traj , y_traj = 0. , [] , []
463
+ stotal , xy_traj = 0. , []
468
464
469
465
try :
470
466
dmap .start_trajectory (x0 , y0 )
471
467
except InvalidIndexError :
472
468
return None
473
469
if integration_direction in ['both' , 'backward' ]:
474
- s , xt , yt = _integrate_rk12 (x0 , y0 , dmap , backward_time , maxlength )
470
+ s , xyt = _integrate_rk12 (x0 , y0 , dmap , backward_time , maxlength )
475
471
stotal += s
476
- x_traj += xt [::- 1 ]
477
- y_traj += yt [::- 1 ]
472
+ xy_traj += xyt [::- 1 ]
478
473
479
474
if integration_direction in ['both' , 'forward' ]:
480
475
dmap .reset_start_point (x0 , y0 )
481
- s , xt , yt = _integrate_rk12 (x0 , y0 , dmap , forward_time , maxlength )
482
- if len (x_traj ) > 0 :
483
- xt = xt [1 :]
484
- yt = yt [1 :]
476
+ s , xyt = _integrate_rk12 (x0 , y0 , dmap , forward_time , maxlength )
485
477
stotal += s
486
- x_traj += xt
487
- y_traj += yt
478
+ xy_traj += xyt [1 :]
488
479
489
480
if stotal > minlength :
490
- return x_traj , y_traj
481
+ return np . broadcast_arrays ( xy_traj , np . empty (( 1 , 2 )))[ 0 ]
491
482
else : # reject short trajectories
492
483
dmap .undo_trajectory ()
493
484
return None
494
485
495
486
return integrate
496
487
497
488
489
+ @_api .deprecated ("3.5" )
490
+ def get_integrator (u , v , dmap , minlength , maxlength , integration_direction ):
491
+ xy_traj = _get_integrator (
492
+ u , v , dmap , minlength , maxlength , integration_direction )
493
+ return (None if xy_traj is None
494
+ else ([], []) if not len (xy_traj )
495
+ else [* zip (* xy_traj )])
496
+
497
+
498
498
class OutOfBounds (IndexError ):
499
499
pass
500
500
@@ -539,14 +539,12 @@ def _integrate_rk12(x0, y0, dmap, f, maxlength):
539
539
stotal = 0
540
540
xi = x0
541
541
yi = y0
542
- xf_traj = []
543
- yf_traj = []
542
+ xyf_traj = []
544
543
545
544
while True :
546
545
try :
547
546
if dmap .grid .within_grid (xi , yi ):
548
- xf_traj .append (xi )
549
- yf_traj .append (yi )
547
+ xyf_traj .append ((xi , yi ))
550
548
else :
551
549
raise OutOfBounds
552
550
@@ -560,9 +558,8 @@ def _integrate_rk12(x0, y0, dmap, f, maxlength):
560
558
# Out of the domain during this step.
561
559
# Take an Euler step to the boundary to improve neatness
562
560
# unless the trajectory is currently empty.
563
- if xf_traj :
564
- ds , xf_traj , yf_traj = _euler_step (xf_traj , yf_traj ,
565
- dmap , f )
561
+ if xyf_traj :
562
+ ds , xyf_traj = _euler_step (xyf_traj , dmap , f )
566
563
stotal += ds
567
564
break
568
565
except TerminateTrajectory :
@@ -595,14 +592,13 @@ def _integrate_rk12(x0, y0, dmap, f, maxlength):
595
592
else :
596
593
ds = min (maxds , 0.85 * ds * (maxerror / error ) ** 0.5 )
597
594
598
- return stotal , xf_traj , yf_traj
595
+ return stotal , xyf_traj
599
596
600
597
601
- def _euler_step (xf_traj , yf_traj , dmap , f ):
598
+ def _euler_step (xyf_traj , dmap , f ):
602
599
"""Simple Euler integration step that extends streamline to boundary."""
603
600
ny , nx = dmap .grid .shape
604
- xi = xf_traj [- 1 ]
605
- yi = yf_traj [- 1 ]
601
+ xi , yi = xyf_traj [- 1 ]
606
602
cx , cy = f (xi , yi )
607
603
if cx == 0 :
608
604
dsx = np .inf
@@ -617,9 +613,8 @@ def _euler_step(xf_traj, yf_traj, dmap, f):
617
613
else :
618
614
dsy = (ny - 1 - yi ) / cy
619
615
ds = min (dsx , dsy )
620
- xf_traj .append (xi + cx * ds )
621
- yf_traj .append (yi + cy * ds )
622
- return ds , xf_traj , yf_traj
616
+ xyf_traj .append ((xi + cx * ds , yi + cy * ds ))
617
+ return ds , xyf_traj
623
618
624
619
625
620
# Utility functions
0 commit comments