00001 __copyright__ = """
00002 Copyright 2008 Sean Ross-Ross
00003 """
00004 __license__ = """
00005 This file is part of SLIMpy .
00006
00007 SLIMpy is free software: you can redistribute it and/or modify
00008 it under the terms of the GNU Lesser General Public License as published by
00009 the Free Software Foundation, either version 3 of the License, or
00010 (at your option) any later version.
00011
00012 SLIMpy is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 GNU Lesser General Public License for more details.
00016
00017 You should have received a copy of the GNU Lesser General Public License
00018 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00019 """
00020
00021 from slimpy_base.Core.User.linop.LinearOperatorType import LinearOperatorType
00022 from slimpy_base.Core.User.linop.linear_operator import Identity
00023 from slimpy_base.Core.User.linop.linear_operator import CompoundOperator
00024
00025
00026
00027
00028 @LinearOperatorType
00029 def is_linear_op( oper ):
00030 '''
00031 is_linear_op( oper ) -> bool
00032 returns true if type( type(oper) ) == LinearOperatorType
00033 '''
00034 bll = type( type(oper) ) == LinearOperatorType
00035 return bll
00036
00037
00038
00039
00040 @LinearOperatorType
00041 def Norm( oper, col=True, default=None ):
00042 """
00043 Norm( oper, col=True, error=False ) -> Weights
00044 normalizes the operator
00045 if error is True then the linear operator must have the appropriate
00046 __norm_col__ or
00047 """
00048 if not is_linear_op(oper):
00049 raise TypeError( "first argument of norm must be a linear operator" )
00050
00051 if oper.isadj:
00052 coll = not col
00053 else:
00054 coll = col
00055
00056
00057 if coll:
00058 name = "__norm_col__"
00059 else:
00060 name = "__norm_row__"
00061
00062
00063 if not hasattr(oper , name):
00064 raise AttributeError( "linear operator %(oper)s "
00065 "has no method %(name)s " %vars() )
00066
00067 normmethod = getattr(oper, name)
00068 weight = normmethod( )
00069
00070 if weight == NotImplemented:
00071 if default is None:
00072 raise Exception( "operator %s can not be normalized" %(oper) )
00073 elif default == 'Identity':
00074 if col:
00075 space = oper.range( )
00076 else:
00077 space = oper.domain( )
00078
00079 return Identity( space )
00080 elif is_linear_op(default):
00081
00082 return default
00083 else:
00084 raise TypeError( 'argument "default" must be None, '
00085 '"Identity" or a LinearOperatorType, got "%s"' %type(default) )
00086 else:
00087 return weight
00088
00089
00090
00091 @LinearOperatorType
00092 def Normalize( oper , col=True, default=None ):
00093 """
00094 Normalize( oper , col=True, error=False )
00095
00096 """
00097 weights = Norm( oper, col=col, default=default )
00098 if col:
00099 oper_list = [ weights ,oper]
00100 else:
00101 oper_list = [ oper, weights]
00102
00103 return CompoundOperator( oper_list )
00104
00105
00106
00107 @LinearOperatorType
00108 def MinVelConst( oper , ang_weights, default=None ):
00109 """
00110 weight = MinVelConst(oper, ang_weights, default=None)
00111 returns a weighting operator for the min
00112 """
00113 assert is_linear_op( oper )
00114
00115 name = "__min_vel_const__"
00116
00117 if not hasattr(oper, name):
00118 if default is None:
00119 raise AttributeError( "oper does not have attribute '__min_vel_const__' " )
00120 elif default == "Identity":
00121 space = oper.domain( )
00122 return Identity(space)
00123 else:
00124 return default
00125
00126 min_vel_const = getattr(oper, name)
00127
00128 const = min_vel_const( ang_weights )
00129
00130 if const == NotImplemented:
00131 if default is None:
00132 raise AttributeError( "oper attribute '__min_vel_const__' returned 'NotImplemented' " )
00133 elif default == "Identity":
00134 space = oper.domain( )
00135 else:
00136 return default
00137 else:
00138 return const
00139
00140