Skip to content

Add rescale_network and param.* metadata - #1165

Merged
jgostick merged 3 commits into
devfrom
fix/614-rescale-network
May 5, 2026
Merged

Add rescale_network and param.* metadata#1165
jgostick merged 3 commits into
devfrom
fix/614-rescale-network

Conversation

@ma-sadeghi

@ma-sadeghi ma-sadeghi commented Apr 26, 2026

Copy link
Copy Markdown
Member

Closes #614.

Network extractions can take days for large images, but until now changing voxel size required re-running the whole thing. This adds:

  1. param.voxel_size and param.ndim written into the network dict by regions_to_network, regions_to_network_parallel, and magnet.
  2. 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 fixes network_from_porespy so 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 .pnm save/load.

Anisotropic voxel sizes (regions_to_network_parallel accepts a tuple) raise NotImplementedError from rescale_network if the components differ. Same-on-all-axes tuples are treated as scalar. rescale_network returns a new dict; the input is not mutated.

@codecov

codecov Bot commented Apr 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.36364% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.9%. Comparing base (a2ffcc5) to head (0b576f8).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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
ma-sadeghi force-pushed the fix/614-rescale-network branch from a0797cc to 2f587e2 Compare April 28, 2026 08:54
… 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.
@ma-sadeghi
ma-sadeghi requested a review from jgostick April 28, 2026 13:19
@jgostick

jgostick commented May 5, 2026

Copy link
Copy Markdown
Member

This seems like a great addition, and I like the implementation.

@jgostick
jgostick merged commit 2056677 into dev May 5, 2026
17 checks passed
@ma-sadeghi
ma-sadeghi deleted the fix/614-rescale-network branch May 9, 2026 09:08
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.

Allow rescaling SNOW based on voxel size

2 participants