File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,13 +22,18 @@ def network_from_porespy(filename):
2222 """
2323 # Parse the filename
2424 if isinstance (filename , dict ):
25- net = filename
25+ net = dict ( filename )
2626 else :
2727 filename = _parse_filename (filename = filename )
2828 with open (filename , mode = 'rb' ) as f :
2929 net = pk .load (f )
3030
31+ # Pop param.* entries so they're routed via __setitem__ into _params
32+ # rather than landing as raw dict items via update().
33+ params = {k : net .pop (k ) for k in list (net ) if k .startswith ('param.' )}
3134 network = Network ()
3235 network .update (net )
36+ for key , value in params .items ():
37+ network [key ] = value
3338
3439 return network
Original file line number Diff line number Diff line change @@ -23,6 +23,26 @@ def test_load_PoreSpy_from_file(self):
2323 assert net .Np == 1637
2424 assert net .Nt == 2785
2525
26+ def test_param_keys_are_routed_to_params (self ):
27+ net_with_params = dict (self .net )
28+ net_with_params ['param.voxel_size' ] = 1.5e-6
29+ net_with_params ['param.ndim' ] = 3
30+ proj = op .io .network_from_porespy (net_with_params )
31+ net = proj .network
32+ assert net ['param.voxel_size' ] == 1.5e-6
33+ assert net ['param.ndim' ] == 3
34+ # Ensure they survive a project save/load round-trip
35+ import tempfile
36+ with tempfile .TemporaryDirectory () as tmp :
37+ fname = os .path .join (tmp , 'proj' )
38+ op .Workspace ().save_project (project = net .project , filename = fname )
39+ ws = op .Workspace ()
40+ ws .clear ()
41+ ws .load_project (filename = fname + '.pnm' )
42+ loaded = list (ws .values ())[0 ][0 ]
43+ assert loaded ['param.voxel_size' ] == 1.5e-6
44+ assert loaded ['param.ndim' ] == 3
45+
2646
2747if __name__ == '__main__' :
2848 # All the tests in this file can be run with 'playing' this file
You can’t perform that action at this time.
0 commit comments