Skip to content

interpret max_cardinality and min_cardinality as axis size constraints? #5

Open
@sneakers-the-rat

Description

@sneakers-the-rat

Something that would be nice to have is the ability to constrain the size of an array. I think the example of a "video" type is a good motivating case - if we are accepting an RGB Video, we want to be able to express "x and y axes of any size, but channels == 3"

I used min_cardinality and max_cardinality in nwb-linkml for this, such that for an RGBImage one expresses the array component as (with minor adjustments to match linkml-array syntax):

RGBImage__Array:
  name: RGBImage__Array
  is_a: linkml:NDArray
  attributes:
    x:
      implements:
        - linkml:axis
      name: x
      range: numeric
      required: true
    y:
      implements:
        - linkml:axis
      name: y
      range: numeric
      required: true
    r, g, b:
      implements:
        - linkml:axis
      name: r, g, b
      range: numeric
      required: true
      minimum_cardinality: 3
      maximum_cardinality: 3

creates a pydantic model like this (i also collapse the array class into the parent class that has other attributes there, but you get the idea)

class RGBImage(Image):
    """
    A color image.
    """
    linkml_meta: ClassVar[LinkML_Meta] = Field(LinkML_Meta(tree_root=True), frozen=True)
    name: str = Field(...)
    array: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], Number]] = Field(None)
    resolution: Optional[float] = Field(None, description="""Pixel resolution of the image, in pixels per centimeter.""")
    description: Optional[str] = Field(None, description="""Description of the image.""")

what do y'all think about having that be the means of specifying array sizes? It seems to match the semantics of that slot as its used elsewhere, and so we basically get it for free right?

If there was one suggestion i'd make to a change to the metamodel, it's sort of awkward to have to specify both the max and min to say that cardinality should == a value, so it might be nice to change that to work like:

# cardinality is exactly three
cardinality: 3

# minimum only
cardinality:
  min: 3

# range
cardinality:
  min: 3
  max: 5

but that's just a "nice to have" not a critical thing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions