def reshape_smoothed_to_2d(subj_num, fwhm_mm): """ Reshapes the original 4-D array data into a 2-D array of a given subject and full width half maximum smoothed version and saves that into a designated file. If file already exists, uses that cached file instead. Parameters ---------- subj_num : int fwhm_mm : int Returns ------- None """ smoothed_path = dp.get_smoothed_path(subj_num, fwhm_mm) smoothed_path_2d = smoothed_path.replace(".npy", "_2d.npy") if not exists(smoothed_path_2d) or not USE_CACHED_DATA: if not exists(smoothed_path): raise ValueError("{0} does not exists, thus cannot be reshaped".format(smoothed_path)) data = np.load(smoothed_path) data_2d = np.reshape(data, (-1, data.shape[-1])) del data np.save(smoothed_path.replace(".npy", "_2d.npy"), data_2d) print("Saved {0}".format(smoothed_path_2d)) else: print("Using cached version of {0}".format(smoothed_path_2d))
def reshape_smoothed_to_2d(subj_num, fwhm_mm): """ Reshapes the original 4-D array data into a 2-D array of a given subject and full width half maximum smoothed version and saves that into a designated file. If file already exists, uses that cached file instead. Parameters ---------- subj_num : int fwhm_mm : int Returns ------- None """ smoothed_path = dp.get_smoothed_path(subj_num, fwhm_mm) smoothed_path_2d = smoothed_path.replace('.npy', '_2d.npy') if not exists(smoothed_path_2d) or not USE_CACHED_DATA: if not exists(smoothed_path): raise ValueError( '{0} does not exists, thus cannot be reshaped'.format( smoothed_path)) data = np.load(smoothed_path) data_2d = np.reshape(data, (-1, data.shape[-1])) del data np.save(smoothed_path.replace('.npy', '_2d.npy'), data_2d) print('Saved {0}'.format(smoothed_path_2d)) else: print('Using cached version of {0}'.format(smoothed_path_2d))
def gaussian_smooth_subj(subj_num, fwhm_mm): """ Retrieves the absolute path to the smoothed data for a particular subject and full width half maximum smoothed version. Loads the data and saves it in the retrieved path. If file already exists, then uses cached version instead. Parameters ---------- subj_num : int fwhm_mm : int Returns ------- None """ smoothed_data_path = dp.get_smoothed_path(subj_num, fwhm_mm) if not exists(smoothed_data_path) or not USE_CACHED_DATA: data = np.load(dp.get_concatenated_path(subj_num)).astype(np.float32) smoothed_data = apply_gaussian_smooth(data, fwhm_mm) del data np.save(smoothed_data_path, smoothed_data) print("Saved {0}".format(smoothed_data_path)) else: print("Using cached version of {0}".format(smoothed_data_path))
def gaussian_smooth_subj(subj_num, fwhm_mm): """ Retrieves the absolute path to the smoothed data for a particular subject and full width half maximum smoothed version. Loads the data and saves it in the retrieved path. If file already exists, then uses cached version instead. Parameters ---------- subj_num : int fwhm_mm : int Returns ------- None """ smoothed_data_path = dp.get_smoothed_path(subj_num, fwhm_mm) if not exists(smoothed_data_path) or not USE_CACHED_DATA: data = np.load(dp.get_concatenated_path(subj_num)).astype(np.float32) smoothed_data = apply_gaussian_smooth(data, fwhm_mm) del data np.save(smoothed_data_path, smoothed_data) print('Saved {0}'.format(smoothed_data_path)) else: print('Using cached version of {0}'.format(smoothed_data_path))
def gaussian_smooth_subj(subj_num, fwhm_mm): smoothed_data_path = dp.get_smoothed_path(subj_num, fwhm_mm) if not exists(smoothed_data_path) or not USE_CACHED_DATA: data = np.load(dp.get_concatenated_path(subj_num)).astype(np.float32) smoothed_data = apply_gaussian_smooth(data, fwhm_mm) del data np.save(smoothed_data_path, smoothed_data) print('Saved {0}'.format(smoothed_data_path)) else: print('Using cached version of {0}'.format(smoothed_data_path))
def test_get_smoothed_path(): paths = [dp.get_smoothed_path(subject, FWHM_MM) for subject in SUBJECTS] assert paths[0] == '{0}/data/processed/sub1_rcds_smoothed_8_mm.npy'.format( REPO_HOME_PATH) assert paths[1] == '{0}/data/processed/sub2_rcds_smoothed_8_mm.npy'.format( REPO_HOME_PATH) assert paths[2] == '{0}/data/processed/sub3_rcds_smoothed_8_mm.npy'.format( REPO_HOME_PATH) assert paths[3] == '{0}/data/processed/sub4_rcds_smoothed_8_mm.npy'.format( REPO_HOME_PATH) assert paths[4] == '{0}/data/processed/sub5_rcds_smoothed_8_mm.npy'.format( REPO_HOME_PATH)
def reshape_smoothed_to_2d(subj_num, fwhm_mm): smoothed_path = dp.get_smoothed_path(subj_num, fwhm_mm) smoothed_path_2d = smoothed_path.replace('.npy', '_2d.npy') if not exists(smoothed_path_2d) or not USE_CACHED_DATA: if not exists(smoothed_path): raise ValueError( '{0} does not exists, thus cannot be reshaped'.format( smoothed_path)) data = np.load(smoothed_path) data_2d = np.reshape(data, (-1, data.shape[-1])) del data np.save(smoothed_path.replace('.npy', '_2d.npy'), data_2d) print('Saved {0}'.format(smoothed_path_2d)) else: print('Using cached version of {0}'.format(smoothed_path_2d))