mne-tools / mne-bids

MNE-BIDS is a Python package that allows you to read and write BIDS-compatible datasets with the help of MNE-Python.
https://mne.tools/mne-bids/
BSD 3-Clause "New" or "Revised" License
131 stars 85 forks source link

minor enh: allow print_dir_tree to return a str #590

Closed sappelhoff closed 3 years ago

sappelhoff commented 3 years ago

if print_dir_tree could return a string, then we could "plot" that string, which could then be used as a thumbnail for the examples gallery.

I think that'd be easy to do, would make the gallery more beautiful, and perhaps even come in handy when one wants to print the dir tree to a file.

Example:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()

# imagine this:
# s = print_dir_tree(".", max_depth=4, return_str=True)

s="""
|eegmmidb_bids_group_conversion/
|--- README
|--- dataset_description.json
|--- participants.json
|--- participants.tsv
|--- sub-001/
|------ ses-01/
|--------- sub-001_ses-01_scans.tsv
|--------- eeg/
|------------ sub-001_ses-01_task-MotorImagery_run-01_channels.tsv
|------------ sub-001_ses-01_task-MotorImagery_run-01_eeg.eeg
|------------ sub-001_ses-01_task-MotorImagery_run-01_eeg.json
|------------ sub-001_ses-01_task-MotorImagery_run-01_eeg.vhdr
|------------ sub-001_ses-01_task-MotorImagery_run-01_eeg.vmrk
|------------ sub-001_ses-01_task-MotorImagery_run-01_events.tsv
|------------ sub-001_ses-01_task-MotorImagery_run-02_channels.tsv
|------------ sub-001_ses-01_task-MotorImagery_run-02_eeg.eeg
|------------ sub-001_ses-01_task-MotorImagery_run-02_eeg.json
"""

ax.text(x=0, y=1, s=s)
ax.axis("off")
fig

image

hoechenberger commented 3 years ago

Generally I think we should have some figure / nice icon for each item in our gallery.

But how would we generate a plot like you propose without adding additional code to the examples?

sappelhoff commented 3 years ago

But how would we generate a plot like you propose without adding additional code to the examples?

without additional code, we'd have to generate images "behind the scenes" during the doc build process, and then link them in the sphinx-gallery config ... or add lots of assets (which I wouldn't like)

however, I think that my proposal with it's 4 added lines would work quite well already. WDYT?

hoechenberger commented 3 years ago

I like it, it’s just that I’m a bit concerned it might confuse users to see this code. Maybe we can somehow mark it clearly as “housekeeping, nothing to see here, move along”?

-- Sent from my phone, please excuse brevity and erroneous auto-correct.

On 21. Oct 2020, at 14:21, Stefan Appelhoff notifications@github.com wrote:

 But how would we generate a plot like you propose without adding additional code to the examples?

without additional code, we'd have to generate images "behind the scenes" during the doc build process, and then link them in the sphinx-gallery config ... or add lots of assets (which I wouldn't like)

however, I think that my proposal with it's 4 added lines would work quite well already. WDYT?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

hoechenberger commented 3 years ago

@sappelhoff It seems we might not need this after all. I believe this will do what we want: https://sphinx-gallery.github.io/stable/configuration.html#providing-a-figure-for-the-thumbnail-image

sappelhoff commented 3 years ago

Yes, this is also what I had in mind with this part of what I said:

without additional code, we'd have to generate images "behind the scenes" during the doc build process, and then link them in the sphinx-gallery config ... or add lots of assets (which I wouldn't like)

I'd be fine with generating a few plots during the build process, and linking them as thumbnails. Including them as static files (assets) would be too much baggage IMHO.

Still, for producing some of these thumbnails, I think a thumbnail like this one would be nice:

image

it just looks BIDSy