Ejemplo n.º 1
0
 def _get_lookup_table(self,name):
     if name is None:
         name = 'default'
         log.info('Using default lookup_table=%s'%(repr(name)))
         return name
     if common.is_string(name):
         name = name.strip().replace(' ','_')
         if name:
             return name
     raise ValueError('lookup_table=%s must be nonempty string'%(repr(name)))
Ejemplo n.º 2
0
 def _get_name(self,name):
     if name is None:
         name = self._get_default_name()
         log.info('Using default name=%s'%(repr(name)))
         return name
     if common.is_string(name):
         name = name.strip().replace(' ','_')
         if name:
             return name
     raise ValueError('name=%s must be non-empty string'%(repr(name)))
Ejemplo n.º 3
0
    def __init__(self, *args, **kws):
        assert args, 'expected at least one argument'
        if type(args[0]) is str:
            if 'only_structure' in kws and kws['only_structure']:
                self.fromfile(args[0], 1)
            else:
                self.fromfile(args[0])
            return
        else:
            structure = args[0]
            args = list(args)[1:]
        if not is_dataset(structure):
            raise TypeError(
                'argument structure must be StructuredPoints|StructuredGrid|UnstructuredGrid|RectilinearGrid|PolyData but got %s'
                % (type(structure)))
        self.structure = structure
        for a in args:
            if common.is_string(a):
                if len(a) > 255:
                    log.warning('striping header string to a length =255')
                self.header = a[:255]
            elif is_pointdata(a):
                self.point_data = a
            elif is_celldata(a):
                self.cell_data = a
            else:
                log.warning('unexpexted argument %s', type(a))
        if self.header is None:
            self.header = 'Really cool data'
            log.info('Using default header=%s' % (repr(self.header)))
        if self.point_data is None and self.cell_data is None:
            log.info('No point/cell data defined')

        if self.point_data is not None:
            s = self.structure.get_size()
            s1 = self.point_data.get_size()
            if s1 != s:
                raise ValueError(
                    'DataSet (size=%s) and PointData (size=%s) have different sizes'
                    % (s, s1))
        else:
            self.point_data = PointData()
        if self.cell_data is not None:
            s = self.structure.get_cell_size()
            s1 = self.cell_data.get_size()
            if s1 != s:
                raise ValueError(
                    'DataSet (cell_size=%s) and CellData (size=%s) have different sizes'
                    % (s, s1))
        else:
            self.cell_data = CellData()
Ejemplo n.º 4
0
 def tofile(self, filename, format = 'ascii'):
     """Save VTK data to file.
     """
     if not common.is_string(filename):
         raise TypeError('argument filename must be string but got %s'%(type(filename)))
     if format not in ['ascii','binary']:
         raise TypeError('argument format must be ascii | binary')
     filename = filename.strip()
     if not filename:
         raise ValueError('filename must be non-empty string')
     if filename[-4:]!='.vtk':
         filename += '.vtk'
     f = open(filename,'wb')
     f.write(self.to_string(format))
     f.close()
Ejemplo n.º 5
0
 def tofile(self, filename, format='ascii'):
     """Save VTK data to file.
     """
     if not common.is_string(filename):
         raise TypeError('argument filename must be string but got %s' %
                         (type(filename)))
     if format not in ['ascii', 'binary']:
         raise TypeError('argument format must be ascii | binary')
     filename = filename.strip()
     if not filename:
         raise ValueError('filename must be non-empty string')
     if filename[-4:] != '.vtk':
         filename += '.vtk'
     f = open(filename, 'wb')
     f.write(self.to_string(format))
     f.close()
Ejemplo n.º 6
0
    def __init__(self,*args,**kws):
        assert args,'expected at least one argument'
        if type(args[0]) is str:
            if 'only_structure' in kws and kws['only_structure']:
                self.fromfile(args[0],1)
            else:
                self.fromfile(args[0])
            return
        else:
            structure = args[0]
            args = list(args)[1:]
        if not is_dataset(structure):
            raise TypeError('argument structure must be StructuredPoints|StructuredGrid|UnstructuredGrid|RectilinearGrid|PolyData but got %s'%(type(structure)))
        self.structure = structure
        for a in args:
            if common.is_string(a):
                if len(a)>255:
                    log.warning('striping header string to a length =255')
                self.header = a[:255]
            elif is_pointdata(a):
                self.point_data = a
            elif is_celldata(a):
                self.cell_data = a
            else:
                log.warning('unexpexted argument %s', type(a))
        if self.header is None:
            self.header = 'Really cool data'
            log.info('Using default header=%s'%(repr(self.header)))
        if self.point_data is None and self.cell_data is None:
            log.info('No point/cell data defined')

        if self.point_data is not None:
            s = self.structure.get_size()
            s1 = self.point_data.get_size()
            if s1 != s:
                raise ValueError('DataSet (size=%s) and PointData (size=%s) have different sizes'%(s,s1))
        else:
            self.point_data = PointData()
        if self.cell_data is not None:
            s = self.structure.get_cell_size()
            s1 = self.cell_data.get_size()
            if s1 != s:
                raise ValueError('DataSet (cell_size=%s) and CellData (size=%s) have different sizes'%(s,s1))
        else:
            self.cell_data = CellData()