00001 """
00002 Functions that do not directly need SLIMpy infastructure
00003 """
00004
00005 __copyright__ = """
00006 Copyright 2008 Sean Ross-Ross
00007 """
00008 __license__ = """
00009 This file is part of SLIMpy .
00010
00011 SLIMpy is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU Lesser General Public License as published by
00013 the Free Software Foundation, either version 3 of the License, or
00014 (at your option) any later version.
00015
00016 SLIMpy is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 GNU Lesser General Public License for more details.
00020
00021 You should have received a copy of the GNU Lesser General Public License
00022 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00023 """
00024
00025
00026 def vector_max( obj1, obj2 ):
00027 """
00028 obj1 can be either a scalar or a vector. obj2 must be a vector
00029 max(obj1,obj2) will return a vector the same size as obj2 with the
00030 largest elements taken from obj1 or obj2.
00031 """
00032 obj2_trh = obj2.thr( obj1 )
00033 return obj2_trh + obj1
00034
00035
00036 def cpt( c, A ):
00037 """
00038 --latex
00039 CurveLet Phase Weighting for thresholding.
00040 \\textit{c} is a SLIMpy vector instance.
00041 \\textit{A} is a SLIMpy fdct lnear operator instance with Sizes file defined.
00042 Recall that curvelet coefficients come in pairs, one for sine and one for cosine,
00043 or equivalently at angles $\\theta$ and $\\theta$ + $\\pi$, corresponding to the 'phase rotation'.
00044 Call $\\phi_{\\mu,a}$ and $\\phi_{\\mu,b}$ two curvelets that only differ by this phase rotation operation.
00045 Then $w_{\\mu,a}$ and $w_{\\mu,b}$ should be the same and defined from
00046 \\begin{equation}
00047 \\label{cpt}
00048 sqrt( {|c_{\\mu,a}|^2 + |c_{\\mu,b}|^2} )
00049 \\end{equation}
00050 instead of $c_{\\mu,a}$, resp. $c_{\\mu,b}$.
00051 Here all the $c_{\\mu}$ are obtained from pred($s_{2}$).
00052 It makes sense if you consider the following situation: $c_{\\mu,a}$ may be zero,
00053 for some non-essential reason (cancellations happen), but $c_{\\mu,b}$ is huge.
00054 Then the penalty on primaries should not depend on whether the prediction of the multiples is of type
00055 'cosine' or type 'sine' independent of phase rotation.
00056 Therefore a and b should be treated on the same footing.
00057 """
00058
00059 cSpace = c.getSpace()
00060 v = cSpace.zeros()
00061 v.flush()
00062
00063
00064
00065 an=cSpace.angles()
00066
00067
00068
00069 v[:an[0][0][0]] = abs( c[:an[0][0][0]] )
00070
00071
00072 for scale in an:
00073 j = len( scale )/2
00074
00075 for i in range( 0, j ):
00076
00077
00078 a1 = c[scale[i][0]-1:scale[i][1]]
00079
00080 a2 = c[scale[i+j][0]-1:scale[i+j][1]]
00081
00082
00083 a3 = ( ( abs( a1 )**2 +abs( a2 )**2 ) )**.5
00084
00085
00086 v[scale[i][0]-1:scale[i][1]] = a3
00087 v[scale[i+j][0]-1:scale[i+j][1]] = a3
00088
00089 return v
00090