pynwb
pynwb copied to clipboard
[Feature]: Add standard mechanism to get units for attributes
What would you like to see added to PyNWB?
While reviewing https://github.com/NeurodataWithoutBorders/nwb-schema/pull/523 to propose a new type for OnePhotonSeries, it occurred to me that for attributes the units of the values that are being stored are specified only in the doc-string for the attribute but we don't have an explicit way in the API to programmatically get the unit for those values. E.g., OnePhotonSeries.intensity
has a unit of mW/mm^2
. For datasets we often have an explicit unit
attribute so that we can get the unit as a property, e.g., in the case of TimeSeries we have TimeSeries.timestamps_unit
, TimeSeries.starting_time_unit
and TimeSeries.unit
.
It would be nice to have a general way to retrieve units for all elements that have units defined in the schema. This could be done in several ways. We could e.g., either:
- Add a generate
get_unit(...)
function forpynwb.core.NWBMixin
, to add it topynwb.core.NWBContainer
andpynwb.core.NWBData
. The function would take the name of an attribute as input and return a string with the unit for that attribute. The default implementation would then simply look if a property exists for that name, so that, e.g.,TimeSeries.get_unit("starting_time") would automatically return the value of
TimeSeries.starting_time_unit``, so that for existing unit information the function would work as expected. Individual neurodata_types would then need to overwrite the method to add the information for attributes that have units specified in the schema but which are not stored. - Consistent with the approach of having properties, e.g.,
TimeSeries.starting_time_unit
we could add corresponding attributes
I think both approaches could be useful and could potentially even be combined. I think having a single function to deal with units would be nice, but it would nice to hear other suggestions.
Is your feature request related to a problem?
The goal is to make all units defined in the schema explicitly accessible through the API, in particular those that are defined for attributes as those are currently only documented in the docstring. This will be useful for analysis and visualization tools.
What solution would you like?
See description above
Do you have any interest in helping implement the feature?
Yes.
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
- [X] Have you checked the Contributing document?
- [X] Have you ensured this change was not already requested?
@rly @bendichter @CodyCBakerPhD thoughts?