shapelets.functions

This module holds all shapelet function definitions.

  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
 18"""
 19This module holds all shapelet function definitions.
 20"""
 21
 22from typing import Union
 23
 24import numpy as np
 25from scipy.special import factorial, genlaguerre, hermite
 26
 27
 28def cartesian1D(
 29    n: int, 
 30    x1: Union[float,np.ndarray], 
 31    beta: float
 32):
 33    r""" Returns a 1D cartesian shapelet function [1]_ 
 34    evaluated at (x1) [float or array].
 35    
 36    The 1D cartesian shapelet function is defined as
 37
 38    .. math::  
 39
 40        S_{n}(x; \beta) = \beta^{-\frac{1}{2}} \phi_{n}(\frac{x}{\beta}) 
 41    
 42    .. math:: 
 43
 44        \phi_n(x) = \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} 
 45                    H_n(x) exp(-\frac{x^2}{2}) 
 46
 47    where :math:`\phi_n` is the dimensionless basis function, 
 48    :math:`\beta` is the shapelet length scale, 
 49    :math:`H_n` is a hermite polynomial of order :math:`n`, where 
 50    :math:`n` is the shapelet order parameter.
 51
 52    Parameters
 53    ----------
 54    n : int  
 55        Shapelet order. Acceptable values are :math:`n \geq 0`  
 56    x1 : Union[float,np.ndarray]  
 57        The input to the shapelet function  
 58    beta : float  
 59        The shapelet length scale parameter  
 60    
 61    References
 62    ----------
 63    .. [1] https://doi.org/10.1046/j.1365-8711.2003.05901.x
 64    """
 65    if n < 0:
 66        raise ValueError('n must be a non-negative integer.')
 67
 68    # Generate Hermite polynomial
 69    H = hermite(n)
 70
 71    # Define common expressions
 72    a = 1 / (( 2**n * np.sqrt(np.pi) * factorial(int(n), exact = True) )**0.5)
 73
 74    # Define shapelet
 75    Sc = lambda x: (1/np.sqrt(beta)) * a \
 76        * H(x/beta) \
 77        * np.exp(- ((x/beta)**2) / 2 )
 78
 79    return Sc(x1)
 80
 81
 82def cartesian2D(
 83    n1: int, 
 84    n2: int, 
 85    x1: Union[float,np.ndarray], 
 86    x2: Union[float,np.ndarray], 
 87    beta: float
 88):
 89    r""" Returns a 2D cartesian shapelet function [1]_
 90    evaluated at (x1,x2) [float or array].
 91    
 92    The 2D cartesian shapelet function is defined as
 93
 94    .. math::
 95
 96        S_{n_1,n_2}(x_1, x_2; \beta) = 
 97            \beta^{-1} \phi_{n_1}(\frac{x_1}{\beta}) 
 98            \phi_{n_2}(\frac{x_2}{\beta}) 
 99
100    .. math::
101        
102        \phi_n(x) = 
103            \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} 
104            H_n(x) exp(-\frac{x^2}{2}) 
105
106    where :math:`\phi_n` is the dimensionless basis function, 
107    :math:`\beta` is the shapelet length scale, 
108    :math:`H_n` is a hermite polynomial of order :math:`n`, and 
109    :math:`n_1` and :math:`n_2` are the shapelet orders.
110
111    Parameters
112    ----------
113    n1 : int  
114        Shapelet order in x direction. :math:`n1 \geq 0`  
115    n2 : int  
116        Shapelet order in y direction. :math:`n2 \geq 0`  
117    x1 : Union[float,np.ndarray]  
118        First input to shapelet function  
119    x2 : Union[float,np.ndarray]  
120        Second input to shapelet function  
121    beta : float  
122        The shapelet length scale parameter  
123
124    References
125    ----------
126    .. [1] https://doi.org/10.1046/j.1365-8711.2003.05901.x
127    """
128    if n1 < 0 or n2 < 0:
129        raise ValueError('n1 and n2 must both be non-negative integers.')
130
131    # Generate Hermite polynomials
132    H1 = hermite(n1)
133    H2 = hermite(n2)
134
135    # Define common expressions
136    a1 = 1 / (( 2**n1 * np.sqrt(np.pi) * factorial(int(n1), exact = True) )**0.5)
137    a2 = 1 / (( 2**n2 * np.sqrt(np.pi) * factorial(int(n2), exact = True) )**0.5)
138
139    # Define shapelet
140    Sc = lambda x,y: (1/beta) * a1 \
141        * H1(x/beta) \
142        * np.exp(-((x/beta)**2) / 2 ) \
143        * a2 * H2(y/beta) * np.exp(-((y/beta)**2) / 2)
144    
145    return Sc(x1, x2)
146
147
148def polar2D(
149    n: int, 
150    m: int, 
151    x1: Union[float,np.ndarray], 
152    x2: Union[float,np.ndarray], 
153    beta: float
154):
155    r""" Returns a 2D polar shapelet function [1]_
156    evaluated at (x1,x2) [float or array].
157    
158    The 2D polar shapelet function is defined as
159
160    .. math:: 
161        
162        S_{n, m}(r, \theta; \beta) = 
163            \alpha_1 \alpha_2 r^{|m|} L_{(n-|m|)/2}^{|m|} 
164            \left(\frac{r^2}{\beta^2}\right) 
165            exp\left( -\frac{r^2}{2\beta^2} \right)
166            exp(-im\theta) 
167
168    .. math:: 
169        
170        \alpha_1 = \frac{(-1)^{(n-|m|)/2}}{\beta^{|m|+1}}
171
172    .. math:: 
173    
174        \alpha_2 = 
175            \left[ \frac{[(n-|m|)/2]!} {\pi[(n+|m|)/2]!} \right]^{\frac{1}{2}}
176
177    where :math:`\beta` is the shapelet length scale, 
178    :math:`L` is the generalized (associated) laguerre polynomial [2]_, 
179    :math:`n` is the shapelet order, and 
180    :math:`m` is also the shapelet order.
181
182    Parameters
183    ----------
184    n : int  
185        Shapelet order. :math:`n \geq 0`  
186    m : int  
187        Shapelet order.:math:`m \in [-n, n]`. If n odd/even, m is odd/even  
188    x1 : Union[float,np.ndarray]  
189        First input to shapelet function  
190    x2 : Union[float,np.ndarray]  
191        Second input to shapelet function  
192    beta : float  
193        The shapelet length scale parameter  
194    
195    References
196    ----------
197    .. [1] https://doi.org/10.1111/j.1365-2966.2005.09453.x
198    .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html
199    """
200    if n < 0:
201        raise ValueError('n must be a non-negative integer.')
202    elif abs(m) > n:
203        raise ValueError('m must be between -n and n.')
204    elif n % 2 == 0 and m % 2 != 0:
205        raise ValueError('m must be even if n is even.')
206    elif n % 2 != 0 and m % 2 == 0:
207        raise ValueError('m must be odd if n is odd.')
208
209    # Define common expressions
210    nm = (n - np.abs(m))/2
211    nm2 = (n + np.abs(m))/2
212
213    # Generate LG polynomial
214    L = genlaguerre(nm, np.abs(m))
215
216    # Calculate the weighting constant
217    c =  ( (-1)**nm / (beta**(np.abs(m)+1)) )  \
218        * np.sqrt(factorial(int(nm), exact = True)) \
219        / (np.pi * factorial(int(nm2), exact = True) )
220
221    # Define shapelet
222    Sp = lambda r,t: c * r**np.abs(m) * L((r/beta)**2) * np.exp(-((r/beta)**2)/2) * np.exp(-1j*m*t)
223    Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x))
224
225    return Sc(x1, x2)
226
227
228def orthonormalpolar2D_n0(
229    m: int, 
230    x1: Union[float,np.ndarray], 
231    x2: Union[float,np.ndarray], 
232    beta: float
233):
234    r""" Returns a 2D orthonormal polar shapelet function [1]_
235    evaluated at (x1,x2) [float or array].
236    
237    The orthonormal 2D polar shapelet function is defined as
238
239    .. math::
240        
241        S_{m}(r, \theta; \beta) = \frac{1}{\beta \sqrt{\pi m!}} 
242            \left( \frac{r}{\beta} \right)^m 
243            exp \left( -\frac{r^2}{2\beta^2}-im\theta \right) 
244
245    .. math::
246
247        \beta = \frac{fl}{\sqrt{m}}
248
249    where :math:`\beta` is the shapelet length scale, 
250    :math:`f` is a geometric scale factor, 
251    :math:`l` is the characteristic wavelength of the image [2]_, and 
252    :math:`m` is the shapelet degree of rotational symmetry.
253
254    Parameters
255    ----------
256    m : int  
257        Shapelet degree of rotational symmetry. :math:`m > 1`  
258    x1 : Union[float,np.ndarray]  
259        First input to shapelet function  
260    x2 : Union[float,np.ndarray]  
261        Second input to shapelet function  
262    beta : float  
263        The shapelet length scale parameter  
264
265    Notes
266    -----
267    This shapelet formulation is a re-parameterization of shapelets.functions.polar2D.
268
269    .. [1] https://doi.org/10.1088/1361-6528/aaf353
270    .. [2] http://dx.doi.org/10.1103/PhysRevE.91.033307
271    """
272    if m < 1:
273        raise ValueError("Function only supports m >= 1.")
274
275    # Generate LG polynomial
276    n = 0
277    L = genlaguerre(n, m)
278
279    # weighting constant
280    c = 1 / (np.sqrt(np.pi * factorial(m)))
281
282    # shapelet function
283    X = lambda r: r**m * L(r**2) * np.exp(-r**2 / 2)
284    Sp = lambda r,t: beta**-1 * c * X(r/beta) * np.exp(-1j*m*t)
285    Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x))
286
287    return Sc(x1, x2)
288
289
290def orthonormalpolar2D_n1(
291    m: int, 
292    x1: Union[float,np.ndarray], 
293    x2: Union[float,np.ndarray], 
294    beta: float
295):
296    r""" Returns a 2D orthonormal polar shapelet function with one
297    degree of radial symmetry [1]_ evaluated at (x1,x2) [float or array].
298
299    The orthonormal 2D polar shapelet function
300    with one degree of radial symmetry is defined as
301
302    .. math::
303        
304        S_{m}(r, \theta; \beta) = \frac{r^m \beta^{-(m+1)}}{\sqrt{\pi m! (m+1)}}
305            \left[ 1 + m- \left( \frac{r}{\beta}\right)^2 \right] 
306            e^{-\frac{r^2}{2\beta^2}} e^{-im\theta} 
307
308    where :math:`\beta` is the shapelet length scale, 
309    :math:`l` is the characteristic wavelength of the image [2]_, and 
310    :math:`m` is the shapelet degree of rotational symmetry.
311
312    Parameters
313    ----------
314    m : int  
315        Shapelet degree of rotational symmetry. :math:`m > 1`  
316    x1 : Union[float,np.ndarray]  
317        First input to shapelet function  
318    x2 : Union[float,np.ndarray]  
319        Second input to shapelet function  
320    beta : float  
321        The shapelet length scale parameter  
322
323    Notes
324    -----
325    This shapelet formulation is a re-parameterization of shapelets.functions.polar2D.
326
327    References
328    ----------
329    .. [1] https://hdl.handle.net/10012/20779
330    .. [2] http://dx.doi.org/10.1103/PhysRevE.91.033307
331    """
332    if m < 1:
333        raise ValueError("Function only supports m >= 1.")
334
335    # weighting constant
336    c = 1 / ( np.sqrt(np.pi * factorial(m, exact=True) * (m+1)) )
337
338    # shapelet function
339    X = lambda r: r**m * (1+m-(r**2)) * np.exp(-0.5 * r**2)
340    Sp = lambda r,t: (c / beta) * X(r/beta) * 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)
344
345
346def exponential1D(
347    n: int, 
348    x1: Union[float,np.ndarray], 
349    beta: float
350):
351    r""" Returns a 1D exponential shapelet function [1]_
352    evaluated at (x1) [float or array].
353
354    The 1D exponential shapelet function is defined as 
355
356    .. math:: 
357    
358        S_n(x; \beta) = \alpha \frac{2x}{n\beta} L^{1}_{n-1} 
359            \left( \frac{2x}{n\beta} \right) 
360            exp\left( -\frac{x}{n\beta} \right) \forall x \geq 0 
361
362    .. math::
363        
364        \alpha = \frac{(-1)^{n-1}}{\sqrt{n^3\beta}} 
365
366    where :math:`\beta` is the shapelet length scale, 
367    :math:`L` is the generalized (associated) laguerre polynomial [2]_, and 
368    :math:`n` is the shapelet order.
369
370    Parameters
371    ----------
372    n : int  
373        Shapelet order. Must be non-negative. :math:`n \geq 1`  
374    x1 : Union[float,np.ndarray]  
375        The input to the shapelet function. :math:`x1 \geq 0`  
376    beta : float  
377        The shapelet length scale parameter  
378    
379    References
380    ----------
381    .. [1] https://doi.org/10.1093/mnras/stz787
382    .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html
383    """
384    if n < 1:
385        raise ValueError('n must be >= 1.')
386    if isinstance(x1, np.ndarray):
387        if x1.min() < 0:
388            raise ValueError('x1 must only contain values for x >= 0.')
389    elif x1 < 0:
390        raise ValueError('x1 must be >= 0.')
391
392    # Generate LG polynomial
393    L = genlaguerre(n-1, 1)
394
395    # Define common expressions
396    a = (-1)**(n-1) / np.sqrt(beta*(n**3))
397
398    # Define shapelet
399    Sc = lambda x: a * 2 * x * (n*beta)**-1 * L(2*x/(n*beta)) * np.exp(-x/(n*beta))
400
401    return Sc(x1)
402
403
404def exponential2D(
405    n: int, 
406    m: int, 
407    x1: Union[float,np.ndarray], 
408    x2: Union[float,np.ndarray], 
409    beta: float
410):
411    r""" Returns a 2D exponential shapelet function [1]_
412    evaluated at (x1,x2) [float or array].
413
414    The 2D exponential shapelet function is defined as  
415
416    .. math:: 
417        
418        S_{n,m}(r, \theta; \beta) = \alpha (2r)^{|m|} L^{2|m|}_{n-|m|}
419            \left( \frac{2r}{\beta(2n+1)} \right) 
420            exp\left( -\frac{r}{\beta(2n+1)} \right) exp(-im\theta) 
421
422    .. math::
423        
424        \alpha = \frac{(-1)^n}{(\beta(2n+1))^{|m|}} 
425            \sqrt{ \frac{2}{\beta\pi(2n+1)^3} \frac{(n-|m|)!}{(n+|m|)!} } 
426
427    where :math:`\beta` is the shapelet length scale, 
428    :math:`L` is the generalized (associated) laguerre polynomial [2]_, 
429    :math:`n` is the shapelet order, and 
430    :math:`m` is also the shapelet order.
431
432    Parameters
433    ----------
434    n : int  
435        Shapelet order. :math:`n \geq 0`  
436    m : int  
437        Shapelet order. :math:`m \in [-n, n]`  
438    x1 : Union[float,np.ndarray]  
439        First input to shapelet function  
440    x2 : Union[float,np.ndarray]  
441        Second input to shapelet function  
442    beta : float  
443        The shapelet length scale parameter  
444
445    References
446    ----------
447    .. [1] https://doi.org/10.1093/mnras/stz787
448    .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html
449    """
450    if n < 0:
451        raise ValueError('n must be a non-negative integer.')
452    elif np.abs(m) > n:
453        raise ValueError('m must be an integer between -n and n.')
454
455    # Define common expressions
456    nm = n - np.abs(m)
457    nm2 = n + np.abs(m)
458    nm3 = (2*n) + 1
459    b = 2 / (beta*nm3)
460
461    # Generate LG polynomial
462    L = genlaguerre(nm, 2*np.abs(m))
463    # Calculate the weighting constant
464    c = (-1)**n * np.sqrt(2 * (beta*np.pi)**-1 * nm3**-3) \
465        * np.sqrt(factorial(int(nm), exact=True) / factorial(int(nm2), exact=True))
466
467    # Define shapelet
468    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)
469    Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x))
470
471    return Sc(x1, x2)
def cartesian1D(n: int, x1: Union[float, numpy.ndarray], beta: float):
29def cartesian1D(
30    n: int, 
31    x1: Union[float,np.ndarray], 
32    beta: float
33):
34    r""" Returns a 1D cartesian shapelet function [1]_ 
35    evaluated at (x1) [float or array].
36    
37    The 1D cartesian shapelet function is defined as
38
39    .. math::  
40
41        S_{n}(x; \beta) = \beta^{-\frac{1}{2}} \phi_{n}(\frac{x}{\beta}) 
42    
43    .. math:: 
44
45        \phi_n(x) = \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} 
46                    H_n(x) exp(-\frac{x^2}{2}) 
47
48    where :math:`\phi_n` is the dimensionless basis function, 
49    :math:`\beta` is the shapelet length scale, 
50    :math:`H_n` is a hermite polynomial of order :math:`n`, where 
51    :math:`n` is the shapelet order parameter.
52
53    Parameters
54    ----------
55    n : int  
56        Shapelet order. Acceptable values are :math:`n \geq 0`  
57    x1 : Union[float,np.ndarray]  
58        The input to the shapelet function  
59    beta : float  
60        The shapelet length scale parameter  
61    
62    References
63    ----------
64    .. [1] https://doi.org/10.1046/j.1365-8711.2003.05901.x
65    """
66    if n < 0:
67        raise ValueError('n must be a non-negative integer.')
68
69    # Generate Hermite polynomial
70    H = hermite(n)
71
72    # Define common expressions
73    a = 1 / (( 2**n * np.sqrt(np.pi) * factorial(int(n), exact = True) )**0.5)
74
75    # Define shapelet
76    Sc = lambda x: (1/np.sqrt(beta)) * a \
77        * H(x/beta) \
78        * np.exp(- ((x/beta)**2) / 2 )
79
80    return Sc(x1)

