Beispiel #1
0
def tumor_near_surface_temperatures(filepath,
                                    region_filepath,
                                    do_print=True,
                                    do_write=True):
    print()
    print('Calc tumor temperatures near surface of {0}.'.format(filepath))

    temp = temperature_array_from_result(filepath)
    tumor = region_array_from_file(region_filepath)
    temp_mean, temp_max, temp_min, temp_std_dev = calc_tumor_near_surface_temperatures(
        temp, tumor)

    depth = DEPTH

    if do_print == True:
        section = 'tumor near surface (first ' + str(depth) + ' nodes)'
        print_results(section, temp_mean, temp_max, temp_min, temp_std_dev)
    if do_write == True:
        filepath = os.path.splitext(filepath)[0] + '_results.dat'
        section = 'Tumor_Near_Surface_' + str(depth) + '_Depth'
        write_results_to_file(section, temp_mean, temp_max, temp_min,
                              temp_std_dev, filepath, 'a')
    print('Done.')

    return temp_mean
def plot_surface(filepath, params):
    print('Plotting {0}.'.format(filepath))

    T = temperature_array_from_result(filepath)
    dim2, dim1, dim0 = T.shape

    filepath = os.path.splitext(filepath)[0]
    title = filepath
    filepath_surface = filepath + '_surface.eps'
    filepath_heatmap = filepath + '_heatmap.eps'
    filepath_heatmap_scaled = filepath + '_heatmap_scaled.eps'
    filepath_heatmap_thermo_scaled = filepath + '_heatmap_thermo_scaled.eps'
    filepath_tumor = filepath + '_tumor.eps'

    # Surface data.
    temperature = np.zeros((dim1, dim0))
    temperature[:, :] = T[-1, :, :]
    plot_3d_surface(temperature, params, title, filepath_surface)
    plot_heatmap(temperature, params, title, filepath_heatmap)
    plot_heatmap_scaled(temperature, params, title, filepath_heatmap_scaled)
    if params['MRI_DATA_CASE'] != '':
        csv_min, csv_max = plot_thermo(params['MRI_DATA_CASE'],
                                       params['MRI_DATA_FOLDER'])
        plot_heatmap_thermo_scaled(temperature, params, title,
                                   filepath_heatmap_thermo_scaled, csv_min,
                                   csv_max)

    # x-z-plane data.
    temperature = np.zeros((dim2, dim0))
    temperature[:, :] = T[:, int(dim1 / 2), :]
    plot_tumor(temperature, params, title, filepath_tumor)

    print('Done.')
Beispiel #3
0
def check_results(filepath):
    a_1 = temperature_array_from_result(filepath[0])
    a_2 = temperature_array_from_result(filepath[1])
    print()
    if np.array_equal(a_1, a_2) == True:
        print('SUCCESS: Last timestep is equal.')
    else:
        if a_1.shape[0] != a_2.shape[0] or \
           a_1.shape[1] != a_2.shape[1] or \
           a_1.shape[2] != a_2.shape[2]:
            print('WARNING: Shape of files is not equal.')
            print('Aborting.')
            exit()
        else:
            print('WARNING: Last timestep is NOT equal.')

    print('Done.')
    def callScaFES(T_blood=T_blood):

        global count
        global params
        count += 1

        print()
        print('##### ScaFES iteration: {} #####'.format(count))

        case = params['NAME_CONFIGFILE_TEMPLATE'].split('.')[0]
        case = case.split('_')[0]
        params['NAME_CONFIGFILE'] = case + '-pymc-' + TESTED_VARIABLES + '.ini'
        params['NAME_RESULTFILE'] = ''
        config = configparser.ConfigParser()
        config.optionxform = str
        config.read(params['NAME_CONFIGFILE_TEMPLATE'])
        # T_blood.
        config['Brain']['T_BLOOD'] = str(T_blood)
        config['Tumor']['T_BLOOD'] = str(T_blood)

        with open(params['NAME_CONFIGFILE'], 'w') as configfile:
            config.write(configfile)

        # Call simulation.
        parse_config_file(params)
        check_variables(params)
        calc_variables(params)
        check_stability(params)
        if params['USE_MRI_FILE'] == False:
            create_region_file(params)
        create_init_file(params)
        set_environment_variables(params)
        call_simulation(params, params['RUN_SCRIPT'])
        if params['NAME_RESULTFILE'] != '':
            # Compute temperatures of normal, tumor, vessel tisue.
            temp = temperature_array_from_result(params['NAME_RESULTFILE'])
            tumor = region_array_from_file(params['NAME_REGION_FILE'])
            vessels = surface_vessels_array_from_file(
                params['NAME_VESSELS_FILE'])

            T_tumor, _, _, _ = calc_tumor_near_surface_temperatures(
                temp, tumor)
            if params['USE_VESSELS_SEGMENTATION'] == True:
                temp = temp[-1, :, :]
                T_vessel, _, _, _ = calc_vessels_temperatures(temp, vessels)
                T_normal, _, _, _ = calc_non_vessels_temperatures(
                    temp, vessels)
            else:
                T_vessel = -1.0
                T_normal = -1.0
        else:
            print('* ERROR: No result file written.')
            print('Aborting.')
            exit()

        return [T_normal, T_tumor, T_vessel]
def calc_diff(filepaths):
    temp_1 = temperature_array_from_result(filepaths[0])
    temp_2 = temperature_array_from_result(filepaths[1])

    filepath = os.path.splitext(filepaths[0])[0] + '_' \
               + os.path.basename(os.path.splitext(filepaths[1])[0]) \
               + '_diff'
    filepath_dat = filepath + '.dat'

    if temp_1.shape == temp_2.shape:
        temp_diff = diff_of_two_equal_files(temp_1, temp_2, filepath_dat)
    else:
        temp_diff = diff_of_file_dimensions_not_equal(temp_1, temp_2,
                                                      filepath_dat)

    filepath_fig = filepath + '_surface.eps'
    plot_diff_on_surface(temp_diff[-1, :, :], filepath_fig)
    filepath_nc = filepath + '.nc'
    save_as_netcdf(temp_diff, filepath_nc)
Beispiel #6
0
def domain_temperatures(filepath, do_print=True, do_write=True):
    print()
    print('Calc domain temperatures of {0}.'.format(filepath))

    temp = temperature_array_from_result(filepath)
    temp_mean, temp_max, temp_min, temp_std_dev = calc_domain_temperatures(
        temp)

    if do_print == True:
        print_results('domain', temp_mean, temp_max, temp_min, temp_std_dev)
    if do_write == True:
        filepath = os.path.splitext(filepath)[0] + '_results.dat'
        write_results_to_file('Domain', temp_mean, temp_max, temp_min,
                              temp_std_dev, filepath, 'a')

    print('Done.')

    return temp_mean
