Create default processing modules #1944
Draft
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.
Motivation
Fix #946. @bendichter let me know what you think.
With this PR, a new
NWBFile
will contain emptyProcessingModule
objects named "ecephys", "icephys", "ophys", and "behavior" on initialization. A user can add to theseProcessingModule
s without needing to create them. AnyProcessingModule
s that are empty are not written to the file. So there is a minor discrepancy between what a user sees in the in-memoryNWBFile
object compared to the one written to disk.To prevent breaking existing code that creates a
ProcessingModule
with one of these names (creating one that already exists will raise an error), I overrode thecreate_processing_module
andadd_processing_module
methods to warn if it exists instead of raise an error.@bendichter I initially liked your suggestion in #946 of implementing
nwb.processing.behavior
ornwb.processing["behavior"]
to "return theProcessingModule
named behavior if it exists, and if it does not exist pynwb would automatically create that module and return it." However, I tried that and it results in creating a processing module named "behavior" simply when a user accesses it. This could happen when exploring a file or when editing a file in append mode. For example, accidentally callingnwb.processing["behavior"]
would create an emptyProcessingModule
that gets written to disk onio.write()
. Now that is probably rare, but I think creating the item when get is called is less intuitive than having the modules automatically created on init and just not writing them if empty, but I'm not totally sure...Alternative 2: we could create methods
nwb.add_behavior_processing
,nwb.add_ecephys_processing
, etc. that create theProcessingModule
and add to it when called. Similar tonwb.add_trial
. Downside: this is a new syntax that is different from other functions. But it avoids both issues above.TODO: add tests
We can add these default
ProcessingModule
objects to the schema too https://github.com/NeurodataWithoutBorders/nwb-schema/tree/default_proc_mod but let's discuss the interface first.How to test the behavior?
Checklist
ruff check . && codespell
from the source directory.