-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with current reporting #341
Comments
So keeping i. and ii. would mean that there would still be some remnants of current reporting, but the plots would be embedded in HTML reports as they are in the nilearn reporting module. |
@man-shu thx for the detailed analysis ! |
Thanks, @bthirion ! Yes, I am on it! |
Hi @man-shu from io import StringIO
from string import Template
import matplotlib.pyplot as plt
# Vectorized fig
figV, axesV = plt.subplots(nrows=10, ncols=5)
# Rasterized fig
figR, axesR = plt.subplots(nrows=10, ncols=5)
# Plot garbage data
for ax in figV.axes:
ax.scatter(range(3000), range(3000))
for ax in figR.axes:
ax.set_rasterized(True)
ax.scatter(range(3000), range(3000))
# Encode figures
with StringIO() as bufferV:
figV.savefig(bufferV, format='svg', dpi=150)
figV_encoded = bufferV.getvalue()
with StringIO() as bufferR:
figR.savefig(bufferR, format='svg', dpi=150)
figR_encoded = bufferR.getvalue()
# Define a super basic HTML template
html_template = Template("<html>\n<body>\n$figure\n</body>\n</html>")
# Save to html files
for name,figenc in zip(["heavy", "light"],
[figV_encoded, figR_encoded]):
with open(f"{name}_report.html", 'w') as fp:
fp.write(html_template.substitute(figure=figenc)) |
If svgs are too heavy, you may want to reduce the dpi. |
Thanks, @NicolasGensollen @bthirion. Yes, this is exactly the problem. I will try this and let you know. |
Problem:
By running the
easy_start
examples, I found that the major issue with pyprocess's current reporting is that the reports show plots by embedding locally saved images into an HTML template. Most of the browsers these days have a security feature which prevents loading locally saved images through HTML. As a result, even though pypreprocess creates and saves the plots on the disk properly, they do not appear in the HTML reports at all.The HTML reports actually mention this issue - "RENDERING OF QA THUMBNAILS IS ENSURED BY LOCAL JQUERY SCRIPTS. THIS MAY NOT BE POSSIBLE ON CHROME DUE TO FILE-ACCESS RESTRICTIONS!"
Solutions:
In Google Chrome browser, this security feature can be disabled by running a terminal command
google-chrome --allow-file-access-from-files
on Linux. A browser window would open now and loading the HTML report in this window would render all the thumbnails and plots properly.Reporting in nilearn provides another (more efficient) solution. It bypasses this security feature by creating SVG URLs from matplotlib figure objects and then embeds those SVG URLs into the HTML reports. This means that the plots are not saved as raster images on the disk at all and the browsers simply render them as vector graphics whenever HTML reports are opened up. This could be implemented for pypreprocess as well. But that could be a bit complicated because there are several functions and class methods in pypreprocess named
generate_x_thumbnails
(where x = various preprocessing steps such as realignment, segmentation etc.) which:If we were to implement nilearn-style reporting, iii. would be completely useless and could be removed. But i. and ii. would still be important and adapting these two to nilearn-style reporting would be a bit complex.
The text was updated successfully, but these errors were encountered: