Skip to content

Commit 7848179

Browse files
committed
[ENH] Add function documentation
1 parent eb9b2a7 commit 7848179

File tree

3 files changed

+354
-0
lines changed

3 files changed

+354
-0
lines changed

docs/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Support functions
5050
:toctree: generated/
5151

5252
get_data_dir
53+
get_atlas_dir
54+
get_annotation_dir
5355

5456
.. _ref_images:
5557

neuromaps_mouse/datasets/annotations.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,155 @@
1212

1313

1414
def get_annotation_dir(data_dir=None):
15+
"""Get the annotations data directory path.
16+
17+
Retrieves the path to the directory where annotation files are stored.
18+
If no data directory is specified, uses the default neuromaps-mouse data directory.
19+
20+
Parameters
21+
----------
22+
data_dir : str or Path, optional
23+
Path to the base neuromaps-mouse data directory. If None, uses the default
24+
directory determined by `get_data_dir()`. Default is None.
25+
26+
Returns
27+
-------
28+
pathlib.Path
29+
Path to the annotations subdirectory.
30+
31+
See Also
32+
--------
33+
neuromaps_mouse.datasets.get_data_dir : Get the base neuromaps-mouse data directory.
34+
35+
Examples
36+
--------
37+
>>> annot_dir = get_annotation_dir()
38+
>>> print(annot_dir)
39+
/home/user/neuromaps-mouse-data/annotations
40+
41+
>>> custom_annot_dir = get_annotation_dir(data_dir='/custom/data')
42+
>>> print(custom_annot_dir)
43+
/custom/data/annotations
44+
"""
1545
data_dir = get_data_dir(data_dir=data_dir)
1646
return data_dir / "annotations"
1747

1848

1949
def available_annotations(
2050
source=None, desc=None, space=None, res=None, tag=None, format=None
2151
):
52+
"""List available annotations with optional filtering.
53+
54+
Returns a list of available annotation datasets that can be fetched,
55+
optionally filtered by various metadata attributes.
56+
57+
See :doc: `/listofmaps` for details on available annotations.
58+
59+
Parameters
60+
----------
61+
source : str, optional
62+
Filter by data source. If 'all', returns all
63+
available annotations without filtering. Default is None.
64+
desc : str, optional
65+
Filter by description. Default is None.
66+
space : str, optional
67+
Filter by anatomical space. Default is None.
68+
res : int or float, optional
69+
Filter by resolution. Default is None.
70+
tag : str, optional
71+
Filter by annotation tag or keyword. Default is None.
72+
format : str, optional
73+
Filter by file format. Default is None.
74+
75+
Returns
76+
-------
77+
list of tuple
78+
List of tuples representing available annotations. Each tuple contains
79+
annotation metadata (source, desc, space, res).
80+
If source='all', returns all available annotations.
81+
82+
See Also
83+
--------
84+
neuromaps_mouse.datasets.fetch_annotation : Download and load annotation files.
85+
86+
Examples
87+
--------
88+
>>> # Get all available annotations
89+
>>> all_annots = available_annotations(source='all')
90+
>>> print(f"Found {len(all_annots)} annotations")
91+
92+
>>> # Filter by specific source
93+
>>> lein2006amba = available_annotations(source='lein2006amba')
94+
95+
>>> # Filter by multiple criteria
96+
>>> annots = available_annotations(source='lein2006amba', desc='sagittalenergy')
97+
"""
2298
if source == "all":
2399
return _annot_full_to_tuple(MOUSEMAPS_ANNOTS)
24100
else:
25101
return _annot_full_to_tuple(_filter_annots_by_keys(locals()))
26102

27103

28104
def fetch_annotation(annotations, data_dir=None, return_single=False, verbose=1):
105+
"""Download and cache annotation files.
106+
107+
Fetches annotation data files from the neuromaps-mouse repository and caches them
108+
locally. Also downloads related metadata files such as region mappings.
109+
110+
Parameters
111+
----------
112+
annotations : str, tuple, or list of str/tuple
113+
Annotation(s) to fetch. Can be specified as:
114+
- A single annotation tuple from `available_annotations()`
115+
- A list of annotation tuples
116+
- A string identifier for a specific annotation
117+
- A list of string identifiers
118+
data_dir : str or Path, optional
119+
Path to the base neuromaps-mouse data directory where files will be cached.
120+
If None, uses the default directory. Default is None.
121+
return_single : bool, optional
122+
If True and only one annotation is requested, returns a tuple of
123+
(annotation_id, file_path). If False, always returns lists.
124+
Default is False.
125+
verbose : int, optional
126+
Verbosity level for download progress (0=silent, 1=verbose).
127+
Default is 1.
128+
129+
Returns
130+
-------
131+
annotations : list of str or str
132+
Input annotation identifier(s). Returned as single string if
133+
return_single=True and one annotation was requested.
134+
file_paths : list of str or str
135+
Path(s) to the downloaded annotation file(s). Returned as single
136+
string if return_single=True and one annotation was requested.
137+
138+
Notes
139+
-----
140+
This function automatically downloads related metadata files (such as
141+
regionmapping files) for each annotation source. Files are cached locally
142+
to avoid re-downloading on subsequent calls.
143+
144+
See Also
145+
--------
146+
neuromaps_mouse.datasets.available_annotations : List available annotations.
147+
neuromaps_mouse.datasets.get_annotation_dir : Get the annotations directory path.
148+
149+
Examples
150+
--------
151+
>>> # Fetch a single annotation
152+
>>> annot_id, annot_path = fetch_annotation(
153+
... ('lein2006amba', 'sagittalenergy', 'allenccfv3', 'region'),
154+
... return_single=True
155+
... )
156+
>>> print(f"Downloaded to: {annot_path}")
157+
158+
>>> # Fetch multiple annotations
159+
>>> annot_ids, annot_paths = fetch_annotation([
160+
... ('lein2006amba', 'sagittalenergy', 'allenccfv3', 'region'),
161+
... ('yao2023abca', 'divimean', 'allenccfv3', 'region')
162+
... ])
163+
"""
29164
data_dir = get_data_dir(data_dir=data_dir)
30165

31166
if not isinstance(annotations, list):

0 commit comments

Comments
 (0)