def save_outputs(self): # savestring_qt, ok = QInputDialog.getText( # None, # "Save", # 'Save output data? Yes/No/All with input data (y/n/a):', # text="a" # ) # savestring = str(savestring_qt) # if savestring in ['Y', 'y', 'a', 'A']: odp = self.output_datapath if not op.exists(odp): os.makedirs(odp) data = self.export() data['version'] = self.version # qmisc.getVersionString() data['experiment_caption'] = self.experiment_caption data['lisa_operator_identifier'] = self.lisa_operator_identifier # data['organ_interactivity_counter'] = self.organ_interactivity_counter pth, filename = op.split(op.normpath(self.datapath)) filename += "-" + self.experiment_caption # if savestring in ['a', 'A']: # save renamed file too filepath = 'org-' + filename + '.' + self.save_filetype # rint filepath # rint 'op ', op filepath = op.join(odp, filepath) filepath = misc.suggest_filename(filepath) misc.obj_to_file(data, filepath, filetype=self.save_filetype) filepath = 'organ_last.' + self.save_filetype filepath = op.join(odp, filepath) # ilepath = misc.suggest_filename(filepath) misc.obj_to_file(data, filepath, filetype=self.save_filetype) # save to mat # iparams = self.get_iparams() # filepath = 'organ_iparams.pklz' # filepath = op.join(odp, filepath) # misc.obj_to_file(iparams, filepath, filetype='pklz') # f savestring in ['a', 'A']: if False: # save renamed file too data['data3d'] = None filepath = 'organ_small-' + filename + '.pklz' filepath = op.join(odp, filepath) filepath = misc.suggest_filename(filepath) misc.obj_to_file(data, filepath, filetype='pklz')
def save_outputs_dcm_overlay(self): # TODO add logger.debug('save dcm') from PyQt4.QtCore import pyqtRemoveInputHook pyqtRemoveInputHook() # mport ipdb; ipdb.set_trace() # BREAKPOINT odp = self.output_datapath pth, filename = op.split(op.normpath(self.datapath)) filename += "-" + self.experiment_caption # f savestring in ['ad']: # save to DICOM filepath = 'dicom-' + filename filepath = os.path.join(odp, filepath) filepath = misc.suggest_filename(filepath) output_dicom_dir = filepath data = self.export() # mport ipdb; ipdb.set_trace() # BREAKPOINT overlays = { 3: (data['segmentation'] == self.output_label).astype(np.int8) } if self.dcmfilelist is not None: datawriter.saveOverlayToDicomCopy( self.dcmfilelist, output_dicom_dir, overlays, data['crinfo'], data['orig_shape'])
def test_suggest_filename(self): """ Testing some files. Not testing recursion in filenames. It is situation if there exist file0, file1, file2 and input file is file """ import misc filename = "mujsoubor" #import ipdb; ipdb.set_trace() # BREAKPOINT new_filename = misc.suggest_filename(filename, exists=True) self.assertTrue(new_filename == "mujsoubor2") filename = "mujsoubor112" new_filename = misc.suggest_filename(filename, exists=True) self.assertTrue(new_filename == "mujsoubor113") filename = "mujsoubor-2.txt" new_filename = misc.suggest_filename(filename, exists=True) self.assertTrue(new_filename == "mujsoubor-3.txt") filename = "mujsoubor-a24.txt" new_filename = misc.suggest_filename(filename, exists=False) self.assertTrue(new_filename == "mujsoubor-a24.txt")
def get_standard_ouptut_filename(self, filetype=None, suffix=''): """ It can be settet filename, or filename end with suffix. """ if filetype is None: filetype = self.save_filetype output_dir = self.output_datapath pth, filename = op.split(op.normpath(self.datapath)) filename += "-" + self.experiment_caption # if savestring in ['a', 'A']: # save renamed file too filename = '' + filename + suffix + '.' + filetype filepath = op.join(output_dir, filename) filepath = misc.suggest_filename(filepath) return filepath
def save_outputs(args, oseg, qt_app): from PyQt4.QtGui import QInputDialog savestring_qt, ok = QInputDialog.getText( None, "Save", 'Save output data? Yes/No/All+Dicom with input data (y/n/a/ad):', text="a" ) savestring = str(savestring_qt) #import pdb; pdb.set_trace() #savestring = raw_input( # 'Save output data? Yes/No/All with input data (y/n/a): ' #) if savestring in ['Y', 'y', 'a', 'A', 'ad']: if not os.path.exists(args["output_datapath"]): os.makedirs(args['output_datapath']) op = args['output_datapath'] # rename data = oseg.export() data['version'] = qmisc.getVersionString() data['experiment_caption'] = args['experiment_caption'] data['lisa_operator_identifier'] = args['lisa_operator_identifier'] #data['organ_segmentation_time'] = t1 iparams = oseg.get_iparams() #import pdb; pdb.set_trace() pth, filename = os.path.split(os.path.normpath(args['datapath'])) filename += "-" + args['experiment_caption'] if savestring in ['a', 'A', 'ad']: # save renamed file too filepath = 'ob-' + filename + '.pklz' filepath = os.path.join(op, filepath) filepath = misc.suggest_filename(filepath) misc.obj_to_file(data, filepath, filetype='pklz') filepath = 'organ.pklz' filepath = os.path.join(op, filepath) #filepath = misc.suggest_filename(filepath) misc.obj_to_file(data, filepath, filetype='pklz') filepath = 'organ_iparams.pklz' filepath = os.path.join(op, filepath) misc.obj_to_file(iparams, filepath, filetype='pklz') data['data3d'] = None filepath = 'organ_small-' + filename + '.pklz' filepath = os.path.join(op, filepath) filepath = misc.suggest_filename(filepath) misc.obj_to_file(data, filepath, filetype='pklz') #output = segmentation.vesselSegmentation(oseg.data3d, # oseg.orig_segmentation) # print "uf" if savestring in ['ad']: # save to DICOM filepath = 'dicom-' + filename filepath = os.path.join(op, filepath) filepath = misc.suggest_filename(filepath) output_dicom_dir = filepath #import ipdb; ipdb.set_trace() # BREAKPOINT overlays = { 3: (data['segmentation'] == args['output_label']).astype(np.int8) } saveOverlayToDicomCopy(oseg.metadata['dcmfilelist'], output_dicom_dir, overlays, data['crinfo'], data['orig_shape'])