Пример #1
0
 def __set_pure_state__(self, state):
     z = state.data
     if z is not None:
         d = gunzip_string(z)
         r = tvtk.DataSetReader(read_from_input_string=1, input_string=d)
         warn = r.global_warning_display
         r.global_warning_display = 0
         r.update()
         r.global_warning_display = warn
         self.data = r.output
     # Now set the remaining state without touching the children.
     set_state(self, state, ignore=['children', 'data'])
     # Setup the children.
     handle_children_state(self.children, state.children)
     # Setup the children's state.
     set_state(self, state, first=['children'], ignore=['*'])
Пример #2
0
 def __set_pure_state__(self, state):
     z = state.data
     if z is not None:
         d = gunzip_string(z)
         r = tvtk.DataSetReader(read_from_input_string=1,
                                input_string=d)
         warn = r.global_warning_display
         r.global_warning_display = 0
         r.update()
         r.global_warning_display = warn
         self.data = r.output
     # Now set the remaining state without touching the children.
     set_state(self, state, ignore=['children', 'data'])
     # Setup the children.
     handle_children_state(self.children, state.children)
     # Setup the children's state.
     set_state(self, state, first=['children'], ignore=['*'])
Пример #3
0
    def __set_pure_state__(self, state):
        z = state.data
        if z:
            d = gunzip_string(z)
            m = re.search('(?<=Filename:)\w+', header)
            file_name = m.group(0)
            m = re.search('(?<=NX:)\w+', d)
            self.nx_redu = int(m.group(0))
            m = re.search('(?<=NX:)\w+', d)
            self.ny_redu = int(m.group(0))
            m = re.search('(?<=NX:)\w+', d)
            self.nz_redu = int(m.group(0))

            if not isfile(file_name):
                msg = 'Could not find file at %s\n' % file_name
                msg += 'Please move the file there and try again.'
                raise IOError, msg

            (step, modelname, metafilepath, filepath) = parsemodel(file_name)
            file_name = metafilepath

            self.filename = file_name

            #self.data = self.citcomshdftougrid.initialize(self.filename,0,0,0,0,False,False)
            f = tables.openFile(file_name, 'r')
            self.nx = int(f.root.input._v_attrs.nodex)
            self.ny = int(f.root.input._v_attrs.nodey)
            self.nz = int(f.root.input._v_attrs.nodez)

            #self.timesteps = int(f.root.time.nrows)

            f.close()
            self.data = self.citcomshdftougrid.initialize(
                self.filename, self.current_timestep, self.nx_redu,
                self.ny_redu, self.nz_redu)
            self.data_changed = True
            self._update_data()
            # Now set the remaining state without touching the children.
            set_state(self, state, ignore=['children', '_file_path'])
            # Setup the children.
            handle_children_state(self.children, state.children)
            # Setup the children's state.
            set_state(self, state, first=['children'], ignore=['*'])
Пример #4
0
    def verify(self, obj, state):
        data = state['data']
        self.assertEqual(state['class_name'], obj.__class__.__name__)
        data = data['data']
        self.assertEqual(data['b'], obj.b)
        self.assertEqual(data['i'], obj.i)
        self.assertEqual(data['l'], obj.l)
        self.assertEqual(data['f'], obj.f)
        self.assertEqual(data['c'], obj.c)
        self.assertEqual(data['n'], obj.n)
        self.assertEqual(data['s'], obj.s)
        self.assertEqual(data['u'], obj.u)
        if isinstance(obj, HasTraits):
            self.assertEqual(data['inst']['type'], 'reference')
        else:
            self.assertEqual(data['inst']['type'], 'reference')
        tup = data['tuple']['data']
        self.assertEqual(tup[:-1], obj.tuple[:-1])
        self.assertEqual(tup[-1]['data']['data']['a'], 't')
        lst = data['list']['data']
        self.assertEqual(lst[:-1], obj.list[:-1])

        if isinstance(obj, HasTraits):
            self.assertEqual(lst[-1]['type'], 'instance')
        else:
            self.assertEqual(lst[-1]['data']['data']['a'], 'b')

        pure_lst = data['pure_list']['data']
        self.assertEqual(pure_lst, obj.pure_list)
        dct = data['dict']['data']
        self.assertEqual(dct['a'], obj.dict['a'])
        self.assertEqual(dct['b'], obj.dict['b'])
        self.assertEqual(dct['ref']['type'], 'reference')

        junk = state_pickler.gunzip_string(
            data['numeric']['data'].decode('base64'))
        num = numpy.loads(junk)
        self.assertEqual(numpy.alltrue(numpy.ravel(num == obj.numeric)), 1)

        self.assertEqual(data['ref']['type'], 'reference')
        self.assertEqual(data['ref']['id'], data['numeric']['id'])
