def execution(self, context): command = ['AimsFileConvert', '-i', self.read, '-o', self.write] if self.ascii: command += ['-a'] if self.voxelType is not None: command += ['-t', self.voxelType] if self.rescaleDynamic: command += ['-r'] if self.useInputTypeLimits: command += ['--itypelimits'] if self.inputDynamicMin != None: command += ['--imin', self.inputDynamicMin] if self.inputDynamicMax != None: command += ['--imax', self.inputDynamicMax] if self.outputDynamicMin != None: command += ['--omin', self.outputDynamicMin] if self.outputDynamicMax != None: command += ['--omax', self.outputDynamicMax] if context.system(*command): raise RuntimeError(_t_( 'Error while converting <em>%s</em> to <em>%s</em>') % (command[2], command[4])) if self.removeSource: for f in self.read.fullPaths(): shelltools.rm(f)
def execution(self, context): from soma import aims graph = aims.read(self.read.fullPath()) aims.GraphManip.buckets2Volume(graph) if self.extract_volume: vol = graph[self.extract_volume] else: atts = [ x for x in graph.keys() if isinstance(graph[x], aims.rc_ptr_Volume_S16) ] if len(atts) == 0: raise RuntimeError(_t_('the ROI graph contains no voxel data')) elif len(atts) > 1: raise RuntimeError( _t_('the ROI graph contains several volumes. ' 'Select the extract_volume parameter as one in ') + '( ' + ', '.join(atts) + ' )') vol = graph[atts[0]] # handle bounding box which may have cropped the data bmin = graph['boundingbox_min'] bmax = graph['boundingbox_max'] context.write('vol:', vol) context.write('bmin:', bmin, ', bmax:', bmax, ', size:', vol.getSize()) if bmin[:3] != [0, 0, 0] \ or bmax[:3] != [x+1 for x in vol.getSize()[:3]]: context.write('enlarging') # needs expanding in a bigger volume vol2 = aims.Volume_S16(bmax[0] + 1, bmax[1] + 1, bmax[2] + 1) vol2.fill(0) ar = vol2.np ar[bmin[0]:bmax[0] + 1, bmin[1]:bmax[1] + 1, bmin[2]:bmax[2] + 1, :] \ = vol.np if self.extract_contours == 'Yes': ar_copy = ar.copy() for label in [v['roi_label'] for v in graph.vertices()]: ind = list(zip(*np.where(ar_copy == label))) for i in ind: erase = True for neigh in neighbors(*i): if ar_copy[neigh] != label: erase = False if erase: ar[i] = 0 vol2.copyHeaderFrom(vol.header()) aims.write(vol2, self.write.fullPath()) else: # bounding box OK aims.write(vol.get(), self.write.fullPath()) registration.getTransformationManager().copyReferential( self.read, self.write) if self.removeSource: for f in self.read.fullPaths(): shelltools.rm(f)
def execution(self, context): command = ['AimsFileConvert', '-i', self.read, '-o', self.write] if self.ascii: command += ['-a'] if context.system(*command): raise RuntimeError( _t_('Error while converting <em>%s</em> to <em>%s</em>') % (command[2], command[4])) if self.removeSource: for f in self.read.fullPaths(): shelltools.rm(f)
def execution(self, context): self.read = None if self.input_file: self.read = self.input_file elif self.input_directory: self.read = self.input_directory else: context.error( "You must give a valid value for input_file or input_directory.") if self.read: context.system( 'AimsFileConvert', '-i', self.read, '-o', self.write) registration.getTransformationManager().copyReferential(self.read, self.write) if self.removeSource: for f in self.read.fullPaths(): shelltools.rm(f)