Skip to content

Instantly share code, notes, and snippets.

@will-henney
Created May 9, 2023 18:59
Show Gist options
  • Save will-henney/efd581c724e8c591a7f50e9e576f2980 to your computer and use it in GitHub Desktop.
Save will-henney/efd581c724e8c591a7f50e9e576f2980 to your computer and use it in GitHub Desktop.
Discrete Gaussian model that behaves well when sigma much less than bin width
import numpy as np
import scipy.stats
import astropy.modeling
def _E_cdf(x, x0, sig):
"General case of any profile via the CDF"
return scipy.stats.norm.cdf(x, loc=x0, scale=sig)
@astropy.modeling.custom_model
def DiscreteGaussianModel(x, amplitude=1.0, mean=0.0, stddev=1.0, bin_width=1.0):
"""
A Gaussian profile, but integrated over bins of width bin_width (in units of x)
"""
return amplitude * (
_E_cdf(x + bin_width/2, mean, stddev) - _E_cdf(x - bin_width/2, mean, stddev)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment