Darioli commited on
Commit
b7f5cb2
·
verified ·
1 Parent(s): 1a61129

Updated README.

Browse files
Files changed (1) hide show
  1. README.md +137 -112
README.md CHANGED
@@ -18,104 +18,120 @@ size_categories:
18
 
19
  # MICrONS Functional Activity Dataset & Reader
20
 
21
- This repository contains a curated portion of the MICrONS (Multi-Scale Networked Analysis of Cellular Responding Order) dataset. It consists of functional calcium imaging data from the visual cortex of mice in response to various visual stimuli (natural clips (Clip) and parametric videos (Monet2, Trippy)).
22
- Videos have been downsampled to match neural activity scan frequency with frame choice corresponding to the the frame appearing at least 66ms before scan time.
 
 
23
  The data is organized into a highly efficient, indexed HDF5 format, allowing for rapid cross-session analysis based on either stimulus identity or brain anatomy.
24
 
 
 
25
  ## 📊 Dataset Overview
26
 
27
- - Sessions: 14 sessions of registered neural activity.
28
- - Stimuli: Three categories of videos (Clip, Monet2, Trippy) identified by unique condition hashes.
29
- - Neural Data: Calcium traces (responses) from thousands of neurons across multiple visual areas (V1, AL, LM, RL).
30
- - Behavioral Data: Synchronized treadmill speed and pupil radius.
31
- - Eye Tracking: Pupil center coordinates (x, y) for gaze analysis.
 
 
 
 
32
 
 
 
 
33
  ```text
34
  root/
35
- ├── 📂 BRAIN_AREAS/ # Anatomical Index
36
  │ └── 📂 <area_name>/ # e.g., V1, AL, LM, RL
37
  │ └── 🔗 <session_id> -> /sessions/<session_id>
38
 
39
- ├── 📂 SESSIONS/ # Primary Data Storage
40
  │ └── 📂 <session_id>/ # e.g., 4_7, 5_6
41
- │ ├── 📂 META/ # Session-wide Metadata
42
- │ │ ├── 📂 AREA_INDICES/ # Pre-calculated neuron masks
43
- │ │ │ └── 📄 <area_name> [Dataset: (N_area_neurons,)]
44
- │ │ ├── 📄 brain_areas [Dataset: (N_total_neurons,)]
45
- │ │ ├── 📄 coordinates [Dataset: (N_total_neurons, 3)]
46
- │ │ ├── 📄 unit_ids [Dataset: (N_total_neurons,)]
47
- │ │ ├── 📄 condition_hashes [Dataset: (N_trials,)]
48
- │ │ └── (Attr) fps [Float: Sampling rate]
49
- │ └── 📂 TRIALS/ # Individual trial folders
50
- │ └── 📂 <trial_idx>/ # Chronological trial index
51
- │ ├── 📄 responses [Dataset: (N_neurons, F_trial)]
52
- │ ├── 📄 behavior [Dataset: (2, F_trial)]
53
- │ ├── 📄 pupil_center [Dataset: (2, F_trial)]
54
- ── (Attr) condition_hash [String: Reference to video]
 
55
 
56
- ├── 📂 TYPES/ # Stimulus Category Index
57
  │ └── 📂 <stim_type>/ # e.g., Clip, Monet2, Trippy
58
  │ └── 🔗 <encoded_hash> -> /videos/<encoded_hash>
59
 
60
- └── 📂 VIDEOS/ # Stimulus Library (Saved once)
61
- └── 📂 <encoded_hash>/ # Encoded version of condition_hash
62
- ├── 📄 clip [Dataset: (Frames, H, W)]
63
- ├── 📂 INSTANCES/ # Reverse-index to trials
 
64
  │ └── 🔗 <session_id>_tr<trial_idx> -> /sessions/<session_id>/trials/<trial_idx>
65
- ── (Attr) original_hash [String: The raw hash]
66
- ── (Attr) type [String: Stimulus type]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  ```
68
 
69
- ## ⚙️ Setup & Installation
70
-
71
- There are two ways of accessing the contents of this repo.
72
 
73
- ### 1. Clone the Repository
74
- Since the dataset is stored as a large HDF5 file (.h5), you must have Git LFS installed.
 
 
 
75
 
