import matplotlib.pyplot as plt
import numpy as np
from astropy.convolution.utils import discretize_model
from astropy.modeling.models import Gaussian1D

gauss_1D = Gaussian1D(1 / (0.5 * np.sqrt(2 * np.pi)), 0, 0.5)
x_range = (-2, 3)
x = np.arange(*x_range)
y_center = discretize_model(gauss_1D, x_range, mode='center')
y_edge = discretize_model(gauss_1D, x_range, mode='linear_interp')
y_oversample = discretize_model(gauss_1D, x_range, mode='oversample')

fig, ax = plt.subplots(figsize=(8, 6))
label = f'center (sum={y_center.sum():.3f})'
ax.plot(x, y_center, '.-', label=label)
label = f'linear_interp (sum={y_edge.sum():.3f})'
ax.plot(x, y_edge, '.-', label=label)
label = f'oversample (sum={y_oversample.sum():.3f})'
ax.plot(x, y_oversample, '.-', label=label)
ax.set_xlabel('x')
ax.set_ylabel('Value')
plt.legend()