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 """
00022 Vector Interface to RSF.
00023 """
00024 from slimpy_base.Core.Interface.node import source
00025 from Storage import Storage
00026 from slimpy_base.Core.Command.Constr import Constr
00027 from slimpy_base.Core.Command.Tran import Tran
00028 from slimpy_base.Core.Command.CommandMap import CommandMap
00029 try:
00030 import numpy
00031 except ImportError:
00032 numpy = None
00033 store = Storage()
00034 class numpyCommandFactory(object):
00035
00036 __shared_state = {}
00037
00038 def __init__(self):
00039 self.__dict__ = self.__shared_state
00040
00041
00042 def add(self,cmnd,**dict):
00043 self.__setattr__(cmnd,dict)
00044
00045
00046
00047 def parse(self,command):
00048
00049 command.update(map=CommandMap(function=command.name,finalize={"Cmnd":None}))
00050
00051 if self.__dict__.has_key(command.name):
00052
00053 sfdict = self.__getattribute__(command.name)
00054
00055 command.update(**sfdict)
00056 else:
00057 pass
00058
00059 def addfunc(*p,**k):
00060
00061 if len(p) == 2:
00062 val = p[1]
00063 elif k.has_key('val'):
00064 val = k['val']
00065 print k['Target'], '=' , p[0],"+",val
00066 store[k['Target']] = numpy.ndarray.__add__(p[0],val)
00067
00068
00069 def addAll():
00070
00071
00072 numpyFactory = numpyCommandFactory()
00073
00074 numpyFactory.add('add',
00075 map = CommandMap(function=addfunc,
00076 pmap=[source]),
00077 unusedSource=True
00078 )
00079 """
00080 sfFactory.addNew("create",
00081 map = CommandMap(kmap1={'out':'output',"data_type":'type'},
00082 pmap1=[sfExec('sfmath')] ,
00083 keep1=['output','type','n1','n2','n3','n4','n5'],
00084 pmap2=[sfExec('sfput')],
00085 discard2=['out','data_type','n1','n2','n3','n4','n5']
00086 )
00087 )
00088
00089 sfFactory.addNew("fft1",
00090 map = CommandMap(pmap=[sfExec('sffft1')] ,
00091 funcs = [truefalseHelper(),CommandMap.addKparam(inv='n')]),
00092 InSpaceConstr = Constr(match=Constr.match(data_type='float') ),
00093 PTransform = Tran(Tran.change(data_type='complex'),
00094 Tran.evalChange(n1_fft="space['n1']",n1="int(ceil(space['n1']/2.)+1)")) )
00095
00096 sfFactory.addNew("fft1Adj",
00097 map = CommandMap(pmap=[sfExec('sffft1')] ,
00098 funcs = [truefalseHelper(),CommandMap.addKparam(inv='y')]),
00099 InSpaceConstr = Constr(match=Constr.match(data_type='complex') ),
00100 PTransform = Tran(Tran.change(data_type='float'),
00101 Tran.evalChange(n1="space['n1_fft']")))
00102
00103 sfFactory.addNew("fft",
00104 map = CommandMap(pmap=[sfExec('sffft3')] ,
00105 funcs = [truefalseHelper()]))
00106 sfFactory.addNew("transp",
00107 map = CommandMap(pmap=[sfExec('sftransp')] ,
00108 funcs = [transphelper]))
00109
00110
00111 sfFactory.addNew("cmplx",
00112 map = CommandMap(pmap=['sfcmplx' , source ] ),
00113 unusedSource=True)
00114 """
00115
00116 def transphelper(params,kparams):
00117 kparams = kparams.copy()
00118 plane = kparams['plane']
00119 kparams['plane'] = '%s%s' %(plane[0],plane[1])
00120 return params , kparams
00121