76
- ```bash
77
- # Install git-lfs if you haven't already
78
- git lfs install
79
-
80
- # Clone the repository
81
- git clone https://huggingface.co/datasets/NeuroBLab/MICrONS
82
- cd microns-functional
83
-
84
- # Install required packages
85
-
86
- pip install - r requirements.txt
87
- ```
88
- ### 2. Programmatic Access (Python)
89
 
90
- If you don't want to clone the full repository, you can download the reader and the data file directly into your Python script using the huggingface_hub library.
91
 
92
- **1. Install the library**
93
 
 
94
  ```bash
95
- pip install huggingface_hub h5py numpy
 
 
 
96
  ```
97
 
98
- **2. Download and Run**
99
-
100
  ```python
101
  import sys
102
  import importlib.util
103
  from huggingface_hub import hf_hub_download
104
 
105
- # 1. Define Repository Info
106
  REPO_ID = "NeuroBLab/MICrONS"
107
- DATA_FILENAME = "microns.h5"
108
- READER_FILENAME = "reader.py"
109
 
110
  print("Downloading files from Hugging Face...")
 
 
111
 
112
- # 2. Download the Reader script
113
- reader_path = hf_hub_download(repo_id=REPO_ID, filename=READER_FILENAME)
114
-
115
- # 3. Download the HDF5 Data file (this handles Git LFS automatically)
116
- data_path = hf_hub_download(repo_id=REPO_ID, filename=DATA_FILENAME)
117
-
118
- # 4. Dynamically import the MicronsReader class from the downloaded file
119
  spec = importlib.util.spec_from_file_location("reader", reader_path)
120
  reader_module = importlib.util.module_from_spec(spec)
121
  sys.modules["reader"] = reader_module
@@ -123,85 +139,94 @@ spec.loader.exec_module(reader_module)
123
 
124
  from reader import MicronsReader
125
 
126
- # 5. Use the reader
127
  with MicronsReader(data_path) as reader:
128
- print("File downloaded and reader initialized!")
129
- reader.print_structure(max_items=1)
130
  ```
131
 
132
- ## 🛠️ Reader API Demo
133
-
134
- The MicronsReader class is designed to handle the hierarchical structure of the HDF5 file transparently, including internal hash encoding and SoftLink navigation.
135
-
136
- ### 1. Initialize the Reader
137
 
138
- The best way to use the reader is via a context manager to ensure the HDF5 file handle is closed properly.
139
 
 
140
  ```python
141
  from reader import MicronsReader
142
 
143
- path = "microns.h5"
144
-
145
- with MicronsReader(path) as reader:
146
- # Your analysis code here
147
  pass
148
  ```
149
 
150
- ### 2. Overview of Dataset Structure
151
-
152
- To see the internal organization of the file without loading the actual data into RAM:
153
-
154
  ```python
155
- with MicronsReader(path) as reader:
156
- reader.print_structure(max_items=3)
 
157
  ```
158
 
159
- ### 3. Exploring Stimuli and Sessions
160
-
161
- You can query the database by session, stimulus type, or brain area.
162
-
163
  ```python
164
- with MicronsReader(path) as reader:
165
- # List available stimulus types
166
- types = reader.get_video_types() # ['Clip', 'Monet2', 'Trippy']
167
 
168
- # Get all unique hashes for a specific type
169
  monet_hashes = reader.get_hashes_by_type('Monet2')
170
 
171
- # Find which videos were shown in a specific session
172
- session_hashes = reader.get_hashes_by_session('4_7', return_unique=True)
 
173
 
174
- # Check which brain areas are recorded in a session
175
- areas = reader.get_available_brain_areas('4_7') # ['V1', 'AL', 'LM', 'RL']
 
176
  ```
177
 
178
- ### 4. Loading Full Data (Stimulus + Responses)
179
-
180
- The get_full_data_by_hash method is the most powerful tool in the library. It aggregates the video pixels and every recorded neural/behavioral repeat across all 14 sessions.
181
 
 
182
  ```python
183
  target_hash = "0JcYLY6eaQxNgD0AqyHf"
184
 
185
- with MicronsReader(path) as reader:
186
- # Load all data for this video, filtering for V1 neurons only
187
  data = reader.get_full_data_by_hash(target_hash, brain_area='V1')
188
 
189
- if data:
190
- print(f"Video Shape: {data['clip'].shape}") # (Frames, H, W)
191
-
192
- for trial in data['trials']:
193
- print(f"Session: {trial['session']}")
194
- print(f"Neural Responses: {trial['responses'].shape}") # (Neurons, Frames)
195
- print(f"Running Speed: {trial['behavior'][0, :]}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  ```
197
 
