Skip to content

Conversation

Copy link

Copilot AI commented Sep 11, 2025

This PR implements separate storage of headstage sensor data (accelerometer, gyroscope, magnetometer) as individual TimeSeries objects in the acquisition module with proper physical units and scaling factors, addressing the issue where all analog data was previously combined into a single TimeSeries with generic units.

Key Changes

Enhanced Analog Data Processing:

  • Automatically detects and categorizes headstage sensor channels by type based on naming patterns:
    • Headstage_AccelX/Y/Z → Accelerometer data scaled by 0.000061 with unit g
    • Headstage_GyroX/Y/Z → Gyroscope data scaled by 0.061 with unit d/s
    • Headstage_MagX/Y/Z → Magnetometer data with unit unspecified
    • ECU_Ain* → Analog input channels with configurable units

Metadata Schema Extensions:

  • Added optional sensor_units field for custom unit specifications per sensor type
  • Enhanced behavioral_events items to support individual unit and comments fields
  • Maintains full backwards compatibility with existing metadata files

Output Structure:

  • New default behavior: Creates separate TimeSeries objects in nwbfile.acquisition with descriptive names and proper units
  • Legacy compatibility: Optional separate_sensor_data=False parameter preserves original combined TimeSeries in processing module

Example Usage:

# Metadata configuration
metadata = {
    "sensor_units": {
        "accelerometer": "g", 
        "gyroscope": "d/s"
    }
}

# Results in separate acquisition TimeSeries:
add_analog_data(nwbfile, rec_files, metadata=metadata)
# - "accelerometer": scaled accelerometer data in g units
# - "gyroscope": scaled gyroscope data in d/s units  
# - "magnetometer": raw magnetometer data
# - "ecu_analog_input": ECU analog channels

Benefits:

  • Proper physical units applied automatically (accelerometer in g, gyroscope in degrees/second)
  • Clear data organization with separate, descriptive TimeSeries objects
  • Accurate scaling from raw integer values to meaningful physical measurements
  • Improved NWB compliance by storing acquisition data in the acquisition module
  • Backwards compatibility for existing workflows

Testing:

  • Added comprehensive unit tests for sensor categorization and TimeSeries creation
  • Integration tests validating full conversion pipeline with both new and legacy modes
  • Tests confirm proper scaling factors and unit assignments

Fixes #19.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Author

Copilot AI commented Sep 11, 2025

@edeno 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI changed the title [WIP] Store Headstage sensor data as separate TimeSeries objects in acquisition using appropriate descriptions and units Store headstage sensor data as separate TimeSeries objects with appropriate units and scaling Sep 11, 2025
Copilot finished work on behalf of edeno September 11, 2025 03:12
Copilot AI requested a review from edeno September 11, 2025 03:12
behavioral_events: "unspecified" # Default for DIO events

# Optional: specify custom units for specific sensor types
sensor_units:
Copy link
Collaborator

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?

rec_file_path: list[str],
timestamps: np.ndarray = None,
behavior_only: bool = False,
metadata: dict = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be optional type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Store Headstage sensor data as separate TimeSeries objects in acquisition using appropriate descriptions and units

2 participants