#import logger from scipy import array,take,asarray,shape import project #from sets import Set as set from itertools import izip class Dataset: """ Dataset base class """ def __init__(self,input_array,def_list,parents=None): self._data = asarray(input_array) self.dims = shape(self._data) self.parents = parents self.def_list = def_list self._ids_set = set() self.ids={} self.children=[] self._dim_num = {} if parents!=None: for parent in self.parents: parent.children.append(self) if len(def_list)!=len(self.dims): raise ValueError,"array dims and identifyer mismatch" for axis,(dim_name,ids) in enumerate(def_list): enum_ids = {} if dim_name not in project.c_p.dim_names: dim_name = project.c_p.suggest_dim_name(dim_name) if not ids: ids = self._create_identifiers(axis) for num,name in enumerate(ids): enum_ids[name] = num self.ids[dim_name] = enum_ids self._ids_set = self._ids_set.union(set(ids)) self._dim_num[dim_name] = axis for df,d in izip(def_list,self.dims): df=df[1] if len(df)!=d and df: raise ValueError,"dim size and identifyer mismatch" def extract_data(self,ids,dim_name): new_def_list = self.def_list[:] ids_index = [self.ids[dim_name][id_name] for id_name in ids] dim_number = self._dim_num[dim_name] try: out_data = take(self._data,ids_index,axis=dim_number) except: raise ValueError new_def_list[dim_number][1] = ids D = Dataset(out_data,def_list=new_def_list,parents=self.parents) return D def _create_identifiers(self,axis): n_dim = self.dims[axis] return [str(axis) + '_' + str(i) for i in range(n_dim)] class Selection: def __init__(self): self.current_selection={}