I/O¶
The voids.io sub-package handles serialization and import/export of networks.
HDF5¶
voids.io.hdf5
¶
save_hdf5
¶
Serialize a network to the project HDF5 interchange format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network to store. |
required |
path
|
str | Path
|
Destination file path. Parent directories must already exist. |
required |
Notes
The file layout is intentionally explicit:
/metastores schema and provenance metadata./samplestores the sample geometry payload./network/poreand/network/throatstore arrays./labelsstores boolean pore and throat labels asuint8datasets./attributeextrastores JSON-compatible auxiliary metadata.
Source code in src/voids/io/hdf5.py
load_hdf5
¶
Load a network from the project HDF5 interchange format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to an HDF5 file produced by :func: |
required |
Returns:
| Type | Description |
|---|---|
Network
|
Reconstructed network object. |
Notes
Boolean labels are stored on disk as uint8 arrays for portability and are
converted back to bool arrays during import.
Source code in src/voids/io/hdf5.py
PoreSpy Import¶
voids.io.porespy
¶
scale_porespy_geometry
¶
Scale common PoreSpy geometry fields from voxel units to physical units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_dict
|
Mapping[str, object]
|
PoreSpy/OpenPNM-style mapping containing keys such as |
required |
voxel_size
|
float
|
Edge length of one voxel in physical units. |
required |
Returns:
| Type | Description |
|---|---|
dict of str to object
|
New mapping with common geometric fields rescaled. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
This helper assumes isotropic voxels. The conversion factors are:
- lengths:
L_phys = L_vox * voxel_size - areas:
A_phys = A_vox * voxel_size**2 - volumes:
V_phys = V_vox * voxel_size**3 - perimeters:
P_phys = P_vox * voxel_size
When throat.volume is absent but throat.cross_sectional_area and
throat.total_length are available, a simple conduit approximation is used:
throat.volume = throat.cross_sectional_area * throat.total_length
This is convenient for manufactured examples and notebook workflows, but it is still a geometric approximation rather than an exact segmented volume.
Source code in src/voids/io/porespy.py
ensure_cartesian_boundary_labels
¶
Infer Cartesian inlet and outlet pore labels from coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_dict
|
Mapping[str, object]
|
Mapping containing at least |
required |
axes
|
tuple[str, ...] | None
|
Axes to label. If omitted, all axes present in the coordinate array are used. |
None
|
tol_fraction
|
float
|
Fraction of the domain span used as a geometric tolerance near each boundary. |
0.05
|
Returns:
| Type | Description |
|---|---|
dict of str to object
|
Updated mapping with labels such as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the coordinate array has invalid shape, if |
Notes
For each active axis, the helper marks pores satisfying
x <= x_min + tolas inlet poresx >= x_max - tolas outlet pores
where tol = tol_fraction * max(x_max - x_min, 1e-12).
Source code in src/voids/io/porespy.py
from_porespy
¶
from_porespy(
network_dict,
*,
sample=None,
provenance=None,
strict=True,
geometry_repairs=None,
repair_seed=0,
)
Build a :class:Network from a PoreSpy/OpenPNM-style mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_dict
|
Mapping[str, object]
|
Mapping containing PoreSpy/OpenPNM keys such as |
required |
sample
|
SampleGeometry | None
|
Sample geometry metadata attached to the resulting network. If omitted,
a default empty :class: |
None
|
provenance
|
Provenance | None
|
Provenance metadata. If omitted, a default record with
|
None
|
strict
|
bool
|
If |
True
|
geometry_repairs
|
str | None
|
Optional extraction-style preprocessing mode. Set to
|
None
|
repair_seed
|
int | None
|
Seed for any stochastic repair branch. Only used when
|
0
|
Returns:
| Type | Description |
|---|---|
Network
|
Imported network in the canonical |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the required topology keys are missing. |
Notes
The importer performs several normalizations:
- PoreSpy/OpenPNM aliases are mapped to canonical
voidsnames. - Two-dimensional coordinates are embedded into 3D as
(x, y, 0). - Basic missing geometry is derived when possible.
- Common boundary aliases such as
leftandrightare mirrored toinlet_xminandoutlet_xmax.
Unsupported nested arrays such as throat.hydraulic_size_factors are
preserved in net.extra so that information is not silently lost.
Source code in src/voids/io/porespy.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
OpenPNM Interoperability¶
voids.io.openpnm
¶
from_porespy
¶
from_porespy(
network_dict,
*,
sample=None,
provenance=None,
strict=True,
geometry_repairs=None,
repair_seed=0,
)
Build a :class:Network from a PoreSpy/OpenPNM-style mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_dict
|
Mapping[str, object]
|
Mapping containing PoreSpy/OpenPNM keys such as |
required |
sample
|
SampleGeometry | None
|
Sample geometry metadata attached to the resulting network. If omitted,
a default empty :class: |
None
|
provenance
|
Provenance | None
|
Provenance metadata. If omitted, a default record with
|
None
|
strict
|
bool
|
If |
True
|
geometry_repairs
|
str | None
|
Optional extraction-style preprocessing mode. Set to
|
None
|
repair_seed
|
int | None
|
Seed for any stochastic repair branch. Only used when
|
0
|
Returns:
| Type | Description |
|---|---|
Network
|
Imported network in the canonical |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the required topology keys are missing. |
Notes
The importer performs several normalizations:
- PoreSpy/OpenPNM aliases are mapped to canonical
voidsnames. - Two-dimensional coordinates are embedded into 3D as
(x, y, 0). - Basic missing geometry is derived when possible.
- Common boundary aliases such as
leftandrightare mirrored toinlet_xminandoutlet_xmax.
Unsupported nested arrays such as throat.hydraulic_size_factors are
preserved in net.extra so that information is not silently lost.
Source code in src/voids/io/porespy.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
to_openpnm_dict
¶
Export a network to an OpenPNM/PoreSpy-style flat dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network to export. |
required |
include_extra
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
dict of str to Any
|
Flat mapping using keys such as |
Notes
The mapping preserves aliases expected by :func:voids.io.porespy.from_porespy.
Conduit-length fields are emitted both under their internal names
(for round-tripping within voids) and under OpenPNM-style names
such as throat.conduit_lengths.pore1.
Source code in src/voids/io/openpnm.py
to_openpnm_network
¶
Convert a :class:Network into an OpenPNM network object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network to convert. |
required |
copy_properties
|
bool
|
If |
True
|
copy_labels
|
bool
|
If |
True
|
include_extra
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
OpenPNM network object. The precise class depends on the installed OpenPNM version. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If OpenPNM is not installed. |
RuntimeError
|
If a compatible OpenPNM network object cannot be instantiated. |
Notes
OpenPNM's constructor signatures vary across versions. This helper tries a small
set of known call patterns and always assigns pore.coords and
throat.conns explicitly afterward so that topology transfer is version-robust.