Skip to content

Add DecompositionSeries unit and source_timeseries checks#687

Open
h-mayorquin wants to merge 10 commits into
devfrom
implement_unit_check_for_decomposition_series
Open

Add DecompositionSeries unit and source_timeseries checks#687
h-mayorquin wants to merge 10 commits into
devfrom
implement_unit_check_for_decomposition_series

Conversation

@h-mayorquin

Copy link
Copy Markdown
Collaborator

DecompositionSeries stores the product of spectral analysis and has a metric field ("phase", "amplitude", "power") that determines what units are appropriate. PyNWB defaults the unit to "no unit", which is almost always wrong since the metric carries enough information to determine the correct unit.

This PR adds two checks:

check_decomposition_series_unit (BEST_PRACTICE_VIOLATION) validates the unit field against the metric. When metric is "phase", the unit should be "radians" or "degrees". When metric is "amplitude" and source_timeseries is linked, the unit should match the source signal's unit (e.g. "volts" for an ElectricalSeries). The PyNWB default "no unit" and empty strings are flagged regardless of metric. The power case is skipped because there is no standard string format for squared units in NWB (see nwb-schema#446 for the ongoing discussion about adopting CMIXF-12 for unit notation).

check_decomposition_series_source_timeseries (BEST_PRACTICE_SUGGESTION) flags when source_timeseries is not set. This field provides provenance about which signal was decomposed and enables the unit validation above. PyNWB itself already warns about this at construction time, but the inspector check catches it for files that were already written.

Related to #208.

@h-mayorquin h-mayorquin self-assigned this Mar 24, 2026
h-mayorquin and others added 5 commits March 24, 2026 15:19
- Fix CHANGELOG PR reference (#676 -> #687).
- Defer empty-unit ("") to the general check_missing_unit so the same field
  is not flagged by two BEST_PRACTICE_VIOLATION checks at once; the new check
  now owns only the PyNWB default "no unit" plus the metric-specific rules.
  Empty units are still reported via check_missing_unit.
- Match the `metric` field case-insensitively so values like "Phase" are
  validated instead of silently skipped.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.13%. Comparing base (13d0d67) to head (0bcc395).
⚠️ Report is 8 commits behind head on dev.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #687      +/-   ##
==========================================
+ Coverage   79.44%   83.13%   +3.69%     
==========================================
  Files          48       49       +1     
  Lines        1897     1933      +36     
==========================================
+ Hits         1507     1607     +100     
+ Misses        390      326      -64     
Files with missing lines Coverage Δ
src/nwbinspector/checks/__init__.py 100.00% <100.00%> (ø)
src/nwbinspector/checks/_misc.py 100.00% <100.00%> (ø)

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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