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

First pass at native NDArray support. #181

Merged
merged 16 commits into from
Feb 8, 2024
2 changes: 2 additions & 0 deletions linkml_model/model/schema/array.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ classes:
slots:
- axis
- array
see_also:
- https://docs.xarray.dev/en/stable/generated/xarray.DataArray.html

GroupingByArrayOrder:
mixin: true
Expand Down
102 changes: 101 additions & 1 deletion linkml_model/model/schema/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ description: |-
[https://w3id.org/linkml/is_a](https://w3id.org/linkml/is_a)

license: https://creativecommons.org/publicdomain/zero/1.0/
version: 2.0.0

prefixes:
linkml: https://w3id.org/linkml/
Expand Down Expand Up @@ -1420,6 +1419,62 @@ slots:
- BasicSubset
- ObjectOrientedProfile

array:
domain: slot_definition
range: array_expression
inherited: true
description: coerces the value of the slot into an array and defines the dimensions of that array
status: testing

dimensions:
aliases:
- axes
description: definitions of each axis in the array
domain: array_expression
range: dimension_expression
multivalued: true
list_elements_ordered: true
status: testing

minimum_number_dimensions:
description: minimum number of dimensions in the array
domain: array_expression
range: integer
status: testing
# minimum_value: 1
comments:
- minimum_cardinality cannot be greater than maximum_cardinality

maximum_number_dimensions:
description: maximum number of dimensions in the array, or False if explicitly no maximum.
If this is unset, and an explicit list of dimensions are passed using dimensions, then this is interpreted
as a closed list and the maximum_number_dimensions is the length of the dimensions list, unless this
value is set to False
domain: array_expression
range: Anything
any_of:
- range: integer
# minimum_value: 1
- range: boolean
status: testing
comments:
- maximum_number_dimensions cannot be less than minimum_number_dimensions

exact_number_dimensions:
description: exact number of dimensions in the array
domain: array_expression
range: integer
status: testing
# minimum_value: 1
comments:
- if exact_number_dimensions is set, then minimum_number_dimensions and maximum_number_dimensions must be unset or have the same value

has_extra_dimensions:
description: If this is set to true
domain: array_expression
range: boolean
status: testing

Comment on lines +1472 to +1477
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
has_extra_dimensions:
description: If this is set to true
domain: array_expression
range: boolean
status: testing

inherited:
domain: slot_definition
range: boolean
Expand Down Expand Up @@ -1521,13 +1576,26 @@ slots:
in_subset:
- SpecificationSubset

exact_cardinality:
is_a: list_value_specification_constant
range: integer
inherited: true
description: the exact number of entries for a multivalued slot
in_subset:
- SpecificationSubset
comments:
- if exact_cardinality is set, then minimum_cardinalty and maximum_cardinality must be unset or have the same value

cmungall marked this conversation as resolved.
Show resolved Hide resolved
minimum_cardinality:
is_a: list_value_specification_constant
range: integer
inherited: true
description: the minimum number of entries for a multivalued slot
in_subset:
- SpecificationSubset
# minimum_value: 0
comments:
- minimum_cardinality cannot be greater than maximum_cardinality

maximum_cardinality:
is_a: list_value_specification_constant
Expand All @@ -1536,6 +1604,9 @@ slots:
description: the maximum number of entries for a multivalued slot
in_subset:
- SpecificationSubset
comments:
- maximum_cardinality cannot be less than minimum_cardinality
# minimum_value: 0

equals_string_in:
is_a: list_value_specification_constant
Expand Down Expand Up @@ -2715,6 +2786,7 @@ classes:
- equals_string_in
- equals_number
- equals_expression
- exact_cardinality
- minimum_cardinality
- maximum_cardinality
- has_member
Expand Down Expand Up @@ -2759,6 +2831,7 @@ classes:
- domain
- slot_uri
- multivalued
- array
- inherited
- readonly
- ifabsent
Expand Down Expand Up @@ -2917,6 +2990,33 @@ classes:
in_subset:
- SpecificationSubset

array_expression:
description: defines the dimensions of an array
mixins:
- extensible
- annotatable
- common_metadata
slots:
- exact_number_dimensions
- minimum_number_dimensions
- maximum_number_dimensions
- has_extra_dimensions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- has_extra_dimensions

- dimensions
status: testing

dimension_expression:
description: defines one of the dimensions of an array
mixins:
- extensible
- annotatable
- common_metadata
slots:
- alias
- maximum_cardinality
- minimum_cardinality
- exact_cardinality
status: testing

pattern_expression:
description: a regular expression pattern used to evaluate conformance of a string
mixins:
Expand Down
1 change: 0 additions & 1 deletion linkml_model/model/schema/types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ id: https://w3id.org/linkml/types

description: Shared type definitions for the core LinkML mode and metamodel
license: https://creativecommons.org/publicdomain/zero/1.0/
version: 2.0.0

prefixes:
linkml: https://w3id.org/linkml/
Expand Down
8 changes: 4 additions & 4 deletions tests/input/examples/schema_definition-array-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classes:
implements:
- linkml:NDArray
annotations:
dimensions: 1
dimensions: "1"
# TODO abstract from children

IrregularlySampledTimestampSeries:
Expand All @@ -47,7 +47,7 @@ classes:
unit:
ucum_code: s
annotations:
dimensions: 1
dimensions: "1"

RegularlySampledTimestampSeries:
is_a: TimestampSeries
Expand Down Expand Up @@ -82,7 +82,7 @@ classes:
unit:
ucum_code: s
annotations:
dimensions: 1
dimensions: "1"

Electrode:
attributes:
Expand All @@ -106,7 +106,7 @@ classes:
implements:
- linkml:elements
annotations:
dimensions: 1
dimensions: "1"

ElectricalDataMatrix:
description: >-
Expand Down
1 change: 0 additions & 1 deletion tests/input/examples/schema_definition-dynamic-enums.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ enums:
source_ontology: http://loinc.org
source_nodes:
- LP43571-6
relationship_types: null
is_direct: true
include_self: true
traverse_up: false
Expand Down
6 changes: 4 additions & 2 deletions tests/input/examples/schema_definition-instantiates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ classes:
Reviewable:
class_uri: mymetamodel:Reviewable
attributes:
description: an expert review of a schema element
review: Review
description:
description: an expert review of a schema element
review:
description: Review

Review:
class_uri: mymetamodel:Review
Expand Down
68 changes: 68 additions & 0 deletions tests/input/examples/schema_definition-native-array-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
id: https://example.org/arrays
name: arrays-temperature-example
title: Array Temperature Example
description: |-
Example LinkML schema to demonstrate a 3D DataArray of temperature values with labeled axes
license: MIT

prefixes:
linkml: https://w3id.org/linkml/
wgs84: http://www.w3.org/2003/01/geo/wgs84_pos#
example: https://example.org/

default_prefix: example

imports:
- linkml:types

classes:

TemperatureDataset:
tree_root: true
annotations:
array_data_mapping:
data: temperatures_in_K
dims: [x, y, t]
coords:
latitude_in_deg: x
longitude_in_deg: y
time_in_d: t
attributes:
name:
identifier: true
range: string
latitude_in_deg:
required: true
range: float
multivalued: true
unit:
ucum_code: deg
array:
exact_number_dimensions: 1
longitude_in_deg:
required: true
range: float
multivalued: true
unit:
ucum_code: deg
array:
exact_number_dimensions: 1
time_in_d:
range: float
multivalued: true
implements:
- linkml:elements
required: true
unit:
ucum_code: d
array:
exact_number_dimensions: 1
temperatures_in_K:
range: float
multivalued: true
required: true
unit:
ucum_code: K
array:
exact_number_dimensions: 3

52 changes: 52 additions & 0 deletions tests/input/examples/schema_definition-native-array-rgb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
id: https://example.org/arrays
name: arrays-temperature-example
title: Array Temperature Example
description: |-
Example LinkML schema to demonstrate a 3D DataArray of temperature values with labeled axes
license: MIT

prefixes:
linkml: https://w3id.org/linkml/
wgs84: http://www.w3.org/2003/01/geo/wgs84_pos#
example: https://example.org/

default_prefix: example

imports:
- linkml:types

classes:

RGBImage:
attributes:
rgb:
range: float
rly marked this conversation as resolved.
Show resolved Hide resolved
array:
# NPtyping: NDArray[Shape["* x, * y, 3 rgb"]
exact_number_dimensions: 3
dimensions:
- alias: x
- alias: y
- alias: rgb
exact_cardinality: 3
description: r, g, b values
annotations:
names: "[red, green, blue]"
SquareDataset:
rly marked this conversation as resolved.
Show resolved Hide resolved
attributes:
square_matrix:
rly marked this conversation as resolved.
Show resolved Hide resolved
array:
exact_number_dimensions: 2
dimensions:
- alias: x
- alias: y

UnboundedTimeSeries:
attributes:
my_matrix:
range: float
array:
dimensions:
- alias: time
maximum_number_dimensions: False

Loading