Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_make_contiguous_contiguity(self):
cont_im = ps.tools.make_contiguous(self.im)
assert sp.all(sp.arange(sp.unique(self.im).size) == sp.unique(cont_im))
def test_make_contiguous_size(self):
cont_im = ps.tools.make_contiguous(self.im)
assert sp.unique(self.im).size == sp.unique(cont_im).size
def test_make_contiguous_size(self):
cont_im = ps.tools.make_contiguous(self.im)
assert sp.unique(self.im).size == sp.unique(cont_im).size
def test_make_contiguous_negs(self):
im = sp.array([[0, 0, 1, 3], [-2, -4, 1, 3], [-4, 3, 5, 0]])
a = ps.tools.make_contiguous(im, keep_zeros=True).max()
b = ps.tools.make_contiguous(im, keep_zeros=False).max()
assert a == b
def test_make_contiguous_contiguity(self):
cont_im = ps.tools.make_contiguous(self.im)
assert sp.all(sp.arange(sp.unique(self.im).size) == sp.unique(cont_im))
def test_make_contiguous_negs(self):
im = sp.array([[0, 0, 1, 3], [-2, -4, 1, 3], [-4, 3, 5, 0]])
a = ps.tools.make_contiguous(im, keep_zeros=True).max()
b = ps.tools.make_contiguous(im, keep_zeros=False).max()
assert a == b
if f is not None:
if im.ndim == 2:
faces = [(int('left' in f)*3, int('right' in f)*3),
(int(('front') in f)*3 or int(('bottom') in f)*3,
int(('back') in f)*3 or int(('top') in f)*3)]
if im.ndim == 3:
faces = [(int('left' in f)*3, int('right' in f)*3),
(int('front' in f)*3, int('back' in f)*3),
(int('top' in f)*3, int('bottom' in f)*3)]
dt = sp.pad(dt, pad_width=faces, mode='edge')
im = sp.pad(im, pad_width=faces, mode='edge')
else:
dt = dt
regions = regions*im
regions = make_contiguous(regions)
# -------------------------------------------------------------------------
# Extract void and throat information from image
net = regions_to_network(im=regions, dt=dt, voxel_size=voxel_size)
# -------------------------------------------------------------------------
# Extract marching cube surface area and interfacial area of regions
if marching_cubes_area:
areas = region_surface_areas(regions=regions, voxel_size=voxel_size)
net['pore.surface_area'] = areas
interface_area = region_interface_areas(regions=regions, areas=areas,
voxel_size=voxel_size)
net['throat.area'] = interface_area.area
# -------------------------------------------------------------------------
# Find void to void connections of boundary and internal voids
boundary_labels = net['pore.label'] > b_num
loc1 = net['throat.conns'][:, 0] < b_num
loc2 = net['throat.conns'][:, 1] >= b_num
regions = sp.pad(regions, 2, 'edge')
# Remove unselected faces
if 'left' not in faces:
regions = regions[3:, :] # x
if 'right' not in faces:
regions = regions[:-3, :]
if 'front' not in faces and 'bottom' not in faces:
regions = regions[:, 3:] # y
if 'back' not in faces and 'top' not in faces:
regions = regions[:, :-3]
else:
print('add_boundary_regions works only on 2D and 3D images')
# ---------------------------------------------------------------------
# Make labels contiguous
regions = make_contiguous(regions)
else:
regions = regions
return regions
# -------------------------------------------------------------------------
# Add boundary regions
f = boundary_faces
regions = add_boundary_regions(regions=snow.regions, faces=f)
# -------------------------------------------------------------------------
# Padding distance transform to extract geometrical properties
dt = pad_faces(im=snow.dt, faces=f)
# -------------------------------------------------------------------------
# For only one phase extraction with boundary regions
phases_num = sp.unique(im).astype(int)
phases_num = sp.trim_zeros(phases_num)
if len(phases_num) == 1:
if f is not None:
snow.im = pad_faces(im=snow.im, faces=f)
regions = regions * (snow.im.astype(bool))
regions = make_contiguous(regions)
# -------------------------------------------------------------------------
# Extract N phases sites and bond information from image
net = regions_to_network(im=regions, dt=dt, voxel_size=voxel_size)
# -------------------------------------------------------------------------
# Extract marching cube surface area and interfacial area of regions
if marching_cubes_area:
areas = region_surface_areas(regions=regions)
interface_area = region_interface_areas(regions=regions, areas=areas,
voxel_size=voxel_size)
net['pore.surface_area'] = areas * voxel_size ** 2
net['throat.area'] = interface_area.area
# -------------------------------------------------------------------------
# Find interconnection and interfacial area between ith and jth phases
net = add_phase_interconnections(net=net, snow_partitioning_n=snow,
marching_cubes_area=marching_cubes_area,
alias=al)