Returns a 1D cartesian shapelet function 1 evaluated at (x1) [float or array].

The 1D cartesian shapelet function is defined as

$$S_{n}(x; \beta) = \beta^{-\frac{1}{2}} \phi_{n}(\frac{x}{\beta})$$

$$\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 \), where \( 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
References
def cartesian2D( n1: int, n2: int, x1: Union[float, numpy.ndarray], x2: Union[float, numpy.ndarray], beta: float):
 83def cartesian2D(
 84    n1: int, 
 85    n2: int, 
 86    x1: Union[float,np.ndarray], 
 87    x2: Union[float,np.ndarray], 
 88    beta: float
 89):
 90    r""" Returns a 2D cartesian shapelet function [1]_
 91    evaluated at (x1,x2) [float or array].
 92    
 93    The 2D cartesian shapelet function is defined as
 94
 95    .. math::
 96
 97        S_{n_1,n_2}(x_1, x_2; \beta) = 
 98            \beta^{-1} \phi_{n_1}(\frac{x_1}{\beta}) 
 99            \phi_{n_2}(\frac{x_2}{\beta}) 
100
101    .. math::
102        
103        \phi_n(x) = 
104            \left( 2^n \pi^{\frac{1}{2}} n! \right)^{-\frac{1}{2}} 
105            H_n(x) exp(-\frac{x^2}{2}) 
106
107    where :math:`\phi_n` is the dimensionless basis function, 
108    :math:`\beta` is the shapelet length scale, 
109    :math:`H_n` is a hermite polynomial of order :math:`n`, and 
110    :math:`n_1` and :math:`n_2` are the shapelet orders.
111
112    Parameters
113    ----------
114    n1 : int  
115        Shapelet order in x direction. :math:`n1 \geq 0`  
116    n2 : int  
117        Shapelet order in y direction. :math:`n2 \geq 0`  
118    x1 : Union[float,np.ndarray]  
119        First input to shapelet function  
120    x2 : Union[float,np.ndarray]  
121        Second input to shapelet function  
122    beta : float  
123        The shapelet length scale parameter  
124
125    References
126    ----------
127    .. [1] https://doi.org/10.1046/j.1365-8711.2003.05901.x
128    """
129    if n1 < 0 or n2 < 0:
130        raise ValueError('n1 and n2 must both be non-negative integers.')
131
132    # Generate Hermite polynomials
133    H1 = hermite(n1)
134    H2 = hermite(n2)
135
136    # Define common expressions
137    a1 = 1 / (( 2**n1 * np.sqrt(np.pi) * factorial(int(n1), exact = True) )**0.5)
138    a2 = 1 / (( 2**n2 * np.sqrt(np.pi) * factorial(int(n2), exact = True) )**0.5)
139
140    # Define shapelet
141    Sc = lambda x,y: (1/beta) * a1 \
142        * H1(x/beta) \
143        * np.exp(-((x/beta)**2) / 2 ) \
144        * a2 * H2(y/beta) * np.exp(-((y/beta)**2) / 2)
145    
146    return Sc(x1, x2)

Returns a 2D cartesian shapelet function 1 evaluated at (x1,x2) [float or array].

The 2D cartesian shapelet function is defined as

$$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})$$

