Skip to content

Error with 2D streamlines and numpy 1.24.0 #3989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Davide-sd opened this issue Dec 19, 2022 · 0 comments · Fixed by #3997
Closed

Error with 2D streamlines and numpy 1.24.0 #3989

Davide-sd opened this issue Dec 19, 2022 · 0 comments · Fixed by #3997

Comments

@Davide-sd
Copy link

My CI is failing with the latest Numpy version (1.24.0).

My plotly version is: 5.11.0

import plotly.figure_factory as ff

import numpy as np

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

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

Traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 12
      9 v = 1 + X - Y**2
     11 # Create streamline figure
---> 12 fig = ff.create_streamline(x, y, u, v, arrow_scale=.1)
     13 fig.show()

File ~/Documents/Development/envs/plot/lib/python3.10/site-packages/plotly/figure_factory/_streamline.py:117, in create_streamline(x, y, u, v, density, angle, arrow_scale, **kwargs)
    114 validate_streamline(x, y)
    115 utils.validate_positive_scalars(density=density, arrow_scale=arrow_scale)
--> 117 streamline_x, streamline_y = _Streamline(
    118     x, y, u, v, density, angle, arrow_scale
    119 ).sum_streamlines()
    120 arrow_x, arrow_y = _Streamline(
    121     x, y, u, v, density, angle, arrow_scale
    122 ).get_streamline_arrows()
    124 streamline = graph_objs.Scatter(
    125     x=streamline_x + arrow_x, y=streamline_y + arrow_y, mode="lines", **kwargs
    126 )

File ~/Documents/Development/envs/plot/lib/python3.10/site-packages/plotly/figure_factory/_streamline.py:168, in _Streamline.__init__(self, x, y, u, v, density, angle, arrow_scale, **kwargs)
    166 self.st_x = []
    167 self.st_y = []
--> 168 self.get_streamlines()
    169 streamline_x, streamline_y = self.sum_streamlines()
    170 arrows_x, arrows_y = self.get_streamline_arrows()

File ~/Documents/Development/envs/plot/lib/python3.10/site-packages/plotly/figure_factory/_streamline.py:299, in _Streamline.get_streamlines(self)
    297 for indent in range(self.density // 2):
    298     for xi in range(self.density - 2 * indent):
--> 299         self.traj(xi + indent, indent)
    300         self.traj(xi + indent, self.density - 1 - indent)
    301         self.traj(indent, xi + indent)

File ~/Documents/Development/envs/plot/lib/python3.10/site-packages/plotly/figure_factory/_streamline.py:289, in _Streamline.traj(self, xb, yb)
    287     return
    288 if self.blank[yb, xb] == 0:
--> 289     t = self.rk4_integrate(xb * self.spacing_x, yb * self.spacing_y)
    290     if t is not None:
    291         self.trajectories.append(t)

File ~/Documents/Development/envs/plot/lib/python3.10/site-packages/plotly/figure_factory/_streamline.py:259, in _Streamline.rk4_integrate(self, x0, y0)
    256             break
    257     return stotal, xf_traj, yf_traj
--> 259 sf, xf_traj, yf_traj = rk4(x0, y0, f)
    260 sb, xb_traj, yb_traj = rk4(x0, y0, g)
    261 stotal = sf + sb

File ~/Documents/Development/envs/plot/lib/python3.10/site-packages/plotly/figure_factory/_streamline.py:234, in _Streamline.rk4_integrate.<locals>.rk4(x0, y0, f)
    232 yf_traj.append(yi)
    233 try:
--> 234     k1x, k1y = f(xi, yi)
    235     k2x, k2y = f(xi + 0.5 * ds * k1x, yi + 0.5 * ds * k1y)
    236     k3x, k3y = f(xi + 0.5 * ds * k2x, yi + 0.5 * ds * k2y)

File ~/Documents/Development/envs/plot/lib/python3.10/site-packages/plotly/figure_factory/_streamline.py:207, in _Streamline.rk4_integrate.<locals>.f(xi, yi)
    206 def f(xi, yi):
--> 207     dt_ds = 1.0 / self.value_at(self.speed, xi, yi)
    208     ui = self.value_at(self.u, xi, yi)
    209     vi = self.value_at(self.v, xi, yi)

File ~/Documents/Development/envs/plot/lib/python3.10/site-packages/plotly/figure_factory/_streamline.py:186, in _Streamline.value_at(self, a, xi, yi)
    184     self.y = yi.astype(np.int)
    185 else:
--> 186     self.val_x = np.int(xi)
    187     self.val_y = np.int(yi)
    188 a00 = a[self.val_y, self.val_x]

File ~/Documents/Development/envs/plot/lib/python3.10/site-packages/numpy/__init__.py:284, in __getattr__(attr)
    281     from .testing import Tester
    282     return Tester
--> 284 raise AttributeError("module {!r} has no attribute "
    285                      "{!r}".format(__name__, attr))

AttributeError: module 'numpy' has no attribute 'int'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant