View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Fitting Gaussian to Data

amoldowa wrote on Mar 11, 2008

Hello,

I am looking for a way to be able to fit a Gaussian to a data set and then check to see how well the Gaussian fits. I know there are a lot of different ways to do this with an image, but I just have data that looks like this;

Line# Star1 Star2 ...
1 1.2 2.3
2 2.5 4.6
3 5.8 7.9
...

I just want to plot Line# on the x-axis and counts on the y-axis and fit with a Gaussian, and then find how well the Gaussian fits.

Any suggestions would be helpful! Thanks in advance.

Francisco Valdes wrote on Mar 11, 2008

Hello,

It was not clear from you message if you are talking about 1D or 2D fitting. I think maybe you mean 1D. Here are some suggestions.

One method is to turn your text data into an image since there are a number of 1D and 2D fitting tasks for images. The main tool for creating an image from text is rtextimage. The tool I'm most familar for 1D fitting is SPLOT that fits 1D gauassians. The task rspectext is a tool like rtextimage that can convert a text file to a spectrum format. Note that it is possible to use non-uniformly spaced points with rspectext and splot.

The stsdas.fitting package has tools for fitting things from lists or tables. A text file can usually be read as a table.

Yours,
Frank Valdes

amoldowa wrote on Mar 11, 2008

Hi Frank,

Thanks for your repsonse. Yes, I am looking for a 1D fit.

I actually have images of these, but they are 2D (basically star fields). Perhaps I should just use the images instead, as it seems easier. I believe SPLOT can only do 1D though, so is there a better tool to fit a 2D image with a gaussian and see how well it fits?

Francisco Valdes wrote on Mar 11, 2008

There are many tools and it depends on what you meean by "see how it fits".

Probably the most used tool for images is IMEXAM which allows things to be done interactively with a display (DS9 or XImtool). The default is actually to fit a Moffat but the 'a' or '.' keys can be used to fit the simpler Gaussian.

Related to the IMEXAM code is PSFMEASURE which is more of a tool for fitting non-interactively or interactively.

As I mentioned, the STSDAS fitting package does both with a somewhat different fitting algorithm.

One way to "see" how good a fit is is by subtraction. The photometry packages generally allow this though the way they define a PSF is probably not what you have in mind. Note you can do something like this with artdata.mkobject where you take the results of fitting (x, y, peak, width), make a simulated gaussian profile, and then use imarith to subtract.

Except possibly for STSDAS, the tools I've mentioned are not very good about giving uncertainties to fitted parameters.

Frank

amoldowa wrote on Mar 11, 2008

Okay, thanks again Frank. I have used IMEXAMINE to generate Gaussian fits but I am looking for what the uncertainty is in the fit. I think the subraction technique could work, so I will try that.

Thanks for your help!

Last post on Mar 11, 2008