def _newVolume(self,data,copyFrom=None,rescale=True): """Takes a numpy array and makes a geoprobe volume. This volume can then be written to disk using the write() method.""" data = np.asarray(data) #Set up the header Dictionary if copyFrom is not None: # Assume the string is the filname of a geoprobe volume if isinstance(copyFrom, basestring): copyFrom = volume(copyFrom) try: self.headerValues = copyFrom.headerValues except AttributeError: raise TypeError('This does not appear to be a valid'\ ' geoprobe volume object') else: # Set default attributes for varname, info in _headerDef.iteritems(): setattr(self, varname, info['default']) (self.originalnx, self.originalny, self.originalnz) = data.shape if rescale: self.v0 = data.min() self.dv = data.ptp() / 255.0 data -= self.v0 data /= self.dv self.data = self._fixAxes(data)
def _newVolume(self, data, copyFrom=None, rescale=True, fix_axes=True): """Takes a numpy array and makes a geoprobe volume. This volume can then be written to disk using the write() method.""" data = np.asarray(data) #Set up the header Dictionary if copyFrom is not None: # Assume the string is the filname of a geoprobe volume if isinstance(copyFrom, basestring): copyFrom = volume(copyFrom) try: self.headerValues = copyFrom.headerValues except AttributeError: raise TypeError('This does not appear to be a valid'\ ' geoprobe volume object') else: # Set default attributes for varname, info in _headerDef.iteritems(): setattr(self, varname, info['default']) (self.originalnx, self.originalny, self.originalnz) = data.shape if rescale: self.v0 = data.min() self.dv = data.ptp() / 255.0 data -= self.v0 data /= self.dv if fix_axes: data = self._fixAxes(data) self._data = data
def read_header(self): """Reads and returns the header of a geoprobe volume.""" header = dict() for varname, info in _headerDef.iteritems(): self._file.seek(info['offset']) value = self._file.readBinary(info['type']) header[varname] = value return header
def write_header(self, header): """Write the values in the dict "header" to the file.""" for varname, info in _headerDef.iteritems(): value = header.get(varname, info['default']) self._file.seek(info['offset']) self._file.writeBinary(info['type'], value)