198
- ## 📂 Internal HDF5 Structure
 
 
 
 
 
 
199
 
200
- The database is structured to minimize redundancy by storing the video "Clip" once and linking it to multiple "Trials" across sessions.
201
- - `/videos/`: Contains the raw video arrays and links to their session instances.
202
- - `/sessions/`: The "source of truth" for neural activity, organized by session ID and trial index.
203
- - `/types/`: An index group for fast lookup of videos by category (Clip, Monet2, etc.).
204
- - `/brain_areas/`: An index group linking brain regions (V1, LM...) to the sessions where they were recorded.
205
 
206
  ## 📝 Citation
207
 
 
18
 
19
  # MICrONS Functional Activity Dataset & Reader
20
 
21
+ This repository contains a curated portion of the MICrONS (Multi-Scale Networked Analysis of Cellular Responding Order) dataset. It consists of functional calcium imaging data from the visual cortex of mice in response to various visual stimuli: natural clips (`Clip`) and parametric videos (`Monet2`, `Trippy`).
22
+
23
+ Videos have been downsampled to match the neural activity scan frequency, with each frame corresponding to the stimulus frame appearing at least 66 ms before scan time. Neural responses are linearly interpolated at each stimulus frame timestamp to align with the video.
24
+
25
  The data is organized into a highly efficient, indexed HDF5 format, allowing for rapid cross-session analysis based on either stimulus identity or brain anatomy.
26
 
27
+ ---
28
+
29
  ## 📊 Dataset Overview
30
 
31
+ | Property | Detail |
32
+ |---|---|
33
+ | Sessions | 14 sessions of registered neural activity |
34
+ | Stimuli | 3 categories (`Clip`, `Monet2`, `Trippy`) identified by unique condition hashes |
35
+ | Neural Data | Calcium traces from thousands of neurons across V1, LM, RL, AL |
36
+ | Behavioral Data | Synchronized treadmill speed and pupil size (major/minor radius) |
37
+ | Eye Tracking | Pupil center coordinates (x, y) for gaze analysis |
38
+
39
+ ---
40
 
