ó
    {ñ:iË]  ã                   ó  • S r SSKrSSKrSSKJrJrJr  SSKJ	r
  SSKJr  SSKJr  S/r     SS jr " S S5      r " S S	5      r " S
 S5      r " S S5      r " S S\5      r " S S\5      rS r " S S\5      rSS jrS rS rS r g)z,
Streamline plotting for 2D vector fields.

é    N)Ú_apiÚcmÚpatchesÚ
streamplotc           	      ó¨  • [        X5      n[        U5      n[        UU5      nUc  [        R                  R
                  nUc  U R                  nUc  U R                  R                  5       nUc  [        R                  S   n0 n[        USU
-  S9n[        R                  " / SQUS9  US:X  a  US-  n[        U[        R                   5      nU(       aH  UR"                  UR"                  :w  a  [%        S	5      e/ /n[        R&                  R)                  U5      nO
UUS
'   UUS
'   [        U[        R                   5      (       a+  UR"                  UR"                  :w  a  [%        S5      e/ US'   O
UUS'   UUS'   UUS'   UUS'   UR"                  UR"                  :w  d  UR"                  UR"                  :w  a  [%        S5      e[        R&                  R)                  U5      n[        R&                  R)                  U5      n[+        X4UUUU5      n/ nUcc  [-        UR"                  5       HH  u  nnUUU4   S:X  d  M  UR/                  UU5      u  nnU" UUU5      n U c  M7  UR1                  U 5        MJ     GOg[        R2                  " U[4        S9R7                  5       n!U! Hy  u  n"n#UR8                  U"s=::  a  UR8                  UR:                  -   ::  a5  O  O2UR<                  U#s=::  a  UR<                  UR>                  -   ::  a  Mg  O  [%        SU" SU# S35      e   U!SS2S4==   UR8                  -  ss'   U!SS2S4==   UR<                  -  ss'   U! H…  u  n"n#URA                  U"U#5      u  nn[        RB                  " USURD                  S-
  5      n[        RB                  " USURF                  S-
  5      nU" UUU5      n U c  Mt  UR1                  U 5        M‡     U(       aL  U	c3  [H        RJ                  " URM                  5       URO                  5       5      n	[P        RR                  " U5      n/ n$/ n%U GHP  n U RT                  u  n&n'URW                  U&U'5      u  n(n)U(UR8                  -  n(U)UR<                  -  n)[        U[        R                   5      (       d  U(       aW  [        RX                  " U(U)/5      R[                  SSS5      n*U$R]                  [        R^                  " U*SS U*SS /5      5        O)[        RX                  " U(U)/5      n*U$R1                  U*5        [        R`                  " [        Rb                  " [        Rd                  " U(5      [        Rd                  " U)5      5      5      n+[        Rf                  " U+U+S   S-  5      n,U(U,   U)U,   4n-[        Rh                  " U(U,U,S-    5      [        Rh                  " U)U,U,S-    5      4n.[        U[        R                   5      (       a,  [k        UU&U'5      SS n/US   R]                  U/5        U/U,   US'   U(       a5  [k        UU&U'5      SS n0WR1                  U05        U" U	" U0U,   5      5      US
'   [l        Rn                  " U-U.4SU0UD6n1U%R1                  U15        GMS     [p        Rr                  " U$4SU0UD6n2UR8                  UR8                  UR:                  -   /U2Rt                  Rv                  SS& UR<                  UR<                  UR>                  -   /U2Rt                  Rx                  SS& U(       aP  U2R{                  [        R&                  R_                  W5      5        U2R}                  U5        U2R                  U	5        U R�                  U25        [p        R‚                  " U%5      n3U% H  n1U R…                  U15        M     U R‡                  5         [‰        U2U35      n4U4$ )a½
  
Draw streamlines of a vector flow.

Parameters
----------
x, y : 1D/2D arrays
    Evenly spaced strictly increasing arrays to make a grid.  If 2D, all
    rows of *x* must be equal and all columns of *y* must be equal; i.e.,
    they must be as if generated by ``np.meshgrid(x_1d, y_1d)``.
u, v : 2D arrays
    *x* and *y*-velocities. The number of rows and columns must match
    the length of *y* and *x*, respectively.
density : float or (float, float)
    Controls the closeness of streamlines. When ``density = 1``, the domain
    is divided into a 30x30 grid. *density* linearly scales this grid.
    Each cell in the grid can have, at most, one traversing streamline.
    For different densities in each direction, use a tuple
    (density_x, density_y).
linewidth : float or 2D array
    The width of the streamlines. With a 2D array the line width can be
    varied across the grid. The array must have the same shape as *u*
    and *v*.
color : :mpltype:`color` or 2D array
    The streamline color. If given an array, its values are converted to
    colors using *cmap* and *norm*.  The array must have the same shape
    as *u* and *v*.
cmap, norm
    Data normalization and colormapping parameters for *color*; only used
    if *color* is an array of floats. See `~.Axes.imshow` for a detailed
    description.
arrowsize : float
    Scaling factor for the arrow size.
arrowstyle : str
    Arrow style specification.
    See `~matplotlib.patches.FancyArrowPatch`.
minlength : float
    Minimum length of streamline in axes coordinates.
start_points : (N, 2) array
    Coordinates of starting points for the streamlines in data coordinates
    (the same coordinates as the *x* and *y* arrays).
zorder : float
    The zorder of the streamlines and arrows.
    Artists with lower zorder values are drawn first.
maxlength : float
    Maximum length of streamline in axes coordinates.
integration_direction : {'forward', 'backward', 'both'}, default: 'both'
    Integrate the streamline in forward, backward or both directions.
data : indexable object, optional
    DATA_PARAMETER_PLACEHOLDER
broken_streamlines : boolean, default: True
    If False, forces streamlines to continue until they
    leave the plot domain.  If True, they may be terminated if they
    come too close to another streamline.

Returns
-------
StreamplotSet
    Container object with attributes

    - ``lines``: `.LineCollection` of streamlines

    - ``arrows``: `.PatchCollection` containing `.FancyArrowPatch`
      objects representing the arrows half-way along streamlines.

    This container will probably change in the future to allow changes
    to the colormap, alpha, etc. for both lines and arrows, but these
    changes should be backward compatible.
Nzlines.linewidthé
   )Ú
arrowstyleÚmutation_scale)ÚbothÚforwardÚbackward)Úintegration_directionr   g       @z?If 'color' is given, it must match the shape of the (x, y) gridÚcolorzCIf 'linewidth' is given, it must match the shape of the (x, y) gridÚ	linewidthÚzorderz3'u' and 'v' must match the shape of the (x, y) gridr   )ÚdtypezStarting point (z, z) outside of data boundariesé   éÿÿÿÿé   Ú	transform)EÚGridÚ
StreamMaskÚ	DomainMapÚmlinesÚLine2Dr   Ú	transDataÚ
_get_linesÚget_next_colorÚmplÚrcParamsÚdictr   Úcheck_in_listÚ
isinstanceÚnpÚndarrayÚshapeÚ
ValueErrorÚmaÚmasked_invalidÚ_get_integratorÚ_gen_starting_pointsÚ	mask2gridÚappendÚ
asanyarrayÚfloatÚcopyÚx_originÚwidthÚy_originÚheightÚ	data2gridÚclipÚnxÚnyÚmcolorsÚ	NormalizeÚminÚmaxr   Ú_ensure_cmapÚTÚ	grid2dataÚ	transposeÚreshapeÚextendÚhstackÚcumsumÚhypotÚdiffÚsearchsortedÚmeanÚ
interpgridr   ÚFancyArrowPatchÚmcollectionsÚLineCollectionÚsticky_edgesÚxÚyÚ	set_arrayÚset_cmapÚset_normÚadd_collectionÚPatchCollectionÚ	add_patchÚautoscale_viewÚStreamplotSet)5ÚaxesrN   rO   ÚuÚvÚdensityr   r   ÚcmapÚnormÚ	arrowsizer	   Ú	minlengthr   r   Ústart_pointsÚ	maxlengthr   Úbroken_streamlinesÚgridÚmaskÚdmapÚline_kwÚarrow_kwÚuse_multicolor_linesÚline_colorsÚ	integrateÚtrajectoriesÚxmÚymÚxgÚygÚtÚsp2ÚxsÚysÚstreamlinesÚarrowsÚtgxÚtgyÚtxÚtyÚpointsÚsÚnÚ
arrow_tailÚ
arrow_headÚline_widthsÚcolor_valuesÚpÚlcÚacÚstream_containers5                                                        ÚX/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/matplotlib/streamplot.pyr   r      sÊ  € ôR �‹:€DÜ�gÓ€DÜ�T˜4Ó €Dà�~Ü—‘×%Ñ%ˆð ÑØ—N‘Nˆ	à�}Ø—‘×.Ñ.Ó0ˆàÑÜ—L‘LÐ!2Ñ3ˆ	à€GÜ˜z¸"¸y¹.ÑI€Hä×ÒÒ6Ø-BòDð  Ó&Ø�R‰ˆ	ä% e¬R¯Z©ZÓ8ÐÞØ�;‰;˜$Ÿ*™*Ó$Üð /ó 0ð 0à�dˆÜ—‘×$Ñ$ UÓ+‰à ˆ�ÑØ!ˆ�Ñä�)œRŸZ™Z×(Ñ(Ø�?‰?˜dŸj™jÓ(Üð 8ó 9ð 9à!ˆ�Òà(ˆ�ÑØ )ˆ�Ñà€GˆHÑØ€HˆXÑð 	‡w�w�$—*‘*Ó §¡¨4¯:©:Ó 5ÜÐNÓOÐOä
�‰×Ñ˜QÓ€AÜ
�‰×Ñ˜QÓ€Aä  d¨I°yØ 5ó7€Ið €LØÑÜ*¨4¯:©:Ö6‰FˆB�Ø�B˜�F‰|˜qÕ ØŸ™¨¨BÓ/‘��BÙ˜b "Ð&8Ó9�Ø“=Ø ×'Ñ'¨Ö*ó 7ô �mŠm˜L´Ñ6×;Ñ;Ó=ˆó ‰FˆB�Ø—M‘M RÕE¨4¯=©=¸4¿:¹:Ñ+EÖEØ—M‘M RÕF¨4¯=©=¸4¿;¹;Ñ+F×FÜ Ð#3°B°4°r¸"¸ð >3ð "3ó 4ð 4ñ ð 	ŠAˆqˆD‹	�T—]‘]Ñ"‹	ØŠAˆqˆD‹	�T—]‘]Ñ"‹	ã‰FˆB�Ø—^‘^ B¨Ó+‰FˆB�ô
 —’˜˜Q §¡¨!¡Ó,ˆBÜ—’˜˜Q §¡¨!¡Ó,ˆBá˜"˜bÐ"4Ó5ˆAØ‹}Ø×#Ñ# AÖ&ñ ö Ø‰<Ü×$Ò$ U§Y¡Y£[°%·)±)³+Ó>ˆDÜ�Š˜tÓ$ˆà€KØ€FÜˆØ—3‘3‰ˆˆSà—‘  SÓ)‰ˆˆBØ
ˆd�m‰mÑˆØ
ˆd�m‰mÑˆô �i¤§¡×,Ñ,Ö0DÜ—\’\ 2 r (Ó+×3Ñ3°B¸¸1Ó=ˆFØ×ÑœrŸyšy¨&°°"¨+°v¸a¸b°zÐ)BÓCÕDä—\’\ 2 r (Ó+ˆFØ×Ñ˜vÔ&ô �IŠI”b—h’hœrŸwšw r›{¬B¯GªG°B«KÓ8Ó9ˆÜ�OŠO˜A˜q ™u r™zÓ*ˆØ˜‘e˜R ™U�^ˆ
Ü—g’g˜b  1 q¡5˜kÓ*¬B¯GªG°B°q¸¸Q¹°KÓ,@ÐAˆ
ä�i¤§¡×,Ñ,Ü$ Y°°SÓ9¸#¸2Ð>ˆKØ�KÑ ×'Ñ'¨Ô4Ø$/°¡NˆH�[Ñ!æÜ% e¨S°#Ó6°s¸Ð;ˆLØ×Ñ˜|Ô,Ù $¡T¨,°q©/Ó%:Ó ;ˆH�WÑä×#Ò#Ø˜
ñEØ.7ðEØ;CñEˆà�‰�a×ñC ôF 
×	$Ò	$Øñ
5Ø(ð
5Ø,3ñ
5€Bà ŸM™M¨4¯=©=¸4¿:¹:Ñ+EÐF€B‡O�O×Ñ‘aÐØ ŸM™M¨4¯=©=¸4¿;¹;Ñ+FÐG€B‡O�O×Ñ‘aÐÞØ
�‰”R—U‘U—\‘\ +Ó.Ô/Ø
�‰�DÔØ
�‰�DÔØ×Ñ˜Ôä	×	%Ò	% fÓ	-€BãˆØ�‰�qÖñ ð 	×ÑÔÜ$ R¨Ó,ÐØÐó    c                   ó   • \ rS rSrS rSrg)rW   éù   c                 ó   • Xl         X l        g ©N)Úlinesru   )Úselfr‹   ru   s      r…   Ú__init__ÚStreamplotSet.__init__û   s   € ØŒ
Ø�r†   )ru   r‹   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r�   Ú__static_attributes__© r†   r…   rW   rW   ù   s   † õr†   rW   c                   óV   • \ rS rSrSrS rS rS rS rS r	SS jr
S	 rSS
 jrS rSrg)r   i  aà  
Map representing different coordinate systems.

Coordinate definitions:

* axes-coordinates goes from 0 to 1 in the domain.
* data-coordinates are specified by the input x-y coordinates.
* grid-coordinates goes from 0 to N and 0 to M for an N x M grid,
  where N and M match the shape of the input data.
* mask-coordinates goes from 0 to N and 0 to M for an N x M mask,
  where N and M are user-specified to control the density of streamlines.

This class also has methods for adding trajectories to the StreamMask.
Before adding a trajectory, run `start_trajectory` to keep track of regions
crossed by a given trajectory. Later, if you decide the trajectory is bad
(e.g., if the trajectory is very short) just call `undo_trajectory`.
c                 óL  • Xl         X l        UR                  S-
  UR                  S-
  -  U l        UR                  S-
  UR                  S-
  -  U l        SU R                  -  U l        SU R
                  -  U l        SUR                  -  U l	        SUR                  -  U l        g )Nr   ç      ð?)rc   rd   r7   Úx_grid2maskr8   Úy_grid2maskÚx_mask2gridÚy_mask2gridÚdxÚx_data2gridÚdyÚy_data2grid)rŒ   rc   rd   s      r…   r�   ÚDomainMap.__init__  sŒ   € ØŒ	ØŒ	à ŸG™G a™K¨D¯G©G°a©KÑ8ˆÔØ ŸG™G a™K¨D¯G©G°a©KÑ8ˆÔà × 0Ñ 0Ñ0ˆÔØ × 0Ñ 0Ñ0ˆÔà §¡™<ˆÔØ §¡™<ˆÕr†   c                 ó^   • [        XR                  -  5      [        X R                  -  5      4$ )z;Return nearest space in mask-coords from given grid-coords.)Úroundr˜   r™   ©rŒ   ÚxiÚyis      r…   Ú	grid2maskÚDomainMap.grid2mask#  s)   € ä�R×*Ñ*Ñ*Ó+¬U°2×8HÑ8HÑ3HÓ-IÐIÐIr†   c                 ó:   • XR                   -  X R                  -  4$ rŠ   )rš   r›   )rŒ   rl   rm   s      r…   r,   ÚDomainMap.mask2grid'  ó   € Ø×$Ñ$Ñ$ b×+;Ñ+;Ñ&;Ð;Ð;r†   c                 ó:   • XR                   -  X R                  -  4$ rŠ   ©r�   rŸ   )rŒ   ÚxdÚyds      r…   r5   ÚDomainMap.data2grid*  rª   r†   c                 ó:   • XR                   -  X R                  -  4$ rŠ   r¬   )rŒ   rn   ro   s      r…   r?   ÚDomainMap.grid2data-  rª   r†   c                 ób   • U R                  X5      u  pEU R                  R                  XEU5        g rŠ   )r¦   rd   Ú_start_trajectory©rŒ   rn   ro   rb   rl   rm   s         r…   Ústart_trajectoryÚDomainMap.start_trajectory0  s'   € Ø—‘ Ó'‰ˆØ�	‰	×#Ñ# BÐ,>Õ?r†   c                 óN   • U R                  X5      u  p4X44U R                  l        g rŠ   )r¦   rd   Ú_current_xy)rŒ   rn   ro   rl   rm   s        r…   Úreset_start_pointÚDomainMap.reset_start_point4  s    € Ø—‘ Ó'‰ˆØ!# ˆ�	‰	Õr†   c                 ó®   • U R                   R                  X5      (       d  [        eU R                  X5      u  pEU R                  R                  XEU5        g rŠ   )rc   Úwithin_gridÚInvalidIndexErrorr¦   rd   Ú_update_trajectoryr´   s         r…   Úupdate_trajectoryÚDomainMap.update_trajectory8  sB   € Ø�y‰y×$Ñ$ R×,Ñ,Ü#Ð#Ø—‘ Ó'‰ˆØ�	‰	×$Ñ$ RÐ-?Õ@r†   c                 ó8   • U R                   R                  5         g rŠ   )rd   Ú_undo_trajectory©rŒ   s    r…   Úundo_trajectoryÚDomainMap.undo_trajectory>  s   € Ø�	‰	×"Ñ"Õ$r†   )rc   rd   r�   r˜   rš   rŸ   r™   r›   N©T)r�   r�   r‘   r’   Ú__doc__r�   r¦   r,   r5   r?   rµ   r¹   r¿   rÄ   r“   r”   r†   r…   r   r     s7   † ñò$(òJò<ò<ò<ô@ò)ôAõ%r†   r   c                   ó4   • \ rS rSrSrS r\S 5       rS rSr	g)r   iB  zGrid of data.c                 ó   • [         R                  " U5      S:X  a  OS[         R                  " U5      S:X  a.  US   n[         R                  " X15      (       d  [        S5      eUnO[        S5      e[         R                  " U5      S:X  a  Oi[         R                  " U5      S:X  aD  [         R                  " U5      nUS   n[         R                  " XT5      (       d  [        S5      eUnO[        S5      e[         R
                  " U5      S:„  R                  5       (       d  [        S5      e[         R
                  " U5      S:„  R                  5       (       d  [        S	5      e[        U5      U l        [        U5      U l	        US   US   -
  U l
        US   US   -
  U l        US   U l        US   U l        US
   US   -
  U l        US
   US   -
  U l        [         R                  " [         R
                  " U5      U R                  U R                  S-
  -  5      (       d  [        S5      e[         R                  " [         R
                  " U5      U R                  U R                  S-
  -  5      (       d  [        S5      eg )Nr   r   r   zThe rows of 'x' must be equalz$'x' can have at maximum 2 dimensionsz The columns of 'y' must be equalz$'y' can have at maximum 2 dimensionsz'x' must be strictly increasingz'y' must be strictly increasingr   z!'x' values must be equally spacedz!'y' values must be equally spaced)r$   ÚndimÚallcloser'   r@   rF   ÚallÚlenr7   r8   rœ   rž   r1   r3   r2   r4   )rŒ   rN   rO   Úx_rowÚytÚy_cols         r…   r�   ÚGrid.__init__D  só  € ä�7Š7�1‹:˜‹?ØÜ�WŠW�Q‹Z˜1‹_Ø�a‘DˆEÜ—;’;˜u×(Ñ(Ü Ð!@ÓAÐAØ‰AäÐCÓDÐDä�7Š7�1‹:˜‹?ØÜ�WŠW�Q‹Z˜1‹_Ü—’˜a“ˆBØ�q‘EˆEÜ—;’;˜u×)Ñ)Ü Ð!CÓDÐDØ‰AäÐCÓDÐDä—’˜“
˜Q‘×#Ñ#×%Ñ%ÜÐ>Ó?Ð?Ü—’˜“
˜Q‘×#Ñ#×%Ñ%ÜÐ>Ó?Ð?ä�a“&ˆŒÜ�a“&ˆŒà�A‘$˜˜1™‘+ˆŒØ�A‘$˜˜1™‘+ˆŒà˜!™ˆŒØ˜!™ˆŒà�r‘U˜Q˜q™T‘\ˆŒ
Ø˜‘e˜a ™d‘lˆŒä�{Š{œ2Ÿ7š7 1›: t§z¡z°T·W±W¸q±[Ñ'A×BÑBÜÐ@ÓAÐAÜ�{Š{œ2Ÿ7š7 1›: t§{¡{°d·g±gÀ±kÑ'B×CÑCÜÐ@ÓAÐAð Dr†   c                 ó2   • U R                   U R                  4$ rŠ   )r8   r7   rÃ   s    r…   r&   Ú
Grid.shapeq  s   € à�w‰w˜Ÿ™ÐÐr†   c                 ó˜   • SUs=:*  =(       a    U R                   S-
  :*  Os  =(       a"    SUs=:*  =(       a    U R                  S-
  :*  $ s  $ )z9Return whether (*xi*, *yi*) is a valid index of the grid.r   r   )r7   r8   r£   s      r…   r¼   ÚGrid.within_gridu  s?   € ð �B×%Ó%˜$Ÿ'™' A™+Ô%×@¨!¨r×*@Ó*@°T·W±W¸q±[Ñ*@Ð@Ñ*@Ð@r†   )rœ   rž   r4   r7   r8   r2   r1   r3   N)
r�   r�   r‘   r’   rÇ   r�   Úpropertyr&   r¼   r“   r”   r†   r…   r   r   B  s&   † Ùò+BðZ ñ ó ð õAr†   r   c                   ó>   • \ rS rSrSrS rS rS
S jrS rS
S jr	Sr
g	)r   i|  a6  
Mask to keep track of discrete regions crossed by streamlines.

The resolution of this grid determines the approximate spacing between
trajectories. Streamlines are only allowed to pass through zeroed cells:
When a streamline enters a cell, that cell is set to 1, and no new
streamlines are allowed to enter.
c                 ó²  •  S[         R                  " US5      -  R                  [        5      u  U l        U l        U R                  S:  d  U R
                  S:  a  [        S5      e[         R                  " U R
                  U R                  45      U l        U R                  R                  U l	        S U l
        g ! [         a  n[        S5      UeS nAff = f)Né   r   z,'density' must be a scalar or be of length 2r   z'density' must be positive)r$   Úbroadcast_toÚastypeÚintr7   r8   r'   ÚzerosÚ_maskr&   r¸   )rŒ   r[   Úerrs      r…   r�   ÚStreamMask.__init__†  s°   € ð	+Ø "¤R§_¢_°W¸aÓ%@Ñ @×HÑHÌÓMÑˆDŒG�T”Wð �7‰7�Q‹;˜$Ÿ'™' A›+ÜÐ9Ó:Ð:Ü—X’X˜tŸw™w¨¯©Ð0Ó1ˆŒ
Ø—Z‘Z×%Ñ%ˆŒ
àˆÕøô ó 	+Üð !ó "Ø'*ð+ûð	+ús   ‚:B; Â;
CÃCÃCc                 ó    • U R                   U   $ rŠ   )rÞ   )rŒ   Úargss     r…   Ú__getitem__ÚStreamMask.__getitem__“  s   € Ø�z‰z˜$ÑÐr†   c                 ó6   • / U l         U R                  XU5        g)z%Start recording streamline trajectoryN)Ú_trajr¾   ©rŒ   rl   rm   rb   s       r…   r³   ÚStreamMask._start_trajectory–  s   € àˆŒ
Ø×Ñ Ð(:Õ;r†   c                 óH   • U R                    H  nSU R                  U'   M     g)z#Remove current trajectory from maskr   N)ræ   rÞ   )rŒ   rp   s     r…   rÂ   ÚStreamMask._undo_trajectory›  s   € à—”ˆAØˆD�J‰J�q‹Mò r†   c                 óÀ   • U R                   X4:w  aM  XU4   S:X  a5  U R                  R                  X!45        SU R                  X!4'   X4U l         gU(       a  [        egg)zv
Update current trajectory position in mask.

If the new position has already been filled, raise `InvalidIndexError`.
r   r   N)r¸   ræ   r-   rÞ   r½   rç   s       r…   r¾   ÚStreamMask._update_trajectory   sa   € ð ×Ñ ˜xÓ'Ø˜�F‰|˜qÓ Ø—
‘
×!Ñ! 2 (Ô+Ø%&�—
‘
˜2˜6Ñ"Ø$& 8�Õ æ%Ü+Ð+àð (r†   )r¸   rÞ   ræ   r7   r8   r&   NrÆ   )r�   r�   r‘   r’   rÇ   r�   rã   r³   rÂ   r¾   r“   r”   r†   r…   r   r   |  s    † ñò ò ô<ò
÷
r†   r   c                   ó   • \ rS rSrSrg)r½   i²  r”   N©r�   r�   r‘   r’   r“   r”   r†   r…   r½   r½   ²  ó   † Úr†   r½   c                   ó   • \ rS rSrSrg)ÚTerminateTrajectoryi¶  r”   Nrî   r”   r†   r…   rñ   rñ   ¶  rï   r†   rñ   c                 ó:  ^ ^^^^^^	^
^• TR                  T T5      u  m mT TR                  R                  S-
  -  nTTR                  R                  S-
  -  n[        R
                  R                  US-  US-  -   5      mUUU U4S jm
U
4S jm	SU	UU
UUU4S jjnU$ )Nr   r   c                 óÒ   >• TR                   R                  X5      (       d  [        e[        TX5      nUS:X  a
  [	        5       eSU-  n[        TX5      n[        T	X5      nXC-  XS-  4$ )Nr   r—   )rc   r¼   ÚOutOfBoundsrI   rñ   )
r¤   r¥   Úds_dtÚdt_dsÚuiÚvire   ÚspeedrY   rZ   s
         €€€€r…   Úforward_timeÚ%_get_integrator.<locals>.forward_timeÇ  sj   ø€ Ø�y‰y×$Ñ$ R×,Ñ,ÜÐÜ˜5 "Ó)ˆØ�A‹:Ü%Ó'Ð'Ø�U‘
ˆÜ˜˜2Ó"ˆÜ˜˜2Ó"ˆØ‰z˜2™:Ð%Ð%r†   c                 ó$   >• T" X5      u  p#U* U* 4$ rŠ   r”   )r¤   r¥   ÚdxiÚdyirú   s       €r…   Úbackward_timeÚ&_get_integrator.<locals>.backward_timeÒ  s   ø€ Ù Ó'‰ˆØˆt�c�TˆzÐr†   c                 óŠ  >• S/ pC TR                  XU5        T
S;   a  [        XTTTU5      u  pVX5-  nXFSSS2   -  nT
S;   a-  TR                  X5        [        XTT	TU5      u  pVX5-  nXFSS -  nUT:”  a.  [        R
                  " U[        R                  " S5      5      S   $ TR                  5         g! [         a     gf = f)	aj  
Return x, y grid-coordinates of trajectory based on starting point.

Integrate both forward and backward in time from starting point in
grid coordinates.

Integration is terminated when a trajectory reaches a domain boundary
or when it crosses into an already occupied cell in the StreamMask. The
resulting trajectory is None if it is shorter than `minlength`.
g        N)r   r   r   )r   r   r   )r   r   r   )rµ   r½   Ú_integrate_rk12r¹   r$   Úbroadcast_arraysÚemptyrÄ   )Úx0Úy0rb   ÚstotalÚxy_trajr{   Úxytrÿ   re   rú   r   ra   r_   s          €€€€€€r…   rj   Ú"_get_integrator.<locals>.integrateÖ  sê   ø€ ð ˜b�ð	Ø×!Ñ! "Ð*<Ô=ð !Ð$8Ó8Ü$ R¨T°=À)Ø%7ó9‰FˆAà‰KˆFØ™4˜R˜4‘yÑ ˆGà Ð$7Ó7Ø×"Ñ" 2Ô*Ü$ R¨T°<ÀØ%7ó9‰FˆAà‰KˆFØ˜1˜2�wÑˆGà�IÓÜ×&Ò& w´·²¸Ó0@ÓAÀ!ÑDÐDà× Ñ Ô"Øøô' !ó 	Ùð	ús   †B5 Â5
CÃCrÆ   )r5   rc   r7   r8   r$   r(   Úsqrt)rY   rZ   re   r_   ra   r   Úu_axÚv_axrj   rÿ   rú   rù   s   ``````   @@@r…   r*   r*   ½  s‹   ÿø€ ð �>‰>˜!˜QÓ�D€A€qð �—	‘	—‘˜qÑ Ñ!€DØ�—	‘	—‘˜qÑ Ñ!€DÜ�E‰E�J‰J�t˜q‘y 4¨1¡9Ñ,Ó-€E÷	&ð 	&õ÷#ô #ðJ Ðr†   c                   ó   • \ rS rSrSrg)rô   iþ  r”   Nrî   r”   r†   r…   rô   rô   þ  rï   r†   rô   c                 óF  • Sn[        SUR                  R                  -  SUR                  R                  -  S5      nUnSn	U n
Un/ n  UR                  R                  X«5      (       a  UR                  X«45        O[        eU" X«5      u  pÞU" X¨U-  -   X¸U-  -   5      u  nnX�-  nXŽ-  nUS-  Xß-   -  nUS-  UU-   -  nUR                  R                  u  nn[        R                  " UU-
  US-
  -  UU-
  US-
  -  5      nUU:  a-  U
U-  n
UU-  n UR                  X«U5        X˜-   U:”  a   Xœ4$ X˜-  n	US:X  a  UnO[        USU-  UU-  S-  -  5      nGM  ! [         a    U(       a  [        XÂU5      u  pŒX˜-  n	 Xœ4$ [         a     Xœ4$ f = f! [         a     Xœ4$ f = f)aÎ  
2nd-order Runge-Kutta algorithm with adaptive step size.

This method is also referred to as the improved Euler's method, or Heun's
method. This method is favored over higher-order methods because:

1. To get decent looking trajectories and to sample every mask cell
   on the trajectory we need a small timestep, so a lower order
   solver doesn't hurt us unless the data is *very* high resolution.
   In fact, for cases where the user inputs
   data smaller or of similar grid size to the mask grid, the higher
   order corrections are negligible because of the very fast linear
   interpolation used in `interpgrid`.

2. For high resolution input data (i.e. beyond the mask
   resolution), we must reduce the timestep. Therefore, an adaptive
   timestep is more suited to the problem as this would be very hard
   to judge automatically otherwise.

This integrator is about 1.5 - 2x as fast as RK4 and RK45 solvers (using
similar Python implementations) in most setups.
gú~j¼t“h?r—   çš™™™™™¹?r   g      à?r   g333333ë?)r;   rd   r7   r8   rc   r¼   r-   rô   Ú_euler_steprñ   r&   r$   rE   r¿   r½   )r  r  re   Úfra   rb   ÚmaxerrorÚmaxdsÚdsr  r¤   r¥   Úxyf_trajÚk1xÚk1yÚk2xÚk2yÚdx1Údy1Údx2Údy2r8   r7   Úerrors                           r…   r  r    s
  € ð4 €Hô ��T—Y‘Y—\‘\Ñ! 2¨¯	©	¯©Ñ#4°cÓ:€Eà	€BØ€FØ	€BØ	€BØ€Hà
ð	Ø�y‰y×$Ñ$ R×,Ñ,Ø—‘  Õ)ä!Ð!ñ
 ˜“y‰HˆCÙ˜ 3™h™¨°#©X©Ó6‰HˆC�ð ‰hˆØ‰hˆØ�3‰h˜#™)Ñ$ˆØ�3‰h˜# ™)Ñ$ˆà—‘—‘‰ˆˆBä—’˜# ™)¨¨Q©Ñ/°#¸±)ÀÀQÁÑ1GÓHˆð �8ÓØ�#‰IˆBØ�#‰IˆBðØ×&Ñ& rÐ/AÔBð ‰{˜YÓ&Øð ÐÐð ‰LˆFð �A‹:Ø‰Bä�U˜D 2™I¨°EÑ)9¸cÑ(AÑAÓBˆBòc øô ó 	ö Ü*¨8¸1Ó=‘�Ø‘�Øð> ÐÐô= #ó 	Øð: ÐÐð=	ûô$ %ó Øð ÐÐðús+   Á
AE ÄF Å#FÆ 	FÆFÆ
F ÆF c                 ób  • UR                   R                  u  p4U S   u  pVU" XV5      u  pxUS:X  a  [        R                  n	OUS:  a  XW* -  n	OUS-
  U-
  U-  n	US:X  a  [        R                  n
OUS:  a  Xh* -  n
OUS-
  U-
  U-  n
[	        Xš5      nU R                  XWU-  -   XhU-  -   45        X°4$ )zBSimple Euler integration step that extends streamline to boundary.r   r   r   )rc   r&   r$   Úinfr;   r-   )r  re   r  r8   r7   r¤   r¥   ÚcxÚcyÚdsxÚdsyr  s               r…   r  r  b  s¹   € à�Y‰Y�_‰_�F€BØ�b‰\�F€BÙˆr‹Y�F€BØ	ˆQƒwÜ�f‰f‰Ø	ˆa‹Ø�3‰h‰à�A‰v˜‰{˜bÑ ˆØ	ˆQƒwÜ�f‰f‰Ø	ˆa‹Ø�3‰h‰à�A‰v˜‰{˜bÑ ˆÜ	ˆS‹€BØ‡O�O�R˜r™'‘\ 2¨R©¡<Ð0Ô1Øˆ<Ðr†   c                 óÐ  • [         R                  " U 5      u  p4[        U[         R                  5      (       ag  UR	                  [
        5      nUR	                  [
        5      n[         R                  " US-   SUS-
  5      n[         R                  " US-   SUS-
  5      nO6[        U5      n[        U5      nXTS-
  :X  a  UnOUS-   nXcS-
  :X  a  UnOUS-   nXU4   n	XU4   n
XU4   nXU4   nX-
  nX&-
  nU	SU-
  -  X­-  -   nUSU-
  -  XÍ-  -   nUSU-
  -  UU-  -   n[        U[         R                  5      (       d*  [         R                  R                  U5      (       a  [        eU$ )z0Fast 2D, linear interpolation on an integer gridr   r   )
r$   r&   r#   r%   rÛ   rÜ   r6   r(   Ú	is_maskedrñ   )Úar¤   r¥   ÚNyÚNxrN   rO   ÚxnÚynÚa00Úa01Úa10Úa11ÚxtrÏ   Úa0Úa1Úais                     r…   rI   rI   {  sY  € ô �XŠX�a‹[�F€BÜ�"”b—j‘j×!Ñ!Ø�I‰I”c‹NˆØ�I‰I”c‹Nˆä�WŠW�Q˜‘U˜A˜r A™vÓ&ˆÜ�WŠW�Q˜‘U˜A˜r A™vÓ&‰ä�‹GˆÜ�‹Gˆà�a‘‹=Ø‰Bà�Q‘ˆBØ�a‘‹=Ø‰Bà�Q‘ˆBà
ˆqˆD‰'€CØ
ˆrˆE‰(€CØ
�ˆE‰(€CØ
�ˆF‰)€CØ	‰€BØ	‰€BØ	��B‘‰˜#™(Ñ	"€BØ	��B‘‰˜#™(Ñ	"€BØ	ˆq�2‰v‰˜˜b™Ñ	 €Bä�bœ"Ÿ*™*×%Ñ%Ü�5‰5�?‰?˜2×ÑÜ%Ð%à€Ir†   c              #   óF  #   • U u  pSnSnUS-
  nUS-
  nSu  pxSn	[        X!-  5       Ht  n
Xx4v •  U	S:X  a  US-  nXu:¼  a	  US-  nSn	M!  M#  U	S:X  a  US-  nX†:¼  a	  US-  nSn	M<  M>  U	S:X  a  US-  nXs::  a	  US-  nSn	MW  MY  U	S:X  d  Ma  US-  nX„::  d  Mm  US-  nSn	Mv     g7f)	a  
Yield starting points for streamlines.

Trying points on the boundary first gives higher quality streamlines.
This algorithm starts with a point on the mask corner and spirals inward.
This algorithm is inefficient, but fast compared to rest of streamplot.
r   r   )r   r   ÚrightÚupÚleftÚdownN)Úrange)r&   r8   r7   ÚxfirstÚyfirstÚxlastÚylastrN   rO   Ú	directionÚis              r…   r+   r+   £  sò   é € ð �F€BØ€FØ€FØ�‰F€EØ�‰F€EØ�D€AØ€IÜ�2‘7Ž^ˆØˆdŠ
à˜ÓØ�‰FˆAØ‹zØ˜‘
�Ø ’	ñ ð ˜$ÓØ�‰FˆAØ‹zØ˜‘
�Ø"’	ñ ð ˜&Ó Ø�‰FˆAØ‹{Ø˜!‘�Ø"’	ñ ð ˜&Õ Ø�‰FˆAØ�{Ø˜!‘�Ø#’	ò- ùs   ‚BB!Â	B!ÂB!)r   NNNNr   z-|>r  NNNg      @r   TrÆ   )!rÇ   Únumpyr$   Ú
matplotlibr   r   r   r   Úmatplotlib.colorsÚcolorsr9   Úmatplotlib.collectionsÚcollectionsrK   Úmatplotlib.linesr‹   r   Ú__all__r   rW   r   r   r   Ú	Exceptionr½   rñ   r*   Ú
IndexErrorrô   r  r  rI   r+   r”   r†   r…   Ú<module>rK     s²   ðñó
 ã ß (Ñ (Ý #Ý -Ý !ð ˆ.€ð CGØ=BØHLØ4:Ø"&ô	d÷Nñ ÷<%ñ <%÷~7Añ 7A÷t3ñ 3ôl	˜	ô 	ô	˜)ô 	ò>ôB	�*ô 	ô]ò@ò2%óP%$r†   