|
| 1 | + |
| 2 | +# Reading Data |
| 3 | + |
| 4 | +This section demonstrates how the `isx` package can be used to read data from Inscopix files. |
| 5 | +Refer to the [file types](../overview) table for reference on the Inscopix file types and read support. |
| 6 | + |
| 7 | +:::{note} |
| 8 | +The following sections assume the `isx` package has been imported, i.e., `import isx` |
| 9 | +::: |
| 10 | + |
| 11 | +## Microscope & Behavior Movies |
| 12 | + |
| 13 | +`Microscope Movie` and `Behavior Movie` file types can be read using the `isx.Movie` class. |
| 14 | + |
| 15 | +```python |
| 16 | + # Open the movie for reading |
| 17 | + movie = isx.Movie.read("movie.isxd") |
| 18 | +``` |
| 19 | + |
| 20 | +Movie objects have timing and spacing properties which can be accessed: |
| 21 | + |
| 22 | + |
| 23 | +```python |
| 24 | + # Timing information can be accessed using: |
| 25 | + movie.timing |
| 26 | + |
| 27 | + # The number of frames can be accessed using: |
| 28 | + movie.timing.num_samples |
| 29 | + |
| 30 | + # The time period can be accessed using: |
| 31 | + movie.timing.period.secs_float |
| 32 | + |
| 33 | + # Spacing information can be accessed using: |
| 34 | + movie.spacing |
| 35 | + |
| 36 | + # The dimensions of the frame can be accessed using: |
| 37 | + # which will return a 2-tuple containing the dimensions of the frame |
| 38 | + # (num_rows, num_cols), or (height, width) |
| 39 | + movie.spacing.num_pixels |
| 40 | +``` |
| 41 | + |
| 42 | +Frames from movies can be read into memory: |
| 43 | + |
| 44 | +```python |
| 45 | + # The pixel data type can accessed using: |
| 46 | + movie.data_type |
| 47 | + |
| 48 | + # Read every frame of the movie, and process it |
| 49 | + for i in range(movie.timing.num_samples): |
| 50 | + # Dimensions of the frame are (num_rows, num_cols), or (height, width) |
| 51 | + frame = movie.get_frame_data(i) |
| 52 | + |
| 53 | + # Process frame |
| 54 | + ... |
| 55 | +``` |
| 56 | + |
| 57 | +::: {warning} |
| 58 | +It's recommended to read one frame into memory at a time to prevent out of memory errors. |
| 59 | +::: |
| 60 | + |
| 61 | +::: {note} |
| 62 | +Python indexes by 0, so the first frame is at index 0, and the the second frame is at index 1, and so on. |
| 63 | +::: |
| 64 | + |
| 65 | +## Cell Sets |
| 66 | + |
| 67 | +`Cell Set` file types can be read using the `isx.CellSet` class. |
| 68 | + |
| 69 | +```python |
| 70 | + # Open the cell set for reading |
| 71 | + cell_set = isx.CellSet.read("cell_set.isxd") |
| 72 | +``` |
| 73 | + |
| 74 | +Similar to movies, cell sets have timing and spacing properties which can be accessed. |
| 75 | +These properties are derived from the parent movie which generated the cell set. |
| 76 | + |
| 77 | +```python |
| 78 | + # Timing information can be accessed using: |
| 79 | + cell_set.timing |
| 80 | + |
| 81 | + # The number of frames can be accessed using: |
| 82 | + cell_set.timing.num_samples |
| 83 | + |
| 84 | + # The time period can be accessed using: |
| 85 | + cell_set.timing.period.secs_float |
| 86 | + |
| 87 | + # Spacing information can be accessed using: |
| 88 | + cell_set.spacing |
| 89 | + |
| 90 | + # The dimensions of the frame can be accessed using: |
| 91 | + # which will return a 2-tuple containing the dimensions of the frame |
| 92 | + # (num_rows, num_cols), or (height, width) |
| 93 | + cell_set.spacing.num_pixels |
| 94 | +``` |
| 95 | + |
| 96 | +Cell data from cell sets can be read into memory: |
| 97 | + |
| 98 | +```python |
| 99 | + # The number of cells in the cell set can accessed using: |
| 100 | + cell_set.num_cells |
| 101 | + |
| 102 | + # Read data of every cell in the cell set, and process it |
| 103 | + for i in range(cell_set.num_cells): |
| 104 | + # Get the cell name |
| 105 | + name = cell_set.get_cell_name(i) |
| 106 | + |
| 107 | + # Get the temporal activity trace of a cell |
| 108 | + trace = cell_set.get_cell_trace(i) |
| 109 | + |
| 110 | + # Get the spatial footprint of a cell |
| 111 | + footprint = cell_set.get_cell_image_data(i) |
| 112 | + |
| 113 | + # Process cell data |
| 114 | + ... |
| 115 | +``` |
| 116 | + |
| 117 | +## Event Sets |
| 118 | + |
| 119 | +`Event Set` file types can be read using the `isx.EventSet` class. |
| 120 | + |
| 121 | +```python |
| 122 | + # open the event set for reading |
| 123 | + event_set = isx.EventSet.read("event_set.isxd") |
| 124 | +``` |
| 125 | + |
| 126 | +Similar to cell sets, event sets have timing properties which can be accessed. |
| 127 | +These properties are derived from the parent cell set which generated the event set. |
| 128 | + |
| 129 | +```python |
| 130 | + # Timing information can be accessed using: |
| 131 | + event_set.timing |
| 132 | + |
| 133 | + # The number of frames can be accessed using: |
| 134 | + event_set.timing.num_samples |
| 135 | + |
| 136 | + # The time period can be accessed using: |
| 137 | + event_set.timing.period.secs_float |
| 138 | +``` |
| 139 | + |
| 140 | +Cell data from event sets can be read into memory: |
| 141 | + |
| 142 | +```python |
| 143 | + # Read data of every cell in the event set, and process it |
| 144 | + for i in range(event_set.timing.num_samples): |
| 145 | + # Get the cell name |
| 146 | + name = event_set.get_cell_name(i) |
| 147 | + |
| 148 | + # Get the event timestamps and amplitudes of a cell |
| 149 | + offsets, amplitudes = event_set.get_cell_data(i) |
| 150 | + |
| 151 | + # Process cell data |
| 152 | + ... |
| 153 | +``` |
| 154 | + |
| 155 | +## Vessel Sets |
| 156 | + |
| 157 | +`Vessel Set` file types can be read using the `isx.VesselSet` class. |
| 158 | + |
| 159 | +```python |
| 160 | + # Open the vessel set for reading |
| 161 | + vessel_set = isx.VesselSet.read("vessel_set.isxd") |
| 162 | +``` |
| 163 | + |
| 164 | +Similar to movies, vessel sets have timing and spacing properties which can be accessed. |
| 165 | +These properties are derived from the parent movie which generated the vessel set. |
| 166 | + |
| 167 | +```python |
| 168 | + # Timing information can be accessed using: |
| 169 | + vessel_set.timing |
| 170 | + |
| 171 | + # The number of frames can be accessed using: |
| 172 | + vessel_set.timing.num_samples |
| 173 | + |
| 174 | + # The time period can be accessed using: |
| 175 | + vessel_set.timing.period.secs_float |
| 176 | + |
| 177 | + # Spacing information can be accessed using: |
| 178 | + vessel_set.spacing |
| 179 | + |
| 180 | + # The dimensions of the frame can be accessed using: |
| 181 | + # which will return a 2-tuple containing the dimensions of the frame |
| 182 | + # (num_rows, num_cols), or (height, width) |
| 183 | + vessel_set.spacing.num_pixels |
| 184 | +``` |
| 185 | + |
| 186 | +Vessel data from vessel sets can be read into memory: |
| 187 | + |
| 188 | +```python |
| 189 | + # The number of vessels in the vessel set can be accessed using: |
| 190 | + vessel_set.num_vessels |
| 191 | + |
| 192 | + # The standard deviation projection image of the parent movie |
| 193 | + # This is the same for every vessel |
| 194 | + image = vessel_set.get_vessel_image_data(0) |
| 195 | + |
| 196 | + # Read data of every vessel in the vessel set, and process it |
| 197 | + for i in range(vessel_set.num_vessels): |
| 198 | + # Get the vessel name |
| 199 | + name = vessel_set.get_vessel_name(i) |
| 200 | + |
| 201 | + # Get the vessel status |
| 202 | + status = vessel_set.get_vessel_status(i) |
| 203 | + |
| 204 | + # For vessel diameter vessel sets, get the following data: |
| 205 | + # The vessel diameter trace |
| 206 | + trace = vessel_set.get_vessel_trace_data(i) |
| 207 | + # The direction of rbc velocity trace |
| 208 | + center_trace = vessel_set.get_vessel_center_trace_data(i) |
| 209 | + # The vessel line points |
| 210 | + line = vessel_set.get_vessel_line_data(i) |
| 211 | + |
| 212 | + # For rbc velocity vessel sets, get the following data: |
| 213 | + # The rbc velocity trace |
| 214 | + trace = vessel_set.get_vessel_trace_data(i) |
| 215 | + # The direction of rbc velocity trace |
| 216 | + direction_trace = vessel_set.get_vessel_direction_trace_data(i) |
| 217 | + # The first correlation heatmap of the vessel |
| 218 | + corr = vessel_set.get_vessel_correlations_data(i, 0) |
| 219 | + # The vessel box points |
| 220 | + box = vessel_set.get_vessel_line_data(i) |
| 221 | + |
| 222 | + # Process vessel data |
| 223 | + ... |
| 224 | +``` |
| 225 | + |
| 226 | +## GPIO & IMU |
| 227 | + |
| 228 | +`GPIO` and `IMU` file types can be read using the `isx.GpioSet` class. |
| 229 | + |
| 230 | +```python |
| 231 | + # open the gpio set for reading |
| 232 | + gpio_set = isx.GpioSet.read("signals.gpio") |
| 233 | +``` |
| 234 | + |
| 235 | +Gpio sets have timing properties which can be accessed. |
| 236 | + |
| 237 | +```python |
| 238 | + # Timing information can be accessed using: |
| 239 | + gpio_set.timing |
| 240 | + |
| 241 | + # The number of frames can be accessed using: |
| 242 | + gpio_set.timing.num_samples |
| 243 | + |
| 244 | + # The time period can be accessed using: |
| 245 | + gpio_set.timing.period.secs_float |
| 246 | +``` |
| 247 | + |
| 248 | +Signal data from gpio sets can be read into memory: |
| 249 | + |
| 250 | +```python |
| 251 | + # Number of channels (i.e., signals) can be accessed using: |
| 252 | + gpio_set.num_channels |
| 253 | + |
| 254 | + # Read data of every cell in the cell set, and process it |
| 255 | + for i in range(gpio_set.num_channels): |
| 256 | + # Get the channel name |
| 257 | + name = gpio_set.get_channel_name(i) |
| 258 | + |
| 259 | + # Get the signal timestamps and amplitudes of a channel |
| 260 | + offsets, amplitudes = gpio_set.get_channel_data(i) |
| 261 | + |
| 262 | + # Process signal data |
| 263 | + ... |
| 264 | +``` |
0 commit comments