Skip to content

Instantly share code, notes, and snippets.

@tspriggs
Created December 14, 2019 14:14
Show Gist options
  • Save tspriggs/608550ced058cc790e7eae49eb7bdb7e to your computer and use it in GitHub Desktop.
Save tspriggs/608550ced058cc790e7eae49eb7bdb7e to your computer and use it in GitHub Desktop.
example of my older astropy dual peak fitting class
# Define custom two peak Gaussian model using Astropy class type.
class Gaussian1D_OIII(Fittable1DModel):
amplitude = Parameter()
mean = Parameter()
stddev = Parameter()
a = Parameter()
b = Parameter()
# evaluate the model. This is composued using the Fittable1DModel class from Astropy.
@staticmethod
def evaluate(x, amplitude, mean, stddev, a, b):
model = a + b*x + np.abs(amplitude) * np.exp(- 0.5 * (x - mean) ** 2 / (np.sqrt((stddev)**2. + 1.16**2.)) ** 2) + np.abs(amplitude)/3 * np.exp(- 0.5 * (x - (mean - 47.9399)) ** 2 / (np.sqrt((stddev)**2. + 1.16**2.)) ** 2)
return model
#%%
# single gaussian plotted at lambda_max position.
# Fit the data using a Gaussian
# curve fit attempt
g_init = Gaussian1D_OIII(amplitude=max(flux_density), mean=5045, stddev=3.0, a=0., b=0.)#, fixed={"stddev":True})
fitter = fitting.LevMarLSQFitter()
g_fit = fitter(g_init, wavelength, flux_density, maxiter=1000000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment