ngaussfit errors
kcwong wrote on Aug 02, 2006
I am using stsdas.analysis.fitting.ngaussfit to fit a Gaussian profile across some quasar spectra. I am running a loop that runs ngaussfit on each column in the spectra and makes a model image from the profiles. While running the loop, sometimes I get a message like "Stop after X iterations. Tolerance = 8.986383E-5 Starting again..." where X is some number. I set my controlpars.maxit to 3000, but this message keeps popping up with X less than 3000. The loop runs fine up until some point, then every column afterwards will get this error message. My model image looks fine up until this column, and everything afterwards is just a pixel with a value of zero, except for a couple horizontal rows. The column where this starts to occur is different for each image, and there does not seem to be anything unusual about the particular column.
There is also another issue I've been having. When I run ngaussfit, I print it to STDOUT so I can get the values for some of the parameters and build my model. So my code is something like:
quasar = iraf.ngaussfit(image + "[" + str(col) + "," + str(cent-7) + ":" + str(cent+25) + "]", "STDOUT", Stdout=1)
quasar_line = quasar[34]
values2 = quasar_line.split()
The first several lines of "quasar" have something like "#c coeff1 d %15.7g", "#c coeff2 d %15.7g", etc. all the way up to around c coeff11, but when I get this error and try to print out "quasar" every time through the loop, it runs fine for a little while, but then at some arbitrary column, it only goes up to c coeff7 or something like that, so that quasar[34] ends up being out of bounds. I don't know what would cause gausspars to change its output parameters while it's running the loop since it seems to work fine up until some point. Again, there isn't anything that appears different about the columns at which this happens.
Any ideas?
There is also another issue I've been having. When I run ngaussfit, I print it to STDOUT so I can get the values for some of the parameters and build my model. So my code is something like:
quasar = iraf.ngaussfit(image + "[" + str(col) + "," + str(cent-7) + ":" + str(cent+25) + "]", "STDOUT", Stdout=1)
quasar_line = quasar[34]
values2 = quasar_line.split()
The first several lines of "quasar" have something like "#c coeff1 d %15.7g", "#c coeff2 d %15.7g", etc. all the way up to around c coeff11, but when I get this error and try to print out "quasar" every time through the loop, it runs fine for a little while, but then at some arbitrary column, it only goes up to c coeff7 or something like that, so that quasar[34] ends up being out of bounds. I don't know what would cause gausspars to change its output parameters while it's running the loop since it seems to work fine up until some point. Again, there isn't anything that appears different about the columns at which this happens.
Any ideas?
Mike Fitzpatrick wrote on Aug 02, 2006
According to the code anyway, the first message is printed when either the maxiter limit is hiw, or some internal flag is set indicated the fit did not converge (where converge is defined to be a tolerance < 5E-6). This is using the 'ameba' method of fitting, do you have any better luck using the Levenberg-Marquardt method? Have you tried adjusting the staring values?
I can't offer any help on the second part of you question other than to suggest that since the output of the task is a table then using one of the TABLES tasks to select the value of interest might be more robust. You might also want to contact the STScI helpdesk (help@stsci.edu) since this is their task and they might have more insight on both points. Hope this helps.
Cheers,
-Mike
I can't offer any help on the second part of you question other than to suggest that since the output of the task is a table then using one of the TABLES tasks to select the value of interest might be more robust. You might also want to contact the STScI helpdesk (help@stsci.edu) since this is their task and they might have more insight on both points. Hope this helps.
Cheers,
-Mike
kcwong wrote on Aug 02, 2006
I've tried adjusting the starting values, and it seems to have the same problem, though the column it messe up on isn't always the same depending on the starting value. I have the same problem with the Levenberg-Marquardt method, except the error becomes:
2 Singular matrix in nl_gj
Starting again... 2 Singular matrix in nl_gj
Starting again... 2 Singular matrix in nl_gj
Starting again... 2 Singular matrix in nl_gj
2 Singular matrix in nl_gj
Starting again... 2 Singular matrix in nl_gj
Starting again... 2 Singular matrix in nl_gj
Starting again... 2 Singular matrix in nl_gj
Last post on Aug 02, 2006