41
+ ## 🗂️ Internal HDF5 Structure
42
+
43
+ The file is organized to minimize redundancy: each unique video stimulus is stored once under `/videos/` and linked to every trial across all sessions via HDF5 SoftLinks. The `/sessions/` group is the source of truth for all neural and behavioral recordings.
44
  ```text
45
  root/
46
+ ├── 📂 BRAIN_AREAS/ # Anatomical index (SoftLinks only)
47
  │ └── 📂 <area_name>/ # e.g., V1, AL, LM, RL
48
  │ └── 🔗 <session_id> -> /sessions/<session_id>
49
 
50
+ ├── 📂 SESSIONS/ # Primary neural data storage
51
  │ └── 📂 <session_id>/ # e.g., 4_7, 5_6
52
+ │ ├── 📂 META/ # Session-wide metadata
53
+ │ │ ├── 📂 AREA_INDICES/ # Pre-computed neuron index masks per area
54
+ │ │ │ └── 📄 <area_name> [Dataset: (N_area_neurons,), int]
55
+ │ │ ├── 📄 brain_areas [Dataset: (N_neurons,), bytes — area label per neuron]
56
+ │ │ ├── 📄 coordinates [Dataset: (N_neurons, 3), float — motor coordinates x/y/z]
57
+ │ │ ├── 📄 unit_ids [Dataset: (N_neurons,), int — unique neuron IDs]
58
+ │ │ ├── 📄 condition_hashes [Dataset: (N_trials,), bytes — hash per trial, in order]
59
+ │ │ └── (Attr) fps [Float scan acquisition rate]
60
+ │ └── 📂 TRIALS/ # One group per trial, indexed chronologically
61
+ │ └── 📂 <trial_idx>/
62
+ │ ├── 📄 responses [Dataset: (N_neurons, F), float — ΔF/F calcium traces]
63
+ │ ├── 📄 treadmill [Dataset: (F,), float — running speed in cm/s]
64
+ │ ├── 📄 pupil [Dataset: (4, F), float — rows: x, y, major_r, minor_r]
65
+ ── 📄 stim_times [Dataset: (F,), float — stimulus frame timestamps in seconds]
66
+ │ └── (Attr) condition_hash [String — identifies the video shown in this trial]
67
 
68
+ ├── 📂 TYPES/ # Stimulus category index (SoftLinks only)
69
  │ └── 📂 <stim_type>/ # e.g., Clip, Monet2, Trippy
70
  │ └── 🔗 <encoded_hash> -> /videos/<encoded_hash>
71
 
72
+ └── 📂 VIDEOS/ # Stimulus library each video stored once
73
+ └── 📂 <encoded_hash>/ # URL-encoded condition hash (/ → %2F)
74
+ ├── 📄 clip [Dataset: (F, H, W), uint8 — grayscale frames]
75
+ ├── 📄 times [Dataset: (F,), float — relative frame timestamps in seconds, starting at 0]
76
+ ├── 📂 INSTANCES/ # Reverse index: all trials that showed this video
77
  │ └── 🔗 <session_id>_tr<trial_idx> -> /sessions/<session_id>/trials/<trial_idx>
78
+ ── (Attr) original_hash [String raw unencoded hash]
79
+ ── (Attr) type [String — one of: Clip, Monet2, Trippy]
80
+
81
+ │ # Clip-specific attributes/datasets:
82
+ ├── (Attr) movie_name [String]
83
+ ├── (Attr) short_movie_name [String]
84
+ ├── (Attr) duration [Float — clip duration in seconds]
85
+ ├── (Attr) fps [Float — original stimulus frame rate]
86
+
87
+ │ # Monet2-specific attributes/datasets:
88
+ ├── 📄 directions [Dataset: (N_orientations,), float — grating directions in degrees]
89
+ ├── 📄 onsets [Dataset: (N_orientations,), float — onset times per grating]
90
+ ├── (Attr) duration [Float]
91
+ ├── (Attr) ori_coherence [Float — orientation coherence parameter]
92
+ ├── (Attr) fps [Float]
93
+
94
+ │ # Trippy-specific attributes/datasets:
95
+ ├── (Attr) temp_freq [Float — temporal frequency in Hz]
96
+ ├── (Attr) spatial_freq [Float — spatial frequency in cycles/degree]
97
+ ├── (Attr) duration [Float]
98
+ └── (Attr) fps [Float]
99
  ```
100
 
101
+ ### Key design notes
 
 
102
 
103
+ - **`/brain_areas/` and `/types/`** contain only SoftLinks — no data. They serve as fast lookup indices.
104
+ - **`/videos/<hash>/instances/`** allows reverse lookup: given a video, find every session and trial that presented it.
105
+ - **`condition_hashes`** in session metadata are stored in trial order and may contain duplicates (the same video can be shown multiple times per session).
106
+ - **`pupil`** rows are ordered `[x, y, major_r, minor_r]` consistently across all sessions.
107
+ - **`stim_times`** are absolute timestamps in seconds; `times` inside `/videos/` are relative (starting at 0), computed as `stim_times - stim_times.min()`.
108
 
109
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
+ ## ⚙️ Setup & Installation
112
 
113
+ ### Option 1 Clone the repository
114
 
115
+ Since the dataset is stored as a large HDF5 file, Git LFS is required.
116
  ```bash
117
+ git lfs install
118
+ git clone https://huggingface.co/datasets/NeuroBLab/MICrONS
119
+ cd MICrONS
120
+ pip install -r requirements.txt
121
  ```
122
 
123
+ ### Option 2 Programmatic download (no clone)
 
124
  ```python
125
  import sys
126
  import importlib.util
127
  from huggingface_hub import hf_hub_download
128
 
 
129
  REPO_ID = "NeuroBLab/MICrONS"
 
 
130
 
131
  print("Downloading files from Hugging Face...")
132
+ reader_path = hf_hub_download(repo_id=REPO_ID, filename="reader.py")
133
+ data_path = hf_hub_download(repo_id=REPO_ID, filename="microns.h5")
134
 
 
 
 
 
 
 
 
135
  spec = importlib.util.spec_from_file_location("reader", reader_path)
136
  reader_module = importlib.util.module_from_spec(spec)
137
  sys.modules["reader"] = reader_module
 
139
 
140
  from reader import MicronsReader
141
 
 
142
  with MicronsReader(data_path) as reader:
143
+ reader.print_structure(max_items=2)
 
144
  ```
