Skip to content
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

Control example order via explicit list, not via sorting titles #1321

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
},
"backreferences_dir": "generated",
"examples_dirs": "../examples",
"within_subsection_order": "ExampleTitleSortKey",
"within_subsection_order": "mne_bids.utils._example_sorter",
"gallery_dirs": "auto_examples",
"filename_pattern": "^((?!sgskip).)*$",
}
Expand Down
16 changes: 16 additions & 0 deletions doc/example_order.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
"read_bids_datasets.py",
"convert_mne_sample.py",
"mark_bad_channels.py",
"convert_eeg_to_bids.py",
"convert_group_studies.py",
"rename_brainvision_files.py",
"convert_mri_and_trans.py",
"convert_ieeg_to_bids.py",
"convert_nirs_to_bids.py",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the one that was previously a duplicate "13" and appearing last. I thought it made more sense to group it with other "converting XXX to BIDS" examples.

Aside: if anyone has strong feelings about order / wants to take this opportunity to shuffle the order a bit more, feel free to push a commit changing this file.

"convert_empty_room.py",
"bidspath.py",
"create_bids_folder.py",
"update_bids_datasets.py",
"anonymize_dataset.py"
]
6 changes: 3 additions & 3 deletions examples/anonymize_dataset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
==============================
13. Anonymizing a BIDS dataset
==============================
==========================
Anonymizing a BIDS dataset
==========================

Consider the following scenario:

Expand Down
6 changes: 3 additions & 3 deletions examples/bidspath.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
.. _bidspath-example:

===============================
10. An introduction to BIDSPath
===============================
===========================
An introduction to BIDSPath
===========================

BIDSPath is MNE-BIDS's working horse when it comes to file and folder
operations. Learn here how to use it.
Expand Down
6 changes: 3 additions & 3 deletions examples/convert_eeg_to_bids.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
===================================
04. Convert EEG data to BIDS format
===================================
===============================
Convert EEG data to BIDS format
===============================

In this example, we use MNE-BIDS to create a BIDS-compatible directory of EEG
data. Specifically, we will follow these steps:
Expand Down
6 changes: 3 additions & 3 deletions examples/convert_empty_room.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
.. _ex-convert-empty-room:

====================================
09. Manually storing empty room data
====================================
================================
Manually storing empty room data
================================

This example demonstrates how to store empty room data "manually" in the BIDS
format and how to retrieve them.
Expand Down
6 changes: 3 additions & 3 deletions examples/convert_group_studies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
=====================================
05. BIDS conversion for group studies
=====================================
=================================
BIDS conversion for group studies
=================================

Here, we show how to do BIDS conversion for group studies.
We will use the
Expand Down
6 changes: 3 additions & 3 deletions examples/convert_ieeg_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

.. currentmodule:: mne_bids

====================================
08. Convert iEEG data to BIDS format
====================================
================================
Convert iEEG data to BIDS format
================================

In this example, we use MNE-BIDS to create a BIDS-compatible directory of iEEG
data. Specifically, we will follow these steps:
Expand Down
6 changes: 3 additions & 3 deletions examples/convert_mne_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

.. _ex-convert-mne-sample:

==========================================
02. Convert MNE sample data to BIDS format
==========================================
======================================
Convert MNE sample data to BIDS format
======================================

In this example we will use MNE-BIDS to organize the MNE sample data according
to the BIDS standard.
Expand Down
6 changes: 3 additions & 3 deletions examples/convert_mri_and_trans.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
==============================================================================
07. Save and load T1-weighted MRI scan along with anatomical landmarks in BIDS
==============================================================================
==========================================================================
Save and load T1-weighted MRI scan along with anatomical landmarks in BIDS
==========================================================================

When working with MEEG data in the domain of source localization, we usually
have to deal with aligning several coordinate systems, such as the coordinate
Expand Down
6 changes: 3 additions & 3 deletions examples/convert_nirs_to_bids.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
====================================
13. Convert NIRS data to BIDS format
====================================
================================
Convert NIRS data to BIDS format
================================

In this example, we use MNE-BIDS to create a BIDS-compatible directory of NIRS
data. Specifically, we will follow these steps:
Expand Down
6 changes: 3 additions & 3 deletions examples/create_bids_folder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
=======================================================
11. Creating BIDS-compatible folder names and filenames
=======================================================
===================================================
Creating BIDS-compatible folder names and filenames
===================================================

The Brain Imaging Data Structure (BIDS) has standard conventions for file
names and folder hierarchy. MNE-BIDS comes with convenience functions if you
Expand Down
6 changes: 3 additions & 3 deletions examples/mark_bad_channels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
=========================================================
03. Interactive data inspection and bad channel selection
=========================================================
=====================================================
Interactive data inspection and bad channel selection
=====================================================

You can use MNE-BIDS interactively inspect your MEG or (i)EEG data.
Problematic channels can be marked as "bad", for example if the connected
Expand Down
6 changes: 3 additions & 3 deletions examples/read_bids_datasets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
.. _read_bids_datasets-example:

======================
01. Read BIDS datasets
======================
==================
Read BIDS datasets
==================

When working with electrophysiological data in the BIDS format, an important
resource is the `OpenNeuro <https://openneuro.org/>`_ database. OpenNeuro
Expand Down
6 changes: 3 additions & 3 deletions examples/rename_brainvision_files.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
=====================================
06. Rename BrainVision EEG data files
=====================================
=================================
Rename BrainVision EEG data files
=================================

According to the EEG extension to BIDS [1]_, the `BrainVision data format`_ is
one of the recommended formats to store EEG data within a BIDS dataset.
Expand Down
6 changes: 3 additions & 3 deletions examples/update_bids_datasets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
==========================
12. Updating BIDS datasets
==========================
======================
Updating BIDS datasets
======================

When working with electrophysiological data in the BIDS format, we usually
do not have all the metadata stored in the ``Raw`` mne-python object.
Expand Down
17 changes: 17 additions & 0 deletions mne_bids/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
from datetime import date, datetime, timedelta, timezone
from os import path as op
from pathlib import Path

import numpy as np
from mne import pick_types
Expand Down Expand Up @@ -519,6 +520,22 @@
return nibabel


# better example sorting, without relying on numbers in example titles
def _example_sorter(filename):
"""Sort MNE-BIDS example filenames in a custom order.

Examples not explicitly listed in `EXAMPLE_ORDER` will be sorted at the end. This
function is defined here (instead of in `conf.py`) because it must be *importable*
in order for the sphinx gallery config dict in `conf.py` to remain serializable.
"""
with open(Path(__file__).parents[1] / "doc" / "example_order.json") as fid:
EXAMPLE_ORDER = json.load(fid)

Check warning on line 532 in mne_bids/utils.py

View check run for this annotation

Codecov / codecov/patch

mne_bids/utils.py#L531-L532

Added lines #L531 - L532 were not covered by tests

if filename not in EXAMPLE_ORDER:
EXAMPLE_ORDER.append(filename)
return EXAMPLE_ORDER.index(filename)

Check warning on line 536 in mne_bids/utils.py

View check run for this annotation

Codecov / codecov/patch

mne_bids/utils.py#L534-L536

Added lines #L534 - L536 were not covered by tests


def warn(
message,
category=RuntimeWarning,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ doc = [
"seaborn",
"sphinx-copybutton",
"sphinx>=7.4.7",
"sphinx_gallery",
"sphinx_gallery @ https://github.com/sphinx-gallery/sphinx-gallery/archive/refs/heads/master.zip",
]
# Dependencies for using all mne_bids features
full = [
Expand Down