Пример #5
0
    def __set_pure_state__(self, state):
        z = state.data
        if z:
            d = gunzip_string(z)
            m = re.search('(?<=Filename:)\w+', header)
            file_name = m.group(0)
            m = re.search('(?<=NX:)\w+', d)
            self.nx_redu = int(m.group(0))
            m = re.search('(?<=NX:)\w+', d)
            self.ny_redu = int(m.group(0))
            m = re.search('(?<=NX:)\w+', d)
            self.nz_redu = int(m.group(0))
        
            if not isfile(file_name):
                msg = 'Could not find file at %s\n'%file_name
                msg += 'Please move the file there and try again.'
                raise IOError, msg
            
            (step, modelname, metafilepath, filepath) = parsemodel(file_name)
            file_name = metafilepath
            
            self.filename = file_name
        
            #self.data = self.citcomshdftougrid.initialize(self.filename,0,0,0,0,False,False)
            f = tables.openFile(file_name,'r')
            self.nx = int(f.root.input._v_attrs.nodex)
            self.ny = int(f.root.input._v_attrs.nodey)
            self.nz = int(f.root.input._v_attrs.nodez)
        
            #self.timesteps = int(f.root.time.nrows)

            f.close()
            self.data = self.citcomshdftougrid.initialize(self.filename,self.current_timestep,self.nx_redu,self.ny_redu,self.nz_redu)
            self.data_changed = True
            self._update_data()
            # Now set the remaining state without touching the children.
            set_state(self, state, ignore=['children', '_file_path'])
            # Setup the children.
            handle_children_state(self.children, state.children)
            # Setup the children's state.
            set_state(self, state, first=['children'], ignore=['*'])
Пример #6
0
    def verify(self, obj, state):
        data = state['data']
        self.assertEqual(state['class_name'], obj.__class__.__name__)
        data = data['data']
        self.assertEqual(data['b'], obj.b)
        self.assertEqual(data['i'], obj.i)
        self.assertEqual(data['l'], obj.l)
        self.assertEqual(data['f'], obj.f)
        self.assertEqual(data['c'], obj.c)
        self.assertEqual(data['n'], obj.n)
        self.assertEqual(data['s'], obj.s)
        self.assertEqual(data['u'], obj.u)
        if isinstance(obj, HasTraits):
            self.assertEqual(data['inst']['type'], 'reference')
        else:
            self.assertEqual(data['inst']['type'], 'reference')
        tup = data['tuple']['data']
        self.assertEqual(tup[:-1], obj.tuple[:-1])
        self.assertEqual(tup[-1]['data']['data']['a'], 't')
        lst = data['list']['data']
        self.assertEqual(lst[:-1], obj.list[:-1])
        
        if isinstance(obj, HasTraits):
            self.assertEqual(lst[-1]['type'], 'instance')
        else:
            self.assertEqual(lst[-1]['data']['data']['a'], 'b')
            
        pure_lst = data['pure_list']['data']
        self.assertEqual(pure_lst, obj.pure_list)
        dct = data['dict']['data']
        self.assertEqual(dct['a'], obj.dict['a'])
        self.assertEqual(dct['b'], obj.dict['b'])
        self.assertEqual(dct['ref']['type'], 'reference')

        junk = state_pickler.gunzip_string(data['numeric']['data'].decode('base64'))
        num = numpy.loads(junk)
        self.assertEqual(numpy.alltrue(numpy.ravel(num == obj.numeric)), 1)

        self.assertEqual(data['ref']['type'], 'reference')
        self.assertEqual(data['ref']['id'], data['numeric']['id'])