Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/openpnm/io/_porespy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ def network_from_porespy(filename):
"""
# Parse the filename
if isinstance(filename, dict):
net = filename
net = dict(filename)
else:
filename = _parse_filename(filename=filename)
with open(filename, mode='rb') as f:
net = pk.load(f)

# Pop param.* entries so they're routed via __setitem__ into _params
# rather than landing as raw dict items via update().
params = {k: net.pop(k) for k in list(net) if k.startswith('param.')}
network = Network()
network.update(net)
for key, value in params.items():
network[key] = value

return network
20 changes: 20 additions & 0 deletions tests/unit/io/PoreSpyTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ def test_load_PoreSpy_from_file(self):
assert net.Np == 1637
assert net.Nt == 2785

def test_param_keys_are_routed_to_params(self):
net_with_params = dict(self.net)
net_with_params['param.voxel_size'] = 1.5e-6
net_with_params['param.ndim'] = 3
proj = op.io.network_from_porespy(net_with_params)
net = proj.network
assert net['param.voxel_size'] == 1.5e-6
assert net['param.ndim'] == 3
# Ensure they survive a project save/load round-trip
import tempfile
with tempfile.TemporaryDirectory() as tmp:
fname = os.path.join(tmp, 'proj')
op.Workspace().save_project(project=net.project, filename=fname)
ws = op.Workspace()
ws.clear()
ws.load_project(filename=fname + '.pnm')
loaded = list(ws.values())[0][0]
assert loaded['param.voxel_size'] == 1.5e-6
assert loaded['param.ndim'] == 3


if __name__ == '__main__':
# All the tests in this file can be run with 'playing' this file
Expand Down
Loading