question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vector data not identified as VECTORS

See original GitHub issue

Description

I’m a bit of a VTK newbie, so I didn’t want to post this for sure as a bug. But there’s something strange going on with assigning point data. The pyvista sphere example provides a minimal working example of what happens, so no data is needed:

sphere = pv.Sphere(radius=3.14)
vectors = np.vstack(
    (
        np.sin(sphere.points[:, 0]),
        np.cos(sphere.points[:, 1]),
        np.cos(sphere.points[:, 2]),
    )
).T
sphere.vectors = vectors * 0.3
sphere.arrows.plot(scalars='GlyphScale')

All of this, of course, works fine. However, suppose you try to save this data in ascii format:

sphere.save('sphere.vtk', binary=False)

If you open the resulting file in a text editor and scroll down to the POINT_DATA field, you get something that to me was rather unexpected:

POINT_DATA 842
SCALARS _vectors float 3
LOOKUP_TABLE default

So, it’s recording the vector data as scalar data with the name “_vectors”, type float, and 3 components (I’m referencing the vtk.org guidance on file-formats). This to me is rather weird. I was expecting a VECTOR dataset attribute with some kind of default name (I’m not sure how one assigns a name to vector data in the pyvista API). Something like:

POINT_DATA 842
VECTORS vectors float

I’m decently sure this is a bug because causes problems down the line: if I try to open this vtk file in something like VisIt to do a vector glyph plot, it can’t find the vector data. But maybe there’s some other way you are supposed to accomplish assigning vector point data? I thought the sphere example was a great showcase of how this should be done, but then there’s this weird formatting issue. Any help/guidance would be greatly appreciated!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mountaindustcommented, Jun 23, 2021

Info about a workaround I am currently using:

I can currently find no way to set VECTOR data in pyvista without resorting to the underlying VTK API. For the moment, here is what I am doing in order to get VECTOR data. This code follows the sphere example in the original post:

from vtk.util import numpy_support
vectors_vtk = numpy_support.numpy_to_vtk(vectors)
vectors_vtk.SetName('myvectors') # name for the dataset, to replace the default 'vectors'
sphere_pt_data = sphere.GetPointData()
sphere_pt_data.SetVectors(vectors_vtk)
sphere.save('sphere.vtk', binary=False)
0reactions
MatthewFlammcommented, Jun 23, 2021

I transferred this to the main repo as I think it has moved out of a support question and into a discussion about how to go about adding this functionality into the codebase (or whether it should be).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vector data not identified as VECTORS · Issue #1431 · pyvista ...
Hi, I was going to raise an issue that might be related. You mentioned that to add vector data you can do sphere.vectors...
Read more >
Introduction to Vector Data - Data Carpentry
Vector data structures represent specific features on the Earth's surface, and assign attributes to those features. Vectors are composed of discrete geometric ...
Read more >
Non-vector data and SVM? - Cross Validated - Stack Exchange
My research is on antimicrobial peptide classification and prediction. I have gathered peptide sequences of lengths ranging from 10 - 200 and ...
Read more >
C++ std::vector.data not found by MinGW - Stack Overflow
Strangely, I do not get this error any other place in the code where I invoke functions such as myMeasuredPoints. push_back() to push...
Read more >
Why Data is represented as a 'Vector' in Data Science ...
The benefit of representing data as vectors is — we can leverage vector algebra to find patterns or relationships within our data.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found