original_docstring: This a function to be used with ipywidgets to interactively view a decomposition analysis
  
          Make sure you have tr and output assigned to variables.
  
          Example:
  
              from ipywidgets import BoundedFloatText, BoundedIntText
              from ipywidgets import interact
  
              tr = 2.4
              output = data_filtered_smoothed.decompose(algorithm='ica', n_components=30, axis='images', whiten=True)
  
              interact(component_inspector, component=BoundedIntText(description='Component', value=0, min=0, max=len(output['components'])-1),
                    threshold=BoundedFloatText(description='Threshold', value=2.0, min=0, max=4, step=.1))
  
          
docstring: This a function to be used with ipywidgets to interactively view a decomposition analysis
  Make sure you have tr and output assigned to variables.
docstring_tokens: This a function to be used with ipywidgets to interactively view a decomposition analysis Make sure you have tr and output assigned to variables .
code: def component_inspector(component, threshold):
          """This a function to be used with ipywidgets to interactively view a decomposition analysis
  
          Make sure you have tr and output assigned to variables.
  
          Example:
  
              from ipywidgets import BoundedFloatText, BoundedIntText
              from ipywidgets import interact
  
              tr = 2.4
              output = data_filtered_smoothed.decompose(algorithm='ica', n_components=30, axis='images', whiten=True)
  
              interact(component_inspector, component=BoundedIntText(description='Component', value=0, min=0, max=len(output['components'])-1),
                    threshold=BoundedFloatText(description='Threshold', value=2.0, min=0, max=4, step=.1))
  
          """
          _, ax = plt.subplots(nrows=3, figsize=(12, 8))
          thresholded = (
              output["components"][component] - output["components"][component].mean()
          ) * (1 / output["components"][component].std())
          thresholded.data[np.abs(thresholded.data) <= threshold] = 0
          plot_stat_map(
              thresholded.to_nifti(),
              cut_coords=range(-40, 70, 10),
              display_mode="z",
              black_bg=True,
              colorbar=True,
              annotate=False,
              draw_cross=False,
              axes=ax[0],
          )
          if isinstance(output["decomposition_object"], (sklearn.decomposition.PCA)):
              var_exp = output["decomposition_object"].explained_variance_ratio_[
                  component
              ]
              ax[0].set_title(
                  f"Component: {component}/{len(output['components'])}, Variance Explained: {var_exp:2.2}",
                  fontsize=18,
              )
          else:
              ax[0].set_title(
                  f"Component: {component}/{len(output['components'])}", fontsize=18
              )
  
          ax[1].plot(output["weights"][:, component], linewidth=2, color="red")
          ax[1].set_ylabel("Intensity (AU)", fontsize=18)
          ax[1].set_title(f"Timecourse (TR={tr})", fontsize=16)
          y = fft(output["weights"][:, component])
          f = fftfreq(len(y), d=tr)
          ax[2].plot(f[f > 0], np.abs(y)[f > 0] ** 2)
          ax[2].set_ylabel("Power", fontsize=18)
          ax[2].set_xlabel("Frequency (Hz)", fontsize=16)
code_tokens: def component_inspector ( component , threshold ) : _ , ax = plt . subplots ( nrows = 3 , figsize = ( 12 , 8 ) ) thresholded = ( output [ "components" ] [ component ] - output [ "components" ] [ component ] . mean ( ) ) * ( 1 / output [ "components" ] [ component ] . std ( ) ) thresholded . data [ np . abs ( thresholded . data ) <= threshold ] = 0 plot_stat_map ( thresholded . to_nifti ( ) , cut_coords = range ( - 40 , 70 , 10 ) , display_mode = "z" , black_bg = True , colorbar = True , annotate = False , draw_cross = False , axes = ax [ 0 ] , ) if isinstance ( output [ "decomposition_object" ] , ( sklearn . decomposition . PCA ) ) : var_exp = output [ "decomposition_object" ] . explained_variance_ratio_ [ component ] ax [ 0 ] . set_title ( f"Component: {component}/{len(output['components'])}, Variance Explained: {var_exp:2.2}" , fontsize = 18 , ) else : ax [ 0 ] . set_title ( f"Component: {component}/{len(output['components'])}" , fontsize = 18 ) ax [ 1 ] . plot ( output [ "weights" ] [ : , component ] , linewidth = 2 , color = "red" ) ax [ 1 ] . set_ylabel ( "Intensity (AU)" , fontsize = 18 ) ax [ 1 ] . set_title ( f"Timecourse (TR={tr})" , fontsize = 16 ) y = fft ( output [ "weights" ] [ : , component ] ) f = fftfreq ( len ( y ) , d = tr ) ax [ 2 ] . plot ( f [ f > 0 ] , np . abs ( y ) [ f > 0 ] ** 2 ) ax [ 2 ] . set_ylabel ( "Power" , fontsize = 18 ) ax [ 2 ] . set_xlabel ( "Frequency (Hz)" , fontsize = 16 )
short_docstring: This a function to be used with ipywidgets to interactively view a decomposition analysis
  Make sure you have tr and output assigned to variables.
short_docstring_tokens: This a function to be used with ipywidgets to interactively view a decomposition analysis Make sure you have tr and output assigned to variables .
comment: """This a function to be used with ipywidgets to interactively view a decomposition analysis
  
          Make sure you have tr and output assigned to variables.
  
          Example:
  
              from ipywidgets import BoundedFloatText, BoundedIntText
              from ipywidgets import interact
  
              tr = 2.4
              output = data_filtered_smoothed.decompose(algorithm='ica', n_components=30, axis='images', whiten=True)
  
              interact(component_inspector, component=BoundedIntText(description='Component', value=0, min=0, max=len(output['components'])-1),
                    threshold=BoundedFloatText(description='Threshold', value=2.0, min=0, max=4, step=.1))
  
          """