Skip to content

Commit

Permalink
fixed centering bug from column and linefit combination
Browse files Browse the repository at this point in the history
  • Loading branch information
sosey committed Feb 8, 2018
1 parent 3c63780 commit 3e5dc41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion imexam/imexam_defpars.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"background": [False, "Solve for background? [bool]"],
"width": [10.0, "Background width in pixels"],
"order": [1, "Polynomial order to fit, 1=line"],
"rplot": [20., "Plotting radius in pixels"],
"rplot": [15., "Plotting radius in pixels"],
"pointmode": [True, "plot points instead of lines? [bool]"],
"logx": [False, "log scale x-axis?"],
"logy": [False, "log scale y-axis?"],
Expand Down
14 changes: 9 additions & 5 deletions imexam/imexamine.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ def line_fit(self, x, y, data=None, form=None, genplot=True, fig=None, col=False

xx = int(x)
yy = int(y)

# fit the center with a 2d gaussian
if pars["center"][0]:
if fitform.name is not "Polynomial1D":
Expand All @@ -705,20 +706,22 @@ def line_fit(self, x, y, data=None, form=None, genplot=True, fig=None, col=False
if col:
line = data[:, xx]
chunk = line[yy - delta:yy + delta]
delta_add = yy - delta
else:
line = data[yy, :]
chunk = line[xx - delta: xx + delta]
delta_add = xx - delta

# fit model to data
if fitform.name is "Gaussian1D":
fitted = math_helper.fit_gauss_1d(chunk)
fitted.mean_0.value += (xx - delta)
fitted.mean_0.value += delta_add
elif fitform.name is "Moffat1D":
fitted = math_helper.fit_moffat_1d(chunk)
fitted.x_0_0.value += (xx - delta)
fitted.x_0_0.value += delta_add
elif fitform.name is "MexicanHat1D":
fitted = math_helper.fit_mex_hat_1d(chunk)
fitted.x_0_0.value += (xx - delta)
fitted.x_0_0.value += delta_add
elif fitform.name is "Polynomial1D":
fitted = math_helper.fit_poly_n(chunk, deg=degree)
if fitted is None:
Expand All @@ -733,8 +736,9 @@ def line_fit(self, x, y, data=None, form=None, genplot=True, fig=None, col=False
self.log.info("{0:s} not implemented".format(fitform.name))
return

xline = np.arange(len(chunk)) + xx - delta
xline = np.arange(len(chunk)) + delta_add
fline = np.linspace(xline[0], xline[-1], 100) # finer sample

if fitform.name is "AiryDisk2D":
yfit = fitted(fline, fline * 0 + fitted.y_0_0.value)
else:
Expand Down Expand Up @@ -802,7 +806,7 @@ def line_fit(self, x, y, data=None, form=None, genplot=True, fig=None, col=False
int(x), int(y), fitted.amplitude_0.value, fitted.radius_0.value)
self.log.info(pstr)
else:
warnings.warn("Unsupported functional form used in line_fit")
warnings.warn("Unsupported functional form specified for fit")
raise ValueError
ax.plot(fline, yfit, c='r', label=str(fitform.__name__) + " fit")
ax.legend()
Expand Down

0 comments on commit 3e5dc41

Please sign in to comment.