File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ """Helper class for holding physiological data and associated metadata information."""
5+
6+ import logging
7+ from functools import wraps
8+
9+ from loguru import logger
10+
11+ LGR = logging .getLogger (__name__ )
12+ LGR .setLevel (logging .DEBUG )
13+
14+
15+ def task (func ):
16+ """
17+ Fake task decorator to import when pydra is not installed/used.
18+
19+ Parameters
20+ ----------
21+ func: function
22+ Function to run the wrapper around
23+
24+ Returns
25+ -------
26+ function
27+ """
28+
29+ @wraps (func )
30+ def wrapper (* args , ** kwargs ):
31+ return func (* args , ** kwargs )
32+ LGR .debug (
33+ "Pydra is not installed, thus generate_physio is not available as a pydra task. Using the function directly"
34+ )
35+
36+ return wrapper
37+
38+
39+ def is_bids_directory (path_to_dir ):
40+ """
41+ Check if a directory is a BIDS compliant directory.
42+
43+ Parameters
44+ ----------
45+ path_to_dir : os.path or str
46+ Path to (supposed) BIDS directory
47+
48+ Returns
49+ -------
50+ bool
51+ True if the given path is a BIDS directory, False is not.
52+ """
53+ try :
54+ from bids import BIDSLayout
55+ except ImportError :
56+ raise ImportError (
57+ "To use BIDS-based feature, pybids must be installed. Install manually or with `pip install physutils[bids]`"
58+ )
59+ try :
60+ # Attempt to create a BIDSLayout object
61+ _ = BIDSLayout (path_to_dir )
62+ return True
63+ except Exception as e :
64+ # Catch other exceptions that might indicate the directory isn't BIDS compliant
65+ logger .error (
66+ f"An error occurred while trying to load { path_to_dir } as a BIDS Layout object: { e } "
67+ )
68+ return False
You can’t perform that action at this time.
0 commit comments