Skip to content

Commit

Permalink
Merge pull request #313 from bluesky/309-add-not-required-things-to-d…
Browse files Browse the repository at this point in the history
…atakey-schema

removed `Optional` on the specified datakey fields
  • Loading branch information
evalott100 authored Sep 23, 2024
2 parents a2f134c + 2d0bf2d commit 3c9ce76
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 61 deletions.
2 changes: 2 additions & 0 deletions event_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import numpy
from typing_extensions import Literal

from .documents import Dtype
from .documents.datum import Datum
from .documents.datum_page import DatumPage
from .documents.event import Event
Expand Down Expand Up @@ -61,6 +62,7 @@


__all__ = [
"Dtype",
"DocumentNames",
"schemas",
"schema_validators",
Expand Down
10 changes: 9 additions & 1 deletion event_model/documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from event_model.documents.datum import Datum
from event_model.documents.datum_page import DatumPage
from event_model.documents.event import Event
from event_model.documents.event_descriptor import EventDescriptor
from event_model.documents.event_descriptor import (
Dtype,
EventDescriptor,
Limits,
LimitsRange,
)
from event_model.documents.event_page import EventPage
from event_model.documents.resource import Resource
from event_model.documents.run_start import RunStart
Expand Down Expand Up @@ -42,9 +47,12 @@
__all__ = [
"Datum",
"DatumPage",
"Dtype",
"Event",
"EventDescriptor",
"EventPage",
"Limits",
"LimitsRange",
"Resource",
"RunStart",
"RunStop",
Expand Down
25 changes: 23 additions & 2 deletions event_model/documents/event_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,30 @@
Dtype = Literal["string", "number", "array", "boolean", "integer"]


class LimitsRange(TypedDict):
low: Optional[float]
high: Optional[float]


class Limits(TypedDict):
"""
Epics limits:
see 3.4.1 https://epics.anl.gov/base/R3-14/12-docs/AppDevGuide/node4.html
"""

control: NotRequired[Annotated[LimitsRange, Field(description="Control limits.")]]
display: NotRequired[Annotated[LimitsRange, Field(description="Display limits.")]]
warning: NotRequired[Annotated[LimitsRange, Field(description="Warning limits.")]]
alarm: NotRequired[Annotated[LimitsRange, Field(description="Alarm limits.")]]


class DataKey(TypedDict):
"""Describes the objects in the data property of Event documents"""

limits: NotRequired[Annotated[Limits, Field(description="Epics limits.")]]
choices: NotRequired[
Annotated[List[str], Field(description="Choices of enum value.")]
]
dims: NotRequired[
Annotated[
List[str],
Expand Down Expand Up @@ -41,7 +62,7 @@ class DataKey(TypedDict):
]
precision: NotRequired[
Annotated[
Optional[int],
int,
Field(
description="Number of digits after decimal place if "
"a floating point number"
Expand All @@ -56,7 +77,7 @@ class DataKey(TypedDict):
str, Field(description="The source (ex piece of hardware) of the data.")
]
units: NotRequired[
Annotated[Optional[str], Field(description="Engineering units of the value")]
Annotated[str, Field(description="Engineering units of the value")]
]


Expand Down
6 changes: 1 addition & 5 deletions event_model/schemas/datum_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
"properties": {
"datum_id": {
"description": "Array unique identifiers for each Datum (akin to 'uid' for other Document types), typically formatted as '<resource>/<integer>'",
"allOf": [
{
"$ref": "#/$defs/DataFrameForDatumPage"
}
]
"$ref": "#/$defs/DataFrameForDatumPage"
},
"datum_kwargs": {
"title": "Datum Kwargs",
Expand Down
77 changes: 65 additions & 12 deletions event_model/schemas/event_descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
"description": "Describes the objects in the data property of Event documents",
"type": "object",
"properties": {
"choices": {
"title": "Choices",
"description": "Choices of enum value.",
"type": "array",
"items": {
"type": "string"
}
},
"dims": {
"title": "Dims",
"description": "The names for dimensions of the data. Null or empty list if scalar data",
Expand All @@ -58,6 +66,10 @@
"type": "string",
"pattern": "^[A-Z]+:?"
},
"limits": {
"description": "Epics limits.",
"$ref": "#/$defs/Limits"
},
"object_name": {
"title": "Object Name",
"description": "The name of the object this key was pulled from.",
Expand All @@ -66,14 +78,7 @@
"precision": {
"title": "Precision",
"description": "Number of digits after decimal place if a floating point number",
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
]
"type": "integer"
},
"shape": {
"title": "Shape",
Expand All @@ -91,9 +96,58 @@
"units": {
"title": "Units",
"description": "Engineering units of the value",
"type": "string"
}
},
"required": [
"dtype",
"shape",
"source"
]
},
"Limits": {
"title": "Limits",
"description": "Epics limits:\nsee 3.4.1 https://epics.anl.gov/base/R3-14/12-docs/AppDevGuide/node4.html",
"type": "object",
"properties": {
"alarm": {
"description": "Alarm limits.",
"$ref": "#/$defs/LimitsRange"
},
"control": {
"description": "Control limits.",
"$ref": "#/$defs/LimitsRange"
},
"display": {
"description": "Display limits.",
"$ref": "#/$defs/LimitsRange"
},
"warning": {
"description": "Warning limits.",
"$ref": "#/$defs/LimitsRange"
}
}
},
"LimitsRange": {
"title": "LimitsRange",
"type": "object",
"properties": {
"high": {
"title": "High",
"anyOf": [
{
"type": "string"
"type": "number"
},
{
"type": "null"
}
]
},
"low": {
"title": "Low",
"anyOf": [
{
"type": "number"
},
{
"type": "null"
Expand All @@ -102,9 +156,8 @@
}
},
"required": [
"dtype",
"shape",
"source"
"high",
"low"
]
},
"PerObjectHint": {
Expand Down
18 changes: 3 additions & 15 deletions event_model/schemas/event_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@
"properties": {
"data": {
"description": "The actual measurement data",
"allOf": [
{
"$ref": "#/$defs/DataFrameForEventPage"
}
]
"$ref": "#/$defs/DataFrameForEventPage"
},
"descriptor": {
"title": "Descriptor",
Expand All @@ -45,11 +41,7 @@
},
"filled": {
"description": "Mapping each of the keys of externally-stored data to an array containing the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded)",
"allOf": [
{
"$ref": "#/$defs/DataFrameForFilled"
}
]
"$ref": "#/$defs/DataFrameForFilled"
},
"seq_num": {
"title": "Seq Num",
Expand All @@ -69,11 +61,7 @@
},
"timestamps": {
"description": "The timestamps of the individual measurement data",
"allOf": [
{
"$ref": "#/$defs/DataFrameForEventPage"
}
]
"$ref": "#/$defs/DataFrameForEventPage"
},
"uid": {
"title": "Uid",
Expand Down
12 changes: 2 additions & 10 deletions event_model/schemas/run_start.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@
"calculation": {
"title": "calculation properties",
"description": "required fields if type is calculated",
"allOf": [
{
"$ref": "#/$defs/Calculation"
}
]
"$ref": "#/$defs/Calculation"
},
"config_device": {
"title": "Config Device",
Expand Down Expand Up @@ -289,11 +285,7 @@
},
"data_type": {
"description": "",
"allOf": [
{
"$ref": "#/$defs/DataType"
}
]
"$ref": "#/$defs/DataType"
},
"group": {
"title": "Group",
Expand Down
6 changes: 1 addition & 5 deletions event_model/schemas/run_stop.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
"properties": {
"data_type": {
"description": "data_type",
"allOf": [
{
"$ref": "#/$defs/DataType"
}
]
"$ref": "#/$defs/DataType"
},
"exit_status": {
"title": "Exit Status",
Expand Down
12 changes: 2 additions & 10 deletions event_model/schemas/stream_datum.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,11 @@
},
"indices": {
"description": "A slice object passed to the StreamResource handler so it can hand back data and timestamps",
"allOf": [
{
"$ref": "#/$defs/StreamRange"
}
]
"$ref": "#/$defs/StreamRange"
},
"seq_nums": {
"description": "A slice object showing the Event numbers the resource corresponds to",
"allOf": [
{
"$ref": "#/$defs/StreamRange"
}
]
"$ref": "#/$defs/StreamRange"
},
"stream_resource": {
"title": "Stream Resource",
Expand Down
2 changes: 1 addition & 1 deletion event_model/tests/test_em.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_compose_run():
assert bundle.compose_stop is compose_stop
bundle = compose_descriptor(
data_keys={
"motor": {"shape": [], "dtype": "number", "source": "...", "units": None},
"motor": {"shape": [], "dtype": "number", "source": "...", "units": "s"},
"image": {
"shape": [512, 512],
"dtype": "number",
Expand Down

0 comments on commit 3c9ce76

Please sign in to comment.