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

Method to calculate grid isosurfaces #246

Merged
merged 5 commits into from
Jul 29, 2020
Merged

Conversation

pfebrer
Copy link
Contributor

@pfebrer pfebrer commented Jul 28, 2020

When plotting grids with plotly I had the problem that non-orthogonal grids didn't make sense because there was no way to indicate the vectors of the cell.

I submitted an issue in plotly and they proposed a workaround, which is to calculate the isosurfaces first with skimage.measure.marching_cubes and then apply a transformation to the vertices to get their real coordinates taking into account the cell vectors.

I thought that maybe this is useful for other cases, not only for the plotly visualization module. This would definitely be useful for representing the grids in blender (because it gives you all that you need to build a 3d mesh), and maybe for someone who wants to do some quantitative analysis with isosurfaces (I'm not sure when would this be useful).

If you think it is worth it to include this in the Grid class I will write some tests for it. Otherwise I will just do the isosurface calculation in the visualization module.

Cheers!

@codecov
Copy link

codecov bot commented Jul 28, 2020

Codecov Report

Merging #246 into master will decrease coverage by 0.03%.
The diff coverage is 9.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #246      +/-   ##
==========================================
- Coverage   84.67%   84.63%   -0.04%     
==========================================
  Files         131      131              
  Lines       20882    20907      +25     
==========================================
+ Hits        17682    17695      +13     
- Misses       3200     3212      +12     
Impacted Files Coverage Δ
sisl/grid.py 86.04% <9.09%> (-1.19%) ⬇️
sisl/physics/self_energy.py 91.45% <0.00%> (-0.13%) ⬇️
sisl/physics/__init__.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81dc4a3...67ec818. Read the comment docs.

Copy link
Owner

@zerothi zerothi left a comment

Choose a reason for hiding this comment

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

Thanks! This looks good!! :)

A few minor points and you are good to go :)

sisl/grid.py Show resolved Hide resolved
sisl/grid.py Outdated Show resolved Hide resolved
sisl/grid.py Outdated Show resolved Hide resolved
sisl/grid.py Outdated Show resolved Hide resolved
sisl/grid.py Outdated Show resolved Hide resolved
sisl/grid.py Show resolved Hide resolved
@pfebrer
Copy link
Contributor Author

pfebrer commented Jul 29, 2020

Everything is done now and I added some tests. I don't know how to specify that the test should fail if scikit-image is not installed. If you could to this, I think there's nothing else to do :)

@zerothi
Copy link
Owner

zerothi commented Jul 29, 2020

Everything is done now and I added some tests. I don't know how to specify that the test should fail if scikit-image is not installed. If you could to this, I think there's nothing else to do :)

You simply do this:

def test_<>(...):
    pytest.importorskip("skimage", reason="scikit-image not available")
    <body of test>

sisl/tests/test_grid.py Show resolved Hide resolved
@pfebrer
Copy link
Contributor Author

pfebrer commented Jul 29, 2020

Done 👍

@pfebrer
Copy link
Contributor Author

pfebrer commented Jul 29, 2020

Nick, I'm thinking now that instead of returning the vertices, faces, normals, etc... we could return an Isosurface object that inherits from Shape. In that way we could use the methods that you already have there. E.g.: to get the atoms that are inside the isosurface.

I'm not familiar with the implementation of shapes, is this possible?

@zerothi
Copy link
Owner

zerothi commented Jul 29, 2020

Nick, I'm thinking now that instead of returning the vertices, faces, normals, etc... we could return an Isosurface object that inherits from Shape. In that way we could use the methods that you already have there. E.g.: to get the atoms that are inside the isosurface.

Good idea, but no.. :(
The Shapes are not meant for this. Currently they only encompass volumetric data. If planes and polygon-surfaces are needed later, then it requires a major effort on this part first before doing this.

But I will have it in mind if need be :)

Thanks for the suggestions!

@zerothi zerothi merged commit 0f58222 into zerothi:master Jul 29, 2020
@pfebrer
Copy link
Contributor Author

pfebrer commented Jul 29, 2020

Right, I was thinking only about closed isosurfaces, but I didn't notice that isosurfaces do not necessarily create a closed volume.

@pfebrer pfebrer deleted the grid_isosurface branch July 31, 2020 11:06
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