00001 """
00002 This is the class for a User Created Linear Operator.
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 from slimpy_base.Core.Interface.Structure import Structure
00027 from slimpy_base.Core.User.linop.linear_operator import LinearOperator
00028
00029
00030 class NewLinop( Structure, LinearOperator ):
00031 """
00032 The base linear operator object should not be called by itself.
00033 This is an abstract class
00034 the newlinop class must be subclassed into a concrete class
00035
00036 for example:
00037 the code:
00038
00039 class fft_user(newlinop):
00040 command = "fft1"
00041 params = ()
00042
00043 def __init__(self,space,opt='y',inv='n'):
00044 self.inSpace = space
00045 self.kparams = dict(opt=opt,inv=inv)
00046 newlinop.__init__(self)
00047
00048 #Initialize/Define the User created Linear Operator
00049 F = fft_user(vec1.getSpace())
00050
00051 will create a new linear operator that will work on an rsf dataset.
00052 the variables may be specified in the __init__ function as well
00053
00054 the variables that must be specified are:
00055 command
00056 params
00057 inSpace
00058 outSpace
00059
00060 optional variables for the adjoint are:
00061 kparams
00062 adj_command
00063 adj_params
00064 adj_kparams
00065
00066 if the optional variables are not specified then they are assumed to be
00067 the same voidSpace.
00068 """
00069 name = "newlinop"
00070 command = None
00071 params = ()
00072
00073 inSpace = None
00074 outSpace = None
00075 kparams = {}
00076 adj_command = None
00077 outSpace = None
00078 adj_params = None
00079 adj_kparams = None
00080
00081 def __init__( self ):
00082 """
00083 Initialize the class, checks the inSpace and otuSpace and sets them to voidSpace if needed.
00084 """
00085
00086 Structure.__init__( self )
00087
00088 if self.command is None:
00089 raise TypeError( "need to define command in operator" )
00090
00091 if self.inSpace is None:
00092 raise TypeError( "need to define inSpace, use voidSpace if unknown" )
00093 if self.outSpace is None:
00094 raise TypeError( "need to define outSpace, use voidSpace if unknown" )
00095
00096 if self.adj_kparams is None:
00097 self.adj_kparams = self.kparams
00098
00099 if self.adj_params is None:
00100 self.adj_params = self.params
00101
00102
00103 if self.adj_command is None:
00104 self.adj_command = self.command
00105
00106 LinearOperator.__init__( self, self.inSpace, self.outSpace , *self.params, **self.kparams )
00107
00108 def adj( self ):
00109 """
00110 Overload the adj command because we now have mor variables to worry about
00111 """
00112 from copy import copy
00113
00114 t = self.copy()
00115
00116 inSpace = copy( t.inSpace )
00117 t.inSpace = copy( t.outSpace )
00118 t.outSpace = inSpace
00119
00120 t.isadj = not self.isadj
00121
00122 kparams = copy( t.kparams )
00123 t.kparams = t.adj_kparams
00124 t.adj_kparams = kparams
00125
00126 params = copy( t.params )
00127 t.params = t.adj_params
00128 t.adj_params = params
00129
00130 com = t.command
00131 t.command = t.adj_command
00132 t.adj_command = com
00133
00134 return t
00135
00136 def applyop( self, other ):
00137 """
00138 applies the operator to other
00139 generates a new instance of the type of other
00140 """
00141 return self.generateNew( other, self.command , *self.params, **self.kparams )
00142
00143