<s> from ilastik . core import dataMgr as dataMgrModule <EOL> from ilastik . core import ILASTIK_VERSION <EOL> import traceback <EOL> import warnings <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" ) <EOL> import h5py <EOL> from ilastik . core import dataImpex <EOL> import os . path , sys <EOL> class Project ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , labeler , description , dataMgr = None , labelNames = None , labelColors = None ) : <EOL> if labelNames is None : <EOL> labelNames = [ ] <EOL> if labelColors is None : <EOL> labelColors = { } <EOL> self . filename = None <EOL> self . fastRepaint = True <EOL> self . useBorderMargin = False <EOL> self . normalizeData = False <EOL> self . drawUpdateInterval = <NUM_LIT> <EOL> self . rgbData = True <EOL> self . name = name <EOL> self . labeler = labeler <EOL> self . description = description <EOL> if dataMgr is not None : <EOL> self . dataMgr = dataMgr <EOL> else : <EOL> self . dataMgr = dataMgrModule . DataMgr ( ) <EOL> self . labelNames = labelNames <EOL> self . labelColors = labelColors <EOL> self . trainingMatrix = None <EOL> self . trainingLabels = None <EOL> self . trainingFeatureNames = None <EOL> def saveToDisk ( self , fileName = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if fileName is not None : <EOL> self . filename = fileName <EOL> else : <EOL> fileName = self . filename <EOL> fileHandle = h5py . File ( fileName , '<STR_LIT:w>' ) <EOL> fileHandle . create_dataset ( '<STR_LIT>' , data = ILASTIK_VERSION ) <EOL> projectG = fileHandle . create_group ( '<STR_LIT>' ) <EOL> dataSetG = fileHandle . create_group ( '<STR_LIT>' ) <EOL> projectG . create_dataset ( '<STR_LIT:Name>' , data = str ( self . name ) ) <EOL> projectG . create_dataset ( '<STR_LIT>' , data = str ( self . labeler ) ) <EOL> projectG . create_dataset ( '<STR_LIT>' , data = str ( self . description ) ) <EOL> self . dataMgr . serialize ( projectG , dataSetG ) <EOL> fileHandle . close ( ) <EOL> if self . dataMgr . module [ "<STR_LIT>" ] is not None : <EOL> self . dataMgr . module [ "<STR_LIT>" ] . exportClassifiers ( fileName , '<STR_LIT>' ) <EOL> except Exception as e : <EOL> print e . message <EOL> traceback . print_exc ( ) <EOL> return False <EOL> return True <EOL> @ staticmethod <EOL> def loadFromDisk ( fileName , featureCache ) : <EOL> fileHandle = h5py . File ( fileName , '<STR_LIT:r>' ) <EOL> projectG = fileHandle [ '<STR_LIT>' ] <EOL> dataG = fileHandle [ '<STR_LIT>' ] <EOL> name = projectG [ '<STR_LIT:Name>' ] . value <EOL> labeler = projectG [ '<STR_LIT>' ] . value <EOL> description = projectG [ '<STR_LIT>' ] . value <EOL> n = len ( dataG ) <EOL> dataMgr = dataMgrModule . DataMgr . deserialize ( projectG , dataG ) <EOL> project = Project ( name , labeler , description , dataMgr ) <EOL> project . filename = fileName <EOL> fileHandle . close ( ) <EOL> return project <EOL> def loadStack ( self , path , fileList , options ) : <EOL> try : <EOL> theDataItem = dataImpex . DataImpex . importDataItem ( fileList , options ) <EOL> except MemoryError : <EOL> raise MemoryError <EOL> if theDataItem is not None : <EOL> dirname = os . path . basename ( os . path . dirname ( path ) ) <EOL> offsetstr = '<STR_LIT:(>' + str ( options . offsets [ <NUM_LIT:0> ] ) + '<STR_LIT:U+002CU+0020>' + str ( options . offsets [ <NUM_LIT:1> ] ) + '<STR_LIT:U+002CU+0020>' + str ( options . offsets [ <NUM_LIT:2> ] ) + '<STR_LIT:)>' <EOL> theDataItem . _name = dirname + '<STR_LIT:U+0020>' + offsetstr <EOL> theDataItem . fileName = path <EOL> try : <EOL> self . dataMgr . append ( theDataItem , True ) <EOL> self . dataMgr . _dataItemsLoaded [ - <NUM_LIT:1> ] = True <EOL> theDataItem . _hasLabels = True <EOL> theDataItem . _isTraining = True <EOL> theDataItem . _isTesting = True <EOL> except Exception , e : <EOL> traceback . print_exc ( file = sys . stdout ) <EOL> print e <EOL> raise e <EOL> return True <EOL> def loadFile ( self , fileList , options ) : <EOL> itemList = [ ] <EOL> try : <EOL> itemList = dataImpex . DataImpex . importDataItems ( fileList , options ) <EOL> except Exception , e : <EOL> traceback . print_exc ( file = sys . stdout ) <EOL> print e <EOL> raise e <EOL> for index , item in enumerate ( itemList ) : <EOL> self . dataMgr . append ( item , True ) <EOL> return True <EOL> def addFile ( self , fileList ) : <EOL> fileList = sorted ( fileList ) <EOL> for file_name in fileList : <EOL> try : <EOL> file_name = str ( file_name ) <EOL> theDataItem = dataImpex . DataImpex . importDataItem ( file_name , None ) <EOL> self . dataMgr . append ( theDataItem , True ) <EOL> except Exception , e : <EOL> traceback . print_exc ( file = sys . stdout ) <EOL> print e <EOL> raise e <EOL> return True <EOL> def removeFile ( self , fileIndex ) : <EOL> self . dataMgr . remove ( fileIndex ) </s>
