The function ps.metrics.porosity() returns an incorrect value if applied to a large image. This happens on Windows if the number of voxels in any phase exceeds the maximum allowable value for np.int32 (2_147_483_647).
Possible fix:
def porespy_porosity(im):
im = np.array(im, dtype=int)
Vp = np.sum(im == 1)
Vs = np.sum(im == 0)
e = Vp / (Vs + Vp)
return e
def fixed_porosity(im):
im = np.array(im, dtype=int)
Vp = np.sum(im == 1, dtype = np.int64)
Vs = np.sum(im == 0, dtype = np.int64)
e = Vp / (Vs + Vp)
return e
img = np.zeros((1500,1500,2000), dtype=int)
img[:,:,:1500] = 1
print(porespy_porosity(img))
print(fixed_porosity(img))
The function
ps.metrics.porosity()
returns an incorrect value if applied to a large image. This happens on Windows if the number of voxels in any phase exceeds the maximum allowable value fornp.int32
(2_147_483_647).Possible fix: