diff --git a/src/event_model/basemodels/event.py b/src/event_model/basemodels/event.py index 1aff0be4..120a83da 100644 --- a/src/event_model/basemodels/event.py +++ b/src/event_model/basemodels/event.py @@ -9,9 +9,9 @@ class PartialEvent(BaseModel): data: Annotated[Dict[str, Any], Field(description="The actual measurement data")] filled: Annotated[ - Union[Dict[str, Union[bool, str]], None], + Dict[str, Union[bool, str]], Field( - default=None, + default_factory=dict, description="Mapping each of the keys of externally-stored data to the " "boolean False, indicating that the data has not been loaded, or to " "foreign keys (moved here from 'data' when the data was loaded)", diff --git a/src/event_model/basemodels/event_descriptor.py b/src/event_model/basemodels/event_descriptor.py index a125f81c..eda9553f 100644 --- a/src/event_model/basemodels/event_descriptor.py +++ b/src/event_model/basemodels/event_descriptor.py @@ -6,6 +6,7 @@ Field, RootModel, ) +from pydantic.config import JsonDict from typing_extensions import Annotated, Literal Dtype = Literal["string", "number", "array", "boolean", "integer"] @@ -172,7 +173,7 @@ class Configuration(BaseModel): ] -EVENT_DESCRIPTOR_EXTRA_SCHEMA = { +EVENT_DESCRIPTOR_EXTRA_SCHEMA: JsonDict = { "patternProperties": {"^([^./]+)$": {"$ref": "#/$defs/DataType"}}, "$defs": { "DataType": { @@ -202,18 +203,17 @@ class EventDescriptor(BaseModel): ), ] data_keys: Annotated[ - Union[Dict[str, DataKey], None], + Dict[str, DataKey], Field( - default=None, description="This describes the data in the Event Documents.", title="data_keys", ), ] hints: Annotated[Union[PerObjectHint, None], Field(default=None)] name: Annotated[ - Union[str, None], + str, Field( - default=None, + default="", description="A human-friendly name for this data stream, such as " "'primary' or 'baseline'.", ), diff --git a/src/event_model/basemodels/event_page.py b/src/event_model/basemodels/event_page.py index e71f2911..3cb5d38e 100644 --- a/src/event_model/basemodels/event_page.py +++ b/src/event_model/basemodels/event_page.py @@ -1,20 +1,14 @@ -from typing import Dict, List, Optional, Union +from typing import Dict, List, Union from pydantic import ( BaseModel, ConfigDict, Field, - RootModel, ) from typing_extensions import Annotated - -class DataFrameForFilled(RootModel): - root: Dict[str, List[Union[bool, str]]] = Field(alias="DataframeForFilled") - - -class DataFrameForEventPage(RootModel): - root: Dict[str, List] = Field(alias="Dataframe") +DataFrameForFilled = Dict[str, List[Union[bool, str]]] +DataFrameForEventPage = Dict[str, List] class PartialEventPage(BaseModel): @@ -25,13 +19,13 @@ class PartialEventPage(BaseModel): Field(description="The actual measurement data"), ] filled: Annotated[ - Optional[DataFrameForFilled], + DataFrameForFilled, Field( 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)", - default=None, + default={}, ), ] timestamps: Annotated[ diff --git a/src/event_model/basemodels/run_start.py b/src/event_model/basemodels/run_start.py index 416321e3..cfd016c8 100644 --- a/src/event_model/basemodels/run_start.py +++ b/src/event_model/basemodels/run_start.py @@ -6,6 +6,7 @@ Field, RootModel, ) +from pydantic.config import JsonDict from typing_extensions import Annotated, Literal @@ -121,7 +122,7 @@ class StaticProjection(BaseModel): ] -RUN_START_EXTRA_SCHEMA = { +RUN_START_EXTRA_SCHEMA: JsonDict = { "$defs": { "DataType": { "patternProperties": {"^([^./]+)$": {"$ref": "#/$defs/DataType"}}, diff --git a/src/event_model/basemodels/run_stop.py b/src/event_model/basemodels/run_stop.py index 6e50d509..b0dfca1b 100644 --- a/src/event_model/basemodels/run_stop.py +++ b/src/event_model/basemodels/run_stop.py @@ -1,11 +1,7 @@ from typing import Any, Dict, Optional -from pydantic import ( - BaseModel, - ConfigDict, - Field, - RootModel, -) +from pydantic import BaseModel, ConfigDict, Field, RootModel +from pydantic.config import JsonDict from typing_extensions import Annotated, Literal @@ -13,7 +9,7 @@ class DataType(RootModel): root: Any = Field(alias="DataType") -RUN_STOP_EXTRA_SCHEMA = { +RUN_STOP_EXTRA_SCHEMA: JsonDict = { "patternProperties": {"^([^./]+)$": {"$ref": "#/$defs/DataType"}}, "additionalProperties": False, } diff --git a/src/event_model/basemodels/stream_resource.py b/src/event_model/basemodels/stream_resource.py index 46d398e1..7a9e9aa4 100644 --- a/src/event_model/basemodels/stream_resource.py +++ b/src/event_model/basemodels/stream_resource.py @@ -30,6 +30,7 @@ class StreamResource(BaseModel): Field( description="Globally unique ID to the run_start document " "this Stream Resource is associated with.", + default="", ), ] mimetype: Annotated[ diff --git a/src/event_model/documents/event.py b/src/event_model/documents/event.py index 27da0106..8cde9c44 100644 --- a/src/event_model/documents/event.py +++ b/src/event_model/documents/event.py @@ -1,11 +1,12 @@ # ruff: noqa # generated by datamodel-codegen: # filename: event.json -# timestamp: 2024-12-18T10:56:19+00:00 +# timestamp: 2024-12-19T11:24:47+00:00 from __future__ import annotations -from typing import Any, Dict, Optional, TypedDict, Union +from typing import Any, Dict, TypedDict, Union, Annotated +from pydantic import Field from typing_extensions import NotRequired @@ -23,7 +24,7 @@ class Event(TypedDict): """ UID of the EventDescriptor to which this Event belongs """ - filled: NotRequired[Optional[Dict[str, Union[bool, str]]]] + filled: NotRequired[Dict[str, Union[bool, str]]] """ Mapping each of the keys of externally-stored data to the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded) """ diff --git a/src/event_model/documents/event_descriptor.py b/src/event_model/documents/event_descriptor.py index 24aad97f..0e626222 100644 --- a/src/event_model/documents/event_descriptor.py +++ b/src/event_model/documents/event_descriptor.py @@ -1,7 +1,7 @@ # ruff: noqa # generated by datamodel-codegen: # filename: event_descriptor.json -# timestamp: 2024-12-18T11:01:13+00:00 +# timestamp: 2024-12-19T11:40:22+00:00 from __future__ import annotations @@ -141,12 +141,12 @@ class EventDescriptor(TypedDict): """ Readings of configurational fields necessary for interpreting data in the Events. """ - data_keys: NotRequired[Optional[Dict[str, DataKey]]] + data_keys: Dict[str, DataKey] """ This describes the data in the Event Documents. """ hints: NotRequired[Optional[PerObjectHint]] - name: NotRequired[Optional[str]] + name: NotRequired[str] """ A human-friendly name for this data stream, such as 'primary' or 'baseline'. """ diff --git a/src/event_model/documents/event_page.py b/src/event_model/documents/event_page.py index b93afe8f..e654d9a1 100644 --- a/src/event_model/documents/event_page.py +++ b/src/event_model/documents/event_page.py @@ -1,26 +1,21 @@ # ruff: noqa # generated by datamodel-codegen: # filename: event_page.json -# timestamp: 2024-12-18T10:56:19+00:00 +# timestamp: 2024-12-19T14:19:55+00:00 from __future__ import annotations -from typing import Dict, List, Optional, TypedDict, Union +from typing import Dict, List, TypedDict, Union from typing_extensions import NotRequired -DataFrameForEventPage = Optional[Dict[str, List]] - - -DataFrameForFilled = Optional[Dict[str, List[Union[bool, str]]]] - class EventPage(TypedDict): """ Page of documents to record a quanta of collected data """ - data: DataFrameForEventPage + data: Dict[str, List] """ The actual measurement data """ @@ -28,7 +23,7 @@ class EventPage(TypedDict): """ The UID of the EventDescriptor to which all of the Events in this page belong """ - filled: NotRequired[Optional[DataFrameForFilled]] + filled: NotRequired[Dict[str, List[Union[bool, str]]]] """ 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) """ @@ -40,7 +35,7 @@ class EventPage(TypedDict): """ Array of Event times. This maybe different than the timestamps on each of the data entries """ - timestamps: DataFrameForEventPage + timestamps: Dict[str, List] """ The timestamps of the individual measurement data """ diff --git a/src/event_model/documents/partial_event.py b/src/event_model/documents/partial_event.py index d85ab298..8106b900 100644 --- a/src/event_model/documents/partial_event.py +++ b/src/event_model/documents/partial_event.py @@ -1,11 +1,11 @@ # ruff: noqa # generated by datamodel-codegen: # filename: partial_event.json -# timestamp: 2024-12-18T10:40:06+00:00 +# timestamp: 2024-12-19T11:24:47+00:00 from __future__ import annotations -from typing import Any, Dict, Optional, TypedDict, Union +from typing import Any, Dict, TypedDict, Union from typing_extensions import NotRequired @@ -15,7 +15,7 @@ class PartialEvent(TypedDict): """ The actual measurement data """ - filled: NotRequired[Optional[Dict[str, Union[bool, str]]]] + filled: NotRequired[Dict[str, Union[bool, str]]] """ Mapping each of the keys of externally-stored data to the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded) """ diff --git a/src/event_model/documents/partial_event_page.py b/src/event_model/documents/partial_event_page.py index 2d0055e3..727e8a22 100644 --- a/src/event_model/documents/partial_event_page.py +++ b/src/event_model/documents/partial_event_page.py @@ -1,26 +1,21 @@ # ruff: noqa # generated by datamodel-codegen: # filename: partial_event_page.json -# timestamp: 2024-12-18T10:56:19+00:00 +# timestamp: 2024-12-19T14:19:55+00:00 from __future__ import annotations -from typing import Dict, List, Optional, TypedDict, Union +from typing import Dict, List, TypedDict, Union from typing_extensions import NotRequired -DataFrameForEventPage = Optional[Dict[str, List]] - - -DataFrameForFilled = Optional[Dict[str, List[Union[bool, str]]]] - class PartialEventPage(TypedDict): - data: DataFrameForEventPage + data: Dict[str, List] """ The actual measurement data """ - filled: NotRequired[Optional[DataFrameForFilled]] + filled: NotRequired[Dict[str, List[Union[bool, str]]]] """ 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) """ @@ -28,7 +23,7 @@ class PartialEventPage(TypedDict): """ Array of Event times. This maybe different than the timestamps on each of the data entries """ - timestamps: DataFrameForEventPage + timestamps: Dict[str, List] """ The timestamps of the individual measurement data """ diff --git a/src/event_model/documents/stream_resource.py b/src/event_model/documents/stream_resource.py index 0733e0a0..b11b08ae 100644 --- a/src/event_model/documents/stream_resource.py +++ b/src/event_model/documents/stream_resource.py @@ -1,12 +1,14 @@ # ruff: noqa # generated by datamodel-codegen: # filename: stream_resource.json -# timestamp: 2024-12-18T10:56:19+00:00 +# timestamp: 2024-12-19T11:38:53+00:00 from __future__ import annotations from typing import Any, Dict, TypedDict +from typing_extensions import NotRequired + class StreamResource(TypedDict): """ @@ -26,7 +28,7 @@ class StreamResource(TypedDict): """ Additional keyword arguments to pass to the Handler to read a Stream Resource """ - run_start: str + run_start: NotRequired[str] """ Globally unique ID to the run_start document this Stream Resource is associated with. """ diff --git a/src/event_model/schemas/event.json b/src/event_model/schemas/event.json index f49fcfe0..a4798663 100644 --- a/src/event_model/schemas/event.json +++ b/src/event_model/schemas/event.json @@ -16,25 +16,17 @@ "filled": { "title": "Filled", "description": "Mapping each of the keys of externally-stored data to the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded)", - "anyOf": [ - { - "additionalProperties": { - "anyOf": [ - { - "type": "boolean" - }, - { - "type": "string" - } - ] + "type": "object", + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" }, - "type": "object" - }, - { - "type": "null" - } - ], - "default": null + { + "type": "string" + } + ] + } }, "seq_num": { "title": "Seq Num", diff --git a/src/event_model/schemas/event_descriptor.json b/src/event_model/schemas/event_descriptor.json index 01cd1460..ad507ebb 100644 --- a/src/event_model/schemas/event_descriptor.json +++ b/src/event_model/schemas/event_descriptor.json @@ -377,18 +377,10 @@ "data_keys": { "title": "data_keys", "description": "This describes the data in the Event Documents.", - "anyOf": [ - { - "additionalProperties": { - "$ref": "#/$defs/DataKey" - }, - "type": "object" - }, - { - "type": "null" - } - ], - "default": null + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/DataKey" + } }, "hints": { "anyOf": [ @@ -404,15 +396,8 @@ "name": { "title": "Name", "description": "A human-friendly name for this data stream, such as 'primary' or 'baseline'.", - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "default": null + "type": "string", + "default": "" }, "object_keys": { "title": "Object Keys", @@ -444,6 +429,7 @@ } }, "required": [ + "data_keys", "run_start", "time", "uid" diff --git a/src/event_model/schemas/event_page.json b/src/event_model/schemas/event_page.json index e61d067d..c52683bd 100644 --- a/src/event_model/schemas/event_page.json +++ b/src/event_model/schemas/event_page.json @@ -2,17 +2,24 @@ "title": "EventPage", "description": "Page of documents to record a quanta of collected data", "type": "object", - "$defs": { - "DataFrameForEventPage": { - "title": "DataFrameForEventPage", + "properties": { + "data": { + "title": "Data", + "description": "The actual measurement data", "type": "object", "additionalProperties": { "items": {}, "type": "array" } }, - "DataFrameForFilled": { - "title": "DataFrameForFilled", + "descriptor": { + "title": "Descriptor", + "description": "The UID of the EventDescriptor to which all of the Events in this page belong", + "type": "string" + }, + "filled": { + "title": "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)", "type": "object", "additionalProperties": { "items": { @@ -26,30 +33,8 @@ ] }, "type": "array" - } - } - }, - "properties": { - "data": { - "description": "The actual measurement data", - "$ref": "#/$defs/DataFrameForEventPage" - }, - "descriptor": { - "title": "Descriptor", - "description": "The UID of the EventDescriptor to which all of the Events in this page belong", - "type": "string" - }, - "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)", - "anyOf": [ - { - "$ref": "#/$defs/DataFrameForFilled" - }, - { - "type": "null" - } - ], - "default": null + }, + "default": {} }, "seq_num": { "title": "Seq Num", @@ -68,8 +53,13 @@ } }, "timestamps": { + "title": "Timestamps", "description": "The timestamps of the individual measurement data", - "$ref": "#/$defs/DataFrameForEventPage" + "type": "object", + "additionalProperties": { + "items": {}, + "type": "array" + } }, "uid": { "title": "Uid", diff --git a/src/event_model/schemas/partial_event.json b/src/event_model/schemas/partial_event.json index 74550e3f..74ce96ef 100644 --- a/src/event_model/schemas/partial_event.json +++ b/src/event_model/schemas/partial_event.json @@ -10,25 +10,17 @@ "filled": { "title": "Filled", "description": "Mapping each of the keys of externally-stored data to the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded)", - "anyOf": [ - { - "additionalProperties": { - "anyOf": [ - { - "type": "boolean" - }, - { - "type": "string" - } - ] + "type": "object", + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" }, - "type": "object" - }, - { - "type": "null" - } - ], - "default": null + { + "type": "string" + } + ] + } }, "time": { "title": "Time", diff --git a/src/event_model/schemas/partial_event_page.json b/src/event_model/schemas/partial_event_page.json index 946e746b..c7d05422 100644 --- a/src/event_model/schemas/partial_event_page.json +++ b/src/event_model/schemas/partial_event_page.json @@ -1,17 +1,19 @@ { "title": "PartialEventPage", "type": "object", - "$defs": { - "DataFrameForEventPage": { - "title": "DataFrameForEventPage", + "properties": { + "data": { + "title": "Data", + "description": "The actual measurement data", "type": "object", "additionalProperties": { "items": {}, "type": "array" } }, - "DataFrameForFilled": { - "title": "DataFrameForFilled", + "filled": { + "title": "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)", "type": "object", "additionalProperties": { "items": { @@ -25,25 +27,8 @@ ] }, "type": "array" - } - } - }, - "properties": { - "data": { - "description": "The actual measurement data", - "$ref": "#/$defs/DataFrameForEventPage" - }, - "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)", - "anyOf": [ - { - "$ref": "#/$defs/DataFrameForFilled" - }, - { - "type": "null" - } - ], - "default": null + }, + "default": {} }, "time": { "title": "Time", @@ -54,8 +39,13 @@ } }, "timestamps": { + "title": "Timestamps", "description": "The timestamps of the individual measurement data", - "$ref": "#/$defs/DataFrameForEventPage" + "type": "object", + "additionalProperties": { + "items": {}, + "type": "array" + } } }, "required": [ diff --git a/src/event_model/schemas/stream_resource.json b/src/event_model/schemas/stream_resource.json index f0fe14e0..b2b29e69 100644 --- a/src/event_model/schemas/stream_resource.json +++ b/src/event_model/schemas/stream_resource.json @@ -21,7 +21,8 @@ "run_start": { "title": "Run Start", "description": "Globally unique ID to the run_start document this Stream Resource is associated with.", - "type": "string" + "type": "string", + "default": "" }, "uid": { "title": "Uid", @@ -38,7 +39,6 @@ "data_key", "mimetype", "parameters", - "run_start", "uid", "uri" ]