$$\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. \( n1 \geq 0 \)
  • n2 (int): Shapelet order in y direction. \( 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
References
def polar2D( n: int, m: int, x1: Union[float, numpy.ndarray], x2: Union[float, numpy.ndarray], beta: float):
149def polar2D(
150    n: int, 
151    m: int, 
152    x1: Union[float,np.ndarray], 
153    x2: Union[float,np.ndarray], 
154    beta: float
155):
156    r""" Returns a 2D polar shapelet function [1]_
157    evaluated at (x1,x2) [float or array].
158    
159    The 2D polar shapelet function is defined as
160
161    .. math:: 
162        
163        S_{n, m}(r, \theta; \beta) = 
164            \alpha_1 \alpha_2 r^{|m|} L_{(n-|m|)/2}^{|m|} 
165            \left(\frac{r^2}{\beta^2}\right) 
166            exp\left( -\frac{r^2}{2\beta^2} \right)
167            exp(-im\theta) 
168
169    .. math:: 
170        
171        \alpha_1 = \frac{(-1)^{(n-|m|)/2}}{\beta^{|m|+1}}
172
173    .. math:: 
174    
175        \alpha_2 = 
176            \left[ \frac{[(n-|m|)/2]!} {\pi[(n+|m|)/2]!} \right]^{\frac{1}{2}}
177
178    where :math:`\beta` is the shapelet length scale, 
179    :math:`L` is the generalized (associated) laguerre polynomial [2]_, 
180    :math:`n` is the shapelet order, and 
181    :math:`m` is also the shapelet order.
182
183    Parameters
184    ----------
185    n : int  
186        Shapelet order. :math:`n \geq 0`  
187    m : int  
188        Shapelet order.:math:`m \in [-n, n]`. If n odd/even, m is odd/even  
189    x1 : Union[float,np.ndarray]  
190        First input to shapelet function  
191    x2 : Union[float,np.ndarray]  
192        Second input to shapelet function  
193    beta : float  
194        The shapelet length scale parameter  
195    
196    References
197    ----------
198    .. [1] https://doi.org/10.1111/j.1365-2966.2005.09453.x
199    .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html
200    """
201    if n < 0:
202        raise ValueError('n must be a non-negative integer.')
203    elif abs(m) > n:
204        raise ValueError('m must be between -n and n.')
205    elif n % 2 == 0 and m % 2 != 0:
206        raise ValueError('m must be even if n is even.')
207    elif n % 2 != 0 and m % 2 == 0:
208        raise ValueError('m must be odd if n is odd.')
209
210    # Define common expressions
211    nm = (n - np.abs(m))/2
212    nm2 = (n + np.abs(m))/2
213
214    # Generate LG polynomial
215    L = genlaguerre(nm, np.abs(m))
216
217    # Calculate the weighting constant
218    c =  ( (-1)**nm / (beta**(np.abs(m)+1)) )  \
219        * np.sqrt(factorial(int(nm), exact = True)) \
220        / (np.pi * factorial(int(nm2), exact = True) )
221
222    # Define shapelet
223    Sp = lambda r,t: c * r**np.abs(m) * L((r/beta)**2) * np.exp(-((r/beta)**2)/2) * np.exp(-1j*m*t)
224    Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x))
225
226    return Sc(x1, x2)

