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.Interface.containers import Abstract_data_container as __adc
00022 from slimpy_base.utils.SLIMpyGlobal import GlobalVars as __slimglobal
00023 from slimpy_base.utils.AbstractLog import log as __log
00024 from Storage import Storage
00025 from numpyCommands import numpyCommandFactory
00026
00027 _numpyContainer__log=__log
00028 _numpyContainer__slimglobal=__slimglobal
00029 _numpyContainer__adc=__adc
00030 class numpyContainer(__adc):
00031 """
00032 rsf_data_container - to keep track of "out of core" vectors corresponding binary files on disk.
00033 """
00034
00035 name = 'numpyDataContainer'
00036 globals = __slimglobal()
00037 log = __log()
00038
00039
00040 try:
00041 import numpy
00042 isavalable = True
00043 except ImportError:
00044 numpy = None
00045 isavalable = False
00046
00047
00048 numpyCommandFactory = numpyCommandFactory()
00049 store = Storage()
00050
00051 @staticmethod
00052 def isCompatibleWith(obj):
00053 return isinstance(obj, numpyContainer.numpy.ndarray)
00054
00055
00056 def __init__(self , data=None ,parameters=None,flow=False):
00057
00058 if not data is None:
00059
00060 name = self.genName()
00061
00062 self.store[name] = data
00063
00064 data = name
00065
00066
00067 __adc.__init__(self,data=data,parameters=parameters ,flow=flow)
00068
00069 def getData(self):
00070 return self.store[self.getName()]
00071
00072
00073 def isempty(self):
00074
00075 return not self.store.Dict.has_key(self.getName())
00076
00077 def parse(self,obj):
00078
00079 return self.numpyCommandFactory.parse(obj)
00080
00081
00082 def __str__(self):
00083 """Adds the current lib's suffix to the end of filename
00084 note: if no lib is set then self.plugin.suffix returns ''
00085 """
00086 return self.genName()
00087
00088 def __repr__(self):
00089 return str(self)
00090
00091
00092 def getName(self):
00093 return self.data
00094
00095
00096 def plot(self):
00097 """
00098 plot returns the path the the plotfile
00099 """
00100 pass
00101
00102 def setName(self,newname):
00103 """wrapped by SLIMpy.serial_vector.setname"""
00104 if self.isfull():
00105 self.store.changeName(newname,self.getName())
00106 else:
00107 self.data = newname
00108
00109
00110
00111
00112
00113 def rm(self):
00114 """
00115 removes the file on disc
00116 """
00117 print >> self.log(10), "call to rm %s" %self.genName()
00118
00119 def readattr(self):
00120
00121 data = self.getData()
00122 file_dict = {}
00123
00124
00125 for i , n in enumerate(data.shape):
00126 file_dict['n%(i)s'] = n
00127
00128 return file_dict
00129
00130 def readbin(self,start=0,shape=(-1,1)):
00131
00132 pass
00133
00134 def writebin(self,data,start=0,size=0):
00135 pass
00136
00137 def book(self,header):
00138 pass
00139
00140 def writeattr(self,header,vector_dict,file_dict):
00141 pass
00142
00143 def write(self,header,data,book):
00144 pass
00145