hdmf-dev / hdmf

The Hierarchical Data Modeling Framework
http://hdmf.readthedocs.io
Other
46 stars 24 forks source link

[Bug]: Resolving spec inheritance fails when attribute has same name as existing attr on another object #1121

Closed rly closed 1 month ago

rly commented 1 month ago

What happened?

From https://github.com/catalystneuro/ndx-microscopy/pull/11#discussion_r1622645107

The relevant spec:

  - neurodata_type_def: ImagingSpace
    neurodata_type_inc: LabMetaData  # Would prefer basic NWBContainer
    doc: Metadata about the region of physical space that imaging data was recorded from.
    datasets:
    - name: origin_coordinates
      dtype: float64
      dims:
        - - x, y, z
      shape:
        - - 3
      doc: Physical location in stereotactic coordinates for the first element of the grid.
        See reference_frame to determine what the coordinates are relative to (e.g., bregma).
      quantity: '?'
      attributes:
        - name: unit
          dtype: text
          default_value: micrometers
          doc: Measurement units for origin coordinates. The default value is 'micrometers'.

  - neurodata_type_def: PlanarImagingSpace
    neurodata_type_inc: ImagingSpace
    doc: Metadata about the 2-dimensional slice of physical space that imaging data was recorded from.
    datasets:
    - name: grid_spacing
      dtype: float64
      dims:
        - - x, y
      shape:
        - - 2
      doc: Amount of space between pixels in the specified unit.
        Specify 'z' only when imaging volume is a regular grid; otherwise only specify 'x' and 'y'.
        See origin_coordinates to determine where the grid begins.
      quantity: '?'
      attributes:
        - name: unit
          dtype: text
          default_value: micrometers
          doc: Measurement units for grid spacing. The default value is 'micrometers'.

After doing some digging, I found that because ImagingSpec.origin_coordinates has an attribute unit and PlanarImagingSpace.grid_spacing also has an attribute unit, that when determining whether PlanarImagingSpace.grid_spacing.unit is inherited or not, HDMF says yes it is inherited because when ImagingSpec.origin_coordinates is inherited and it has an attribute with the same name, unit. That is not correct.

I have a fix.

Steps to Reproduce

Install ndx-microscopy linked above. Uncomment `unit` attribute spec on the `PlanarImagingSpace` spec. Instantiate a `PlanarImagingSpace` with `grid_spacing__unit="unit"`

Traceback

No response

Operating System

macOS

Python Executable

Conda

Python Version

3.12

Package Versions

No response

mavaylon1 commented 1 month ago

Thanks for diving into this! @rly