2.1.2.1.4. sf_tools.image.shape module

SHAPE ESTIMATION ROUTINES

This module contains methods and classes for estimating galaxy shapes.

Author:Samuel Farrens <samuel.farrens@gmail.com>
Version:1.4
Date:20/10/2017

Notes

Some of the methods in this module are based on work by Fred Ngole.

sf_tools.image.shape.ellipticity_atoms(data, offset=0)[source]

Calculate ellipticity

This method calculates the ellipticity of an image from its shape projection components.

Parameters:
  • data (np.ndarray) – Input data array, the image to be analysed
  • offset (int, optional) – Shape projection offset (default is ‘0’)
Returns:

Return type:

np.ndarray of the image ellipticity components

See also

shape_project()
shape projection matrix

Notes

This technique was developed by Fred Ngole and implements the following equations:

  • Equations C.1 and C.2 from [NS2016] appendix:
\[ \begin{align}\begin{aligned}e_1(\mathbf{X}_i) = \frac{<\mathbf{X}_i, \mathbf{U}_4> <\mathbf{X}_i, \mathbf{U}_2> - <\mathbf{X}_i, \mathbf{U}_0>^2 + <\mathbf{X}_i, \mathbf{U}_1>^2} {<\mathbf{X}_i, \mathbf{U}_3> <\mathbf{X}_i, \mathbf{U}_2> - <\mathbf{X}_i, \mathbf{U}_0>^2 - <\mathbf{X}_i, \mathbf{U}_1>^2 }\\e_2(\mathbf{X}_i) = \frac{2\left(<\mathbf{X}_i, \mathbf{U}_5> <\mathbf{X}_i, \mathbf{U}_2> - <\mathbf{X}_i, \mathbf{U}_0> <\mathbf{X}_i, \mathbf{U}_1>\right)} {<\mathbf{X}_i, \mathbf{U}_3> <\mathbf{X}_i, \mathbf{U}_2> - <\mathbf{X}_i, \mathbf{U}_0>^2 - <\mathbf{X}_i, \mathbf{U}_1>^2 }\end{aligned}\end{align} \]

Examples

>>> from image.shape import ellipticity_atoms
>>> import numpy as np
>>> a = np.zeros((5, 5))
>>> a[2, 1:4] += 1
>>> ellipticity_atoms(a)
array([-1.,  0.])
>>> b = np.zeros((5, 5))
>>> b[1:4, 2] += 1
>>> ellipticity_atoms(b)
array([ 1.,  0.])
sf_tools.image.shape.shape_project(shape, offset=0, return_norm=False)[source]

Shape projection matrix

This method generates a shape projection matrix for a given image.

Parameters:
  • shape (list, tuple or np.ndarray) – List of image dimensions
  • offset (int, optional) – Shape projection offset (default is ‘0’)
  • return_norm (bool, optional) – Option to return l2 normalised shape projection components (default is ‘False’)
Returns:

Return type:

np.ndarray of shape projection components

See also

ellipticity_atoms()
calculate ellipticity

Notes

This technique was developed by Fred Ngole and implements the following equations:

  • Equations from [NS2016] appendix:
\[\begin{split}U_1 &= (k)_{1 \leq k \leq N_l, 1 \leq l \leq N_c} \\ U_2 &= (l)_{1 \leq k \leq N_l, 1 \leq l \leq N_c} \\ U_3 &= (1)_{1 \leq k \leq N_l, 1 \leq l \leq N_c} \\ U_4 &= (k^2 + l^2)_{1 \leq k \leq N_l, 1 \leq l \leq N_c} \\ U_5 &= (k^2 - l^2)_{1 \leq k \leq N_l, 1 \leq l \leq N_c} \\ U_6 &= (kl)_{1 \leq k \leq N_l, 1 \leq l \leq N_c}\end{split}\]

Examples

