Skip to content

Commit

Permalink
pep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sosey committed Oct 18, 2021
1 parent f9cc6ca commit 226dcbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
17 changes: 7 additions & 10 deletions imexam/imexamine.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ def save(self, filename=None, fig=None):

if fig is None:
fig = self._plot_windows[-1]
fig.savefig(self.plot_name)

fig.savefig(self.plot_name)
pstr = f"plot {fig.number} saved to {self.plot_name}"
self.log.info(pstr)

Expand Down Expand Up @@ -879,7 +879,6 @@ def line_fit(self, x, y, data=None, form=None, genplot=True, fig=None, col=False
fig.canvas.draw_idle()
self._plot_windows[-1] = plt.gcf()


else:
return fitted

Expand Down Expand Up @@ -1053,7 +1052,7 @@ def radial_profile(self, x, y, data=None, form=None,
form = getattr(models, pars["func"][0])
if form.name not in self._fit_models:
raise ValueError(f"Functional {form.name} not in available: {self._fit_models}")

self.log.info(f"using model: {form}")

subtract_background = bool(pars["background"][0])
Expand All @@ -1062,7 +1061,6 @@ def radial_profile(self, x, y, data=None, form=None,
"background subtraction")
subtract_background = False


getdata = bool(pars["getdata"][0])
delta = int(pars["delta"][0])

Expand All @@ -1085,8 +1083,8 @@ def radial_profile(self, x, y, data=None, form=None,
datasize = 3

if pars["center"][0]:
xx=int(x)
yy=int(y)
xx = int(x)
yy = int(y)
data_chunk = data[yy - datasize:yy + datasize,
xx - datasize:xx + datasize]
amp, xx, yy, sigma, sigmay = self.gauss_center(xx,
Expand Down Expand Up @@ -1167,12 +1165,11 @@ def radial_profile(self, x, y, data=None, form=None,
self.log.info(info)
self.log.info(radius, flux)


# Fit the functional form to the radial profile flux
if fitplot:
fline = np.linspace(0, datasize, 100) # finer sample
# fit model to data
if form.name == "Gaussian1D":# make center radii at max ********
if form.name == "Gaussian1D": # make center radii at max ********

fitted = math_helper.fit_gauss_1d(radius, flux,
sigma_factor=sig_factor,
Expand Down Expand Up @@ -1211,7 +1208,7 @@ def radial_profile(self, x, y, data=None, form=None,
legendy = np.max(flux) / 2

if fitted is None:
msg = f"Problem with the {fitform.name} fit"
msg = f"Problem with the {form.name} fit"
self.log.info(msg)
raise ValueError(msg)

Expand Down
8 changes: 3 additions & 5 deletions imexam/math_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def fit_moffat_1d(data, gamma=2., alpha=1., sigma_factor=0.,
x0 = center_at
fluxmax = max(data)


# assumes negligable background
if weighted:
z = np.nan_to_num(1. / np.sqrt(data)) # use as weight
Expand Down Expand Up @@ -168,15 +167,14 @@ def fit_gauss_1d(radius, flux, sigma_factor=0, center_at=None, weighted=False):
if radius.shape != flux.shape:
raise ValueError("Expected same sizes for radius and flux")


if center_at is None:
center_mean = sum(radius)/len(radius)
fixed = {'amplitude': False}
bounds = {'amplitude': (flux.max()/2.,flux.max())}
bounds = {'amplitude': (flux.max() / 2., flux.max())}
else:
center_mean = center_at
fixed = {'mean': True, 'amplitude': True}
bounds = {'amplitude': (flux.max()/2., flux.max())}
bounds = {'amplitude': (flux.max() / 2., flux.max())}

# assumes negligable background
if weighted:
Expand All @@ -194,7 +192,7 @@ def fit_gauss_1d(radius, flux, sigma_factor=0, center_at=None, weighted=False):

# Gaussian1D + a constant
model = (models.Gaussian1D(amplitude=flux.max(),
mean=center_mean, stddev=1.,
mean=center_mean, stddev=1.,
fixed=fixed,
bounds=bounds) +
models.Polynomial1D(c0=flux.min(), degree=0))
Expand Down

0 comments on commit 226dcbb

Please sign in to comment.