00001 ##@package new_noise_rsf_integration 00002 # This is the second step in creating a linear operator. There are two substeps to this module. 00003 # - create a \ref slimpy_base.api.Plugins.slim2rsf.sfcommands.sfConverter "sfConverter" 00004 # subclass that defines how to use a SLIMpy operator with rsf commands. 00005 # - register the converter with the rsf plugin. 00006 # 00007 # @code 00008 # from numpy import ceil 00009 # from slimpy_base.api.Plugins.slim2rsf.sfCommandFactory import rsfCommandFactory 00010 # from slimpy_base.api.Plugins.slim2rsf.sfcommands.sfConverter import sfConverter 00011 # 00012 # ######################################################################## 00013 # # Define how noisex behaves 00014 # ######################################################################## 00015 # 00016 # # create a Converter class 00017 # class noiseX_Converter( sfConverter ): 00018 # \""" 00019 # This is a mapping instance that maps a SLIMpy command into an object that 00020 # can be run. 00021 # There are three types of function this class should have. 00022 # - map 00023 # - trans 00024 # - constr 00025 # Each of these functions can have an optional '_adj' at the end of the name 00026 # if the operator's adjoint is different than the forward. 00027 # 00028 # \par map should change the arguments of the operator such that it can run as 00029 # an rsf command line. 00030 # \par trans defines how this operator affects the domain of the input. 00031 # this is also to calculate the range of the operator at initialization. 00032 # \par constr defines any run time error messages if the vector is not in the domain of 00033 # the operator. 00034 # 00035 # 00036 # \""" 00037 # # alwas use classmethod or static method 00038 # @classmethod 00039 # def map( cls, source, command ): 00040 # \""" 00041 # map a SLIMpy command to a rsf command 00042 # \""" 00043 # # the RSF bin and 'sf' will be automaticaly prepended to noise executable 00044 # command = cls.default_function( command, "noise" ) 00045 # #change all python True/False objects to 'y'/'n' strings 00046 # command = cls.truefalseHelper( command ) 00047 # #map the adj flage to inv 00048 # command = cls.keywordmap( command, {'adj':'inv'} ) 00049 # #alwas must return a CommandPack instance 00050 # return cls.pack( command ) 00051 # 00052 # 00053 # @classmethod 00054 # def trans( cls, command, space, *spaces ): 00055 # 'define how this operator affect the space' 00056 # n1 = spaces[0]['n1'] 00057 # space['n1_noise']= n1 00058 # space["n1"] = int( ceil( n1/2. )+1 ) 00059 # space['data_type']='float' 00060 # return space 00061 # 00062 # @classmethod 00063 # def trans_adj( cls, command, space, *spaces ): 00064 # \""" 00065 # trans_adj will automatically be called in the case 00066 # where the command has an adj keyword that is true 00067 # \""" 00068 # n1 = spaces[0]['n1_noise'] 00069 # space['data_type']='float' 00070 # space['n1']= n1 00071 # return space 00072 # 00073 # @classmethod 00074 # def constr( cls, command, space ): 00075 # 'make sure the data on the forward command is float' 00076 # cls.match( space, data_type='float' ) 00077 # 00078 # 00079 # @classmethod 00080 # def constr_adj( cls, command, space ): 00081 # 'make sure the data on the adjoint command is float' 00082 # cls.match( space, data_type='float' ) 00083 # 00084 # 00085 # 00086 # #=============================================================================== 00087 # # Add it to the list of existing rsf commands by 00088 # # by registering the converter with the rsf plugin. 00089 # #=============================================================================== 00090 # 00091 # factory = rsfCommandFactory() 00092 # # add the converter class to the factory 00093 # # now converter will be invoked when 00094 # # a linear operator with the 'name' attribute 00095 # # of noiseX 00096 # factory['noiseX'] = noiseX_Converter 00097 # @endcode 00098 00099 from numpy import ceil 00100 from slimpy_base.api.Plugins.slim2rsf.sfCommandFactory import rsfCommandFactory 00101 from slimpy_base.api.Plugins.slim2rsf.sfcommands.sfConverter import sfConverter 00102 00103 ######################################################################## 00104 # Define how noisex behaves 00105 ######################################################################## 00106 00107 # create a Converter class 00108 class noiseX_Converter( sfConverter ): 00109 """ 00110 This is a mapping instance that maps a SLIMpy command into an object that 00111 can be run. 00112 There are three types of function this class should have. 00113 - map 00114 - trans 00115 - constr 00116 Each of these functions can have an optional '_adj' at the end of the name 00117 if the operator's adjoint is different than the forward. 00118 00119 \par map should change the arguments of the operator such that it can run as 00120 an rsf command line. 00121 \par trans defines how this operator affects the domain of the input. 00122 this is also to calculate the range of the operator at initialization. 00123 \par constr defines any run time error messages if the vector is not in the domain of 00124 the operator. 00125 00126 00127 """ 00128 # alwas use classmethod or static method 00129 @classmethod 00130 def map( cls, source, command ): 00131 """ 00132 map a SLIMpy command to a rsf command 00133 """ 00134 # the RSF bin and 'sf' will be automaticaly prepended to noise executable 00135 command = cls.default_function( command, "noise" ) 00136 #change all python True/False objects to 'y'/'n' strings 00137 command = cls.truefalseHelper( command ) 00138 #map the adj flage to inv 00139 command = cls.keywordmap( command, {'adj':'inv'} ) 00140 #alwas must return a CommandPack instance 00141 return cls.pack( command ) 00142 00143 00144 @classmethod 00145 def trans( cls, command, space, *spaces ): 00146 'define how this operator affect the space' 00147 n1 = spaces[0]['n1'] 00148 space['n1_noise']= n1 00149 space["n1"] = int( ceil( n1/2. )+1 ) 00150 space['data_type']='float' 00151 return space 00152 00153 @classmethod 00154 def trans_adj( cls, command, space, *spaces ): 00155 """ 00156 trans_adj will automatically be called in the case 00157 where the command has an adj keyword that is true 00158 """ 00159 n1 = spaces[0]['n1_noise'] 00160 space['data_type']='float' 00161 space['n1']= n1 00162 return space 00163 00164 @classmethod 00165 def constr( cls, command, space ): 00166 'make sure the data on the forward command is float' 00167 cls.match( space, data_type='float' ) 00168 00169 00170 @classmethod 00171 def constr_adj( cls, command, space ): 00172 'make sure the data on the adjoint command is float' 00173 cls.match( space, data_type='float' ) 00174 00175 00176 00177 #=============================================================================== 00178 # Add it to the list of existing rsf commands by 00179 # by registering the converter with the rsf plugin. 00180 #=============================================================================== 00181 00182 factory = rsfCommandFactory() 00183 # add the converter class to the factory 00184 # now converter will be invoked when 00185 # a linear operator with the 'name' attribute 00186 # of noiseX 00187 factory['noiseX'] = noiseX_Converter 00188