-
Notifications
You must be signed in to change notification settings - Fork 4
Store headstage sensor data as separate TimeSeries objects with appropriate units and scaling #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/fix-19
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+789
−12
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # Headstage Sensor Data Separation | ||
|
|
||
| This document describes the new functionality for separating headstage sensor data into individual TimeSeries objects with appropriate units and scaling. | ||
|
|
||
| ## Overview | ||
|
|
||
| Previously, all analog data (including headstage sensors) was combined into a single TimeSeries object stored in the processing module with unit "-1". The new implementation creates separate TimeSeries objects for each sensor type and stores them in the acquisition module with proper units and scaling. | ||
|
|
||
| ## Sensor Types and Scaling | ||
|
|
||
| The following sensor types are automatically detected and processed: | ||
|
|
||
| ### Accelerometer Data | ||
| - **Channels**: `Headstage_AccelX`, `Headstage_AccelY`, `Headstage_AccelZ` | ||
| - **Scaling**: Raw values × 0.000061 (converts to g units) | ||
| - **Unit**: `g` (gravity units) | ||
| - **Description**: Headstage accelerometer data with ±2G full range | ||
|
|
||
| ### Gyroscope Data | ||
| - **Channels**: `Headstage_GyroX`, `Headstage_GyroY`, `Headstage_GyroZ` | ||
| - **Scaling**: Raw values × 0.061 (converts to degrees/second) | ||
| - **Unit**: `d/s` (degrees per second) | ||
| - **Description**: Headstage gyroscope data with ±2000 dps range | ||
|
|
||
| ### Magnetometer Data | ||
| - **Channels**: `Headstage_MagX`, `Headstage_MagY`, `Headstage_MagZ` | ||
| - **Scaling**: No scaling applied (1.0) | ||
| - **Unit**: `unspecified` | ||
| - **Description**: Headstage magnetometer data | ||
|
|
||
| ### Analog Input Channels | ||
| - **Channels**: `ECU_Ain1`, `ECU_Ain2`, etc., `Controller_Ain1`, etc. | ||
| - **Scaling**: No scaling applied (1.0) | ||
| - **Unit**: `unspecified` (can be customized in metadata) | ||
| - **Description**: Analog input channel data | ||
|
|
||
| ## Metadata Configuration | ||
|
|
||
| ### Basic Configuration | ||
| The existing `units` section in your YAML metadata still works: | ||
|
|
||
| ```yaml | ||
| units: | ||
| analog: "unspecified" | ||
| behavioral_events: "unspecified" | ||
| ``` | ||
|
|
||
| ### Advanced Configuration | ||
| You can now specify custom units for each sensor type using the new `sensor_units` section: | ||
|
|
||
| ```yaml | ||
| sensor_units: | ||
| accelerometer: "g" # Custom unit for accelerometer | ||
| gyroscope: "d/s" # Custom unit for gyroscope | ||
| magnetometer: "T" # Custom unit for magnetometer (Tesla) | ||
| analog_input: "V" # Custom unit for analog inputs (Volts) | ||
| ``` | ||
|
|
||
| ### Behavioral Events with Units | ||
| Individual behavioral events can now specify their own units: | ||
|
|
||
| ```yaml | ||
| behavioral_events: | ||
| - description: Din1 | ||
| name: Light_1 | ||
| comments: Indicator for reward delivery | ||
| unit: "unspecified" | ||
| - description: ECU_Ain1 | ||
| name: Analog_Input_1 | ||
| comments: Voltage measurement | ||
| unit: "V" | ||
| ``` | ||
|
|
||
| ## Output Structure | ||
|
|
||
| ### New Behavior (Default) | ||
| - Separate TimeSeries objects stored in `nwbfile.acquisition` | ||
| - Each sensor type gets its own TimeSeries with proper units | ||
| - Applied scaling factors for accelerometer and gyroscope data | ||
| - Descriptive names and channel information | ||
|
|
||
| ### Legacy Behavior (Optional) | ||
| You can still use the old combined approach by setting `separate_sensor_data=False`: | ||
|
|
||
| ```python | ||
| add_analog_data(nwbfile, rec_files, metadata=metadata, separate_sensor_data=False) | ||
| ``` | ||
|
|
||
| This will create the original single TimeSeries in the processing module. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```python | ||
| from trodes_to_nwb.convert_analog import add_analog_data | ||
|
|
||
| # Load your metadata with optional sensor_units configuration | ||
| metadata = { | ||
| "sensor_units": { | ||
| "accelerometer": "g", | ||
| "gyroscope": "d/s" | ||
| } | ||
| } | ||
|
|
||
| # Add analog data with new separated sensor approach | ||
| add_analog_data(nwbfile, rec_files, metadata=metadata) | ||
|
|
||
| # Result: Individual TimeSeries in nwbfile.acquisition: | ||
| # - "accelerometer" (scaled data in g units) | ||
| # - "gyroscope" (scaled data in d/s units) | ||
| # - "magnetometer" (raw data) | ||
| # - "ecu_analog_input" (ECU analog channels) | ||
| ``` | ||
|
|
||
| ## Benefits | ||
|
|
||
| 1. **Clear Data Organization**: Each sensor type has its own TimeSeries with descriptive names | ||
| 2. **Proper Units**: Automatic application of correct physical units | ||
| 3. **Accurate Scaling**: Raw integer values converted to meaningful physical measurements | ||
| 4. **Better Documentation**: Channel names and descriptions preserved in TimeSeries | ||
| 5. **NWB Compliance**: Data stored in appropriate acquisition module | ||
| 6. **Backwards Compatibility**: Option to use legacy behavior if needed | ||
|
|
||
| ## Migration Notes | ||
|
|
||
| - Existing code will continue to work with the new default behavior | ||
| - The new approach stores data in `acquisition` instead of `processing["analog"]` | ||
| - If you need the old behavior, use `separate_sensor_data=False` | ||
| - Update analysis code to read from `nwbfile.acquisition` instead of `nwbfile.processing["analog"]` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| experimenter_name: | ||
| - lastname, firstname | ||
| lab: Loren Frank Lab | ||
| institution: UCSF | ||
| experiment_description: Test Conversion with Headstage Sensor Units | ||
| session_description: test yaml insertion with separate sensor TimeSeries | ||
| session_id: "12345" | ||
| keywords: | ||
| - testing | ||
| - headstage_sensors | ||
| subject: | ||
| description: Long-Evans Rat | ||
| genotype: Obese Prone CD Rat | ||
| sex: M | ||
| species: Rattus pyctoris | ||
| subject_id: "54321" | ||
| date_of_birth: 2000-01-01T00:00:00.000Z | ||
| weight: 100 | ||
| data_acq_device: | ||
| - name: SpikeGadgets | ||
| system: SpikeGadgets | ||
| amplifier: Intan | ||
| adc_circuit: Intan | ||
| cameras: | ||
| - id: 0 | ||
| meters_per_pixel: 0.001 | ||
| manufacturer: Allied Vision | ||
| model: model1 | ||
| lens: lens1 | ||
| camera_name: test camera 1 | ||
| tasks: | ||
| - task_name: Sleep | ||
| task_description: sleeping | ||
| task_environment: sleep box | ||
| camera_id: | ||
| - 0 | ||
| task_epochs: | ||
| - 1 | ||
| associated_files: [] | ||
| associated_video_files: [] | ||
|
|
||
| # Updated units specification with individual sensor units | ||
| units: | ||
| analog: "unspecified" # Default for uncategorized analog channels | ||
| behavioral_events: "unspecified" # Default for DIO events | ||
|
|
||
| # Optional: specify custom units for specific sensor types | ||
| sensor_units: | ||
| accelerometer: "g" # Will override default | ||
| gyroscope: "d/s" # Will override default | ||
| magnetometer: "unspecified" | ||
| analog_input: "V" # For ECU analog inputs | ||
|
|
||
| times_period_multiplier: 1 | ||
| raw_data_to_volts: 1.95e-07 | ||
| default_header_file_path: /stelmo/sam/test_data | ||
|
|
||
| device: | ||
| name: | ||
| - device1 | ||
|
|
||
| # Enhanced behavioral_events with individual unit specifications | ||
| behavioral_events: | ||
| - description: Din1 | ||
| name: Light_1 | ||
| comments: Indicator for reward delivery | ||
| unit: "unspecified" # Digital events are dimensionless | ||
| - description: Din2 | ||
| name: Light_2 | ||
| unit: "unspecified" | ||
| - description: Dout2 | ||
| name: Poke_1 | ||
| unit: "unspecified" | ||
| - description: ECU_Ain1 | ||
| name: Analog_Input_1 | ||
| comments: Custom analog input channel | ||
| unit: "V" # Voltage | ||
| - description: ECU_Ain2 | ||
| name: Analog_Input_2 | ||
| comments: Another analog input | ||
| unit: "mV" # Millivolts | ||
|
|
||
| electrode_groups: [] | ||
| ntrode_electrode_group_channel_map: [] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this isn't present in the yaml?