Skip to content

Added support for loading native object for openvdb - #170

Merged
orbeckst merged 16 commits into
MDAnalysis:masterfrom
spyke7:grid_openvdb_native
Sep 1, 2026
Merged

Added support for loading native object for openvdb#170
orbeckst merged 16 commits into
MDAnalysis:masterfrom
spyke7:grid_openvdb_native

Conversation

@spyke7

@spyke7 spyke7 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #171

Changes -

  • Made _extract_from_vdb_grid that gets the delta, origin, data type and metadata, if a native object is passed - OpenVDB.py
  • made the datatypes list global as _DATATYPES and checked for instance if a openvdb.gridbase is passed - OpenVDB.py
  • In core.py, checked if not a filename (str) is given, and called the OpenVDBField - core.py
  • Updated the tests for the _extract_from_vdb_grid - test_vdb.py

@orbeckst please have a look at this when you are free and have time.
Also, made a new section in changelog, with enhancement in it

@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.34884% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.76%. Comparing base (ab29b50) to head (549ab2e).

Files with missing lines Patch % Lines
gridData/OpenVDB.py 94.11% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #170      +/-   ##
==========================================
+ Coverage   90.59%   90.76%   +0.16%     
==========================================
  Files           6        6              
  Lines         946      985      +39     
  Branches      126      131       +5     
==========================================
+ Hits          857      894      +37     
- Misses         52       53       +1     
- Partials       37       38       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@orbeckst

Copy link
Copy Markdown
Member

Is the objective of the PR to enable #162 for openvdb objects only or implement it for all available formats?

It's totally ok to only do it for OpenVDB, I just want to know when reviewing the PR.

@orbeckst orbeckst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great that you're starting the work on #162 . The type-selection mechanism needs to be reworked.

We also need to have a more general architecture for Grid for (1) detecting the format, (2) dispatching to the correct loader. We can decide to do this in a separate PR if for right now we're only focusing on VDB.

Comment thread CHANGELOG Outdated
Comment thread CHANGELOG Outdated
Comment thread gridData/OpenVDB.py Outdated
for key in self.vdb_grid.metadata:
try:
self.metadata[key] = self.vdb_grid[key]
except (TypeError, ValueError):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Under which conditions does that fail? I am always suspicious of try/except that passes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

vec3f can be one of the example. But I can create a path for a warning to be raised for this

Comment thread gridData/OpenVDB.py Outdated
self.origin = v_origin
self.delta = v_delta

dtype = np.dtype("float32")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's cleaner to set the dtype to the default in an else block of the for loop:

        for numpy_dtype, vdb_names in self._DATATYPES.items():
            name_dtype = vdb_names[0]
            ...
            if vdb_class_name == canonical_name:
                dtype = numpy_dtype
                break
        else:
             # could not find a matching dtype, use default
             dtype = np.float32

Or maybe should we use float64? @BradyAJohnston @PardhavMaradani do you have an opinion?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should also log a warning if you encounter an unknown type and use the default.

Comment thread gridData/OpenVDB.py Outdated
Comment thread gridData/OpenVDB.py
shape = tuple(np.array(bbox[1]) - np.array(bbox[0]) + 1)

self.grid = np.zeros(shape, dtype=dtype)
print(dtype)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

still a print there!

Comment thread gridData/OpenVDB.py Outdated
Comment thread gridData/core.py
world = native_grid.transform.indexToWorld((0, 0, 0))
assert_allclose([world[0], world[1], world[2]], g.origin, rtol=1e-5)

def test_extract_from_vdb_grid(self, grid345):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

parameterize the test to try out all normally supported vdb gridtypes

Comment thread gridData/tests/test_vdb.py
@orbeckst

Copy link
Copy Markdown
Member

For right now I linked this PR to the OpenVDB-only issue #171

spyke7 and others added 2 commits May 30, 2026 11:23
Co-authored-by: Oliver Beckstein <orbeckst@gmail.com>
Co-authored-by: Oliver Beckstein <orbeckst@gmail.com>
@orbeckst orbeckst mentioned this pull request May 30, 2026
4 tasks
@read-the-docs-community

read-the-docs-community Bot commented May 30, 2026

Copy link
Copy Markdown

Comment thread gridData/OpenVDB.py Outdated
@spyke7

spyke7 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi Prof @orbeckst
I was busy with my sem exams and going on, that's why I wasn't active regarding this. I hope, I can apply more improvements and changes.
Thanks

@orbeckst orbeckst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for making the last changes. This looks ready, nice work!

Apologies for the delayed review.

@orbeckst
orbeckst merged commit 4acc4c3 into MDAnalysis:master Sep 1, 2026
10 checks passed
@spyke7

spyke7 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for making the last changes. This looks ready, nice work!

Apologies for the delayed review.

Thanks professor @orbeckst . Learned a lot about openvdb and the other APIs during this!! 😊

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.

create Grid from openvdb grid object

2 participants