def trim_edge_cube(cube):
""" trim_edge_cube: Function that reads in a cube and removes the edges
in the cube.
It runs the erode function to make sure that pixels within 3 pixels away
from the edges are blanked.
This is useful to remove very noisy pixels due to lower coverage by KFPA.
----------------------------------------
Warning: This function modifies the cube.
"""
#
mask = np.isfinite(cube)
if len(cube.shape) == 2:
mask_2d = mask[:,:]
else:
mask_2d = mask[0,:,:]
# remove image edges
mask_2d[:,0] = mask_2d[:,-1] = False
mask_2d[0,:] = mask_2d[-1,:] = False
# now erode image (using disk) and convert back to 3D mask
# then replace all voxels with NaN
mask &= erosion(mask_2d,disk(5))
cube[~mask] = np.nan
评论列表
文章目录