# Sérsic fit, weighted by the photutils intensity errors
init = Sersic1D(
amplitude=np.interp(20, isolist.sma, isolist.intens), r_eff=20.0, n=1.0
)
sersic = fitting.TRFLSQFitter()(
init, isolist.sma, isolist.intens, weights=1 / isolist.int_err
)
print(f"Sérsic: I_e = {sersic.amplitude.value:.1f}, R_e = {sersic.r_eff.value:.1f} pix, n = {sersic.n.value:.2f}")
fig, axes = plt.subplots(2, 2, figsize=(10, 7), sharex=True, constrained_layout=True)
kw = dict(fmt="o", ms=3, elinewidth=1)
axes[0, 0].errorbar(isolist.sma, isolist.eps, isolist.ellip_err, **kw)
axes[0, 1].errorbar(isolist.sma, np.rad2deg(isolist.pa), np.rad2deg(isolist.pa_err), **kw)
axes[1, 0].errorbar(isolist.sma, isolist.b4, isolist.b4_err, **kw)
axes[1, 1].errorbar(isolist.sma, isolist.intens, isolist.int_err, **kw)
# Input values of the two Gaussians
for ax, (v_in, v_out) in zip(axes[0], [(1 - 5/7, 1 - 16/28), (20, 60)]):
ax.axhline(v_in, color="C3", ls=":", label="inner input")
ax.axhline(v_out, color="C2", ls=":", label="outer input")
# Inner and transition regions (see text below)
for ax in axes.flat:
ax.axvspan(isolist.sma[0], 12, color="g", alpha=0.1, lw=0)
ax.axvspan(15, 35, color="r", alpha=0.1, lw=0)
for x, name in [(np.sqrt(isolist.sma[0] * 12), "Inner"), (np.sqrt(15 * 35), "Transition region")]:
axes[0, 1].text(
x, 0.97, f"{name}\n(see text below)",
transform=axes[0, 1].get_xaxis_transform(),
ha="center", va="top"
)
# Sérsic fit, and typical n = 1 and 4 with the same I_e and R_e
a_grid = np.geomspace(isolist.sma[0], isolist.sma[-1], 200)
axes[1, 1].plot(a_grid, sersic(a_grid), "k-", lw=1, label=f"Sérsic fit: $n$ = {sersic.n.value:.2f}")
for n, ls in [(1, "--"), (4, "-.")]:
ref = Sersic1D(sersic.amplitude, sersic.r_eff, n)
axes[1, 1].plot(
a_grid, ref(a_grid), "k", ls=ls, lw=0.8, alpha=0.6,
label=f"$n$ = {n} (same $I_e$, $R_e$)"
)
axes[1, 1].set_ylim(0.5 * isolist.intens.min(), 2 * isolist.intens.max())
axes[0, 0].legend()
axes[1, 1].legend()
axes[1, 0].axhline(0, color="k", lw=0.6)
axes[1, 0].set_ylim(-0.1, 0.1)
axes[1, 1].set_yscale("log")
labels = [r"$ε$", r"$θ$ from +x (°)", r"$b_4$ (> 0: disky)", "intensity"]
for ax, label in zip(axes.flat, labels):
ax.set(xscale="log", ylabel=label)
for ax in axes[1]:
ax.set_xlabel("semimajor axis a (pix)")
fig.suptitle("Using photutils Ellipse, EllipseGeometry, and Isolist")
plt.show()