
    6Dh8                         S SK r S SKJrJr  S SKJr  S SKJr  \R                  " S5      r	S r
S\ R                  S-  S	4S
 jr " S S\5      rg)    N)
exceptionsoptional_imports)utils)
graph_objsnumpyc                 l   [         SL a  [        S5      e[        [        U 5      S-
  5       H5  nXS-      X   -
  U S   U S   -
  -
  S:  d  M!  [        R
                  " S5      e   [        [        U5      S-
  5       H5  nXS-      X   -
  US   US   -
  -
  S:  d  M!  [        R
                  " S5      e   g)	aS  
Streamline-specific validations

Specifically, this checks that x and y are both evenly spaced,
and that the package numpy is available.

See FigureFactory.create_streamline() for params

:raises: (ImportError) If numpy is not available.
:raises: (PlotlyError) If x is not evenly spaced.
:raises: (PlotlyError) If y is not evenly spaced.
Fz.FigureFactory.create_streamline requires numpy   r   g-C6?z.x must be a 1 dimensional, evenly spaced arrayz.y must be a 1 dimensional, evenly spaced arrayN)npImportErrorrangelenr   PlotlyError)xyindexs      S/var/www/html/env/lib/python3.13/site-packages/plotly/figure_factory/_streamline.pyvalidate_streamliner   
   s     
U{JKKs1vz"qy\AH$1!5?((C  #
 s1vz"qy\AH$1!5?((C  #    r	   	   g
ףp=
?c           	         [         R                  " X5        [         R                  " X#5        [        X5        [         R                  " XFS9  [	        XX#XEU5      R                  5       u  p[	        XX#XEU5      R                  5       u  p[        R                  " SX-   X-   SS.UD6nU/n[        R                  " SS9n[        R                  " XS9$ )a  
Returns data for a streamline plot.

:param (list|ndarray) x: 1 dimensional, evenly spaced list or array
:param (list|ndarray) y: 1 dimensional, evenly spaced list or array
:param (ndarray) u: 2 dimensional array
:param (ndarray) v: 2 dimensional array
:param (float|int) density: controls the density of streamlines in
    plot. This is multiplied by 30 to scale similiarly to other
    available streamline functions such as matplotlib.
    Default = 1
:param (angle in radians) angle: angle of arrowhead. Default = pi/9
:param (float in [0,1]) arrow_scale: value to scale length of arrowhead
    Default = .09
:param kwargs: kwargs passed through plotly.graph_objs.Scatter
    for more information on valid kwargs call
    help(plotly.graph_objs.Scatter)

:rtype (dict): returns a representation of streamline figure.

Example 1: Plot simple streamline and increase arrow size

>>> from plotly.figure_factory import create_streamline
>>> import plotly.graph_objects as go
>>> import numpy as np
>>> import math

>>> # Add data
>>> x = np.linspace(-3, 3, 100)
>>> y = np.linspace(-3, 3, 100)
>>> Y, X = np.meshgrid(x, y)
>>> u = -1 - X**2 + Y
>>> v = 1 + X - Y**2
>>> u = u.T  # Transpose
>>> v = v.T  # Transpose

>>> # Create streamline
>>> fig = create_streamline(x, y, u, v, arrow_scale=.1)
>>> fig.show()

Example 2: from nbviewer.ipython.org/github/barbagroup/AeroPython

>>> from plotly.figure_factory import create_streamline
>>> import numpy as np
>>> import math

>>> # Add data
>>> N = 50
>>> x_start, x_end = -2.0, 2.0
>>> y_start, y_end = -1.0, 1.0
>>> x = np.linspace(x_start, x_end, N)
>>> y = np.linspace(y_start, y_end, N)
>>> X, Y = np.meshgrid(x, y)
>>> ss = 5.0
>>> x_s, y_s = -1.0, 0.0

>>> # Compute the velocity field on the mesh grid
>>> u_s = ss/(2*np.pi) * (X-x_s)/((X-x_s)**2 + (Y-y_s)**2)
>>> v_s = ss/(2*np.pi) * (Y-y_s)/((X-x_s)**2 + (Y-y_s)**2)

>>> # Create streamline
>>> fig = create_streamline(x, y, u_s, v_s, density=2, name='streamline')

>>> # Add source point
>>> point = go.Scatter(x=[x_s], y=[y_s], mode='markers',
...                    marker_size=14, name='source point')

>>> fig.add_trace(point) # doctest: +SKIP
>>> fig.show()
)densityarrow_scalelines)r   r   modeclosest)	hovermode)datalayout )r   validate_equal_lengthr   validate_positive_scalars_Streamlinesum_streamlinesget_streamline_arrowsr   ScatterLayoutFigure)r   r   uvr   angler   kwargsstreamline_xstreamline_yarrow_xarrow_y
streamliner   r   s                  r   create_streamliner1   %   s    R 
%	%	##GM!,	aGK"o L #	aGK G ## 

 L$:LRJ <D3F$66r   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)r"      z:
