[PySide] Keeping GUI responsive

Andrew Nelson andyfaff at gmail.com
Fri Dec 6 21:34:14 CET 2019


Whilst I'm not familiar with pandas it's behaviour is probably similar to
NumPy in terms of vectorisation. It looks to me that you can vectorise that
loop. Removing loops will give you *enormous* speedup. I don't claim this
is the most numpythonic, there may be some kind of modulo arithmetic for
doing this more easily.

```
dx = self.contour_df['delta_utmx_volc']
dy = self.contour_df['delta_utmy_volc']

loc = np.logical_and(dx > 0, dy > 0)
self.contour_df['volc_azimuth'][loc] = self.contour_df['volc_theta'][loc]

# the complement of loc is both dx and dy are negative, or equal to zero
(you didn't deal with that case)
self.contour_df['volc_azimuth'][~loc] = 360 -
self.contour_df['volc_theta'][~loc]

loc = np.logical_and(dx > 0, dy < 0)
self.contour_df['volc_azimuth'][loc] = 180 -
self.contour_df['volc_theta'][loc]

loc = np.logical_and(dx < 0, dy > 0)
self.contour_df['volc_azimuth'][loc] = 180 +
self.contour_df['volc_theta'][loc]
```


        for i in range(self.contour_df.index[0],
> self.contour_df.index.max()):
>             dx = self.contour_df['delta_utmx_volc'][i]
>             dy = self.contour_df['delta_utmy_volc'][i]
>
>             if dx > 0 and dy > 0:
>                 self.contour_df['volc_azimuth'][i] =
> self.contour_df['volc_theta'][i]
>
>             elif dx > 0 > dy:
>                 self.contour_df['volc_azimuth'][i] = 180 -
> self.contour_df['volc_theta'][i]
>
>             elif dx < 0 and dy < 0:
>                 self.contour_df['volc_azimuth'][i] = 180 +
> self.contour_df['volc_theta'][i]
>
>             elif dx < 0 < dy:
>                 self.contour_df['volc_azimuth'][i] = 360 -
> self.contour_df['volc_theta'][i]
>
>             if i % 50 == 0:
>                 self.yield_thread()
>
>         self.contour_df['volc_dist'] =
> np.sqrt((self.contour_df['delta_utmy_volc']**2) +
> (self.contour_df['delta_utmx_volc']**2))  # distance from point to volcano
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20191207/6023b3b2/attachment-0001.html>


More information about the PySide mailing list