Beispiel #7
0
def tumor_temperatures(filepath,
                       region_filepath,
                       do_print=True,
                       do_write=True):
    print()
    print('Calc tumor temperatures of {0}.'.format(filepath))

    temp = temperature_array_from_result(filepath)
    tumor = region_array_from_file(region_filepath)
    temp_mean, temp_max, temp_min, temp_std_dev = calc_tumor_temperatures(
        temp, tumor)

    if do_print == True:
        print_results('tumor', temp_mean, temp_max, temp_min, temp_std_dev)
    if do_write == True:
        filepath = os.path.splitext(filepath)[0] + '_results.dat'
        write_results_to_file('Tumor', temp_mean, temp_max, temp_min,
                              temp_std_dev, filepath, 'a')

    print('Done.')

    return temp_mean
    def callScaFES(omega_brain=omega_brain,
                   omega_tumor=omega_tumor,
                   omega_vessel=omega_vessel,
                   T_blood=T_blood,
                   q_brain=q_brain,
                   q_tumor=q_tumor,
                   lambda_bt=lambda_bt,
                   rho_c_brain=rho_c_brain,
                   rho_c_tumor=rho_c_tumor,
                   h=h):

        global count
        global params
        count += 1

        print()
        print('##### ScaFES iteration: {} #####'.format(count))

        case = params['NAME_CONFIGFILE_TEMPLATE'].split('.')[0]
        case = case.split('_')[0]
        params['NAME_CONFIGFILE'] = case + '-pymc-' + TESTED_VARIABLES + '.ini'
        params['NAME_RESULTFILE'] = ''
        config = configparser.ConfigParser()
        config.optionxform = str
        config.read(params['NAME_CONFIGFILE_TEMPLATE'])
        # Omega.
        config['Brain']['OMEGA'] = str(omega_brain)
        config['Tumor']['OMEGA'] = str(omega_tumor)
        config['MRI']['USE_VESSELS_SEGMENTATION'] = 'True'
        config['MRI']['VARIABLES_VESSELS'] = 'omega'
        config['MRI']['VALUES_VESSELS'] = str(omega_vessel)
        config['MRI']['VALUES_NON_VESSELS'] = str(omega_brain)
        # T_blood.
        config['Brain']['T_BLOOD'] = str(T_blood)
        config['Tumor']['T_BLOOD'] = str(T_blood)
        # Q.
        config['Brain']['Q'] = str(q_brain)
        config['Tumor']['Q'] = str(q_tumor)
        # lambda.
        config['Brain']['LAMBDA'] = str(lambda_bt)
        config['Tumor']['LAMBDA'] = str(lambda_bt)
        # rho * c.
        config['Brain']['C'] = str(rho_c_brain)
        config['Brain']['RHO'] = str(1000.0)
        config['Tumor']['C'] = str(rho_c_tumor)
        config['Tumor']['RHO'] = str(1000.0)
        # h.
        config['Parameters']['H'] = str(h)

        with open(params['NAME_CONFIGFILE'], 'w') as configfile:
            config.write(configfile)

        # Call simulation.
        parse_config_file(params)
        check_variables(params)
        calc_variables(params)
        check_stability(params)
        if params['USE_MRI_FILE'] == False:
            create_region_file(params)
        create_init_file(params)
        set_environment_variables(params)
        call_simulation(params, params['RUN_SCRIPT'])
        if params['NAME_RESULTFILE'] != '':
            # Compute temperatures of normal, tumor, vessel tisue.
            temp = temperature_array_from_result(params['NAME_RESULTFILE'])
            tumor = region_array_from_file(params['NAME_REGION_FILE'])
            vessels = surface_vessels_array_from_file(
                params['NAME_VESSELS_FILE'])

            T_tumor, _, _, _ = calc_tumor_near_surface_temperatures(
                temp, tumor)
            if params['USE_VESSELS_SEGMENTATION'] == True:
                temp = temp[-1, :, :]
                T_vessel, _, _, _ = calc_vessels_temperatures(temp, vessels)
                T_normal, _, _, _ = calc_non_vessels_temperatures(
                    temp, vessels)
            else:
                T_vessel = -1.0
                T_normal = -1.0
        else:
            print('* ERROR: No result file written.')
            print('Aborting.')
            exit()

        global dat_file_name
        with open(dat_file_name, 'a') as backupfile:
            backupfile.write(str(omega_brain) + '\t' \
                             + str(omega_tumor) + '\t' \
                             + str(omega_vessel) + '\t' \
                             + str(T_blood) + '\t' \
                             + str(q_brain) + '\t' \
                             + str(q_tumor) + '\t' \
                             + str(lambda_bt) + '\t' \
                             + str(rho_c_brain) + '\t' \
                             + str(rho_c_tumor) + '\t' \
                             + str(h) + '\t' \
                             + str(T_normal) + '\t' \
                             + str(T_tumor) + '\t' \
                             + str(T_vessel) + '\n')

        if (count % 25 == 0):
            searchpath = './' + params['NAME_EXECUTABLE'] + '-' + case + '-*.*'
            log_files = glob.glob(searchpath)
            for f in log_files:
                os.remove(f)

        return [T_normal, T_tumor, T_vessel]