Add rescale_network and param.* metadata - #1165
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #1165 +/- ##
=======================================
+ Coverage 70.8% 70.9% +0.1%
=======================================
Files 45 45
Lines 6533 6577 +44
=======================================
+ Hits 4627 4665 +38
- Misses 1906 1912 +6 🚀 New features to boost your workflow:
|
Networks now carry `param.voxel_size` and `param.ndim` from extraction. `rescale_network` reads those to rescale all length/area/volume fields to a new voxel size, matching what a fresh extraction would produce. Closes #614
ma-sadeghi
force-pushed
the
fix/614-rescale-network
branch
from
April 28, 2026 08:54
a0797cc to
2f587e2
Compare
… print Plain Python `float`/`int` for these new metadata entries crashed `print(pn)` after `op.io.network_from_porespy`, because OpenPNM's `get_printable_props` does `v.dtype != bool` on every dict value before filtering by key. Wrapping with `np.asarray` gives them a `.dtype` without changing their semantics. `rescale_network` now uses `vs_old.ndim > 0` and `.flat[0]` instead of `hasattr(__len__)` so it handles 0-d arrays correctly.
Member
|
This seems like a great addition, and I like the implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #614.
Network extractions can take days for large images, but until now changing voxel size required re-running the whole thing. This adds:
param.voxel_sizeandparam.ndimwritten into the network dict byregions_to_network,regions_to_network_parallel, andmagnet.ps.networks.rescale_network(network, voxel_size)which reads those, computes the scale factor, and rescales all length / area / volume fields. Output matches a fresh extraction at the new voxel size.The function is name-driven: it inspects the part after the last
.(e.g.pore.inscribed_diameter->inscribed_diameter) and looks up an exponent (1 for length-like, 2 for area, ndim for volume, 1 for size-factor-like). Anything it doesn't recognize is left alone.param.*is the OpenPNM-blessed namespace for scalar metadata. PMEAL/OpenPNM#3046 fixesnetwork_from_porespyso these keys round-trip cleanly through OpenPNM project save/load. Without that fix, the keys still work in-memory and through plain pickle, just not through.pnmsave/load.Anisotropic voxel sizes (
regions_to_network_parallelaccepts a tuple) raiseNotImplementedErrorfromrescale_networkif the components differ. Same-on-all-axes tuples are treated as scalar.rescale_networkreturns a new dict; the input is not mutated.