pmelchior / scarlet2

Scarlet, all new and shiny
MIT License
14 stars 3 forks source link

Profile morphology from ellipticities #50

Closed b-remy closed 4 months ago

b-remy commented 4 months ago

Hi @SampsonML , @pmelchior ,

I think I found the issue with generating ProfileMorphology from ellipticities.

The coordinate transformation matrix $\dfrac{1}{\sqrt{1-g²}} \begin{pmatrix} 1+g_1 & g_2 \\ g_2 & 1-g_1 \end{pmatrix}$ (the covariance matrix is the inverse of this one),

is defined with respect to $g$ which is the reduced definition of the ellipticity. However, the input parameters of the profile are $e_1$ and $e_2$ which are the distortion definition (see here for definitions and how to convert one from the other).

I am fine working with $e_1$ and $e_2$ and this is what is computed using the moments in Melchior et al. (2010) eq. 2:

$\epsilon = [G{20} - G{02} + 2iG{11}] / [G{20} + G_{02}]$.

I am not familiar with the formula in #47 using an additional term in the denominator, and everything is consistent with the definition above.

Therefore, I think the moments method in measure.py is correct, we just need to make a conversion when using distortion ellipticities in morphology.py (hence this PR). For later, we may want to have the flexibility to take as input either distortion or reduced ellipticities, let me know if you want me to add these options.

Here is a notebook which compares the two definitions (for ellipticity computation) and where the profile is generated using the conversion from distortion to reduced ellipticities.

SampsonML commented 4 months ago

Nice, from the notebook the size however is still overestimating by a bit bigger than a factor of root 2?

pmelchior commented 4 months ago

OK, great. So, the take-aways:

  1. The elliptical profile definition is identical between ProfileMorphology and galsim's profiles. I might have looked at the galsim code when I created it years ago, not sure anymore..
  2. Both use the simpler definition (which in Bartelmann & Schneider is called $\chi$ instead of $\epsilon$).
  3. Both give moment sizes $T=47$ when we set it with a size of $\sigma=30$.

3 is a result of 1, but nonetheless weird. One culprit can be the factor $1/\sqrt{1-e^2}$, which both we and galsim use in the profile definition. I tried setting $e=0$ and got a factor of $\sqrt{2}$ up to uncertainties from the pixel sizes, so this is still wrong. I wonder if this definition is meant to preserve flux or surface brightness or something else. Can one of you dig through the galsim docs to see if they mention it anywhere.

pmelchior commented 4 months ago

OK, I found it. The correct form of the size given the flux-normalized 2nd moments of the profile is $det(Q)^{1/4}$, i.e.

(g[(0,2)] * g[(2,0)] - (g[(1,1)])**2)**(1/4)

Matt tried this earlier, but using only the exponent 1/2 instead of 1/4.

b-remy commented 4 months ago

Awesome! I think we are good for this little PR then.