Returns a 2D polar shapelet function 1 evaluated at (x1,x2) [float or array].

The 2D polar shapelet function is defined as

$$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)$$

$$\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 polynomial 2, \( n \) is the shapelet order, and \( m \) is also the shapelet order.

Parameters
  • n (int): Shapelet order. \( n \geq 0 \)
  • m (int): Shapelet order.\( m \in [-n, n] \). If n odd/even, m is odd/even
  • 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
References
def orthonormalpolar2D_n0( m: int, x1: Union[float, numpy.ndarray], x2: Union[float, numpy.ndarray], beta: float):
229def orthonormalpolar2D_n0(
230    m: int, 
231    x1: Union[float,np.ndarray], 
232    x2: Union[float,np.ndarray], 
233    beta: float
234):
235    r""" Returns a 2D orthonormal polar shapelet function [1]_
236    evaluated at (x1,x2) [float or array].
237    
238    The orthonormal 2D polar shapelet function is defined as
239
240    .. math::
241        
242        S_{m}(r, \theta; \beta) = \frac{1}{\beta \sqrt{\pi m!}} 
243            \left( \frac{r}{\beta} \right)^m 
244            exp \left( -\frac{r^2}{2\beta^2}-im\theta \right) 
245
246    .. math::
247
248        \beta = \frac{fl}{\sqrt{m}}
249
250    where :math:`\beta` is the shapelet length scale, 
251    :math:`f` is a geometric scale factor, 
252    :math:`l` is the characteristic wavelength of the image [2]_, and 
253    :math:`m` is the shapelet degree of rotational symmetry.
254
255    Parameters
256    ----------
257    m : int  
258        Shapelet degree of rotational symmetry. :math:`m > 1`  
259    x1 : Union[float,np.ndarray]  
260        First input to shapelet function  
261    x2 : Union[float,np.ndarray]  
262        Second input to shapelet function  
263    beta : float  
264        The shapelet length scale parameter  
265
266    Notes
267    -----
268    This shapelet formulation is a re-parameterization of shapelets.functions.polar2D.
269
270    .. [1] https://doi.org/10.1088/1361-6528/aaf353
271    .. [2] http://dx.doi.org/10.1103/PhysRevE.91.033307
272    """
273    if m < 1:
274        raise ValueError("Function only supports m >= 1.")
275
276    # Generate LG polynomial
277    n = 0
278    L = genlaguerre(n, m)
279
280    # weighting constant
281    c = 1 / (np.sqrt(np.pi * factorial(m)))
282
283    # shapelet function
284    X = lambda r: r**m * L(r**2) * np.exp(-r**2 / 2)
285    Sp = lambda r,t: beta**-1 * c * X(r/beta) * np.exp(-1j*m*t)
286    Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x))
287
288    return Sc(x1, x2)

