|
12 | 12 |
|
13 | 13 |
|
14 | 14 | 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 | + """ |
15 | 45 | data_dir = get_data_dir(data_dir=data_dir) |
16 | 46 | return data_dir / "annotations" |
17 | 47 |
|
18 | 48 |
|
19 | 49 | def available_annotations( |
20 | 50 | source=None, desc=None, space=None, res=None, tag=None, format=None |
21 | 51 | ): |
| 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 | + """ |
22 | 98 | if source == "all": |
23 | 99 | return _annot_full_to_tuple(MOUSEMAPS_ANNOTS) |
24 | 100 | else: |
25 | 101 | return _annot_full_to_tuple(_filter_annots_by_keys(locals())) |
26 | 102 |
|
27 | 103 |
|
28 | 104 | 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 | + """ |
29 | 164 | data_dir = get_data_dir(data_dir=data_dir) |
30 | 165 |
|
31 | 166 | if not isinstance(annotations, list): |
|
0 commit comments