Hi Ala,
I believe that the problem with the "bad fit" is that the data read in from one of the FITS files is single-precision float, whereas the fitting codes all really need double-precision.
That is, I think everything should work if you do:
vel = data[:, 0].astype('float64')
counts = data[0, 1].astype('float64')
FWIW, you might also try something like this as a cleaner way to get the smaller data based on range of "vel":
def indexat(array, value):
"""return index of array *nearest* to value
>>> ix = indexat(array, value)
"""
return np.abs(array-value).argmin()
minIndex = indexat(vel, velmin)
maxIndex = indexat(vel, velmax)
y = counts[minIndex:maxIndex] - offset
x = vel[minIndex:maxIndex]