コード例 #1
0
def test_nifti_maps_masker_report_displayed_maps_errors(
        niftimapsmasker_inputs, displayed_maps):
    """Tests that a TypeError is raised when the argument `displayed_maps`
    of `generate_report()` is not valid.
    """
    masker = NiftiMapsMasker(**niftimapsmasker_inputs)
    masker.fit()
    with pytest.raises(TypeError, match=("Parameter ``displayed_maps``")):
        masker.generate_report(displayed_maps)
コード例 #2
0
def test_nifti_maps_masker_report_maps_number_errors(niftimapsmasker_inputs,
                                                     displayed_maps):
    """Tests that a ValueError is raised when the argument `displayed_maps`
    contains invalid map numbers.
    """
    masker = NiftiMapsMasker(**niftimapsmasker_inputs)
    masker.fit()
    with pytest.raises(ValueError,
                       match="Report cannot display the following maps"):
        masker.generate_report(displayed_maps)
コード例 #3
0
def test_nifti_maps_masker_report_image_in_fit(niftimapsmasker_inputs):
    """"""
    masker = NiftiMapsMasker(**niftimapsmasker_inputs)
    image, _ = generate_random_img((13, 11, 12), affine=np.eye(4), length=3)
    masker.fit(image)
    html = masker.generate_report(2)
    assert masker._report_content['report_id'] == 0
    assert masker._report_content['number_of_maps'] == 9
    assert masker._report_content['warning_message'] is None
    assert html.body.count("<img") == 2
コード例 #4
0
def test_nifti_maps_masker_report_integer_and_all_displayed_maps(
        niftimapsmasker_inputs, displayed_maps):
    """Tests NiftiMapsMasker reporting with no image provided to fit
    and displayed_maps provided as an integer or as 'all'.
    """
    masker = NiftiMapsMasker(**niftimapsmasker_inputs)
    masker.fit()
    expected_n_maps = 9 if displayed_maps == 'all' else min(9, displayed_maps)
    if displayed_maps != 'all' and displayed_maps > 9:
        with pytest.warns(UserWarning, match="masker only has 9 maps."):
            html = masker.generate_report(displayed_maps)
    else:
        html = masker.generate_report(displayed_maps)
    assert masker._report_content['report_id'] == 0
    assert masker._report_content['number_of_maps'] == 9
    assert (masker._report_content['displayed_maps'] == list(
        range(expected_n_maps)))
    msg = ("No image provided to fit in NiftiMapsMasker. "
           "Plotting only spatial maps for reporting.")
    assert masker._report_content['warning_message'] == msg
    assert html.body.count("<img") == expected_n_maps
コード例 #5
0
def test_nifti_maps_masker_report_list_and_arrays_maps_number(
        niftimapsmasker_inputs, displayed_maps):
    """Tests report generation for NiftiMapsMasker with displayed_maps
    passed as a list of a Numpy arrays.
    """
    masker = NiftiMapsMasker(**niftimapsmasker_inputs)
    masker.fit()
    html = masker.generate_report(displayed_maps)
    assert masker._report_content['report_id'] == 0
    assert masker._report_content['number_of_maps'] == 9
    assert (masker._report_content['displayed_maps'] == list(displayed_maps))
    msg = ("No image provided to fit in NiftiMapsMasker. "
           "Plotting only spatial maps for reporting.")
    assert masker._report_content['warning_message'] == msg
    assert html.body.count("<img") == len(displayed_maps)
コード例 #6
0
# Extract the time series
# ------------------------
from nilearn.input_data import NiftiMapsMasker
masker = NiftiMapsMasker(maps_img=atlas_filename, standardize=True,
                         memory='nilearn_cache', verbose=5)
masker.fit(data.func[0])
time_series = masker.transform(data.func[0],
                               confounds=data.confounds)

############################################################################
# We can generate an HTML report and visualize the components of the
# :class:`~nilearn.input_data.NiftiMapsMasker`.
# You can pass the indices of the spatial maps you want to include in the
# report in the order you want them to appear.
# Here, we only include maps 2, 6, 7, 16, and 21 in the report:
report = masker.generate_report(displayed_maps=[2, 6, 7, 16, 21])
report

############################################################################
# `time_series` is now a 2D matrix, of shape (number of time points x
# number of regions)
print(time_series.shape)

############################################################################
# Build and display a correlation matrix
# ---------------------------------------
from nilearn.connectome import ConnectivityMeasure
correlation_measure = ConnectivityMeasure(kind='correlation')
correlation_matrix = correlation_measure.fit_transform([time_series])[0]

# Display the correlation matrix