We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG] MultiNiftiMapsMasker reports are empty
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Operating system

- [X] Linux
- [ ] Mac
- [ ] Windows

### Operating system version

For example one of the following:
- Linux Ubuntu 22.04



### Python version

- [ ] 3.12
- [X] 3.11
- [ ] 3.10
- [ ] 3.9
- [ ] 3.8

### nilearn version

dev

### Expected behavior

to have non empty reports

### Current behavior & error messages

This is what I got:

![image](https://github.com/nilearn/nilearn/assets/6961185/3b0cc2fb-3ebf-4268-bc83-452d99573b76)

![image](https://github.com/nilearn/nilearn/assets/6961185/391cde29-9fbc-43de-9f72-6dfc4f99052e)



### Steps and code to reproduce bug

```python
from pathlib import Path
from nilearn import datasets
from nilearn.maskers import (
    MultiNiftiMapsMasker
)

REPORTS_DIR = Path().cwd()

difumo = datasets.fetch_atlas_difumo(
    dimension=64, resolution_mm=2, legacy_format=False
)

data = datasets.fetch_development_fmri(n_subjects=2)

masker = MultiNiftiMapsMasker(
    maps_img=difumo.maps,
    standardize="zscore_sample",
    standardize_confounds="zscore_sample",
    memory="nilearn_cache",
    n_jobs=2,
)

masker.fit()
report = masker.generate_report()
report.save_as_html(REPORTS_DIR / "multi_nifti_maps_masker_atlas.html")

_ = masker.fit_transform(data.func, confounds=data.confounds)
report = masker.generate_report()
report.save_as_html(REPORTS_DIR / "multi_nifti_maps_masker_fitted.html")
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nilearn/reporting/html_report.py`
Content:
```
1 """Generate HTML reports."""
2 
3 import copy
4 import os
5 import warnings
6 from pathlib import Path
7 from string import Template
8 
9 from nilearn.externals import tempita
10 from nilearn.maskers import NiftiSpheresMasker
11 from nilearn.plotting.html_document import HTMLDocument
12 from nilearn.reporting.utils import figure_to_svg_base64
13 
14 ESTIMATOR_TEMPLATES = {
15     "NiftiLabelsMasker": "report_body_template_niftilabelsmasker.html",
16     "NiftiMapsMasker": "report_body_template_niftimapsmasker.html",
17     "NiftiSpheresMasker": "report_body_template_niftispheresmasker.html",
18     "default": "report_body_template.html",
19 }
20 
21 
22 def _get_estimator_template(estimator):
23     """Return the HTML template to use for a given estimator \
24     if a specific template was defined in ESTIMATOR_TEMPLATES, \
25     otherwise return the default template.
26 
27     Parameters
28     ----------
29     estimator : object instance of BaseEstimator
30         The object we wish to retrieve template of.
31 
32     Returns
33     -------
34     template : str
35         Name of the template file to use.
36 
37     """
38     if estimator.__class__.__name__ in ESTIMATOR_TEMPLATES:
39         return ESTIMATOR_TEMPLATES[estimator.__class__.__name__]
40     else:
41         return ESTIMATOR_TEMPLATES["default"]
42 
43 
44 def _embed_img(display):
45     """Embed an image or just return its instance if already embedded.
46 
47     Parameters
48     ----------
49     display : obj
50         A Nilearn plotting object to display.
51 
52     Returns
53     -------
54     embed : str
55         Binary image string.
56 
57     """
58     if display is None:  # no image to display
59         return None
60     # If already embedded, simply return as is
61     if isinstance(display, str):
62         return display
63     return figure_to_svg_base64(display.frame_axes.figure)
64 
65 
66 def _str_params(params):
67     """Convert NoneType values to the string 'None' for display.
68 
69     Parameters
70     ----------
71     params : dict
72         A dictionary of input values to a function.
73 
74     """
75     params_str = copy.deepcopy(params)
76     for k, v in params_str.items():
77         if v is None:
78             params_str[k] = "None"
79     return params_str
80 
81 
82 def _update_template(
83     title, docstring, content, overlay, parameters, data, template_name=None
84 ):
85     """Populate a report with content.
86 
87     Parameters
88     ----------
89     title : str
90         The title for the report.
91 
92     docstring : str
93         The introductory docstring for the reported object.
94 
95     content : img
96         The content to display.
97 
98     overlay : img
99         Overlaid content, to appear on hover.
100 
101     parameters : dict
102         A dictionary of object parameters and their values.
103 
104     data : dict
105         A dictionary holding the data to be added to the report.
106         The keys must match exactly the ones used in the template.
107         The default template accepts the following:
108             - description (str) : Description of the content.
109             - warning_message (str) : An optional warning
110               message to be displayed in red. This is used
111               for example when no image was provided to the
112               estimator when fitting.
113         The NiftiLabelsMasker template accepts the additional
114         fields:
115             - summary (dict) : A summary description of the
116               region labels and sizes. This will be displayed
117               as an expandable table in the report.
118 
119     template_name : str, optional
120         The name of the template to use. If not provided, the
121         default template `report_body_template.html` will be
122         used.
123 
124     Returns
125     -------
126     report : HTMLReport
127         An instance of a populated HTML report.
128 
129     """
130     resource_path = Path(__file__).resolve().parent.joinpath("data", "html")
131 
132     if template_name is None:
133         body_template_name = "report_body_template.html"
134     else:
135         body_template_name = template_name
136     body_template_path = resource_path.joinpath(body_template_name)
137     if not os.path.exists(str(body_template_path)):
138         raise FileNotFoundError(f"No template {body_template_name}")
139     tpl = tempita.HTMLTemplate.from_filename(
140         str(body_template_path), encoding="utf-8"
141     )
142     body = tpl.substitute(
143         title=title,
144         content=content,
145         overlay=overlay,
146         docstring=docstring,
147         parameters=parameters,
148         **data,
149     )
150 
151     head_template_name = "report_head_template.html"
152     head_template_path = resource_path.joinpath(head_template_name)
153     with open(str(head_template_path)) as head_file:
154         head_tpl = Template(head_file.read())
155 
156     return HTMLReport(body=body, head_tpl=head_tpl)
157 
158 
159 def _define_overlay(estimator):
160     """Determine whether an overlay was provided and \
161     update the report text as appropriate."""
162     displays = estimator._reporting()
163 
164     if len(displays) == 1:  # set overlay to None
165         overlay, image = None, displays[0]
166 
167     elif isinstance(estimator, NiftiSpheresMasker):
168         overlay, image = None, displays
169 
170     elif len(displays) == 2:
171         overlay, image = displays[0], displays[1]
172 
173     else:
174         overlay, image = None, displays
175 
176     return overlay, image
177 
178 
179 def generate_report(estimator):
180     """Generate a report for Nilearn objects.
181 
182     Reports are useful to visualize steps in a processing pipeline.
183     Example use case: visualize the overlap of a mask and reference image
184     in NiftiMasker.
185 
186     Parameters
187     ----------
188     estimator : Object instance of BaseEstimator.
189         Object for which the report should be generated.
190 
191     Returns
192     -------
193     report : HTMLReport
194 
195     """
196     if hasattr(estimator, "_report_content"):
197         data = estimator._report_content
198     else:
199         data = {}
200     if not hasattr(estimator, "_reporting_data"):
201         warnings.warn(
202             "This object has not been fitted yet ! "
203             "Make sure to run `fit` before inspecting reports."
204         )
205         return _update_template(
206             title="Empty Report",
207             docstring=(
208                 "This report was not generated. Please `fit` the object."
209             ),
210             content=_embed_img(None),
211             overlay=None,
212             parameters={},
213             data=data,
214         )
215 
216     elif estimator._reporting_data is None:
217         warnings.warn(
218             "Report generation not enabled ! "
219             "No visual outputs will be created."
220         )
221         return _update_template(
222             title="Empty Report",
223             docstring=(
224                 "This report was not "
225                 "generated. Please check "
226                 "that reporting is enabled."
227             ),
228             content=_embed_img(None),
229             overlay=None,
230             parameters={},
231             data=data,
232         )
233 
234     return _create_report(estimator, data)
235 
236 
237 def _create_report(estimator, data):
238     html_template = _get_estimator_template(estimator)
239     overlay, image = _define_overlay(estimator)
240     embeded_images = (
241         [_embed_img(i) for i in image]
242         if isinstance(image, list)
243         else _embed_img(image)
244     )
245     parameters = _str_params(estimator.get_params())
246     docstring = estimator.__doc__
247     snippet = docstring.partition("Parameters\n    ----------\n")[0]
248     return _update_template(
249         title=estimator.__class__.__name__,
250         docstring=snippet,
251         content=embeded_images,
252         overlay=_embed_img(overlay),
253         parameters=parameters,
254         data=data,
255         template_name=html_template,
256     )
257 
258 
259 class HTMLReport(HTMLDocument):
260     """A report written as HTML.
261 
262     Methods such as ``save_as_html``, or ``open_in_browser``
263     are inherited from class ``nilearn.plotting.html_document.HTMLDocument``.
264 
265     """
266 
267     def __init__(self, head_tpl, body, head_values={}):
268         """Construct the ``HTMLReport`` class.
269 
270         Parameters
271         ----------
272         head_tpl : Template
273             This is meant for display as a full page, eg writing on disk.
274             This is the Template object used to generate the HTML head
275             section of the report. The template should be filled with:
276 
277                 - title: The title of the HTML page.
278                 - body: The full body of the HTML page. Provided through
279                   the ``body`` input.
280 
281         body : :obj:`str`
282             This parameter is used for embedding in the provided
283             ``head_tpl`` template. It contains the full body of the
284             HTML page.
285 
286         head_values : :obj:`dict`, default={}
287             Additional substitutions in ``head_tpl``.
288 
289             .. note::
290                 This can be used to provide additional values
291                 with custom templates.
292 
293         """
294         html = head_tpl.safe_substitute(body=body, **head_values)
295         super().__init__(html)
296         self.head_tpl = head_tpl
297         self.body = body
298 
299     def _repr_html_(self):
300         """Return body of the report.
301 
302         Method used by the Jupyter notebook.
303         Users normally won't call this method explicitly.
304         """
305         return self.body
306 
307     def __str__(self):
308         return self.body
309
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/nilearn/reporting/html_report.py b/nilearn/reporting/html_report.py
--- a/nilearn/reporting/html_report.py
+++ b/nilearn/reporting/html_report.py
@@ -13,7 +13,9 @@
 
 ESTIMATOR_TEMPLATES = {
     "NiftiLabelsMasker": "report_body_template_niftilabelsmasker.html",
+    "MultiNiftiLabelsMasker": "report_body_template_niftilabelsmasker.html",
     "NiftiMapsMasker": "report_body_template_niftimapsmasker.html",
+    "MultiNiftiMapsMasker": "report_body_template_niftimapsmasker.html",
     "NiftiSpheresMasker": "report_body_template_niftispheresmasker.html",
     "default": "report_body_template.html",
 }

{"golden_diff": "diff --git a/nilearn/reporting/html_report.py b/nilearn/reporting/html_report.py\n--- a/nilearn/reporting/html_report.py\n+++ b/nilearn/reporting/html_report.py\n@@ -13,7 +13,9 @@\n \n ESTIMATOR_TEMPLATES = {\n     \"NiftiLabelsMasker\": \"report_body_template_niftilabelsmasker.html\",\n+    \"MultiNiftiLabelsMasker\": \"report_body_template_niftilabelsmasker.html\",\n     \"NiftiMapsMasker\": \"report_body_template_niftimapsmasker.html\",\n+    \"MultiNiftiMapsMasker\": \"report_body_template_niftimapsmasker.html\",\n     \"NiftiSpheresMasker\": \"report_body_template_niftispheresmasker.html\",\n     \"default\": \"report_body_template.html\",\n }\n", "issue": "[BUG] MultiNiftiMapsMasker reports are empty\n### Is there an existing issue for this?\n\n- [X] I have searched the existing issues\n\n### Operating system\n\n- [X] Linux\n- [ ] Mac\n- [ ] Windows\n\n### Operating system version\n\nFor example one of the following:\r\n- Linux Ubuntu 22.04\r\n\r\n\n\n### Python version\n\n- [ ] 3.12\n- [X] 3.11\n- [ ] 3.10\n- [ ] 3.9\n- [ ] 3.8\n\n### nilearn version\n\ndev\n\n### Expected behavior\n\nto have non empty reports\n\n### Current behavior & error messages\n\nThis is what I got:\r\n\r\n![image](https://github.com/nilearn/nilearn/assets/6961185/3b0cc2fb-3ebf-4268-bc83-452d99573b76)\r\n\r\n![image](https://github.com/nilearn/nilearn/assets/6961185/391cde29-9fbc-43de-9f72-6dfc4f99052e)\r\n\r\n\n\n### Steps and code to reproduce bug\n\n```python\r\nfrom pathlib import Path\r\nfrom nilearn import datasets\r\nfrom nilearn.maskers import (\r\n    MultiNiftiMapsMasker\r\n)\r\n\r\nREPORTS_DIR = Path().cwd()\r\n\r\ndifumo = datasets.fetch_atlas_difumo(\r\n    dimension=64, resolution_mm=2, legacy_format=False\r\n)\r\n\r\ndata = datasets.fetch_development_fmri(n_subjects=2)\r\n\r\nmasker = MultiNiftiMapsMasker(\r\n    maps_img=difumo.maps,\r\n    standardize=\"zscore_sample\",\r\n    standardize_confounds=\"zscore_sample\",\r\n    memory=\"nilearn_cache\",\r\n    n_jobs=2,\r\n)\r\n\r\nmasker.fit()\r\nreport = masker.generate_report()\r\nreport.save_as_html(REPORTS_DIR / \"multi_nifti_maps_masker_atlas.html\")\r\n\r\n_ = masker.fit_transform(data.func, confounds=data.confounds)\r\nreport = masker.generate_report()\r\nreport.save_as_html(REPORTS_DIR / \"multi_nifti_maps_masker_fitted.html\")\r\n```\r\n\n", "before_files": [{"content": "\"\"\"Generate HTML reports.\"\"\"\n\nimport copy\nimport os\nimport warnings\nfrom pathlib import Path\nfrom string import Template\n\nfrom nilearn.externals import tempita\nfrom nilearn.maskers import NiftiSpheresMasker\nfrom nilearn.plotting.html_document import HTMLDocument\nfrom nilearn.reporting.utils import figure_to_svg_base64\n\nESTIMATOR_TEMPLATES = {\n    \"NiftiLabelsMasker\": \"report_body_template_niftilabelsmasker.html\",\n    \"NiftiMapsMasker\": \"report_body_template_niftimapsmasker.html\",\n    \"NiftiSpheresMasker\": \"report_body_template_niftispheresmasker.html\",\n    \"default\": \"report_body_template.html\",\n}\n\n\ndef _get_estimator_template(estimator):\n    \"\"\"Return the HTML template to use for a given estimator \\\n    if a specific template was defined in ESTIMATOR_TEMPLATES, \\\n    otherwise return the default template.\n\n    Parameters\n    ----------\n    estimator : object instance of BaseEstimator\n        The object we wish to retrieve template of.\n\n    Returns\n    -------\n    template : str\n        Name of the template file to use.\n\n    \"\"\"\n    if estimator.__class__.__name__ in ESTIMATOR_TEMPLATES:\n        return ESTIMATOR_TEMPLATES[estimator.__class__.__name__]\n    else:\n        return ESTIMATOR_TEMPLATES[\"default\"]\n\n\ndef _embed_img(display):\n    \"\"\"Embed an image or just return its instance if already embedded.\n\n    Parameters\n    ----------\n    display : obj\n        A Nilearn plotting object to display.\n\n    Returns\n    -------\n    embed : str\n        Binary image string.\n\n    \"\"\"\n    if display is None:  # no image to display\n        return None\n    # If already embedded, simply return as is\n    if isinstance(display, str):\n        return display\n    return figure_to_svg_base64(display.frame_axes.figure)\n\n\ndef _str_params(params):\n    \"\"\"Convert NoneType values to the string 'None' for display.\n\n    Parameters\n    ----------\n    params : dict\n        A dictionary of input values to a function.\n\n    \"\"\"\n    params_str = copy.deepcopy(params)\n    for k, v in params_str.items():\n        if v is None:\n            params_str[k] = \"None\"\n    return params_str\n\n\ndef _update_template(\n    title, docstring, content, overlay, parameters, data, template_name=None\n):\n    \"\"\"Populate a report with content.\n\n    Parameters\n    ----------\n    title : str\n        The title for the report.\n\n    docstring : str\n        The introductory docstring for the reported object.\n\n    content : img\n        The content to display.\n\n    overlay : img\n        Overlaid content, to appear on hover.\n\n    parameters : dict\n        A dictionary of object parameters and their values.\n\n    data : dict\n        A dictionary holding the data to be added to the report.\n        The keys must match exactly the ones used in the template.\n        The default template accepts the following:\n            - description (str) : Description of the content.\n            - warning_message (str) : An optional warning\n              message to be displayed in red. This is used\n              for example when no image was provided to the\n              estimator when fitting.\n        The NiftiLabelsMasker template accepts the additional\n        fields:\n            - summary (dict) : A summary description of the\n              region labels and sizes. This will be displayed\n              as an expandable table in the report.\n\n    template_name : str, optional\n        The name of the template to use. If not provided, the\n        default template `report_body_template.html` will be\n        used.\n\n    Returns\n    -------\n    report : HTMLReport\n        An instance of a populated HTML report.\n\n    \"\"\"\n    resource_path = Path(__file__).resolve().parent.joinpath(\"data\", \"html\")\n\n    if template_name is None:\n        body_template_name = \"report_body_template.html\"\n    else:\n        body_template_name = template_name\n    body_template_path = resource_path.joinpath(body_template_name)\n    if not os.path.exists(str(body_template_path)):\n        raise FileNotFoundError(f\"No template {body_template_name}\")\n    tpl = tempita.HTMLTemplate.from_filename(\n        str(body_template_path), encoding=\"utf-8\"\n    )\n    body = tpl.substitute(\n        title=title,\n        content=content,\n        overlay=overlay,\n        docstring=docstring,\n        parameters=parameters,\n        **data,\n    )\n\n    head_template_name = \"report_head_template.html\"\n    head_template_path = resource_path.joinpath(head_template_name)\n    with open(str(head_template_path)) as head_file:\n        head_tpl = Template(head_file.read())\n\n    return HTMLReport(body=body, head_tpl=head_tpl)\n\n\ndef _define_overlay(estimator):\n    \"\"\"Determine whether an overlay was provided and \\\n    update the report text as appropriate.\"\"\"\n    displays = estimator._reporting()\n\n    if len(displays) == 1:  # set overlay to None\n        overlay, image = None, displays[0]\n\n    elif isinstance(estimator, NiftiSpheresMasker):\n        overlay, image = None, displays\n\n    elif len(displays) == 2:\n        overlay, image = displays[0], displays[1]\n\n    else:\n        overlay, image = None, displays\n\n    return overlay, image\n\n\ndef generate_report(estimator):\n    \"\"\"Generate a report for Nilearn objects.\n\n    Reports are useful to visualize steps in a processing pipeline.\n    Example use case: visualize the overlap of a mask and reference image\n    in NiftiMasker.\n\n    Parameters\n    ----------\n    estimator : Object instance of BaseEstimator.\n        Object for which the report should be generated.\n\n    Returns\n    -------\n    report : HTMLReport\n\n    \"\"\"\n    if hasattr(estimator, \"_report_content\"):\n        data = estimator._report_content\n    else:\n        data = {}\n    if not hasattr(estimator, \"_reporting_data\"):\n        warnings.warn(\n            \"This object has not been fitted yet ! \"\n            \"Make sure to run `fit` before inspecting reports.\"\n        )\n        return _update_template(\n            title=\"Empty Report\",\n            docstring=(\n                \"This report was not generated. Please `fit` the object.\"\n            ),\n            content=_embed_img(None),\n            overlay=None,\n            parameters={},\n            data=data,\n        )\n\n    elif estimator._reporting_data is None:\n        warnings.warn(\n            \"Report generation not enabled ! \"\n            \"No visual outputs will be created.\"\n        )\n        return _update_template(\n            title=\"Empty Report\",\n            docstring=(\n                \"This report was not \"\n                \"generated. Please check \"\n                \"that reporting is enabled.\"\n            ),\n            content=_embed_img(None),\n            overlay=None,\n            parameters={},\n            data=data,\n        )\n\n    return _create_report(estimator, data)\n\n\ndef _create_report(estimator, data):\n    html_template = _get_estimator_template(estimator)\n    overlay, image = _define_overlay(estimator)\n    embeded_images = (\n        [_embed_img(i) for i in image]\n        if isinstance(image, list)\n        else _embed_img(image)\n    )\n    parameters = _str_params(estimator.get_params())\n    docstring = estimator.__doc__\n    snippet = docstring.partition(\"Parameters\\n    ----------\\n\")[0]\n    return _update_template(\n        title=estimator.__class__.__name__,\n        docstring=snippet,\n        content=embeded_images,\n        overlay=_embed_img(overlay),\n        parameters=parameters,\n        data=data,\n        template_name=html_template,\n    )\n\n\nclass HTMLReport(HTMLDocument):\n    \"\"\"A report written as HTML.\n\n    Methods such as ``save_as_html``, or ``open_in_browser``\n    are inherited from class ``nilearn.plotting.html_document.HTMLDocument``.\n\n    \"\"\"\n\n    def __init__(self, head_tpl, body, head_values={}):\n        \"\"\"Construct the ``HTMLReport`` class.\n\n        Parameters\n        ----------\n        head_tpl : Template\n            This is meant for display as a full page, eg writing on disk.\n            This is the Template object used to generate the HTML head\n            section of the report. The template should be filled with:\n\n                - title: The title of the HTML page.\n                - body: The full body of the HTML page. Provided through\n                  the ``body`` input.\n\n        body : :obj:`str`\n            This parameter is used for embedding in the provided\n            ``head_tpl`` template. It contains the full body of the\n            HTML page.\n\n        head_values : :obj:`dict`, default={}\n            Additional substitutions in ``head_tpl``.\n\n            .. note::\n                This can be used to provide additional values\n                with custom templates.\n\n        \"\"\"\n        html = head_tpl.safe_substitute(body=body, **head_values)\n        super().__init__(html)\n        self.head_tpl = head_tpl\n        self.body = body\n\n    def _repr_html_(self):\n        \"\"\"Return body of the report.\n\n        Method used by the Jupyter notebook.\n        Users normally won't call this method explicitly.\n        \"\"\"\n        return self.body\n\n    def __str__(self):\n        return self.body\n", "path": "nilearn/reporting/html_report.py"}], "after_files": [{"content": "\"\"\"Generate HTML reports.\"\"\"\n\nimport copy\nimport os\nimport warnings\nfrom pathlib import Path\nfrom string import Template\n\nfrom nilearn.externals import tempita\nfrom nilearn.maskers import NiftiSpheresMasker\nfrom nilearn.plotting.html_document import HTMLDocument\nfrom nilearn.reporting.utils import figure_to_svg_base64\n\nESTIMATOR_TEMPLATES = {\n    \"NiftiLabelsMasker\": \"report_body_template_niftilabelsmasker.html\",\n    \"MultiNiftiLabelsMasker\": \"report_body_template_niftilabelsmasker.html\",\n    \"NiftiMapsMasker\": \"report_body_template_niftimapsmasker.html\",\n    \"MultiNiftiMapsMasker\": \"report_body_template_niftimapsmasker.html\",\n    \"NiftiSpheresMasker\": \"report_body_template_niftispheresmasker.html\",\n    \"default\": \"report_body_template.html\",\n}\n\n\ndef _get_estimator_template(estimator):\n    \"\"\"Return the HTML template to use for a given estimator \\\n    if a specific template was defined in ESTIMATOR_TEMPLATES, \\\n    otherwise return the default template.\n\n    Parameters\n    ----------\n    estimator : object instance of BaseEstimator\n        The object we wish to retrieve template of.\n\n    Returns\n    -------\n    template : str\n        Name of the template file to use.\n\n    \"\"\"\n    if estimator.__class__.__name__ in ESTIMATOR_TEMPLATES:\n        return ESTIMATOR_TEMPLATES[estimator.__class__.__name__]\n    else:\n        return ESTIMATOR_TEMPLATES[\"default\"]\n\n\ndef _embed_img(display):\n    \"\"\"Embed an image or just return its instance if already embedded.\n\n    Parameters\n    ----------\n    display : obj\n        A Nilearn plotting object to display.\n\n    Returns\n    -------\n    embed : str\n        Binary image string.\n\n    \"\"\"\n    if display is None:  # no image to display\n        return None\n    # If already embedded, simply return as is\n    if isinstance(display, str):\n        return display\n    return figure_to_svg_base64(display.frame_axes.figure)\n\n\ndef _str_params(params):\n    \"\"\"Convert NoneType values to the string 'None' for display.\n\n    Parameters\n    ----------\n    params : dict\n        A dictionary of input values to a function.\n\n    \"\"\"\n    params_str = copy.deepcopy(params)\n    for k, v in params_str.items():\n        if v is None:\n            params_str[k] = \"None\"\n    return params_str\n\n\ndef _update_template(\n    title, docstring, content, overlay, parameters, data, template_name=None\n):\n    \"\"\"Populate a report with content.\n\n    Parameters\n    ----------\n    title : str\n        The title for the report.\n\n    docstring : str\n        The introductory docstring for the reported object.\n\n    content : img\n        The content to display.\n\n    overlay : img\n        Overlaid content, to appear on hover.\n\n    parameters : dict\n        A dictionary of object parameters and their values.\n\n    data : dict\n        A dictionary holding the data to be added to the report.\n        The keys must match exactly the ones used in the template.\n        The default template accepts the following:\n            - description (str) : Description of the content.\n            - warning_message (str) : An optional warning\n              message to be displayed in red. This is used\n              for example when no image was provided to the\n              estimator when fitting.\n        The NiftiLabelsMasker template accepts the additional\n        fields:\n            - summary (dict) : A summary description of the\n              region labels and sizes. This will be displayed\n              as an expandable table in the report.\n\n    template_name : str, optional\n        The name of the template to use. If not provided, the\n        default template `report_body_template.html` will be\n        used.\n\n    Returns\n    -------\n    report : HTMLReport\n        An instance of a populated HTML report.\n\n    \"\"\"\n    resource_path = Path(__file__).resolve().parent.joinpath(\"data\", \"html\")\n\n    if template_name is None:\n        body_template_name = \"report_body_template.html\"\n    else:\n        body_template_name = template_name\n    body_template_path = resource_path.joinpath(body_template_name)\n    if not os.path.exists(str(body_template_path)):\n        raise FileNotFoundError(f\"No template {body_template_name}\")\n    tpl = tempita.HTMLTemplate.from_filename(\n        str(body_template_path), encoding=\"utf-8\"\n    )\n    body = tpl.substitute(\n        title=title,\n        content=content,\n        overlay=overlay,\n        docstring=docstring,\n        parameters=parameters,\n        **data,\n    )\n\n    head_template_name = \"report_head_template.html\"\n    head_template_path = resource_path.joinpath(head_template_name)\n    with open(str(head_template_path)) as head_file:\n        head_tpl = Template(head_file.read())\n\n    return HTMLReport(body=body, head_tpl=head_tpl)\n\n\ndef _define_overlay(estimator):\n    \"\"\"Determine whether an overlay was provided and \\\n    update the report text as appropriate.\"\"\"\n    displays = estimator._reporting()\n\n    if len(displays) == 1:  # set overlay to None\n        overlay, image = None, displays[0]\n\n    elif isinstance(estimator, NiftiSpheresMasker):\n        overlay, image = None, displays\n\n    elif len(displays) == 2:\n        overlay, image = displays[0], displays[1]\n\n    else:\n        overlay, image = None, displays\n\n    return overlay, image\n\n\ndef generate_report(estimator):\n    \"\"\"Generate a report for Nilearn objects.\n\n    Reports are useful to visualize steps in a processing pipeline.\n    Example use case: visualize the overlap of a mask and reference image\n    in NiftiMasker.\n\n    Parameters\n    ----------\n    estimator : Object instance of BaseEstimator.\n        Object for which the report should be generated.\n\n    Returns\n    -------\n    report : HTMLReport\n\n    \"\"\"\n    if hasattr(estimator, \"_report_content\"):\n        data = estimator._report_content\n    else:\n        data = {}\n    if not hasattr(estimator, \"_reporting_data\"):\n        warnings.warn(\n            \"This object has not been fitted yet ! \"\n            \"Make sure to run `fit` before inspecting reports.\"\n        )\n        return _update_template(\n            title=\"Empty Report\",\n            docstring=(\n                \"This report was not generated. Please `fit` the object.\"\n            ),\n            content=_embed_img(None),\n            overlay=None,\n            parameters={},\n            data=data,\n        )\n\n    elif estimator._reporting_data is None:\n        warnings.warn(\n            \"Report generation not enabled ! \"\n            \"No visual outputs will be created.\"\n        )\n        return _update_template(\n            title=\"Empty Report\",\n            docstring=(\n                \"This report was not \"\n                \"generated. Please check \"\n                \"that reporting is enabled.\"\n            ),\n            content=_embed_img(None),\n            overlay=None,\n            parameters={},\n            data=data,\n        )\n\n    return _create_report(estimator, data)\n\n\ndef _create_report(estimator, data):\n    html_template = _get_estimator_template(estimator)\n    overlay, image = _define_overlay(estimator)\n    embeded_images = (\n        [_embed_img(i) for i in image]\n        if isinstance(image, list)\n        else _embed_img(image)\n    )\n    parameters = _str_params(estimator.get_params())\n    docstring = estimator.__doc__\n    snippet = docstring.partition(\"Parameters\\n    ----------\\n\")[0]\n    return _update_template(\n        title=estimator.__class__.__name__,\n        docstring=snippet,\n        content=embeded_images,\n        overlay=_embed_img(overlay),\n        parameters=parameters,\n        data=data,\n        template_name=html_template,\n    )\n\n\nclass HTMLReport(HTMLDocument):\n    \"\"\"A report written as HTML.\n\n    Methods such as ``save_as_html``, or ``open_in_browser``\n    are inherited from class ``nilearn.plotting.html_document.HTMLDocument``.\n\n    \"\"\"\n\n    def __init__(self, head_tpl, body, head_values={}):\n        \"\"\"Construct the ``HTMLReport`` class.\n\n        Parameters\n        ----------\n        head_tpl : Template\n            This is meant for display as a full page, eg writing on disk.\n            This is the Template object used to generate the HTML head\n            section of the report. The template should be filled with:\n\n                - title: The title of the HTML page.\n                - body: The full body of the HTML page. Provided through\n                  the ``body`` input.\n\n        body : :obj:`str`\n            This parameter is used for embedding in the provided\n            ``head_tpl`` template. It contains the full body of the\n            HTML page.\n\n        head_values : :obj:`dict`, default={}\n            Additional substitutions in ``head_tpl``.\n\n            .. note::\n                This can be used to provide additional values\n                with custom templates.\n\n        \"\"\"\n        html = head_tpl.safe_substitute(body=body, **head_values)\n        super().__init__(html)\n        self.head_tpl = head_tpl\n        self.body = body\n\n    def _repr_html_(self):\n        \"\"\"Return body of the report.\n\n        Method used by the Jupyter notebook.\n        Users normally won't call this method explicitly.\n        \"\"\"\n        return self.body\n\n    def __str__(self):\n        return self.body\n", "path": "nilearn/reporting/html_report.py"}]}