Autostronomy / AutoProf

Automatic Isophotal solutions for galaxy images
https://autoprof.readthedocs.io/
GNU General Public License v3.0
27 stars 4 forks source link

AutoProf fails to fit isophotes of face-on galaxies #8

Open hgao-astro opened 1 year ago

hgao-astro commented 1 year ago

The optimization of isophotal ellipticity fails when the initialized ellipticity is close to 0 or 1. Because the perturbation was done after converting the ellipticity to another parameter space of $[-\infty, +\infty]$ using _inv_x_to_eps and then scaling back using _x_to_eps. The functional form makes any finite perturbation at $\epsilon \rightarrow 0$ and $\epsilon \rightarrow 1$ (corresponds to $-\infty$ and $+\infty$ in the perturbed parameter space) negligible. Since there are few galaxies with global ellipticity close to 1, the problem mostly affects nearly face-on galaxies.

https://github.com/Autostronomy/AutoProf/blob/8db0fd2c84a95f15eb7a3267506b336764f2a627/autoprof/pipeline_steps/Isophote_Fit.py#L628-L631

I assume that the purpose of such scaling is to do optimization in a continuous parameter space. However, since the perturbation was done in a Monte-Carlo manner, I presume that it is not critical to do such scaling. I try directly perturbing the ellipticity and when it hits its parameter boundary I simply reflect it against the boundary.

tmp_eps = perturbations[-1][i]["ellip"] + np.random.normal(
    loc=0, scale=perturb_scale
)
if tmp_eps < 0:
    tmp_eps = -tmp_eps % 1
    # tmp_eps = 0
elif tmp_eps > 1:
    tmp_eps = 1 - tmp_eps % 1
    # tmp_eps = 1
perturbations[-1][i]["ellip"] = tmp_eps

This temporary solution seems working. Let me know if you have other ideas. I would be happy to initiate a pull request when ready. Below I show a failed example and a successful fit using the new code above.

fit_ellipse_shalo_099-7_v1_HSC_I_fail fit_ellipse_shalo_099-7_v1_HSC_I_success

hgao-astro commented 1 year ago

btw, during initialization, the optimization of global ellipticity also involves _inv_x_to_eps and _x_to_eps. https://github.com/Autostronomy/AutoProf/blob/8db0fd2c84a95f15eb7a3267506b336764f2a627/autoprof/pipeline_steps/Isophote_Initialize.py#L285-L308 I have no evidence this will cause an issue. Please weigh in on this. Thanks!

ConnorStoneAstro commented 1 year ago

Hi @hgao-astro,

Wow, this is great work! To me this seems clearly better for face-on galaxies. My only concern is for edge-on systems with ellip close to 1. In that case the shape becomes very sensitive to small changes in the ellipticity and so part of the remapping of _x_to_eps was to effectively decrease the step size near edge-on. Perhaps we could get the best of both worlds by adding an if statement which does the _x_to_eps scheme when ellip > 0.5 and doing your reflection scheme when ellip < 0.5. Both method are basically equivalent around ellip = 0.5 so it should be a pretty smooth transition. What do you think about that?

I agree for the initialization it is fine to just keep it since its more the optimization that encounters the issue.

hgao-astro commented 1 year ago

Thanks for the prompt reply. Let me give it a try and see if it works as expected. btw, I forgot to mention that I used a perturbation scale = 0.1 to achieve successful face-on fits, and have not yet evaluated the impact on computation time.

hgao-astro commented 11 months ago

Thanks for your patience. I have been occupied by job searching these days. I will try to get to it in Jan. 2024.

ConnorStoneAstro commented 11 months ago

@hgao-astro Good luck with your job search! I look forward to hearing from you in the new year!