Skip to content

Commit 2ca9c98

Browse files
authored
Merge pull request #181 from linkml/first-class-arrays
First pass at native NDArray support.
2 parents 62841e4 + e04e027 commit 2ca9c98

File tree

8 files changed

+231
-9
lines changed

8 files changed

+231
-9
lines changed

linkml_model/model/schema/array.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ classes:
6363
slots:
6464
- axis
6565
- array
66+
see_also:
67+
- https://docs.xarray.dev/en/stable/generated/xarray.DataArray.html
6668

6769
GroupingByArrayOrder:
6870
mixin: true

linkml_model/model/schema/meta.yaml

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ description: |-
2929
[https://w3id.org/linkml/is_a](https://w3id.org/linkml/is_a)
3030
3131
license: https://creativecommons.org/publicdomain/zero/1.0/
32-
version: 2.0.0
3332

3433
prefixes:
3534
linkml: https://w3id.org/linkml/
@@ -1419,6 +1418,62 @@ slots:
14191418
- BasicSubset
14201419
- ObjectOrientedProfile
14211420

1421+
array:
1422+
domain: slot_definition
1423+
range: array_expression
1424+
inherited: true
1425+
description: coerces the value of the slot into an array and defines the dimensions of that array
1426+
status: testing
1427+
1428+
dimensions:
1429+
aliases:
1430+
- axes
1431+
description: definitions of each axis in the array
1432+
domain: array_expression
1433+
range: dimension_expression
1434+
multivalued: true
1435+
list_elements_ordered: true
1436+
status: testing
1437+
1438+
minimum_number_dimensions:
1439+
description: minimum number of dimensions in the array
1440+
domain: array_expression
1441+
range: integer
1442+
status: testing
1443+
# minimum_value: 1
1444+
comments:
1445+
- minimum_cardinality cannot be greater than maximum_cardinality
1446+
1447+
maximum_number_dimensions:
1448+
description: maximum number of dimensions in the array, or False if explicitly no maximum.
1449+
If this is unset, and an explicit list of dimensions are passed using dimensions, then this is interpreted
1450+
as a closed list and the maximum_number_dimensions is the length of the dimensions list, unless this
1451+
value is set to False
1452+
domain: array_expression
1453+
range: Anything
1454+
any_of:
1455+
- range: integer
1456+
# minimum_value: 1
1457+
- range: boolean
1458+
status: testing
1459+
comments:
1460+
- maximum_number_dimensions cannot be less than minimum_number_dimensions
1461+
1462+
exact_number_dimensions:
1463+
description: exact number of dimensions in the array
1464+
domain: array_expression
1465+
range: integer
1466+
status: testing
1467+
# minimum_value: 1
1468+
comments:
1469+
- if exact_number_dimensions is set, then minimum_number_dimensions and maximum_number_dimensions must be unset or have the same value
1470+
1471+
has_extra_dimensions:
1472+
description: If this is set to true
1473+
domain: array_expression
1474+
range: boolean
1475+
status: testing
1476+
14221477
inherited:
14231478
domain: slot_definition
14241479
range: boolean
@@ -1520,13 +1575,26 @@ slots:
15201575
in_subset:
15211576
- SpecificationSubset
15221577

1578+
exact_cardinality:
1579+
is_a: list_value_specification_constant
1580+
range: integer
1581+
inherited: true
1582+
description: the exact number of entries for a multivalued slot
1583+
in_subset:
1584+
- SpecificationSubset
1585+
comments:
1586+
- if exact_cardinality is set, then minimum_cardinalty and maximum_cardinality must be unset or have the same value
1587+
15231588
minimum_cardinality:
15241589
is_a: list_value_specification_constant
15251590
range: integer
15261591
inherited: true
15271592
description: the minimum number of entries for a multivalued slot
15281593
in_subset:
15291594
- SpecificationSubset
1595+
# minimum_value: 0
1596+
comments:
1597+
- minimum_cardinality cannot be greater than maximum_cardinality
15301598

15311599
maximum_cardinality:
15321600
is_a: list_value_specification_constant
@@ -1535,6 +1603,9 @@ slots:
15351603
description: the maximum number of entries for a multivalued slot
15361604
in_subset:
15371605
- SpecificationSubset
1606+
comments:
1607+
- maximum_cardinality cannot be less than minimum_cardinality
1608+
# minimum_value: 0
15381609

15391610
equals_string_in:
15401611
is_a: list_value_specification_constant
@@ -2714,6 +2785,7 @@ classes:
27142785
- equals_string_in
27152786
- equals_number
27162787
- equals_expression
2788+
- exact_cardinality
27172789
- minimum_cardinality
27182790
- maximum_cardinality
27192791
- has_member
@@ -2758,6 +2830,7 @@ classes:
27582830
- domain
27592831
- slot_uri
27602832
- multivalued
2833+
- array
27612834
- inherited
27622835
- readonly
27632836
- ifabsent
@@ -2916,6 +2989,33 @@ classes:
29162989
in_subset:
29172990
- SpecificationSubset
29182991

2992+
array_expression:
2993+
description: defines the dimensions of an array
2994+
mixins:
2995+
- extensible
2996+
- annotatable
2997+
- common_metadata
2998+
slots:
2999+
- exact_number_dimensions
3000+
- minimum_number_dimensions
3001+
- maximum_number_dimensions
3002+
- has_extra_dimensions
3003+
- dimensions
3004+
status: testing
3005+
3006+
dimension_expression:
3007+
description: defines one of the dimensions of an array
3008+
mixins:
3009+
- extensible
3010+
- annotatable
3011+
- common_metadata
3012+
slots:
3013+
- alias
3014+
- maximum_cardinality
3015+
- minimum_cardinality
3016+
- exact_cardinality
3017+
status: testing
3018+
29193019
pattern_expression:
29203020
description: a regular expression pattern used to evaluate conformance of a string
29213021
mixins:

linkml_model/model/schema/types.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ id: https://w3id.org/linkml/types
44

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

98
prefixes:
109
linkml: https://w3id.org/linkml/

tests/input/examples/schema_definition-array-2.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classes:
2626
implements:
2727
- linkml:NDArray
2828
annotations:
29-
dimensions: 1
29+
dimensions: "1"
3030
# TODO abstract from children
3131

3232
IrregularlySampledTimestampSeries:
@@ -47,7 +47,7 @@ classes:
4747
unit:
4848
ucum_code: s
4949
annotations:
50-
dimensions: 1
50+
dimensions: "1"
5151

5252
RegularlySampledTimestampSeries:
5353
is_a: TimestampSeries
@@ -82,7 +82,7 @@ classes:
8282
unit:
8383
ucum_code: s
8484
annotations:
85-
dimensions: 1
85+
dimensions: "1"
8686

8787
Electrode:
8888
attributes:
@@ -106,7 +106,7 @@ classes:
106106
implements:
107107
- linkml:elements
108108
annotations:
109-
dimensions: 1
109+
dimensions: "1"
110110

111111
ElectricalDataMatrix:
112112
description: >-

tests/input/examples/schema_definition-dynamic-enums.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ enums:
163163
source_ontology: http://loinc.org
164164
source_nodes:
165165
- LP43571-6
166-
relationship_types: null
167166
is_direct: true
168167
include_self: true
169168
traverse_up: false

tests/input/examples/schema_definition-instantiates.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ classes:
4242
Reviewable:
4343
class_uri: mymetamodel:Reviewable
4444
attributes:
45-
description: an expert review of a schema element
46-
review: Review
45+
description:
46+
description: an expert review of a schema element
47+
review:
48+
description: Review
4749

4850
Review:
4951
class_uri: mymetamodel:Review
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
id: https://example.org/arrays
2+
name: arrays-temperature-example
3+
title: Array Temperature Example
4+
description: |-
5+
Example LinkML schema to demonstrate a 3D DataArray of temperature values with labeled axes
6+
license: MIT
7+
8+
prefixes:
9+
linkml: https://w3id.org/linkml/
10+
wgs84: http://www.w3.org/2003/01/geo/wgs84_pos#
11+
example: https://example.org/
12+
13+
default_prefix: example
14+
15+
imports:
16+
- linkml:types
17+
18+
classes:
19+
20+
TemperatureDataset:
21+
tree_root: true
22+
annotations:
23+
array_data_mapping:
24+
data: temperatures_in_K
25+
dims: [x, y, t]
26+
coords:
27+
latitude_in_deg: x
28+
longitude_in_deg: y
29+
time_in_d: t
30+
attributes:
31+
name:
32+
identifier: true
33+
range: string
34+
latitude_in_deg:
35+
required: true
36+
range: float
37+
multivalued: true
38+
unit:
39+
ucum_code: deg
40+
array:
41+
exact_number_dimensions: 1
42+
longitude_in_deg:
43+
required: true
44+
range: float
45+
multivalued: true
46+
unit:
47+
ucum_code: deg
48+
array:
49+
exact_number_dimensions: 1
50+
time_in_d:
51+
range: float
52+
multivalued: true
53+
implements:
54+
- linkml:elements
55+
required: true
56+
unit:
57+
ucum_code: d
58+
array:
59+
exact_number_dimensions: 1
60+
temperatures_in_K:
61+
range: float
62+
multivalued: true
63+
required: true
64+
unit:
65+
ucum_code: K
66+
array:
67+
exact_number_dimensions: 3
68+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
id: https://example.org/arrays
2+
name: arrays-temperature-example
3+
title: Array Temperature Example
4+
description: |-
5+
Example LinkML schema to demonstrate a 3D DataArray of temperature values with labeled axes
6+
license: MIT
7+
8+
prefixes:
9+
linkml: https://w3id.org/linkml/
10+
wgs84: http://www.w3.org/2003/01/geo/wgs84_pos#
11+
example: https://example.org/
12+
13+
default_prefix: example
14+
15+
imports:
16+
- linkml:types
17+
18+
classes:
19+
20+
RGBImage:
21+
attributes:
22+
rgb:
23+
range: float
24+
array:
25+
# NPtyping: NDArray[Shape["* x, * y, 3 rgb"]
26+
exact_number_dimensions: 3
27+
dimensions:
28+
- alias: x
29+
- alias: y
30+
- alias: rgb
31+
exact_cardinality: 3
32+
description: r, g, b values
33+
annotations:
34+
names: "[red, green, blue]"
35+
SquareDataset:
36+
attributes:
37+
square_matrix:
38+
array:
39+
exact_number_dimensions: 2
40+
dimensions:
41+
- alias: x
42+
- alias: y
43+
44+
UnboundedTimeSeries:
45+
attributes:
46+
my_matrix:
47+
range: float
48+
array:
49+
dimensions:
50+
- alias: time
51+
maximum_number_dimensions: False
52+

0 commit comments

Comments
 (0)