>>> from image.shape import shape_project
>>> shape_project([3, 3])
array([[[ 0.,  0.,  0.],
        [ 1.,  1.,  1.],
        [ 2.,  2.,  2.]],

       [[ 0.,  1.,  2.],
        [ 0.,  1.,  2.],
        [ 0.,  1.,  2.]],

       [[ 1.,  1.,  1.],
        [ 1.,  1.,  1.],
        [ 1.,  1.,  1.]],

       [[ 0.,  1.,  4.],
        [ 1.,  2.,  5.],
        [ 4.,  5.,  8.]],

       [[ 0., -1., -4.],
        [ 1.,  0., -3.],
        [ 4.,  3.,  0.]],

       [[ 0.,  0.,  0.],
        [ 0.,  1.,  2.],
        [ 0.,  2.,  4.]]])
class sf_tools.image.shape.Ellipticity(data, sigma=1000, centroid=None, moments=None, ellip_type='chi')[source]

Image ellipticity class

This class calculates image ellipticities from quadrupole moments.

Parameters:
  • data (np.ndarray) – Input data array, the image to be analysed
  • sigma (int, optional) – Estimation error (default is ‘1000’)
  • centroid (np.ndarray, optional) – Centroid positions [x, y] of the input image (defualt is ‘None’)
  • moments (np.ndarray, optional) – Quadrupole moments [[q00, q01], [q10, q11]] of the input image (defualt is ‘None’)
  • ellip_type (str {'chi', 'epsilon'}, optional) – Ellipticity type (default is ‘chi’)

Examples

>>> from image.shape import Ellipticity
>>> import numpy as np
>>> a = np.zeros((5, 5))
>>> a[2, 1:4] += 1
>>> Ellipticity(a).e
array([-1.,  0.])
>>> b = np.zeros((5, 5))
>>> b[1:4, 2] += 1
>>> Ellipticity(b).e
array([ 1.,  0.])
_check_ellip_type()[source]

Check Ellipticity Type

This method raises an error if ellip_type is not ‘chi’ or ‘epsilon’.

Raises:ValueError for invalid ellip_type
_update_xy()[source]

Update the x and y values

This method updates the values of x and y using the current centroid.

_update_weights()[source]

Update the weights

This method updates the value of the weights using the current values of x and y.

Notes

This method implements the following equations:

  • The exponential part of equation 1 from [BM2007] to calculate the weights:
\[w(x,y) = e^{-\frac{\left((x-x_c)^2+(y-y_c)^2\right)} {2\sigma^2}}\]
_update_centroid()[source]

Update the centroid

This method updates the centroid value using the current weights.

Notes

This method implements the following equations:

  • Equation 2a, 2b and 2c from [BM2007] to calculate the position moments:
\[ \begin{align}\begin{aligned}S_w = \sum_{x,y} I(x,y)w(x,y)\\S_x = \sum_{x,y} xI(x,y)w(x,y)\\S_y = \sum_{x,y} yI(x,y)w(x,y)\end{aligned}\end{align} \]
  • Equation 3 from [BM2007] to calculate the centroid:
\[X_c = S_x/S_w,\ Y_c = S_y/S_w\]
_get_centroid(n_iter=10)[source]

Calculate centroid

This method iteratively calculates the centroid of the image.

Parameters:n_iter (int, optional) – Number of iterations (deafult is ‘10’)
_get_moments()[source]

Calculate the quadrupole moments

This method calculates the quadrupole moments.

Notes

This method implements the following equations:

  • Equation 10 from [C2013] to calculate the moments:
\[Q_{ij}=\frac{\int\int\Phi(x_i,x_j) w(x_i,x_j) (x_i-\bar{x_i})(x_j-\bar{x_j}) dx_idx_j} {\int\int\Phi(x_i,x_j)w(x_i,x_j)dx_idx_j}\]
_get_ellipse()[source]

Calculate the ellipticities

This method cacluates ellipticities from quadrupole moments.

Notes

This method implements the following equations:

  • Equation 11 from [C2013] to calculate the size:
\[R^2 = Q_{00} + Q_{11}\]
  • Equation 7 from [S2005] to calculate the ellipticities:
\[ \begin{align}\begin{aligned}\chi = \frac{Q_{00}-Q_{11}+iQ_{01}+iQ_{10}}{R^2}\\\epsilon = \frac{Q_{00}-Q_{11}+iQ_{01}+iQ_{10}}{R^2 + 2\sqrt{(Q_{00}Q_{11} - Q_{01}Q_{10})}}\end{aligned}\end{align} \]