Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpret max_cardinality and min_cardinality as axis size constraints? #5

Open
sneakers-the-rat opened this issue Feb 3, 2024 · 3 comments

Comments

@sneakers-the-rat
Copy link

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

@rly
Copy link
Collaborator

rly commented Feb 3, 2024

I used min_cardinality and max_cardinality

That makes sense and looks good to me.

I also think your suggested change to the metamodel would be nice. @cmungall what do you think?

@cmungall
Copy link
Member

cmungall commented Feb 3, 2024 via email

@sneakers-the-rat
Copy link
Author

Yes maybe i need to clear up how y'all are thinking about the DataArray axes, but wherever we would put them, in this case just suggesting these be the terms used (i figure y'all had probably already thought about this, just wanted to start the ball rolling on getting it in the model somehow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants