Skip to content

Commit

Permalink
First pass at native NDArray support.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmungall committed Feb 5, 2024
1 parent aab9842 commit f526171
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 4 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
65 changes: 65 additions & 0 deletions linkml_model/model/schema/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,34 @@ slots:
- BasicSubset
- ObjectOrientedProfile

array_shape:
domain: slot_definition
range: array_shape_expression
inherited: true
description: coerces the value of the slot into an array and defines the dimensions of that array

array_axes:
description: definitions of each axis in the array
domain: array_shape_expression
range: array_axis_expression
multivalued: true
inlined: true

minimum_dimensions:
description: minimum number of dimensions in the array
domain: array_shape_expression
range: integer

maximum_dimensions:
description: maximum number of dimensions in the array
domain: array_shape_expression
range: integer

exact_dimensions:
description: exact number of dimensions in the array
domain: array_shape_expression
range: integer

inherited:
domain: slot_definition
range: boolean
Expand Down Expand Up @@ -1521,6 +1549,14 @@ 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

minimum_cardinality:
is_a: list_value_specification_constant
range: integer
Expand Down Expand Up @@ -2715,6 +2751,7 @@ classes:
- equals_string_in
- equals_number
- equals_expression
- exact_cardinality
- minimum_cardinality
- maximum_cardinality
- has_member
Expand Down Expand Up @@ -2759,6 +2796,7 @@ classes:
- domain
- slot_uri
- multivalued
- array_shape
- inherited
- readonly
- ifabsent
Expand Down Expand Up @@ -2917,6 +2955,33 @@ classes:
in_subset:
- SpecificationSubset

array_shape_expression:
description: defines the dimensions of an array
mixins:
- extensible
- annotatable
- common_metadata
slots:
- exact_dimensions
- minimum_dimensions
- maximum_dimensions
- array_axes

array_axis_expression:
description: defines one of the dimensions of an array
mixins:
- extensible
- annotatable
- common_metadata
slots:
- name
- rank
- equals_expression
- alias
- maximum_cardinality
- minimum_cardinality
- exact_cardinality

pattern_expression:
description: a regular expression pattern used to evaluate conformance of a string
mixins:
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
70 changes: 70 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,70 @@
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
attributes:
name:
identifier: true
range: string
latitude_in_deg:
required: true
range: float
multivalued: true
unit:
ucum_code: deg
array_shape:
exact_dimensions: 1
longitude_in_deg:
required: true
range: float
multivalued: true
unit:
ucum_code: deg
array_shape:
exact_dimensions: 1
time_in_d:
range: float
multivalued: true
implements:
- linkml:elements
required: true
unit:
ucum_code: d
array_shape:
exact_dimensions: 1
temperatures_in_K:
range: float
multivalued: true
required: true
unit:
ucum_code: K
array_shape:
exact_dimensions: 3
array_axes:
x:
rank: 0
alias: latitude_in_deg
y:
rank: 1
alias: longitude_in_deg
t:
rank: 2
alias: time_in_d

37 changes: 37 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,37 @@
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:
x:
range: integer
y:
range: integer

rgb:
range: float
array_shape:
exact_dimensions: 3
array_axes:
x:
y:
rgb:
exact_cardinality: 3
description: r, g, b values

0 comments on commit f526171

Please sign in to comment.