//// TO DO: this only works for 1 pixel at a time, specified by [row][col]
//// assuming that inBlockT has correctly accessed a numpy ndarray
pixel = inBlockT[0][0]
// solve simultaneous equations with numpy linear algebra least squares
results = np.linalg.lstsq(signaturesT, pixel)
//// TO DO:
After Change
// [B, G, R, NIR1, SWIR1, SWIR2] at each pixel
inBlockT = inBlock.transpose([1, 2, 0])
// reshape to slightly flatten to 2d array
inBlockTFlat = inBlockT.reshape((-1, inBlockT.shape[-1]))
// solve simultaneous functions at each pixel stack
// looping and output of new array of all lstsq results
def unmixPixel(pixelStack, sigs):
solution = np.linalg.lstsq(sigs, pixelStack)
results = np.append(solution[0], solution[1][0]) // return endmembers and residual
return results
// np.apply_along_axis seems to be slower than native Python looping
outBlock = np.apply_along_axis(unmixPixel, 1, inBlockTFlat, signaturesT)
// outBlock shape is (n, 4); must reconstruct into endmember bands with values in correct x,y
// e.g. you can reconstruct: inBlockTFlat.reshape((1994,2310,6)) back to inBlockT
// here we need (1994,2310,4) without residuals; (1994,2310,5) with residuals
outBlockReshaped = outBlock.reshape(-1, inBlock.shape[-1], 5).transpose((2,0,1))
pixelBlocks["output_pixels"] = outBlockReshaped.astype(props["pixelType"])
return pixelBlocks