Skip to content

Add example of setting Units.resolution in the ecephys tutorial#2174

Open
h-mayorquin wants to merge 5 commits into
devfrom
add_tutorial_for_unit_resolution
Open

Add example of setting Units.resolution in the ecephys tutorial#2174
h-mayorquin wants to merge 5 commits into
devfrom
add_tutorial_for_unit_resolution

Conversation

@h-mayorquin
Copy link
Copy Markdown
Contributor

@h-mayorquin h-mayorquin commented Mar 24, 2026

Motivation

At the inspector we are working on check_units_resolution_is_set check (NeurodataWithoutBorders/nwbinspector#685), which flags Units tables that contain spike_times but have no resolution set. Users running the inspector on files created by following our tutorials would get this warning with no guidance on how to fix it.

I have added a short section to the ecephys tutorial that sets nwbfile.units.resolution right after the existing add_unit loop, with a brief explanation of what the field means and why it matters. I kept the change minimal to avoid restructuring the existing tutorial flow.

What was the reasoning behind this change? Please explain the changes briefly.

Checklist

  • Did you update CHANGELOG.md with your changes?
  • Have you checked our Contributing document?
  • Have you ensured the PR clearly describes the problem and the solution?
  • Is your contribution compliant with our coding style? This can be checked running ruff check . && codespell from the source directory.
  • Have you checked to ensure that there aren't other open Pull Requests for the same change?
  • Have you included the relevant issue number using "Fix #XXX" notation where XXX is the issue number? By including "Fix #XXX" you allow GitHub to close issue #XXX when the PR is merged.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.18%. Comparing base (9231882) to head (ef79487).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #2174   +/-   ##
=======================================
  Coverage   95.18%   95.18%           
=======================================
  Files          30       30           
  Lines        2991     2991           
  Branches      444      444           
=======================================
  Hits         2847     2847           
  Misses         86       86           
  Partials       58       58           
Flag Coverage Δ
integration 73.05% <ø> (ø)
unit 85.59% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@h-mayorquin h-mayorquin marked this pull request as ready for review March 24, 2026 22:23
@h-mayorquin h-mayorquin self-assigned this Mar 24, 2026
@h-mayorquin h-mayorquin added the topic: docs issues related to documentation label Mar 24, 2026
Comment thread docs/gallery/domain/ecephys.py Outdated
Comment on lines +351 to +358
#
# When creating the :py:class:`~pynwb.misc.Units` table directly, you can pass it to the constructor:
#
# .. code-block:: python
#
# units = Units(name="units", resolution=1 / 30000) # 30 kHz recording system
#
# Since the tutorial uses :py:meth:`.NWBFile.add_unit`, we set it after the fact:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
#
# When creating the :py:class:`~pynwb.misc.Units` table directly, you can pass it to the constructor:
#
# .. code-block:: python
#
# units = Units(name="units", resolution=1 / 30000) # 30 kHz recording system
#
# Since the tutorial uses :py:meth:`.NWBFile.add_unit`, we set it after the fact:

I don't think we need to show how to set it on the constructor. That is a rare edge case.

Copy link
Copy Markdown
Contributor Author

@h-mayorquin h-mayorquin May 6, 2026

Choose a reason for hiding this comment

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

how is that an edge case? how are you thinking about it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think most users would use nwbfile.add_unit() and nwbfile.add_unit_column() as we recommend here, rather than setting nwbfile.units = Units(name="units", ...) or creating a Units object to add elsewhere. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We use the pattern in neuroconv:
https://github.com/catalystneuro/neuroconv/blob/2ddf1744208050a6229ad67d0e45f634253ae69e/src/neuroconv/tools/spikeinterface/spikeinterface.py#L2041-L2064

But yes, for the units table we don't realy use the Units constructor so it will somehow off.

I will remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As an aside: looking at the tutorials, the constructor is used for pretty much everything (ElectricalSeries, LFP, DecompositionSeries, etc.) except the "canonical" dynamic tables on NWBFile (units, trials, epochs, electrodes, invalid_times), which always go through the add_X / add_X_column methods. The only place the gallery constructs a TimeIntervals directly is for custom (non-canonical) interval tables like sleep_stages in plot_timeintervals.py.

That convention makes sense, but I don't think it is written down anywhere, which is why "edge case" didn't immediately click for me. I remember being confused myself about how to add a constructed Units table to an NWBFile.

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

Labels

topic: docs issues related to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants