Skip to content

Commit

Permalink
Merge pull request #181 from linkml/first-class-arrays
Browse files Browse the repository at this point in the history
First pass at native NDArray support.
  • Loading branch information
cmungall authored Feb 8, 2024
2 parents 62841e4 + e04e027 commit 2ca9c98
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 9 deletions.
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 @@ -29,7 +29,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 @@ -1419,6 +1418,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

inherited:
domain: slot_definition
range: boolean
Expand Down Expand Up @@ -1520,13 +1575,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

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 @@ -1535,6 +1603,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 @@ -2714,6 +2785,7 @@ classes:
- equals_string_in
- equals_number
- equals_expression
- exact_cardinality
- minimum_cardinality
- maximum_cardinality
- has_member
Expand Down Expand Up @@ -2758,6 +2830,7 @@ classes:
- domain
- slot_uri
- multivalued
- array
- inherited
- readonly
- ifabsent
Expand Down Expand Up @@ -2916,6 +2989,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
- 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
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:
attributes:
square_matrix:
array:
exact_number_dimensions: 2
dimensions:
- alias: x
- alias: y

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

0 comments on commit 2ca9c98

Please sign in to comment.