00001 """
00002 Some more Linear operators
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.User.linop.rclinOp import linearop_r as LinearOperatorStruct
00027 from slimpy_base.Core.Interface.ContainerBase import DataContainer
00028 from slimpy_base.Core.Interface.node import Source
00029 from slimpy_base.Core.User.Structures.VectorType import is_vector
00030 from slimpy_base.Core.User.linop.linear_operator import LinearOperator
00031
00032
00033
00034
00035 class pickingoper( LinearOperatorStruct ):
00036 """
00037 Zero a portion of a dataset based on a header mask
00038 """
00039 name = 'pick'
00040 __block_diagonal__ = True
00041 def __init__( self, inSpace, mask, axis=2 ):
00042 self.axis = axis
00043 kparams = dict( mask = Source( mask.container ) )
00044
00045 LinearOperatorStruct.__init__( self, inSpace , **kparams )
00046
00047 def applyop( self, other ):
00048 """
00049 Apply self to a vector other
00050 """
00051
00052
00053 othertransp = other.transp( a1=2, a2=self.axis )
00054
00055 picadj = LinearOperatorStruct.applyop( self, othertransp )
00056
00057 picdata = picadj.transp( a1=2, a2=self.axis )
00058
00059 return picdata
00060
00061
00062
00063 class DiagonalWeight( LinearOperator ):
00064 """
00065 DiagonalWeight( domain, weight ) -> D
00066 diagonal weighting operator
00067 for D*other, if other is not a vector
00068 returns new DiagonalWeight instance
00069 """
00070 name = 'DiagonalWeight'
00071 def __init__( self, domain, weight ):
00072 self.weight = weight
00073 range = domain
00074 LinearOperator.__init__( self, domain, range )
00075
00076 def applyop(self,other):
00077 ret = self.weight * other
00078 if is_vector( other ):
00079 return ret
00080 else:
00081 return DiagonalWeight( self.range(), ret )
00082
00083
00084
00085 class weightoper( LinearOperatorStruct ):
00086 """
00087 the Input parameter must be a vecor
00088 """
00089 cmnd = 'mul'
00090 def __init__( self, wvec, inSpace ):
00091 """
00092 The param wvec must be able to be applied to another vector. Or is it is out of core, can be a string
00093 TODO if wvec is None, it is the Identity operator.
00094 TODO - error trap that if wvec is same type as other when applying.
00095 """
00096
00097 msg = "weightoper:Dont use this class!!! use DiagonalWeight"
00098 import warnings; warnings.warn( msg, DeprecationWarning )
00099
00100 self.wvec = wvec
00101 if is_vector( wvec):
00102 par = Source( wvec.container )
00103 LinearOperatorStruct.__init__( self, inSpace, vec=par )
00104 if isinstance( wvec, DataContainer ):
00105 par = Source( wvec )
00106 LinearOperatorStruct.__init__( self, inSpace, vec=par )
00107 else:
00108 LinearOperatorStruct.__init__( self, inSpace, wvec )
00109
00110 def applyop( self, other ):
00111 """
00112 apply this operator to a vector
00113 """
00114
00115 return self.wvec * other
00116
00117
00118
00119 class restrictoper( LinearOperatorStruct ):
00120 """
00121 The restriction operator takes mask
00122 """
00123 name = 'restrict'
00124 def __init__( self, inSpace, mask):
00125
00126 from slimpy_base.Core.User.Structures.serial_vector import Vector
00127 if isinstance(mask, str):
00128 from slimpy_base import vector
00129 mask = vector(mask)
00130 elif not isinstance(mask, Vector):
00131 raise TypeError( "argument 'mask' must be a 'Vector' or a 'str' instance got '%s'" %type(mask) )
00132
00133 LinearOperatorStruct.__init__( self, inSpace, mask=Source(mask.container) )
00134
00135
00136 class conjoper( weightoper ):
00137 """
00138 This will apply the conj operator to the input.
00139 """
00140 cmnd = 'conj'
00141 def __init__( self, inspace ):
00142 """
00143 Just call the superclass weight operator, that will apply the conj op.
00144 """
00145 LinearOperatorStruct.__init__( self, inspace )
00146
00147 def applyop( self, other ):
00148 return other.conj()
00149
00150
00151 class transpoper( LinearOperatorStruct ):
00152 """
00153 This will apply the transp operator to the input.
00154 """
00155 name = 'transp'
00156 def __init__( self, inspace, plane=[1,2], **kparams ):
00157
00158 LinearOperatorStruct.__init__( self, inspace, plane=plane, **kparams )
00159
00160
00161 class Cosine( LinearOperatorStruct ):
00162 """
00163 Cosine transform
00164 """
00165 name = 'cosinetrans'
00166 def __init__( self, domain , adj=False ):
00167
00168
00169 LinearOperatorStruct.__init__( self, domain, adj=False )
00170
00171
00172
00173
00174
00175
00176
00177