Refer to FigureFactory.create_streamline() for docstring
c                 v   [         R                  U5      U l        [         R                  U5      U l        [         R                  U5      U l        [         R                  U5      U l        X`l        Xpl        [        SU-  5      U l	        U R                  S   U R                  S   -
  U l
        U R                  S   U R                  S   -
  U l        U R                  U l        U R                  U l        [         R                  U R                  U R                  45      U l        [!        U R                  5      [#        U R                  S-
  5      -  U l        [!        U R                  5      [#        U R                  S-
  5      -  U l        / U l        U R                  U R                  S   U R                  S   -
  -  U l        U R
                  U R                  S   U R                  S   -
  -  U l        [         R+                  U R                  S-  U R
                  S-  -   5      U l        U =R                  [!        U R                  5      -  sl        U =R
                  [!        U R                  5      -  sl        / U l        / U l        U R3                  5         U R5                  5       u  pU R7                  5       u  pg )N   r	   r      )r
   arrayr   r   r(   r)   r*   r   intr   delta_xdelta_yval_xval_yzerosblankr   float	spacing_x	spacing_ytrajectoriessqrtspeedst_xst_yget_streamlinesr#   r$   )selfr   r   r(   r)   r   r*   r   r+   r,   r-   arrows_xarrows_ys                r   __init___Streamline.__init__   s   !!!!
&2<(vvay466!9,vvay466!9,VV
VV
 XXt||T\\:;
TVVuT\\A-='>>TVVuT\\A-='>> 466":q	12466":q	12WWTVVQY23
 	#dff+#dff+		%)%9%9%;"!779(r   c                 j    [        XR                  -  S-   5      [        X R                  -  S-   5      4$ )zA
Set up positions for trajectories to be used with rk4 function.
      ?)r9   rA   rB   )rI   xiyis      r   	blank_pos_Streamline.blank_pos   s1     R..(C/0#rNN7Jc6Q2RSSr   c                 X   [        U[        R                  5      (       a5  UR                  [        5      U l        UR                  [        5      U l        O [	        U5      U l        [	        U5      U l        XR                  U R                  4   nXR                  U R                  S-   4   nXR                  S-   U R                  4   nXR                  S-   U R                  S-   4   nX R                  -
  nX0R                  -
  n	USU-
  -  XX-  -   n
USU-
  -  Xx-  -   nU
SU	-
  -  X-  -   $ )z;
Set up for RK4 function, based on Bokeh's streamline code
r	   )	
isinstancer
   ndarrayastyper9   r   r   r<   r=   )rI   arP   rQ   a00a01a10a11xtyta0a1s               r   value_at_Streamline.value_at   s     b"**%%YYs^DFYYs^DFRDJRDJ

DJJ&'

DJJN*+

Q

*+

Q

Q./**_**_AF^ch&AF^ch&QV}rw&&r   c                   ^ ^^^ U 4S jnU 4S jnU 4S jm/ m/ mUU UU4S jnU" XU5      u  pgnU" XU5      u  pnXi-   nU
SSS2   USS -   nUSSS2   USS -   n[        U5      S:  a  gUS:  a(  T R                  X5      u  nnST R                  UU4'   X4$ [        TT5       H  u  nnS	T R                  UU4'   M     g)
z
RK4 forward and back trajectories from the initial conditions.

Adapted from Bokeh's streamline -uses Runge-Kutta method to fill
x and y trajectories then checks length of traj (s in units of axes)
c                    > STR                  TR                  X5      -  nTR                  TR                  X5      nTR                  TR                  X5      nX2-  XB-  4$ Ng      ?ra   rE   r(   r)   rP   rQ   dt_dsuivirI   s        r   f$_Streamline.rk4_integrate.<locals>.f   sS    $--

B;;Etvvr.Btvvr.B:rz))r   c                    > STR                  TR                  X5      -  nTR                  TR                  X5      nTR                  TR                  X5      nU* U-  U* U-  4$ re   rf   rg   s        r   g$_Streamline.rk4_integrate.<locals>.g   s[    $--

B;;Etvvr.Btvvr.B3;e++r   c                    > SU s=:*  =(       a    [        TR                  5      S-
  :  Os  =(       a+    SUs=:*  =(       a    [        TR                  5      S-
  :  $ s  $ )Nr   r	   )r   r   r   )rP   rQ   rI   s     r   <lambda>+_Streamline.rk4_integrate.<locals>.<lambda>   sF    R 9 9#dff+/ 9 Wa2>W>WDFFVW>W W>W Wr   c                   > SnSnU nUnTR                  XV5      u  px/ n	/ n
T" XV5      (       GaG  U	R                  U5        U
R                  U5         U" XV5      u  pU" USU-  U-  -   USU-  U-  -   5      u  pU" USU-  U-  -   USU-  U-  -   5      u  nnU" XSU-  -   XcU-  -   5      u  nnXSUSU-  -   SU-  -   U-   -  S-  -  nXcUSU-  -   SU-  -   U-   -  S-  -  nT" XV5      (       d  OXC-  nTR                  XV5      u  nnUU:w  d  UU:w  aN  TR                  UU4   S:X  a8  STR                  UU4'   TR                  U5        TR                  U5        UnUnOOUS:  a  OT" XV5      (       a  GMG  XIU
4$ ! [         a     M  f = f)Ng{Gz?r   rO   r7   g      @r	   )rR   append
IndexErrorr?   )x0y0rk   dsstotalrP   rQ   xbybxf_trajyf_trajk1xk1yk2xk2yk3xk3yk4xk4ynew_xbnew_ybcheckrI   
xb_changes
yb_changess                        r   rk4&_Streamline.rk4_integrate.<locals>.rk4   s   BFBB^^B+FBGG--r"r" yHC cBhn!4b38c>6IJHC cBhn!4b38c>6IJHC 3h#X>HC C!c'MAG3c9:S@@C!c'MAG3c9:S@@R}}!%!7R<6R<zz&&.1Q656

66>2"))&1"))&1##A:5 --6 G++' " s   AE: :
FFNr6   r	   g?r   )r   rR   r?   zip)rI   rv   rw   rk   rn   r   sfr|   r}   sbxb_trajyb_trajry   x_trajy_trajinitxbinitybrz   r{   r   r   r   s   `                  @@@r   rk4_integrate_Streamline.rk4_integrate   s    	*	, Y

#	, #	,J  #21~W"21~W2,2,v;?C<!^^B3NFF)*DJJvv~&>!j*5B%&

2r6" 6r   c                    US:  d$  XR                   :  d  US:  d  X R                   :  a  gU R                  X!4   S:X  aJ  U R                  XR                  -  X R                  -  5      nUb  U R
                  R                  U5        ggg)z
Integrate trajectories

:param (int) xb: results of passing xi through self.blank_pos
:param (int) xy: results of passing yi through self.blank_pos

Calculate each trajectory based on rk4 integrate method.
r   N)r   r?   r   rA   rB   rC   rt   )rI   rz   r{   ts       r   traj_Streamline.traj  s|     6R<<'26R<<5G::bf"""2#6^^8KLA}!!((+  #r   c                    [        U R                  S-  5       H  n[        U R                  SU-  -
  5       Hs  nU R                  X!-   U5        U R                  X!-   U R                  S-
  U-
  5        U R                  XU-   5        U R                  U R                  S-
  U-
  X!-   5        Mu     M     U R                   Vs/ s H8  n[        R                  US   5      U R                  -  U R                  S   -   PM:     snU l        U R                   Vs/ s H8  n[        R                  US   5      U R                  -  U R                  S   -   PM:     snU l        [        [        U R                  5      5       HY  nU R                  U   R                  5       U R                  U'   U R                  U   R                  [        R                  5        M[     [        [        U R                  5      5       HY  nU R                  U   R                  5       U R                  U'   U R                  U   R                  [        R                  5        M[     gs  snf s  snf )z-
Get streamlines by building trajectory set.
r7   r	   r   N)r   r   r   rC   r
   r8   r:   r   rF   r;   r   rG   r   tolistrt   nan)rI   indentrP   r   r   s        r   rH   _Streamline.get_streamlines#  s    DLLA-.FDLL1v:56		"+v.		"+t||a'7&'@A		&v+.		$,,*V3R[A	 7 / @D?P?P
?P!BHHQqTNT\\)DFF1I5?P
	 @D?P?P
?P!BHHQqTNT\\)DFF1I5?P
	 3tyy>*E#yy/668DIIeIIe##BFF+ + 3tyy>*E#yy/668DIIeIIe##BFF+ +

s    ?I?Ic                    [         R                  [        U R                  5      5      n[         R                  [        U R                  5      5      n[         R                  [        U R                  5      5      n[         R                  [        U R                  5      5      n[        [        U R                  5      5       H  nU R                  U   [        [        U R                  U   5      S-  5         X'   U R                  U   [        [        U R                  U   5      S-  5      S-
     X5'   U R                  U   [        [        U R                  U   5      S-  5         X%'   U R                  U   [        [        U R                  U   5      S-  5      S-
     XE'   M     X-
  nX$-
  n[         R                  5       n[         R                  SSS9  [         R                  Xv-  5      n	[         R                  " S0 UD6  XR                  -   n
XR                  -
  n[         R                  U
5      U R                  -  n[         R                  U
5      U R                  -  n[         R                  U5      U R                  -  n[         R                  U5      U R                  -  n[         R                  [        U5      5      n[         R                  [        U5      5      n[         R                  [        U5      5      n[         R                  [        U5      5      n[        [        U5      5       Hm  nXe   S:  a2  X   X   -
  UU'   X%   X   -
  UU'   X   X   -
  UU'   X%   X   -
  UU'   M=  X   X   -   UU'   X%   X   -   UU'   X   X   -   UU'   X%   X   -   UU'   Mo     [         R                  [        U5      5      n[         R                  USS& [         R                  UUUU/5      nUR!                  S5      nUR#                  5       n[         R                  UUUU/5      nUR!                  S5      nUR#                  5       nUU4$ )	a  
Makes an arrow for each streamline.

Gets angle of streamline at 1/3 mark and creates arrow coordinates
based off of user defined angle and arrow_scale.

:param (array) st_x: x-values for all streamlines
:param (array) st_y: y-values for all streamlines
:param (angle in radians) angle: angle of arrowhead. Default = pi/9
:param (float in [0,1]) arrow_scale: value to scale length of arrowhead
    Default = .09
:rtype (list, list) arrows_x: x-values to create arrowhead and
    arrows_y: y-values to create arrowhead
   r	   ignore)divideinvalidr   NFr   )r
   emptyr   rF   rG   r   r9   geterrseterrarctanr*   cosr   sinr   r8   flattenr   )rI   arrow_end_xarrow_end_yarrow_start_xarrow_start_yr   dif_xdif_yorig_errstreamline_angang1ang2seg1_xseg1_yseg2_xseg2_ypoint1_xpoint1_ypoint2_xpoint2_yspacerJ   rK   s                          r   r$   !_Streamline.get_streamline_arrows=  s    hhDII0hhDII0#dii.2#dii.23tyy>*E!%5!1#c$))E:J6Ka6O2P!QK#'99U#3S5)*Q./14$M  "&5!1#c$))E:J6Ka6O2P!QK#'99U#3S5)*Q./14$M  + ++99;
		8	45=1
		H,, 0 00 0 00 0 00 0 0088SZ)88SZ)88SZ)88SZ)3u:&E|q "-"4v}"D"-"4v}"D"-"4v}"D"-"4v}"D"-"4v}"D"-"4v}"D"-"4v}"D"-"4v}"D ' #h-)66a 88X{HeDE##C(??$ 88X{HeDE##C(??$!!r   c                 `    [        U R                  / 5      n[        U R                  / 5      nX4$ )z
Makes all streamlines readable as a single trace.

:rtype (list, list): streamline_x: all x values for each streamline
    combined into single list and streamline_y: all y values for each
    streamline combined into single list
)sumrF   rG   )rI   r,   r-   s      r   r#   _Streamline.sum_streamlines  s-     499b)499b)))r   )r*   r   r?   r:   r;   r   rA   rB   rE   rF   rG   rC   r(   r)   r<   r=   r   r   N)__name__
__module____qualname____firstlineno____doc__rL   rR   ra   r   r   rH   r$   r#   __static_attributes__r   r   r   r"   r"      s5    :BT'(L\,",4K"Z
*r   r"   )mathplotlyr   r   plotly.figure_factoryr   plotly.graph_objsr   
get_moduler
   r   pir1   objectr"   r   r   r   <module>r      sL     / ' (  )8 1$\7~P*& P*r   