LDDMM error: IndexError: index 1 is out of bounds for dimension 0 with size 1
IndexError Traceback (most recent call last) Cell In[132], line 26 10 # keep all other parameters default 11 params = {'L':L,'T':T, 12 'niter': 200, 13 'pointsI': pointsI, (...) 23 'epV': 5e1 24 } ---> 26 out = STalign.LDDMM([YI,XI], I, [YJ,XJ], J, **params)
File ~/.local/lib/python3.10/site-packages/STalign/STalign.py:1074, in LDDMM(xI, I, xJ, J, pointsI, pointsJ, L, T, A, v, xv, a, p, expand, nt, niter, diffeo_start, epL, epT, epV, sigmaM, sigmaB, sigmaA, sigmaR, sigmaP, device, dtype, muB, muA) 1072 else: 1073 raise Exception(f'If inputting an initial v, must input both xv and v') -> 1074 extentV = extent_from_x(xv) 1075 dv = torch.as_tensor([x[1]-x[0] for x in xv],device=device,dtype=dtype) 1079 fv = [torch.arange(n,device=device,dtype=dtype)/n/d for n,d in zip(XV.shape,dv)]
File ~/.local/lib/python3.10/site-packages/STalign/STalign.py:857, in extent_from_x(xJ)
834 def extent_from_x(xJ):
835 ''' Given a set of pixel locations, returns an extent 4-tuple for use with np.imshow.
836
837 Note inputs are locations of pixels along each axis, i.e. row column not xy.
(...)
855
856 '''
--> 857 dJ = [x[1]-x[0] for x in xJ]
858 extentJ = ( (xJ[1][0] - dJ[1]/2.0).item(),
859 (xJ[1][-1] + dJ[1]/2.0).item(),
860 (xJ[0][-1] + dJ[0]/2.0).item(),
861 (xJ[0][0] - dJ[0]/2.0).item())
862 return extentJ
File ~/.local/lib/python3.10/site-packages/STalign/STalign.py:857, in
837 Note inputs are locations of pixels along each axis, i.e. row column not xy.
(...)
855
856 '''
--> 857 dJ = [x[1]-x[0] for x in xJ]
858 extentJ = ( (xJ[1][0] - dJ[1]/2.0).item(),
859 (xJ[1][-1] + dJ[1]/2.0).item(),
860 (xJ[0][-1] + dJ[0]/2.0).item(),
861 (xJ[0][0] - dJ[0]/2.0).item())
862 return extentJ
IndexError: index 1 is out of bounds for dimension 0 with size 1
A simple affine alignment is needed to align the single-cell spatial transcriptomics dataset with the H&E staining image. So I performed non-linear local alignments via LDDMM. However, I encountered the bug illustrated as above.
I encountered the same issue as you.
The core problem occurs when running extentV = extent_from_x(xv).
After debugging the code, I found that the default value of parameter a of LDDMM is 500, which results in an excessively large step size and causes an error.
I resolved this issue by reducing the value of a.
In fact, the spatial distances between spots in my dataset are much smaller than those in standard datasets like Visium, which leads to errors when using the default parameter.