145
 
146
+ ---
 
 
 
 
147
 
148
+ ## 🛠️ Reader API
149
 
150
+ ### Initialize
151
  ```python
152
  from reader import MicronsReader
153
 
154
+ with MicronsReader("microns.h5") as reader:
155
+ # all calls go here
 
 
156
  pass
157
  ```
158
 
159
+ ### Explore structure
 
 
 
160
  ```python
161
+ with MicronsReader("microns.h5") as reader:
162
+ # Tree view — SoftLinks are shown without dereferencing by default
163
+ reader.print_structure(max_items=3, follow_links=False)
164
  ```
165
 
166
+ ### Query available metadata
 
 
 
167
  ```python
168
+ with MicronsReader("microns.h5") as reader:
169
+ # All stimulus types in the file
170
+ types = list(reader.f['types'].keys()) # ['Clip', 'Monet2', 'Trippy']
171
 
172
+ # All hashes for a given stimulus type
173
  monet_hashes = reader.get_hashes_by_type('Monet2')
174
 
175
+ # All (or unique) hashes shown in a session
176
+ all_hashes = reader.get_hashes_by_session('4_7')
177
+ unique_hashes = reader.get_hashes_by_session('4_7', return_unique=True)
178
 
179
+ # Brain areas recorded in a session, or all areas in the file
180
+ areas_in_session = reader.get_available_brain_areas('4_7') # ['AL', 'LM', 'RL', 'V1']
181
+ all_areas = reader.get_available_brain_areas()
182
  ```
183
 
184
+ ### Load video + all associated trials
 
 
185
 
186
+ `get_full_data_by_hash` is the primary access method. It aggregates the video and every neural/behavioral trial across all sessions that presented that stimulus.
187
  ```python
188
  target_hash = "0JcYLY6eaQxNgD0AqyHf"
189
 
190
+ with MicronsReader("microns.h5") as reader:
191
+ # Optionally filter responses to a single brain area
192
  data = reader.get_full_data_by_hash(target_hash, brain_area='V1')
193
 
194
+ print(data['clip'].shape) # (F, H, W) — grayscale video frames
195
+ print(data['stim_type']) # e.g. 'Clip'
196
+
197
+ for trial in data['trials']:
198
+ print(trial['session']) # e.g. '4_7'
199
+ print(trial['trial_idx']) # e.g. '12'
200
+ print(trial['responses'].shape) # (N_V1_neurons, F)
201
+ print(trial['treadmill'].shape) # (F,) — running speed in cm/s
202
+ print(trial['pupil'].shape) # (4, F) — rows: x, y, major_r, minor_r
203
+ print(trial['stim_times'].shape) # (F,) — absolute timestamps in seconds
204
+ ```
205
+
206
+ ### Load only neural responses
207
+ ```python
208
+ with MicronsReader("microns.h5") as reader:
209
+ trials = reader.get_responses_by_hash(target_hash, brain_area='LM')
210
+ # Returns: [{'session': str, 'trial_idx': str, 'responses': np.array}, ...]
211
+ ```
212
+
213
+ ### Direct single-trial access
214
+ ```python
215
+ with MicronsReader("microns.h5") as reader:
216
+ trial = reader.get_trial('4_7', trial_idx=12, brain_area='V1')
217
+ print(trial['responses'].shape) # (N_V1_neurons, F)
218
+ print(trial['stim_times']) # absolute timestamps for this trial
219
  ```
220
 
221
+ ### Load only the video
222
+ ```python
223
+ with MicronsReader("microns.h5") as reader:
224
+ clip, stim_type = reader.get_video_data("0JcYLY6eaQxNgD0AqyHf")
225
+ print(clip.shape) # (F, H, W)
226
+ print(stim_type) # 'Clip'
227
+ ```
228
 
229
+ ---
 
 
 
 
230
 
231
  ## 📝 Citation
232