def load_fom(self, schema): soma_app = Application('capsul', plugin_modules=['soma.fom']) if 'soma.fom' not in soma_app.loaded_plugin_modules: # WARNING: this is unsafe, may erase configured things, and # probably not thread-safe. soma_app.initialize() fom = soma_app.fom_manager.load_foms(schema) self.study_config.modules_data.all_foms[schema] = fom # Create FOM completion data in self.study_config.modules_data formats = tuple(getattr(self.study_config, key) \ for key in self.study_config.user_traits() \ if key.endswith('_format') \ and getattr(self.study_config, key) is not Undefined) directories = {} directories['spm'] = self.study_config.spm_directory directories['shared'] = self.study_config.shared_directory directories['input'] = self.study_config.input_directory directories['output'] = self.study_config.output_directory atp = AttributesToPaths(fom, selection={}, directories=directories, preferred_formats=set((formats))) self.study_config.modules_data.fom_atp['all'][schema] = atp pta = PathToAttributes(fom, selection={}) self.study_config.modules_data.fom_pta['all'][schema] = pta return fom, atp, pta
def initialize_module(self): '''Load configured FOMs and create FOM completion data in self.study_config.modules_data ''' if self.study_config.use_fom is False: return soma_app = Application('capsul', plugin_modules=['soma.fom']) if 'soma.fom' not in soma_app.loaded_plugin_modules: # WARNING: this is unsafe, may erase configured things, and # probably not thread-safe. soma_app.initialize() self.study_config.modules_data.foms = {} self.study_config.modules_data.all_foms = SortedDictionary() self.study_config.modules_data.fom_atp = {'all': {}} self.study_config.modules_data.fom_pta = {'all': {}} foms = (('input', self.study_config.input_fom), ('output', self.study_config.output_fom), ('shared', self.study_config.shared_fom)) for fom_type, fom_filename in foms: if fom_filename != "": fom, atp, pta = self.load_fom(fom_filename) self.study_config.modules_data.foms[fom_type] = fom self.study_config.modules_data.fom_atp[fom_type] = atp self.study_config.modules_data.fom_pta[fom_type] = pta self.study_config.use_fom = True self.update_module()
def reset_foms(capsul_engine, environment): soma_app = Application('capsul', plugin_modules=['soma.fom']) if 'soma.fom' not in soma_app.loaded_plugin_modules: # WARNING: this is unsafe, may erase configured things, and # probably not thread-safe. soma_app.initialize() soma_app.fom_manager.clear_cache() update_fom(capsul_engine, environment)
def load_fom(capsul_engine, schema, config, session, environment='global'): #print('=== load fom', schema, '===') #import time #t0 = time.time() soma_app = Application('capsul', plugin_modules=['soma.fom']) if 'soma.fom' not in soma_app.loaded_plugin_modules: # WARNING: this is unsafe, may erase configured things, and # probably not thread-safe. soma_app.initialize() old_fom_path = soma_app.fom_path if config.fom_path: soma_app.fom_path = [six.ensure_str(p) for p in config.fom_path if p not in soma_app.fom_path] \ + soma_app.fom_path else: soma_app.fom_path = list(soma_app.fom_path) fom = soma_app.fom_manager.load_foms(schema) soma_app.fom_path = old_fom_path store = capsul_engine._modules_data['fom'] store['all_foms'][schema] = fom # Create FOM completion data fields = config._dbs.get_fields_names(config._collection) formats = tuple(getattr(config, key) \ for key in fields \ if key.endswith('_format') \ and getattr(config, key) is not None) directories = {} spm = session.config('spm', environment) if spm: directories['spm'] = spm.directory axon = session.config('axon', environment) if axon: directories['shared'] = axon.shared_directory directories['input'] = config.input_directory directories['output'] = config.output_directory atp = AttributesToPaths(fom, selection={}, directories=directories, preferred_formats=set((formats))) store['fom_atp']['all'][schema] = atp pta = PathToAttributes(fom, selection={}) store['fom_pta']['all'][schema] = pta #print(' load fom done:', time.time() - t0, 's') return fom, atp, pta
def initialize_module(self): '''Load configured FOMs and create FOM completion data in self.study_config.modules_data ''' if self.study_config.use_fom is False: return soma_app = Application('capsul', plugin_modules=['soma.fom']) if 'soma.fom' not in soma_app.loaded_plugin_modules: # WARNING: this is unsafe, may erase configured things, and # probably not thread-safe. soma_app.initialize() self.study_config.modules_data.foms = {} foms = (('input', self.study_config.input_fom), ('output', self.study_config.output_fom), ('shared', self.study_config.shared_fom)) for fom_type, fom_filename in foms: if fom_filename != "": fom = soma_app.fom_manager.load_foms(fom_filename) self.study_config.modules_data.foms[fom_type] = fom # Create FOM completion data in self.study_config.modules_data formats = tuple(getattr(self.study_config, key) \ for key in self.study_config.user_traits() \ if key.endswith('_format') \ and getattr(self.study_config, key) is not Undefined) directories = {} directories['spm'] = self.study_config.spm_directory directories['shared'] = self.study_config.shared_directory directories['input'] = self.study_config.input_directory directories['output'] = self.study_config.output_directory self.study_config.modules_data.fom_atp = {} self.study_config.modules_data.fom_pta = {} for fom_type, fom \ in six.iteritems(self.study_config.modules_data.foms): atp = AttributesToPaths( fom, selection={}, directories=directories, prefered_formats=set((formats))) self.study_config.modules_data.fom_atp[fom_type] = atp pta = PathToAttributes(fom, selection={}) self.study_config.modules_data.fom_pta[fom_type] = pta self.study_config.use_fom = True
import os import glob from morphologist.core.analysis import SharedPipelineAnalysis from morphologist.core.subject import Subject from capsul.process import get_process_instance from capsul.process.process_with_fom import ProcessWithFom # the following 4 lines are a hack to add /tmp to the FOM search path # before it is used by StudyConfig from soma.application import Application soma_app = Application('capsul', plugin_modules=['soma.fom']) soma_app.initialize() soma_app.fom_manager.paths.append('/tmp') fom_content = '''{ "fom_name": "mock_fom", "formats": { "NIFTI": "nii", "NIFTI gz": "nii.gz" }, "format_lists": { "images": ["NIFTI gz", "NIFTI"] }, "shared_patterns": { "subject": "<group>-<subject>" }, "processes": {
def update_fom(capsul_engine, environment='global', param=None, value=None): '''Load configured FOMs and create FOM completion data ''' #print('***update_fom ***') with capsul_engine.settings as session: config = session.config('fom', environment) if config is None: return soma_app = Application('capsul', plugin_modules=['soma.fom']) if 'soma.fom' not in soma_app.loaded_plugin_modules: # WARNING: this is unsafe, may erase configured things, and # probably not thread-safe. soma_app.initialize() if config.fom_path: fom_path = [p for p in config.fom_path if p not in soma_app.fom_path] \ + soma_app.fom_path else: fom_path = list(soma_app.fom_path) soma_app.fom_manager.paths = fom_path soma_app.fom_manager.fom_files() store = capsul_engine._modules_data['fom'] if config.auto_fom \ and len(store['all_foms']) <= 3: for schema in soma_app.fom_manager.fom_files(): if schema not in store['all_foms']: store['all_foms'][schema] = None # not loaded yet. foms = (('input', config.input_fom), ('output', config.output_fom), ('shared', config.shared_fom)) for fom_type, fom_filename in foms: if fom_filename not in ("", None, traits.Undefined): fom = store['all_foms'].get(fom_filename) if fom is None: fom, atp, pta = load_fom(capsul_engine, fom_filename, config, session, environment) else: atp = store['fom_atp']['all'][fom_filename] pta = store['fom_pta']['all'][fom_filename] store['foms'][fom_type] = fom store['fom_atp'][fom_type] = atp store['fom_pta'][fom_type] = pta # update directories directories = {} spm = session.config('spm', environment) if spm: directories['spm'] = spm.directory axon = session.config('axon', environment) if axon: directories['shared'] = axon.shared_directory directories['input'] = config.input_directory directories['output'] = config.output_directory for atp in store['fom_atp']['all'].values(): atp.directories = directories # backward compatibility for StudyConfig capsul_engine.study_config.modules_data.foms = store['foms'] capsul_engine.study_config.modules_data.all_foms = store['all_foms'] capsul_engine.study_config.modules_data.fom_atp = store['fom_atp'] capsul_engine.study_config.modules_data.fom_pta = store['fom_pta']