MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _get_integrator

Function _get_integrator

lib/matplotlib/streamplot.py:492–559  ·  view source on GitHub ↗
(u, v, dmap, minlength, maxlength, integration_direction)

Source from the content-addressed store, hash-verified

490# =======================
491
492def _get_integrator(u, v, dmap, minlength, maxlength, integration_direction):
493
494 # rescale velocity onto grid-coordinates for integrations.
495 u, v = dmap.data2grid(u, v)
496
497 # speed (path length) will be in axes-coordinates
498 u_ax = u / (dmap.grid.nx - 1)
499 v_ax = v / (dmap.grid.ny - 1)
500 speed = np.ma.sqrt(u_ax ** 2 + v_ax ** 2)
501
502 def forward_time(xi, yi):
503 if not dmap.grid.within_grid(xi, yi):
504 raise OutOfBounds
505 ds_dt = interpgrid(speed, xi, yi)
506 if ds_dt == 0:
507 raise TerminateTrajectory()
508 dt_ds = 1. / ds_dt
509 ui = interpgrid(u, xi, yi)
510 vi = interpgrid(v, xi, yi)
511 return ui * dt_ds, vi * dt_ds
512
513 def backward_time(xi, yi):
514 dxi, dyi = forward_time(xi, yi)
515 return -dxi, -dyi
516
517 def integrate(x0, y0, broken_streamlines=True, integration_max_step_scale=1.0,
518 integration_max_error_scale=1.0):
519 """
520 Return x, y grid-coordinates of trajectory based on starting point.
521
522 Integrate both forward and backward in time from starting point in
523 grid coordinates.
524
525 Integration is terminated when a trajectory reaches a domain boundary
526 or when it crosses into an already occupied cell in the StreamMask. The
527 resulting trajectory is None if it is shorter than `minlength`.
528 """
529
530 stotal, xy_traj = 0., []
531
532 try:
533 dmap.start_trajectory(x0, y0, broken_streamlines)
534 except InvalidIndexError:
535 return None
536 if integration_direction in ['both', 'backward']:
537 s, xyt = _integrate_rk12(x0, y0, dmap, backward_time, maxlength,
538 broken_streamlines,
539 integration_max_step_scale,
540 integration_max_error_scale)
541 stotal += s
542 xy_traj += xyt[::-1]
543
544 if integration_direction in ['both', 'forward']:
545 dmap.reset_start_point(x0, y0)
546 s, xyt = _integrate_rk12(x0, y0, dmap, forward_time, maxlength,
547 broken_streamlines,
548 integration_max_step_scale,
549 integration_max_error_scale)

Callers 1

streamplotFunction · 0.85

Calls 2

data2gridMethod · 0.80
sqrtMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…