Returns a 2D orthonormal polar shapelet function 1 evaluated at (x1,x2) [float or array].

The orthonormal 2D polar shapelet function is defined as

$$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)$$

$$\beta = \frac{fl}{\sqrt{m}}$$

where \( \beta \) is the shapelet length scale, \( f \) is a geometric scale factor, \( l \) is the characteristic wavelength of the image 2, and \( m \) is the shapelet degree of rotational symmetry.

Parameters
  • m (int): Shapelet degree of rotational symmetry. \( 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
Notes

This shapelet formulation is a re-parameterization of shapelets.functions.polar2D.

def orthonormalpolar2D_n1( m: int, x1: Union[float, numpy.ndarray], x2: Union[float, numpy.ndarray], beta: float):
291def orthonormalpolar2D_n1(
292    m: int, 
293    x1: Union[float,np.ndarray], 
294    x2: Union[float,np.ndarray], 
295    beta: float
296):
297    r""" Returns a 2D orthonormal polar shapelet function with one
298    degree of radial symmetry [1]_ evaluated at (x1,x2) [float or array].
299
300    The orthonormal 2D polar shapelet function
301    with one degree of radial symmetry is defined as
302
303    .. math::
304        
305        S_{m}(r, \theta; \beta) = \frac{r^m \beta^{-(m+1)}}{\sqrt{\pi m! (m+1)}}
306            \left[ 1 + m- \left( \frac{r}{\beta}\right)^2 \right] 
307            e^{-\frac{r^2}{2\beta^2}} e^{-im\theta} 
308
309    where :math:`\beta` is the shapelet length scale, 
310    :math:`l` is the characteristic wavelength of the image [2]_, and 
311    :math:`m` is the shapelet degree of rotational symmetry.
312
313    Parameters
314    ----------
315    m : int  
316        Shapelet degree of rotational symmetry. :math:`m > 1`  
317    x1 : Union[float,np.ndarray]  
318        First input to shapelet function  
319    x2 : Union[float,np.ndarray]  
320        Second input to shapelet function  
321    beta : float  
322        The shapelet length scale parameter  
323
324    Notes
325    -----
326    This shapelet formulation is a re-parameterization of shapelets.functions.polar2D.
327
328    References
329    ----------
330    .. [1] https://hdl.handle.net/10012/20779
331    .. [2] http://dx.doi.org/10.1103/PhysRevE.91.033307
332    """
333    if m < 1:
334        raise ValueError("Function only supports m >= 1.")
335
336    # weighting constant
337    c = 1 / ( np.sqrt(np.pi * factorial(m, exact=True) * (m+1)) )
338
339    # shapelet function
340    X = lambda r: r**m * (1+m-(r**2)) * np.exp(-0.5 * r**2)
341    Sp = lambda r,t: (c / beta) * X(r/beta) * np.exp(-1j*m*t)
342    Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x))
343
344    return Sc(x1, x2)

