shapelets.functions
1######################################################################################################################## 2# Copyright 2023 the authors (see AUTHORS file for full list). # 3# # 4# This file is part of shapelets. # 5# # 6# Shapelets is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General # 7# Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) # 8# any later version. # 9# # 10# Shapelets is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied # 11# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # 12# details. # 13# # 14# You should have received a copy of the GNU Lesser General Public License along with shapelets. If not, see # 15# <https://www.gnu.org/licenses/>. # 16######################################################################################################################## 17 18from typing import Union 19 20import numpy as np 21from scipy.special import factorial, genlaguerre, hermite 22 23__all__ = [ 24 'cartesian1D', 25 'cartesian2D', 26 'polar2D', 27 'orthonormalpolar2D', 28 'exponential1D', 29 'exponential2D' 30] 31 32def cartesian1D(n: int, x1: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 33 r""" 34 1D cartesian shapelet function defined as[1]_, 35 36 $$ S_{n}(x; \beta) = \beta^{-\frac{1}{2}} \phi_{n}(\frac{x}{\beta}) $$ 37 38 with $$ \phi_n(x) = \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} H_n(x) exp(-\frac{x^2}{2}) $$ 39 40 where $\phi_n$ is the dimensionless basis function, $\beta$ is the shapelet length scale, $H_n$ is a hermite polynomial of order $n$, and $n$ is the shapelet order parameter. 41 42 Parameters 43 ---------- 44 * n: int 45 * Shapelet order. Acceptable values are $n \geq 0$ 46 * x1: Union[float,np.ndarray] 47 * The input to the shapelet function 48 * beta: float 49 * The shapelet length scale parameter 50 51 Returns 52 ------- 53 * Sc(x1): Union[float,np.ndarray] 54 * Shapelet function evaluated at (x1) 55 56 References 57 ---------- 58 .. [1] https://doi.org/10.1046/j.1365-8711.2003.05901.x 59 60 """ 61 if n < 0: 62 raise ValueError('n must be a non-negative integer.') 63 64 # Generate Hermite polynomial 65 H = hermite(n) 66 67 # Define common expressions 68 a = 1 / (( 2**n * np.sqrt(np.pi) * factorial(int(n), exact = True) )**0.5) 69 70 # Define shapelet 71 Sc = lambda x: (1/np.sqrt(beta)) * a * H(x/beta) * np.exp(- ((x/beta)**2) / 2 ) 72 73 return Sc(x1) 74 75def cartesian2D(n1: int, n2: int, x1: Union[float,np.ndarray], x2: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 76 r""" 77 2D cartesian shapelet function defined as[1]_, 78 79 $$ S_{n_1,n_2}(x_1, x_2; \beta) = \beta^{-1} \phi_{n_1}(\frac{x_1}{\beta}) \phi_{n_2}(\frac{x_2}{\beta}) $$ 80 81 with $$ \phi_n(x) = \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} H_n(x) exp(-\frac{x^2}{2}) $$ 82 83 where $\phi_n$ is the dimensionless basis function, $\beta$ is the shapelet length scale, $H_n$ is a hermite polynomial of order $n$, and $n_1$ and $n_2$ are the shapelet orders. 84 85 Parameters 86 ---------- 87 * n1: int 88 * Shapelet order in x direction. Acceptable values are $n1 \geq 0$ 89 * n2: int 90 * Shapelet order in y direction. Acceptable values are $n2 \geq 0$ 91 * x1: Union[float,np.ndarray] 92 * First input to shapelet function 93 * x2: Union[float,np.ndarray] 94 * Second input to shapelet function 95 * beta: float 96 * The shapelet length scale parameter 97 98 Returns 99 ------- 100 * Sc(x1, x2): Union[float,np.ndarray] 101 * Shapelet function evaluated at (x1, x2) 102 103 References 104 ---------- 105 .. [1] https://doi.org/10.1046/j.1365-8711.2003.05901.x 106 107 """ 108 if n1 < 0 or n2 < 0: 109 raise ValueError('n1 and n2 must both be non-negative integers.') 110 111 # Generate Hermite polynomials 112 H1 = hermite(n1) 113 H2 = hermite(n2) 114 115 # Define common expressions 116 a1 = 1 / (( 2**n1 * np.sqrt(np.pi) * factorial(int(n1), exact = True) )**0.5) 117 a2 = 1 / (( 2**n2 * np.sqrt(np.pi) * factorial(int(n2), exact = True) )**0.5) 118 119 # Define shapelet 120 Sc = lambda x,y: (1/beta) * a1 * H1(x/beta) * np.exp(-((x/beta)**2) / 2 ) \ 121 * a2 * H2(y/beta) * np.exp(-((y/beta)**2) / 2) 122 123 return Sc(x1, x2) 124 125def polar2D(n: int, m: int, x1: Union[float,np.ndarray], x2: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 126 r""" 127 2D polar shapelet function defined as[1]_, 128 129 $$ S_{n, m}(r, \theta; \beta) = \alpha_1 \alpha_2 r^{|m|} L_{(n-|m|)/2}^{|m|} \left(\frac{r^2}{\beta^2}\right) exp\left( -\frac{r^2}{2\beta^2} \right) exp(-im\theta) $$ 130 131 with 132 $$ \alpha_1 = \frac{(-1)^{(n-|m|)/2}}{\beta^{|m|+1}} $$ 133 $$ \alpha_2 = \left[ \frac{[(n-|m|)/2]!} {\pi[(n+|m|)/2]!} \right]^{\frac{1}{2}} $$ 134 135 where $\beta$ is the shapelet length scale, $L$ is the generalized (associated) laguerre polynomial[2]_, $n$ is the shapelet order, and $m$ is also the shapelet order. 136 137 Parameters 138 ---------- 139 * n: int 140 * Shapelet order. Acceptable values are $n \geq 0$ 141 * m: int 142 * Also describes shapelet order. Acceptable values $m \in [-n, n]$. However, if n is odd/even, m must also be odd/even respectively 143 * x1: Union[float,np.ndarray] 144 * First input to shapelet function 145 * x2: Union[float,np.ndarray] 146 * Second input to shapelet function 147 * beta: float 148 * The shapelet length scale parameter 149 150 Returns 151 ------- 152 * Sc(x1, x2): Union[float,np.ndarray] 153 * Shapelet function evaluated at (x1, x2) 154 155 References 156 ---------- 157 .. [1] https://doi.org/10.1111/j.1365-2966.2005.09453.x 158 .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html 159 160 """ 161 if n < 0: 162 raise ValueError('n must be a non-negative integer.') 163 elif abs(m) > n: 164 raise ValueError('m must be between -n and n.') 165 elif n % 2 == 0 and m % 2 != 0: 166 raise ValueError('m must be even if n is even.') 167 elif n % 2 != 0 and m % 2 == 0: 168 raise ValueError('m must be odd if n is odd.') 169 170 # Define common expressions 171 nm = (n - np.abs(m))/2 172 nm2 = (n + np.abs(m))/2 173 174 # Generate Laguerre polynomial 175 L = genlaguerre(nm, np.abs(m)) 176 177 # Calculate the weighting constant 178 c = ( (-1)**nm / (beta**(np.abs(m)+1)) ) \ 179 * np.sqrt(factorial(int(nm), exact = True)) \ 180 / (np.pi * factorial(int(nm2), exact = True) ) 181 182 # Define shapelet 183 Sp = lambda r,t: c * r**np.abs(m) * L((r/beta)**2) * np.exp(-((r/beta)**2)/2) * np.exp(-1j*m*t) 184 Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x)) 185 186 return Sc(x1, x2) 187 188def orthonormalpolar2D(m: int, x1: Union[float,np.ndarray], x2: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 189 r""" 190 Orthonormal 2D polar shapelet function defined as[1]_, 191 192 $$ S_{m}(r, \theta; \beta) = \frac{1}{\beta \sqrt{\pi m!}} \left( \frac{r}{\beta} \right)^m exp \left( -\frac{r^2}{2\beta^2}-im\theta \right) $$ 193 194 with $$ \beta = \frac{fl}{\sqrt{m}} $$ 195 196 where $\beta$ is the shapelet length scale, $f$ is a geometric scale factor[1]_, $l$ is the characteristic wavelength of the image[2]_, and $m$ is the shapelet degree of rotational symmetry. 197 198 Parameters 199 ---------- 200 * m: int 201 * Shapelet degree of rotational symmetry. Acceptable values are $m > 1$ 202 * x1: Union[float,np.ndarray] 203 * First input to shapelet function 204 * x2: Union[float,np.ndarray] 205 * Second input to shapelet function 206 * beta: float 207 * The shapelet length scale parameter 208 209 Returns 210 ------- 211 * Sc(x1, x2): Union[float,np.ndarray] 212 * Shapelet function evaluated at (x1, x2) 213 214 Notes 215 ----- 216 The orthonormal shapelet framework[1]_ only supports $n = 0$. See ref.[2]_ for computing the characteristic wavelength of an image. Note that this shapelet formulation is a re-parameterization of that found in shapelets.functions.polar2D. 217 218 References 219 ---------- 220 .. [1] https://doi.org/10.1088/1361-6528/aaf353 221 .. [2] http://dx.doi.org/10.1103/PhysRevE.91.033307 222 223 """ 224 if m < 1: 225 raise ValueError("Function only supports m >= 1.") 226 227 # Generate Laguerre polynomial 228 n = 0 229 L = genlaguerre(n, m) 230 231 # weighting constant 232 c = 1 / (np.sqrt(np.pi * factorial(m))) 233 234 # shapelet function 235 X = lambda r: r**m * L(r**2) * np.exp(-r**2 / 2) 236 Sp = lambda r,t: beta**-1 * c * X(r/beta) * np.exp(-1j*m*t) 237 Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x)) 238 239 return Sc(x1, x2) 240 241def exponential1D(n: int, x1: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 242 r""" 243 1D exponential shapelet function defined as[1]_, 244 245 $$ S_n(x; \beta) = \alpha \frac{2x}{n\beta} L^{1}_{n-1} \left( \frac{2x}{n\beta} \right) exp\left( -\frac{x}{n\beta} \right) \forall x \geq 0 $$ 246 247 with $$ \alpha = \frac{(-1)^{n-1}}{\sqrt{n^3\beta}} $$ 248 249 where $\beta$ is the shapelet length scale, $L$ is the generalized (associated) laguerre polynomial[2]_, and $n$ is the shapelet order. 250 251 Parameters 252 ---------- 253 * n: int 254 * Shapelet order. Must be non-negative. Acceptable values are $n \geq 1$ 255 * x1: Union[float,np.ndarray] 256 * The input to the shapelet function. Acceptable values are $x1 \geq 0$ 257 * beta: float 258 * The shapelet length scale parameter 259 260 Returns 261 ------- 262 * Sc(x1): Union[float,np.ndarray] 263 * Shapelet function evaluated at (x1) 264 265 References 266 ---------- 267 .. [1] https://doi.org/10.1093/mnras/stz787 268 .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html 269 270 """ 271 if n < 1: 272 raise ValueError('n must be >= 1.') 273 if isinstance(x1, np.ndarray): 274 if x1.min() < 0: 275 raise ValueError('x1 must only contain values for x >= 0.') 276 elif x1 < 0: 277 raise ValueError('x1 must be >= 0.') 278 279 # Generate Laguerre polynomial 280 L = genlaguerre(n-1, 1) 281 # Define common expressions 282 a = (-1)**(n-1) / np.sqrt(beta*(n**3)) 283 # Define shapelet 284 Sc = lambda x: a * 2 * x * (n*beta)**-1 * L(2*x/(n*beta)) * np.exp(-x/(n*beta)) 285 286 return Sc(x1) 287 288def exponential2D(n: int, m: int, x1: Union[float,np.ndarray], x2: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 289 r""" 290 2D exponential shapelet function defined as[1]_, 291 292 $$ S_{n,m}(r, \theta; \beta) = \alpha (2r)^{|m|} L^{2|m|}_{n-|m|}\left( \frac{2r}{\beta(2n+1)} \right) exp\left( -\frac{r}{\beta(2n+1)} \right) exp(-im\theta) $$ 293 294 with $$ \alpha = \frac{(-1)^n}{(\beta(2n+1))^{|m|}} \sqrt{ \frac{2}{\beta\pi(2n+1)^3} \frac{(n-|m|)!}{(n+|m|)!} } $$ 295 296 where $\beta$ is the shapelet length scale, $L$ is the generalized (associated) laguerre polynomial[2]_, $n$ is the shapelet order, and $m$ is also the shapelet order. 297 298 Parameters 299 ---------- 300 * n: int 301 * Shapelet order. Must be non-negative. Acceptable values are $n \geq 0$ 302 * m: int 303 * Also describes shapelet order. Acceptable values are $m \in [-n, n]$ 304 * x1: Union[float,np.ndarray] 305 * First input to shapelet function 306 * x2: Union[float,np.ndarray] 307 * Second input to shapelet function 308 * beta: float 309 * The shapelet length scale parameter 310 311 Returns 312 ------- 313 * Sc(x1, x2): Union[float,np.ndarray] 314 * Shapelet function evaluated at (x1, x2) 315 316 References 317 ---------- 318 .. [1] https://doi.org/10.1093/mnras/stz787 319 .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html 320 321 """ 322 if n < 0: 323 raise ValueError('n must be a non-negative integer.') 324 elif np.abs(m) > n: 325 raise ValueError('m must be an integer between -n and n.') 326 327 # Define common expressions 328 nm = n - np.abs(m) 329 nm2 = n + np.abs(m) 330 nm3 = (2*n) + 1 331 b = 2 / (beta*nm3) 332 333 # Generate Laguerre polynomial 334 L = genlaguerre(nm, 2*np.abs(m)) 335 # Calculate the weighting constant 336 c = (-1)**n * np.sqrt(2 * (beta*np.pi)**-1 * nm3**-3) * np.sqrt(factorial(int(nm), exact=True) / factorial(int(nm2), exact=True)) 337 338 # Define shapelet 339 def Sp(r, t): return c * (r*b)**(np.abs(m)) * L(r*b) * np.exp(-(r/beta) * nm3**-1) * np.exp(-1j*m*t) 340 Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x)) 341 342 return Sc(x1, x2)
33def cartesian1D(n: int, x1: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 34 r""" 35 1D cartesian shapelet function defined as[1]_, 36 37 $$ S_{n}(x; \beta) = \beta^{-\frac{1}{2}} \phi_{n}(\frac{x}{\beta}) $$ 38 39 with $$ \phi_n(x) = \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} H_n(x) exp(-\frac{x^2}{2}) $$ 40 41 where $\phi_n$ is the dimensionless basis function, $\beta$ is the shapelet length scale, $H_n$ is a hermite polynomial of order $n$, and $n$ is the shapelet order parameter. 42 43 Parameters 44 ---------- 45 * n: int 46 * Shapelet order. Acceptable values are $n \geq 0$ 47 * x1: Union[float,np.ndarray] 48 * The input to the shapelet function 49 * beta: float 50 * The shapelet length scale parameter 51 52 Returns 53 ------- 54 * Sc(x1): Union[float,np.ndarray] 55 * Shapelet function evaluated at (x1) 56 57 References 58 ---------- 59 .. [1] https://doi.org/10.1046/j.1365-8711.2003.05901.x 60 61 """ 62 if n < 0: 63 raise ValueError('n must be a non-negative integer.') 64 65 # Generate Hermite polynomial 66 H = hermite(n) 67 68 # Define common expressions 69 a = 1 / (( 2**n * np.sqrt(np.pi) * factorial(int(n), exact = True) )**0.5) 70 71 # Define shapelet 72 Sc = lambda x: (1/np.sqrt(beta)) * a * H(x/beta) * np.exp(- ((x/beta)**2) / 2 ) 73 74 return Sc(x1)
1D cartesian shapelet function defined as1,
$$ S_{n}(x; \beta) = \beta^{-\frac{1}{2}} \phi_{n}(\frac{x}{\beta}) $$
with $$ \phi_n(x) = \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} H_n(x) exp(-\frac{x^2}{2}) $$
where $\phi_n$ is the dimensionless basis function, $\beta$ is the shapelet length scale, $H_n$ is a hermite polynomial of order $n$, and $n$ is the shapelet order parameter.
Parameters
- n: int
- Shapelet order. Acceptable values are $n \geq 0$
- x1: Union[float,np.ndarray]
- The input to the shapelet function
- beta: float
- The shapelet length scale parameter
Returns
- Sc(x1): Union[float,np.ndarray]
- Shapelet function evaluated at (x1)
References
76def cartesian2D(n1: int, n2: int, x1: Union[float,np.ndarray], x2: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 77 r""" 78 2D cartesian shapelet function defined as[1]_, 79 80 $$ S_{n_1,n_2}(x_1, x_2; \beta) = \beta^{-1} \phi_{n_1}(\frac{x_1}{\beta}) \phi_{n_2}(\frac{x_2}{\beta}) $$ 81 82 with $$ \phi_n(x) = \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} H_n(x) exp(-\frac{x^2}{2}) $$ 83 84 where $\phi_n$ is the dimensionless basis function, $\beta$ is the shapelet length scale, $H_n$ is a hermite polynomial of order $n$, and $n_1$ and $n_2$ are the shapelet orders. 85 86 Parameters 87 ---------- 88 * n1: int 89 * Shapelet order in x direction. Acceptable values are $n1 \geq 0$ 90 * n2: int 91 * Shapelet order in y direction. Acceptable values are $n2 \geq 0$ 92 * x1: Union[float,np.ndarray] 93 * First input to shapelet function 94 * x2: Union[float,np.ndarray] 95 * Second input to shapelet function 96 * beta: float 97 * The shapelet length scale parameter 98 99 Returns 100 ------- 101 * Sc(x1, x2): Union[float,np.ndarray] 102 * Shapelet function evaluated at (x1, x2) 103 104 References 105 ---------- 106 .. [1] https://doi.org/10.1046/j.1365-8711.2003.05901.x 107 108 """ 109 if n1 < 0 or n2 < 0: 110 raise ValueError('n1 and n2 must both be non-negative integers.') 111 112 # Generate Hermite polynomials 113 H1 = hermite(n1) 114 H2 = hermite(n2) 115 116 # Define common expressions 117 a1 = 1 / (( 2**n1 * np.sqrt(np.pi) * factorial(int(n1), exact = True) )**0.5) 118 a2 = 1 / (( 2**n2 * np.sqrt(np.pi) * factorial(int(n2), exact = True) )**0.5) 119 120 # Define shapelet 121 Sc = lambda x,y: (1/beta) * a1 * H1(x/beta) * np.exp(-((x/beta)**2) / 2 ) \ 122 * a2 * H2(y/beta) * np.exp(-((y/beta)**2) / 2) 123 124 return Sc(x1, x2)
2D cartesian shapelet function defined as1,
$$ S_{n_1,n_2}(x_1, x_2; \beta) = \beta^{-1} \phi_{n_1}(\frac{x_1}{\beta}) \phi_{n_2}(\frac{x_2}{\beta}) $$
with $$ \phi_n(x) = \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} H_n(x) exp(-\frac{x^2}{2}) $$
where $\phi_n$ is the dimensionless basis function, $\beta$ is the shapelet length scale, $H_n$ is a hermite polynomial of order $n$, and $n_1$ and $n_2$ are the shapelet orders.
Parameters
- n1: int
- Shapelet order in x direction. Acceptable values are $n1 \geq 0$
- n2: int
- Shapelet order in y direction. Acceptable values are $n2 \geq 0$
- x1: Union[float,np.ndarray]
- First input to shapelet function
- x2: Union[float,np.ndarray]
- Second input to shapelet function
- beta: float
- The shapelet length scale parameter
Returns
- Sc(x1, x2): Union[float,np.ndarray]
- Shapelet function evaluated at (x1, x2)
References
126def polar2D(n: int, m: int, x1: Union[float,np.ndarray], x2: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 127 r""" 128 2D polar shapelet function defined as[1]_, 129 130 $$ S_{n, m}(r, \theta; \beta) = \alpha_1 \alpha_2 r^{|m|} L_{(n-|m|)/2}^{|m|} \left(\frac{r^2}{\beta^2}\right) exp\left( -\frac{r^2}{2\beta^2} \right) exp(-im\theta) $$ 131 132 with 133 $$ \alpha_1 = \frac{(-1)^{(n-|m|)/2}}{\beta^{|m|+1}} $$ 134 $$ \alpha_2 = \left[ \frac{[(n-|m|)/2]!} {\pi[(n+|m|)/2]!} \right]^{\frac{1}{2}} $$ 135 136 where $\beta$ is the shapelet length scale, $L$ is the generalized (associated) laguerre polynomial[2]_, $n$ is the shapelet order, and $m$ is also the shapelet order. 137 138 Parameters 139 ---------- 140 * n: int 141 * Shapelet order. Acceptable values are $n \geq 0$ 142 * m: int 143 * Also describes shapelet order. Acceptable values $m \in [-n, n]$. However, if n is odd/even, m must also be odd/even respectively 144 * x1: Union[float,np.ndarray] 145 * First input to shapelet function 146 * x2: Union[float,np.ndarray] 147 * Second input to shapelet function 148 * beta: float 149 * The shapelet length scale parameter 150 151 Returns 152 ------- 153 * Sc(x1, x2): Union[float,np.ndarray] 154 * Shapelet function evaluated at (x1, x2) 155 156 References 157 ---------- 158 .. [1] https://doi.org/10.1111/j.1365-2966.2005.09453.x 159 .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html 160 161 """ 162 if n < 0: 163 raise ValueError('n must be a non-negative integer.') 164 elif abs(m) > n: 165 raise ValueError('m must be between -n and n.') 166 elif n % 2 == 0 and m % 2 != 0: 167 raise ValueError('m must be even if n is even.') 168 elif n % 2 != 0 and m % 2 == 0: 169 raise ValueError('m must be odd if n is odd.') 170 171 # Define common expressions 172 nm = (n - np.abs(m))/2 173 nm2 = (n + np.abs(m))/2 174 175 # Generate Laguerre polynomial 176 L = genlaguerre(nm, np.abs(m)) 177 178 # Calculate the weighting constant 179 c = ( (-1)**nm / (beta**(np.abs(m)+1)) ) \ 180 * np.sqrt(factorial(int(nm), exact = True)) \ 181 / (np.pi * factorial(int(nm2), exact = True) ) 182 183 # Define shapelet 184 Sp = lambda r,t: c * r**np.abs(m) * L((r/beta)**2) * np.exp(-((r/beta)**2)/2) * np.exp(-1j*m*t) 185 Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x)) 186 187 return Sc(x1, x2)
2D polar shapelet function defined as1,
$$ S_{n, m}(r, \theta; \beta) = \alpha_1 \alpha_2 r^{|m|} L_{(n-|m|)/2}^{|m|} \left(\frac{r^2}{\beta^2}\right) exp\left( -\frac{r^2}{2\beta^2} \right) exp(-im\theta) $$
with $$ \alpha_1 = \frac{(-1)^{(n-|m|)/2}}{\beta^{|m|+1}} $$ $$ \alpha_2 = \left[ \frac{[(n-|m|)/2]!} {\pi[(n+|m|)/2]!} \right]^{\frac{1}{2}} $$
where $\beta$ is the shapelet length scale, $L$ is the generalized (associated) laguerre polynomial2, $n$ is the shapelet order, and $m$ is also the shapelet order.
Parameters
- n: int
- Shapelet order. Acceptable values are $n \geq 0$
- m: int
- Also describes shapelet order. Acceptable values $m \in [-n, n]$. However, if n is odd/even, m must also be odd/even respectively
- x1: Union[float,np.ndarray]
- First input to shapelet function
- x2: Union[float,np.ndarray]
- Second input to shapelet function
- beta: float
- The shapelet length scale parameter
Returns
- Sc(x1, x2): Union[float,np.ndarray]
- Shapelet function evaluated at (x1, x2)
References
189def orthonormalpolar2D(m: int, x1: Union[float,np.ndarray], x2: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 190 r""" 191 Orthonormal 2D polar shapelet function defined as[1]_, 192 193 $$ S_{m}(r, \theta; \beta) = \frac{1}{\beta \sqrt{\pi m!}} \left( \frac{r}{\beta} \right)^m exp \left( -\frac{r^2}{2\beta^2}-im\theta \right) $$ 194 195 with $$ \beta = \frac{fl}{\sqrt{m}} $$ 196 197 where $\beta$ is the shapelet length scale, $f$ is a geometric scale factor[1]_, $l$ is the characteristic wavelength of the image[2]_, and $m$ is the shapelet degree of rotational symmetry. 198 199 Parameters 200 ---------- 201 * m: int 202 * Shapelet degree of rotational symmetry. Acceptable values are $m > 1$ 203 * x1: Union[float,np.ndarray] 204 * First input to shapelet function 205 * x2: Union[float,np.ndarray] 206 * Second input to shapelet function 207 * beta: float 208 * The shapelet length scale parameter 209 210 Returns 211 ------- 212 * Sc(x1, x2): Union[float,np.ndarray] 213 * Shapelet function evaluated at (x1, x2) 214 215 Notes 216 ----- 217 The orthonormal shapelet framework[1]_ only supports $n = 0$. See ref.[2]_ for computing the characteristic wavelength of an image. Note that this shapelet formulation is a re-parameterization of that found in shapelets.functions.polar2D. 218 219 References 220 ---------- 221 .. [1] https://doi.org/10.1088/1361-6528/aaf353 222 .. [2] http://dx.doi.org/10.1103/PhysRevE.91.033307 223 224 """ 225 if m < 1: 226 raise ValueError("Function only supports m >= 1.") 227 228 # Generate Laguerre polynomial 229 n = 0 230 L = genlaguerre(n, m) 231 232 # weighting constant 233 c = 1 / (np.sqrt(np.pi * factorial(m))) 234 235 # shapelet function 236 X = lambda r: r**m * L(r**2) * np.exp(-r**2 / 2) 237 Sp = lambda r,t: beta**-1 * c * X(r/beta) * np.exp(-1j*m*t) 238 Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x)) 239 240 return Sc(x1, x2)
Orthonormal 2D polar shapelet function defined as1,
$$ S_{m}(r, \theta; \beta) = \frac{1}{\beta \sqrt{\pi m!}} \left( \frac{r}{\beta} \right)^m exp \left( -\frac{r^2}{2\beta^2}-im\theta \right) $$
with $$ \beta = \frac{fl}{\sqrt{m}} $$
where $\beta$ is the shapelet length scale, $f$ is a geometric scale factor2, $l$ is the characteristic wavelength of the image3, and $m$ is the shapelet degree of rotational symmetry.
Parameters
- m: int
- Shapelet degree of rotational symmetry. Acceptable values are $m > 1$
- x1: Union[float,np.ndarray]
- First input to shapelet function
- x2: Union[float,np.ndarray]
- Second input to shapelet function
- beta: float
- The shapelet length scale parameter
Returns
- Sc(x1, x2): Union[float,np.ndarray]
- Shapelet function evaluated at (x1, x2)
Notes
The orthonormal shapelet framework4 only supports $n = 0$. See ref.5 for computing the characteristic wavelength of an image. Note that this shapelet formulation is a re-parameterization of that found in polar2D.
References
242def exponential1D(n: int, x1: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 243 r""" 244 1D exponential shapelet function defined as[1]_, 245 246 $$ S_n(x; \beta) = \alpha \frac{2x}{n\beta} L^{1}_{n-1} \left( \frac{2x}{n\beta} \right) exp\left( -\frac{x}{n\beta} \right) \forall x \geq 0 $$ 247 248 with $$ \alpha = \frac{(-1)^{n-1}}{\sqrt{n^3\beta}} $$ 249 250 where $\beta$ is the shapelet length scale, $L$ is the generalized (associated) laguerre polynomial[2]_, and $n$ is the shapelet order. 251 252 Parameters 253 ---------- 254 * n: int 255 * Shapelet order. Must be non-negative. Acceptable values are $n \geq 1$ 256 * x1: Union[float,np.ndarray] 257 * The input to the shapelet function. Acceptable values are $x1 \geq 0$ 258 * beta: float 259 * The shapelet length scale parameter 260 261 Returns 262 ------- 263 * Sc(x1): Union[float,np.ndarray] 264 * Shapelet function evaluated at (x1) 265 266 References 267 ---------- 268 .. [1] https://doi.org/10.1093/mnras/stz787 269 .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html 270 271 """ 272 if n < 1: 273 raise ValueError('n must be >= 1.') 274 if isinstance(x1, np.ndarray): 275 if x1.min() < 0: 276 raise ValueError('x1 must only contain values for x >= 0.') 277 elif x1 < 0: 278 raise ValueError('x1 must be >= 0.') 279 280 # Generate Laguerre polynomial 281 L = genlaguerre(n-1, 1) 282 # Define common expressions 283 a = (-1)**(n-1) / np.sqrt(beta*(n**3)) 284 # Define shapelet 285 Sc = lambda x: a * 2 * x * (n*beta)**-1 * L(2*x/(n*beta)) * np.exp(-x/(n*beta)) 286 287 return Sc(x1)
1D exponential shapelet function defined as1,
$$ S_n(x; \beta) = \alpha \frac{2x}{n\beta} L^{1}_{n-1} \left( \frac{2x}{n\beta} \right) exp\left( -\frac{x}{n\beta} \right) \forall x \geq 0 $$
with $$ \alpha = \frac{(-1)^{n-1}}{\sqrt{n^3\beta}} $$
where $\beta$ is the shapelet length scale, $L$ is the generalized (associated) laguerre polynomial2, and $n$ is the shapelet order.
Parameters
- n: int
- Shapelet order. Must be non-negative. Acceptable values are $n \geq 1$
- x1: Union[float,np.ndarray]
- The input to the shapelet function. Acceptable values are $x1 \geq 0$
- beta: float
- The shapelet length scale parameter
Returns
- Sc(x1): Union[float,np.ndarray]
- Shapelet function evaluated at (x1)
References
289def exponential2D(n: int, m: int, x1: Union[float,np.ndarray], x2: Union[float,np.ndarray], beta: float = 1.) -> Union[float,np.ndarray]: 290 r""" 291 2D exponential shapelet function defined as[1]_, 292 293 $$ S_{n,m}(r, \theta; \beta) = \alpha (2r)^{|m|} L^{2|m|}_{n-|m|}\left( \frac{2r}{\beta(2n+1)} \right) exp\left( -\frac{r}{\beta(2n+1)} \right) exp(-im\theta) $$ 294 295 with $$ \alpha = \frac{(-1)^n}{(\beta(2n+1))^{|m|}} \sqrt{ \frac{2}{\beta\pi(2n+1)^3} \frac{(n-|m|)!}{(n+|m|)!} } $$ 296 297 where $\beta$ is the shapelet length scale, $L$ is the generalized (associated) laguerre polynomial[2]_, $n$ is the shapelet order, and $m$ is also the shapelet order. 298 299 Parameters 300 ---------- 301 * n: int 302 * Shapelet order. Must be non-negative. Acceptable values are $n \geq 0$ 303 * m: int 304 * Also describes shapelet order. Acceptable values are $m \in [-n, n]$ 305 * x1: Union[float,np.ndarray] 306 * First input to shapelet function 307 * x2: Union[float,np.ndarray] 308 * Second input to shapelet function 309 * beta: float 310 * The shapelet length scale parameter 311 312 Returns 313 ------- 314 * Sc(x1, x2): Union[float,np.ndarray] 315 * Shapelet function evaluated at (x1, x2) 316 317 References 318 ---------- 319 .. [1] https://doi.org/10.1093/mnras/stz787 320 .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html 321 322 """ 323 if n < 0: 324 raise ValueError('n must be a non-negative integer.') 325 elif np.abs(m) > n: 326 raise ValueError('m must be an integer between -n and n.') 327 328 # Define common expressions 329 nm = n - np.abs(m) 330 nm2 = n + np.abs(m) 331 nm3 = (2*n) + 1 332 b = 2 / (beta*nm3) 333 334 # Generate Laguerre polynomial 335 L = genlaguerre(nm, 2*np.abs(m)) 336 # Calculate the weighting constant 337 c = (-1)**n * np.sqrt(2 * (beta*np.pi)**-1 * nm3**-3) * np.sqrt(factorial(int(nm), exact=True) / factorial(int(nm2), exact=True)) 338 339 # Define shapelet 340 def Sp(r, t): return c * (r*b)**(np.abs(m)) * L(r*b) * np.exp(-(r/beta) * nm3**-1) * np.exp(-1j*m*t) 341 Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x)) 342 343 return Sc(x1, x2)
2D exponential shapelet function defined as1,
$$ S_{n,m}(r, \theta; \beta) = \alpha (2r)^{|m|} L^{2|m|}_{n-|m|}\left( \frac{2r}{\beta(2n+1)} \right) exp\left( -\frac{r}{\beta(2n+1)} \right) exp(-im\theta) $$
with $$ \alpha = \frac{(-1)^n}{(\beta(2n+1))^{|m|}} \sqrt{ \frac{2}{\beta\pi(2n+1)^3} \frac{(n-|m|)!}{(n+|m|)!} } $$
where $\beta$ is the shapelet length scale, $L$ is the generalized (associated) laguerre polynomial2, $n$ is the shapelet order, and $m$ is also the shapelet order.
Parameters
- n: int
- Shapelet order. Must be non-negative. Acceptable values are $n \geq 0$
- m: int
- Also describes shapelet order. Acceptable values are $m \in [-n, n]$
- x1: Union[float,np.ndarray]
- First input to shapelet function
- x2: Union[float,np.ndarray]
- Second input to shapelet function
- beta: float
- The shapelet length scale parameter
Returns
- Sc(x1, x2): Union[float,np.ndarray]
- Shapelet function evaluated at (x1, x2)