Skip to content

Introducing MultiNodeObservation class#588

Merged
jpalm3r merged 26 commits intojapr/network-supportfrom
japr/multinodeobs
Feb 27, 2026
Merged

Introducing MultiNodeObservation class#588
jpalm3r merged 26 commits intojapr/network-supportfrom
japr/multinodeobs

Conversation

@jpalm3r
Copy link
Collaborator

@jpalm3r jpalm3r commented Feb 23, 2026

Introduces MultiNodeObservation class to streamline creation of multiple node observations from a single data source, significantly improving the user experience for network model workflows.

Changes

New Features

  • MultiNodeObservation class: Creates multiple NodeObservation objects from a single DataFrame or Dataset
  • Auto-assignment: Automatically maps data columns to nodes when counts match
  • Flexible naming: Supports both string prefixes ("S""S_0", "S_1") and explicit name lists
  • Consistent metadata: Applies quantity, aux_items, and attrs uniformly across all observations

API Improvements

  • Updated documentation: Added MultiNodeObservation to module docstring alongside existing observation types
  • Factory function compatibility: Maintains consistency with existing observation() patterns

Usage Examples

Before (manual creation)

# Tedious: create each observation separately
obs1 = ms.NodeObservation(df, item=0, node=123, quantity=quantity)
obs2 = ms.NodeObservation(df, item=1, node=456, quantity=quantity) 
obs3 = ms.NodeObservation(df, item=2, node=789, quantity=quantity)
observations = [obs1, obs2, obs3]

After (streamlined)

# Efficient: create all observations at once
observations = ms.MultiNodeObservation(df, nodes=[123, 456, 789], quantity=quantity)

Benefits

  • 🚀 Reduced boilerplate: Single call replaces multiple manual instantiations
  • 🔧 Error prevention: Validates node count against data columns
  • 📊 Consistency: Ensures uniform metadata across all node observations
  • ⚡ Better UX: Simplified workflow for network modeling scenarios

Technical Details

  • Inherits from list for familiar collection behavior
  • Validates input data structure against node requirements
  • Supports both DataFrame and xarray.Dataset inputs
  • Maintains full compatibility with existing NodeObservation functionality

This enhancement makes network data handling more intuitive and reduces the cognitive load for users working with multi-node datasets.

- Updated NodeObservation class to allow creation of multiple observations by passing lists for node and item parameters.
- Implemented auto-assignment of item indices when only nodes are provided and their count matches the number of data columns.
- Added validation to ensure that the lengths of node, item, and name lists match when provided.
- Enhanced documentation for NodeObservation to reflect new functionality.
- Added unit tests to verify the new behavior, including auto-assignment and error handling for mismatched lengths.
@jpalm3r jpalm3r changed the base branch from main to japr/network-support February 23, 2026 15:06
@jpalm3r jpalm3r changed the base branch from japr/network-support to main February 23, 2026 15:06
@jpalm3r jpalm3r mentioned this pull request Feb 24, 2026
@jpalm3r jpalm3r changed the base branch from main to japr/network-support February 25, 2026 09:26
@jpalm3r jpalm3r marked this pull request as ready for review February 25, 2026 09:26
@jpalm3r jpalm3r requested a review from ryan-kipawa February 25, 2026 10:27
Copy link
Collaborator

@ryan-kipawa ryan-kipawa left a comment

Choose a reason for hiding this comment

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

General comment: why is there no MultiPointObservation?

I am sort of questioning if we need such an abstraction. Do users need list-like functionality on a collection of observations, or is this more a convenience for constructing many observations from a single source?

One disadvantage I see is that it only works for collections of observations that share the same time index. If it's as a convenience function, then I wonder if it fits better as a static method or something like that on NodeObesrvation?

@jpalm3r
Copy link
Collaborator Author

jpalm3r commented Feb 26, 2026

General comment: why is there no MultiPointObservation?

I am sort of questioning if we need such an abstraction. Do users need list-like functionality on a collection of observations, or is this more a convenience for constructing many observations from a single source?

One disadvantage I see is that it only works for collections of observations that share the same time index. If it's as a convenience function, then I wonder if it fits better as a static method or something like that on NodeObesrvation?

It is just for convenience, after our previous discussions on user-friendliness and a potential use case of one model vs multiple sensors.

@jpalm3r jpalm3r requested a review from ryan-kipawa February 27, 2026 15:47
@jpalm3r jpalm3r merged commit 6104e77 into japr/network-support Feb 27, 2026
3 checks passed
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.

3 participants