# Efficient methods for creating many source objects

**URL:** https://discourse.paraview.org/t/efficient-methods-for-creating-many-source-objects/1416
**Category:** ParaView Support
**Tags:** python
**Created:** [March 7, 2019, 6:17pm UTC](https://discourse.paraview.org/t/efficient-methods-for-creating-many-source-objects/1416 "2019-03-07T18:17:21Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![krvorren](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/b9e5f3/32.png) [@krvorren](https://discourse.paraview.org/u/krvorren)
#### Post date: [March 7, 2019, 6:17pm UTC](https://discourse.paraview.org/t/efficient-methods-for-creating-many-source-objects/1416/1 "2019-03-07T18:17:21Z")

</div>

Hello,

I’ve been trying to use a python script to render about ~1000 Line() objects. This is a simple task to perform, but it takes a long time. As a very bare bones example, if you process the following in the python shell:

> test = [None]\*1000  
> for i in xrange(len(test)):  
> …test[i] = Line()

it takes roughly 10 seconds (on my laptop anyway) for the objects to show up in the pipeline browser. It then takes about 3 times as long to render all the line objects. I’m looking for a way to speed this process up through parallelization, as this seems like an embarrassingly parallel routine.

I have tried running a script using pvbatch that was called by mpiexec.hydra -np 8. I didn’t really see nor expect a speed increase however, because my code uses standard python for-loops to create and render the source objects (lines). I considered playing around with the python [joblib](https://joblib.readthedocs.io/en/latest/parallel.html) package to see if that sped things up, but for now joblib is not working in my pvbatch environment (at work I don’t have the privileges to fix this). Would this be a reasonable route to pursue to improve performance?

Finally, to articulate an actual question: is there a fast method, or efficient coding practices I can use to quickly instantiate and render \> ~ 1000 simple source objects (e.g. lines, cones, boxes) in python? Any guidance would be greatly appreciated.

Thanks,  
-Kris

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [March 8, 2019, 9:43am UTC](https://discourse.paraview.org/t/efficient-methods-for-creating-many-source-objects/1416/2 "2019-03-08T09:43:13Z")

</div>

It is definitelly not recommended to create lots of sources. It will slow down rendering a lot.

Why not having a dataset with hundreds lines ? or maybe a multiblock with hundreds of blocks ?

---

<div class="post-metadata">

### Author: ![krvorren](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/b9e5f3/32.png) [@krvorren](https://discourse.paraview.org/u/krvorren)
#### Post date: [March 8, 2019, 1:51pm UTC](https://discourse.paraview.org/t/efficient-methods-for-creating-many-source-objects/1416/3 "2019-03-08T13:51:52Z")

</div>

The data set I’m working with is a large ascii format collection of start points and endpoints for disconnected line segments (I could convert to .csv), so my first thought was to create a python script with a loop that would draw a line segment for each pair of points. This became too slow once I included too many line segments.

I’m not sure how to render hundreds of lines with a single source object–the poly line isn’t quite what I need since the segments are disconnected. I might try playing around with the .csv reader because I’ve used that before to visualize very large (~1M points) data sets fairly quickly.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [March 8, 2019, 1:53pm UTC](https://discourse.paraview.org/t/efficient-methods-for-creating-many-source-objects/1416/4 "2019-03-08T13:53:24Z")

</div>

Just use line cells.

eg : 4 points, 2 cells.  
cell 0 : line, point0, point1  
cell 1 : line, point2, point3

---

<div class="post-metadata">

### Author: ![krvorren](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/b9e5f3/32.png) [@krvorren](https://discourse.paraview.org/u/krvorren)
#### Post date: [March 8, 2019, 1:59pm UTC](https://discourse.paraview.org/t/efficient-methods-for-creating-many-source-objects/1416/5 "2019-03-08T13:59:05Z")

</div>

Ok thanks Mathieu, I’ll look into that.

---

<div class="post-metadata">

### Author: ![krvorren](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/b9e5f3/32.png) [@krvorren](https://discourse.paraview.org/u/krvorren)
#### Post date: [March 8, 2019, 3:34pm UTC](https://discourse.paraview.org/t/efficient-methods-for-creating-many-source-objects/1416/6 "2019-03-08T15:34:13Z")

</div>

This is going to work. It also leads to the solution to my more general question in the OP. One followup question:

Right now I’m generating the point and cell data using the [legacy vtk file format](https://www.paraview.org/Wiki/images/5/51/VTK-File-Formats.pdf). Is there a wiki or document describing a better way that I should be doing this within paraview? Unfortunately I don’t have experience with xml (maybe this is a good time to learn).

Thanks again for the help!

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [March 8, 2019, 3:36pm UTC](https://discourse.paraview.org/t/efficient-methods-for-creating-many-source-objects/1416/7 "2019-03-08T15:36:08Z")

</div>

You indeed should use the XML based vtk format.  
[https://vtk.org/Wiki/VTK\_XML\_Formats](https://vtk.org/Wiki/VTK_XML_Formats)
