def fit_model(): input_data = mdt.load_input_data( os.path.realpath(args.dwi), os.path.realpath(args.protocol), os.path.realpath(args.mask), gradient_deviations=args.gradient_deviations, noise_std=noise_std, extra_protocol=get_extra_protocol(args.extra_protocol, os.path.realpath(''))) optimizer_options = {} if args.patience is not None: optimizer_options['patience'] = args.patience mdt.fit_model(args.model, input_data, output_folder, method=args.method, optimizer_options=optimizer_options, recalculate=args.recalculate, only_recalculate_last=args.only_recalculate_last, cl_device_ind=args.cl_device_ind, double_precision=args.double_precision, tmp_results_dir=tmp_results_dir, use_cascaded_inits=args.use_cascaded_inits)
def run(self, args, extra_args): input_data = mdt.load_input_data(os.path.realpath(args.dwi), os.path.realpath(args.protocol), os.path.realpath(args.mask)) with mdt.with_logging_to_debug(): noise_std = mdt.estimate_noise_std(input_data) print(noise_std)
def build_input_data(self): return mdt.load_input_data( self.dwi, self.protocol, self.mask, noise_std=self.noise_std, gradient_deviations=self.gradient_deviations, extra_protocol=self.extra_protocol)
def _run_b1k_b2k_analysis(cls): pjoin = mdt.make_path_joiner( os.path.join(cls._tmp_dir, cls._tmp_dir_subdir, 'b1k_b2k')) input_data = mdt.load_input_data( pjoin('b1k_b2k_example_slices_24_38'), pjoin('b1k_b2k.prtcl'), pjoin('b1k_b2k_example_slices_24_38_mask')) for model_name in ['BallStick_r1', 'Tensor', 'NODDI']: mdt.fit_model(model_name, input_data, pjoin('output', 'b1k_b2k_example_slices_24_38_mask'))
def run(self, args, extra_args): input_data = mdt.load_input_data(os.path.realpath(args.dwi), os.path.realpath(args.protocol), os.path.realpath(args.mask)) estimator = None if args.estimator: estimator = mdt.load_component('noise_std_estimators', args.estimator) with mdt.with_logging_to_debug(): noise_std = mdt.estimate_noise_std(input_data, estimator=estimator) print(noise_std)
def _run_b6k_analysis(cls): pjoin = mdt.make_path_joiner( os.path.join(cls._tmp_dir, cls._tmp_dir_subdir, 'multishell_b6k_max')) input_data = mdt.load_input_data( pjoin('multishell_b6k_max_example_slices_24_38'), pjoin('multishell_b6k_max.prtcl'), pjoin('multishell_b6k_max_example_slices_24_38_mask')) for model_name in ['CHARMED_r1', 'CHARMED_r2', 'CHARMED_r3']: mdt.fit_model( model_name, input_data, pjoin('output', 'multishell_b6k_max_example_slices_24_38_mask'))
def fit_model(): mdt.fit_model(args.model, mdt.load_input_data( os.path.realpath(args.dwi), os.path.realpath(args.protocol), os.path.realpath(args.mask), gradient_deviations=args.gradient_deviations, noise_std=noise_std, extra_protocol=get_extra_protocol( args.extra_protocol, os.path.realpath(''))), output_folder, recalculate=args.recalculate, only_recalculate_last=args.only_recalculate_last, cl_device_ind=args.cl_device_ind, double_precision=args.double_precision, tmp_results_dir=tmp_results_dir)
def fit_model(): mdt.fit_model(args.model, mdt.load_input_data( os.path.realpath(args.dwi), os.path.realpath(args.protocol), os.path.realpath(args.mask), gradient_deviations=args.gradient_deviations, noise_std=noise_std, protocol_maps=get_protocol_maps( args.protocol_maps, os.path.realpath(''))), output_folder, recalculate=args.recalculate, only_recalculate_last=args.only_recalculate_last, cl_device_ind=args.cl_device_ind, double_precision=args.double_precision, cascade_subdir=args.cascade_subdir, tmp_results_dir=tmp_results_dir, save_user_script_info=None)
def CHARMED(dwi, mask): import mdt import os import nibabel as nib from mdt.configuration import SetGeneralOptimizer protocol = '/media/amr/HDD/Work/October_Acquistion/MDT_multishell_protocol.prtcl' model = 'CHARMED_r2 (Cascade|fixed)' algorithm = 'Levenberg-Marquardt' patience = 100 output_folder = os.getcwd() input_data = mdt.load_input_data(dwi, protocol, mask, noise_std=5, gradient_deviations=None, extra_protocol={}) with mdt.config_context( SetGeneralOptimizer(algorithm, settings={'patience': patience})): mdt.fit_model(model, input_data, output_folder, recalculate=True, only_recalculate_last=True, double_precision=False, cl_device_ind=[0]) os.chdir('CHARMED_r2') CHARMED_FA = os.path.abspath('Tensor.FA.nii.gz') CHARMED_MD = os.path.abspath('Tensor.MD.nii.gz') CHARMED_AD = os.path.abspath('Tensor.AD.nii.gz') CHARMED_RD = os.path.abspath('Tensor.RD.nii.gz') CHARMED_FR = os.path.abspath('FR.nii.gz') #I assumed that CHARMEDRestricted0.d to be the intra-axonal diffusvity CHARMED_IAD = os.path.abspath('CHARMEDRestricted0.d.nii.gz') return CHARMED_FA, CHARMED_MD, CHARMED_AD, CHARMED_RD, CHARMED_FR, CHARMED_IAD
if model_name.startswith('CHARMED'): model_specific_protocols = ['hcp_mgh_1003'] for protocol_name in model_specific_protocols: for snr in noise_snrs: print('Going to process', trial_ind, model_name, protocol_name, snr) noise_std = simulations_unweighted_signal_height / snr current_pjoin = pjoin.create_extended(protocol_name, model_name) input_data = mdt.load_input_data( current_pjoin('noisy_signals_{}.nii'.format(snr)), pjoin(protocol_name + '.prtcl'), current_pjoin('mask.nii'), noise_std=noise_std) fit_results = mdt.fit_model( model_name + ' (Cascade)', input_data, current_pjoin('output', str(snr), str(trial_ind))) with mdt.config_context(''' processing_strategies: sampling: max_nmr_voxels: 5000 '''): mdt.sample_model( model_name, input_data,
os.chdir(experiment_dir + '/' + sub) #location/directory containing all the data for this study/subject #load data if mdt_model == "NODDI_test": mask_file = "data_brain_mask.nii.gz" # generate scheme file from the bvals/bvecs protocol = mdt.create_protocol(bvecs='data.bvec', bvals='data.bval', out_file=experiment_dir + '/' + sub + '/data.prtcl') mdt_dir = opj(experiment_dir, sub, mdt_model) if not os.path.exists(mdt_dir): os.mkdir(mdt_dir) input_data = mdt.load_input_data('data.nii.gz', 'data.prtcl', 'data_brain_mask.nii.gz') test = mdt.get_optimization_inits('NODDI', input_data, 'output') mdt.fit_model('NODDI', input_data, 'output') if mdt_model == "ActiveAx": mask_file = "data_brain_mask.nii.gz" protocol = mdt.create_protocol(bvecs='data.bvec', bvals='data.bval', out_file=experiment_dir + '/' + sub + '/data.prtcl') mdt_dir = opj(experiment_dir, sub, mdt_model) if not os.path.exists(mdt_dir): os.mkdir(mdt_dir)