matnwb
matnwb copied to clipboard
Question: How to resolve if a property is required
I am trying to understand what makes something required entity in nwb according to the schema and I am not sure how it works for nested types:
- Can a group be optional, but have only required subgroups/datasets, making it required?
- If a dataset is optional and all it's attributes are required, the dataset is still optional, correct?
The background is this code snippet from the class generator in MatNWB, which is classifying whether a property should be required or not: https://github.com/NeurodataWithoutBorders/matnwb/blob/a85496b1f7970cac468f373217674819c41fbc85/%2Bfile/fillClass.m#L17-L27
prop in this case refers to a dataset or a group. It seems to be always scalar, so I think there must be a mistake in the code. But I am wondering if the intention of the code is to loop over all subgroups/datasets/attributes of the original group/dataset to check if they are all required, and then decide that the original dataset/group is required if all of it's sub-properties are required.
However, I don't really see this being supported by the format specifications
@rly @oruebel @stephprince @bendichter
Throughout the schema, "required" (and more generally all constraints on the number of things ) is a relationship between an object and its owner.
If an attribute of a group is required, it means if the group that contains it exists, then the attribute must also exist. This requirement status does not get passed up to the group that contains it. That group does not become required just because it has an attribute that is required. That group has its own requirement status with the group that contains it.
I'm not sure about the matlab code, but that is how the schema should be understood.
An example is the start_time and rate of TimeSeries. rate is a required attribute of starting_time, so if starting_time exists, so must rate, but starting_time does not become required just because it has a required attribute. The same is true for all element types.
Agreed. The scoping for "required" is within the context of the parent object. In most cases that means within the context of the closest neurodata_type or the dataset or group that the object is associated with. I.e,. an object is required only if the object that come before it is actually present. So if group A contains datasets B and A is optional but B is required then this means, B is required when A is present, but A does not become required just because it contains B.
Related: https://github.com/NeurodataWithoutBorders/nwb-schema/issues/592
Looked a bit more into this, and it only applies in practice to groups of the NWBFile with unnamed subgroups, like acquisition, analysis, scratch and stimulation.
Instead of checking the required state of that group, the code checks if all the subgroups are required, and uses that to decide if the parent group should be required or not.