Skip to content
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

Skip Array data when constructing VTKData #65

Merged
merged 3 commits into from
Sep 6, 2024

Conversation

williamjsdavis
Copy link
Contributor

Regarding issue #63, when reading data from a vtk/pvtk file, the current read implementation only work if all elements in the PointData/CellData section are of type DataArray. In some use cases, string data is stored in these sections as Array type, (e.g., as label for visualization projects, link). These elements have the form:

Currently, if there is a single Array element in the PointData/CellData section, reading data will fail due to an assertion breach in the get_data_section method:

@assert LightXML.name(xml_element) == "DataArray"

In the new implementation I present in this pull request, XML elements that are not DataArray type are skipped over in get_data_section, but error later when one attempts to index the VTKData object with a key that references non-numeric data:

function Base.getindex(data::VTKData, name)

This new logic allows for the reading of numeric data from files with both numeric and non-numeric contents.

I have also expanded existing tests to:

  1. Add string data to a generated .vti file,
  2. Add string data to a generated .pvti file,
  3. Test for expected KeyErrors when attempting to read the string data for the .vti file, and
  4. Test for expected KeyErrors when attempting to read the string data for the .pvti file

And the fact that the existing tests for reading cell/point data pass as they previously were doing indicates that numeric data can still be correctly read from .vti and .pvti files.

Feedback is appreciated!

@ranocha
Copy link
Member

ranocha commented Sep 5, 2024

Thanks! This looks quite good to me. Would you like to add your name to the list of authors in https://github.com/JuliaVTK/ReadVTK.jl?tab=readme-ov-file#authors?

@williamjsdavis
Copy link
Contributor Author

Yes please! I'd be very happy to continue contributing! Please add me as:

William Davis (Terra AI, USA)

@ranocha
Copy link
Member

ranocha commented Sep 5, 2024

Could you please do that in this PR?

@williamjsdavis
Copy link
Contributor Author

Ah understood! I've added it to the PR!

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@ranocha ranocha merged commit 0aa9453 into JuliaVTK:main Sep 6, 2024
11 checks passed
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 this pull request may close these issues.

2 participants