Returns a 2D orthonormal polar shapelet function with one degree of radial symmetry 1 evaluated at (x1,x2) [float or array].

The orthonormal 2D polar shapelet function with one degree of radial symmetry is defined as

$$S_{m}(r, \theta; \beta) = \frac{r^m \beta^{-(m+1)}}{\sqrt{\pi m! (m+1)}} \left[ 1 + m- \left( \frac{r}{\beta}\right)^2 \right] e^{-\frac{r^2}{2\beta^2}} e^{-im\theta}$$

where \( \beta \) is the shapelet length scale, \( l \) is the characteristic wavelength of the image 2, and \( m \) is the shapelet degree of rotational symmetry.

Parameters
  • m (int): Shapelet degree of rotational symmetry. \( 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
Notes

This shapelet formulation is a re-parameterization of shapelets.functions.polar2D.

References
def exponential1D(n: int, x1: Union[float, numpy.ndarray], beta: float):
347def exponential1D(
348    n: int, 
349    x1: Union[float,np.ndarray], 
350    beta: float
351):
352    r""" Returns a 1D exponential shapelet function [1]_
353    evaluated at (x1) [float or array].
354
355    The 1D exponential shapelet function is defined as 
356
357    .. math:: 
358    
359        S_n(x; \beta) = \alpha \frac{2x}{n\beta} L^{1}_{n-1} 
360            \left( \frac{2x}{n\beta} \right) 
361            exp\left( -\frac{x}{n\beta} \right) \forall x \geq 0 
362
363    .. math::
364        
365        \alpha = \frac{(-1)^{n-1}}{\sqrt{n^3\beta}} 
366
367    where :math:`\beta` is the shapelet length scale, 
368    :math:`L` is the generalized (associated) laguerre polynomial [2]_, and 
369    :math:`n` is the shapelet order.
370
371    Parameters
372    ----------
373    n : int  
374        Shapelet order. Must be non-negative. :math:`n \geq 1`  
375    x1 : Union[float,np.ndarray]  
376        The input to the shapelet function. :math:`x1 \geq 0`  
377    beta : float  
378        The shapelet length scale parameter  
379    
380    References
381    ----------
382    .. [1] https://doi.org/10.1093/mnras/stz787
383    .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html
384    """
385    if n < 1:
386        raise ValueError('n must be >= 1.')
387    if isinstance(x1, np.ndarray):
388        if x1.min() < 0:
389            raise ValueError('x1 must only contain values for x >= 0.')
390    elif x1 < 0:
391        raise ValueError('x1 must be >= 0.')
392
393    # Generate LG polynomial
394    L = genlaguerre(n-1, 1)
395
396    # Define common expressions
397    a = (-1)**(n-1) / np.sqrt(beta*(n**3))
398
399    # Define shapelet
400    Sc = lambda x: a * 2 * x * (n*beta)**-1 * L(2*x/(n*beta)) * np.exp(-x/(n*beta))
401
402    return Sc(x1)

Returns a 1D exponential shapelet function 1 evaluated at (x1) [float or array].

The 1D exponential shapelet function is defined as

$$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$$

$$\alpha = \frac{(-1)^{n-1}}{\sqrt{n^3\beta}}$$

where \( \beta \) is the shapelet length scale, \( L \) is the generalized (associated) laguerre polynomial 2, and \( n \) is the shapelet order.

Parameters
  • n (int): Shapelet order. Must be non-negative. \( n \geq 1 \)
  • x1 (Union[float,np.ndarray]): The input to the shapelet function. \( x1 \geq 0 \)
  • beta (float): The shapelet length scale parameter
References
def exponential2D( n: int, m: int, x1: Union[float, numpy.ndarray], x2: Union[float, numpy.ndarray], beta: float):
405def exponential2D(
406    n: int, 
407    m: int, 
408    x1: Union[float,np.ndarray], 
409    x2: Union[float,np.ndarray], 
410    beta: float
411):
412    r""" Returns a 2D exponential shapelet function [1]_
413    evaluated at (x1,x2) [float or array].
414
415    The 2D exponential shapelet function is defined as  
416
417    .. math:: 
418        
419        S_{n,m}(r, \theta; \beta) = \alpha (2r)^{|m|} L^{2|m|}_{n-|m|}
420            \left( \frac{2r}{\beta(2n+1)} \right) 
421            exp\left( -\frac{r}{\beta(2n+1)} \right) exp(-im\theta) 
422
423    .. math::
424        
425        \alpha = \frac{(-1)^n}{(\beta(2n+1))^{|m|}} 
426            \sqrt{ \frac{2}{\beta\pi(2n+1)^3} \frac{(n-|m|)!}{(n+|m|)!} } 
427
428    where :math:`\beta` is the shapelet length scale, 
429    :math:`L` is the generalized (associated) laguerre polynomial [2]_, 
430    :math:`n` is the shapelet order, and 
431    :math:`m` is also the shapelet order.
432
433    Parameters
434    ----------
435    n : int  
436        Shapelet order. :math:`n \geq 0`  
437    m : int  
438        Shapelet order. :math:`m \in [-n, n]`  
439    x1 : Union[float,np.ndarray]  
440        First input to shapelet function  
441    x2 : Union[float,np.ndarray]  
442        Second input to shapelet function  
443    beta : float  
444        The shapelet length scale parameter  
445
446    References
447    ----------
448    .. [1] https://doi.org/10.1093/mnras/stz787
449    .. [2] https://scipy.github.io/devdocs/reference/generated/scipy.special.genlaguerre.html
450    """
451    if n < 0:
452        raise ValueError('n must be a non-negative integer.')
453    elif np.abs(m) > n:
454        raise ValueError('m must be an integer between -n and n.')
455
456    # Define common expressions
457    nm = n - np.abs(m)
458    nm2 = n + np.abs(m)
459    nm3 = (2*n) + 1
460    b = 2 / (beta*nm3)
461
462    # Generate LG polynomial
463    L = genlaguerre(nm, 2*np.abs(m))
464    # Calculate the weighting constant
465    c = (-1)**n * np.sqrt(2 * (beta*np.pi)**-1 * nm3**-3) \
466        * np.sqrt(factorial(int(nm), exact=True) / factorial(int(nm2), exact=True))
467
468    # Define shapelet
469    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)
470    Sc = lambda x,y: Sp(np.sqrt(x**2 + y**2), np.arctan2(y,x))
471
472    return Sc(x1, x2)

Returns a 2D exponential shapelet function 1 evaluated at (x1,x2) [float or array].

The 2D exponential shapelet function is defined as

$$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)$$

$$\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 polynomial 2, \( n \) is the shapelet order, and \( m \) is also the shapelet order.

Parameters
  • n (int): Shapelet order. \( n \geq 0 \)
  • m (int): Shapelet order. \( 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
References