abagen
abagen copied to clipboard
Bug Report: ‘check_surface’ Function Offset Calculation Issue in ‘images.py’
I have identified a potential bug within the check_surface function of images.py, specifically between lines 297-301. The code segment is designed to prevent the overlapping of labels across hemispheres and to implement a correction mechanism. However, there appears to be an issue with the calculation of the 'offset'. When surface data is entered as 'adata', which is a list comprising two 'nynum' arrays, the 'np.unique(adata)' function does not execute as expected.
offset = len(np.intersect1d(*adata))
if offset > 1:
offset = len(np.unique(adata)
adata[1] += offset
labs[1] = {k + offset: v for k, v in labs[1].items()}
A viable solution would be to modify the calculation of 'offset' to prevent label duplication. Changing line 299 from
offset = len(np.unique(adata))
to offset = len(np.unique(adata[0]))
might resolve the issue, as it would only consider the labels from the first set of the 'adata' list.
Additionally, I've encountered some issues due to the fact that the label encoding in some annot files may include 0. Therefore, the offset setting might need to be slightly larger. It could be consistent to add +1 subsequently.Like this
offset = len(np.intersect1d(*adata))
if offset > 1:
offset = len(np.unique(adata[0]))
adata[1] += offset + 1
labs[1] = {k + offset + 1: v for k, v in labs[1].items()}