Skewed Gaussian Model

182 views
Skip to first unread message

Ala

unread,
Feb 3, 2021, 1:06:07 PM2/3/21
to lmfit-py
Hi, 

I am pretty new to python so this may be a relatively simple fix.

I have been using the skewed gaussian model to fit some data for a while. Usually, I don't have any problems with setting initial parameters, even if they're far off from the final fit. With this new set of data I tried setting the initial parameters closer to what the final fit would be, and the variables still remain at their initial values after running the code instead of finding new ones with uncertainty. Normally, I can fix any issue by playing around with my initial boundary conditions but this does not seem to help either.  

I was hoping I could get some insight as to why it would be having trouble with this data set and not others as well as how I might go about resolving the issue. I have attached code for two different sets of data, one I am having trouble with and one that works with data that has roughly the same size and level of noise. 

Thank you
code and data.zip

Matt Newville

unread,
Feb 5, 2021, 11:14:35 AM2/5/21
to lmfit-py
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]



--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/2065455c-1759-4472-a024-b01748d1a669n%40googlegroups.com.


--
--Matt Newville <newville at cars.uchicago.edu> 630-327-7411
Reply all
Reply to author
Forward
0 new messages