def test_decode_roi_with_priors(): """Acceptance test of ROI-based decoding with topic priors. """ model_file = join(get_test_data_path(), 'gclda_model.pkl') roi_file = join(get_test_data_path(), 'roi.nii.gz') model = Model.load(model_file) _, priors = decode_roi(model, roi_file) decoded_df, _ = decode_roi(model, roi_file, topic_priors=priors) assert decoded_df.shape[0] == model.n_word_labels
def test_decode_roi_from_file(): """Acceptance test of ROI-based decoding with str input. """ model_file = join(get_test_data_path(), 'gclda_model.pkl') roi_file = join(get_test_data_path(), 'roi.nii.gz') model = Model.load(model_file) decoded_df, _ = decode_roi(model, roi_file) assert decoded_df.shape[0] == model.n_word_labels
############################################################################### # Create region of interest (ROI) image # -------------------------------------- coords = [[-40, -52, -20]] radii = [6] * len(coords) roi_img = create_sphere(coords, radius=radii, mask=model.dataset.mask_img) fig = plotting.plot_roi(roi_img, display_mode='ortho', cut_coords=[-40, -52, -20], draw_cross=False) ############################################################################### # Decode ROI # ----------- df, topic_weights = decode_roi(model, roi_img) ############################################################################### # Get associated terms # --------------------- df = df.sort_values(by='Weight', ascending=False) print(df.head(10)) ############################################################################### # Plot topic weights # ------------------ fig2, ax2 = plt.subplots() ax2.plot(topic_weights) ax2.set_xlabel('Topic #') ax2.set_ylabel('Weight') fig2.show()
affine = model.dataset.mask_img.affine mask = nib.Nifti1Image(mask_data, affine) ############################################################################### # Temporoparietal seed # -------------------------------------- coords = [[-52, -56, 18]] radii = [6] * len(coords) roi_img = create_sphere(coords, radius=radii, mask=mask) fig = plotting.plot_roi(roi_img, display_mode='ortho', cut_coords=[-52, -56, 18], draw_cross=False) df, _ = decode_roi(model, roi_img) df = df.sort_values(by='Weight', ascending=False) print(df.head(10)) ############################################################################### # Temporoparietal, medial parietal, and dorsomedial prefrontal seeds # ------------------------------------------------------------------ coords = [[-56, -52, 18], [0, -58, 38], [4, 54, 26]] radii = [6] * len(coords) roi_img = create_sphere(coords, radius=radii, mask=mask) fig = plotting.plot_roi(roi_img, display_mode='ortho', cut_coords=[-52, -56, 18], draw_cross=False)