Skip to content

Commit

Permalink
ENH: add dtype_str and dtype_descr to descriptor schema
Browse files Browse the repository at this point in the history
  • Loading branch information
tacaswell committed Sep 10, 2021
1 parent c912871 commit 956bf30
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 22 deletions.
24 changes: 24 additions & 0 deletions event_model/schemas/event_descriptor.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"definitions": {
"np_dtype": {
"title": "nd_dtype",
"type": ["array", "string"],
"pattern": "[|<>][tbiufcmMOSUV][0-9]+",
"items": {
"type": "array",
"items": [{"type": "string"}, {"$ref": "#/definitions/np_dtype"}],
"additionalItems": {"type": "array", "items": {"type":"integer"}}
}
},
"data_key": {
"title": "data_key",
"description": "Describes the objects in the data property of Event documents",
Expand All @@ -15,6 +25,20 @@
"type": "string",
"description": "The type of the data in the event."
},
"dtype_str" : {
"type": "string",
"description": "The __array_protocol__ typestring of the 'inner' data",
"pattern": "[|<>][tbiufcmMOSUV][0-9]+"
},
"dtype_descr" : {
"type": "array",
"description": "The __array_protocol__ description of the 'inner' data. This maybe nested.",
"items": {
"type": "array",
"items": [{"type": "string"}, {"$ref": "#/definitions/np_dtype"}],
"additionalItems": {"type": "array", "items": {"type":"integer"}}
}
},
"external": {
"pattern": "^[A-Z]+:?",
"type": "string",
Expand Down
62 changes: 40 additions & 22 deletions event_model/tests/test_em.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from distutils.version import LooseVersion
import json
import pickle
import numpy as np


import event_model
import jsonschema
import numpy
import pytest

from event_model._numpy import infer_datakeys

JSONSCHEMA_2 = LooseVersion(jsonschema.__version__) < LooseVersion("3.0.0")

Expand Down Expand Up @@ -46,39 +48,55 @@ def test_compose_run():
assert bundle.compose_descriptor is compose_descriptor
assert bundle.compose_resource is compose_resource
assert bundle.compose_stop is compose_stop
motor_data = 5.0
counter_data = 10
image_data = np.zeros((512, 512))
bundle = compose_descriptor(
data_keys={'motor': {'shape': [], 'dtype': 'number', 'source': '...'},
'image': {'shape': [512, 512], 'dtype': 'array',
'source': '...', 'external': 'FILESTORE:'}},
name='primary')
data_keys={
"motor": {"source": "...", **infer_datakeys(motor_data)},
"counter": {"source": "...", **infer_datakeys(counter_data)},
"image": {
**infer_datakeys(image_data),
"source": "...",
"external": "FILESTORE:",
},
},
name="primary",
)
descriptor_doc, compose_event, compose_event_page = bundle
assert bundle.descriptor_doc is descriptor_doc
assert bundle.compose_event is compose_event
assert bundle.compose_event_page is compose_event_page
bundle = compose_resource(
spec='TIFF', root='/tmp', resource_path='stack.tiff',
resource_kwargs={})
spec="TIFF", root="/tmp", resource_path="stack.tiff", resource_kwargs={}
)
resource_doc, compose_datum, compose_datum_page = bundle
assert bundle.resource_doc is resource_doc
assert bundle.compose_datum is compose_datum
assert bundle.compose_datum_page is compose_datum_page
datum_doc = compose_datum(datum_kwargs={'slice': 5})
datum_doc = compose_datum(datum_kwargs={"slice": 5})
event_doc = compose_event(
data={'motor': 0, 'image': datum_doc['datum_id']},
timestamps={'motor': 0, 'image': 0}, filled={'image': False})
datum_page = compose_datum_page(datum_kwargs={'slice': [10, 15]})
event_page = compose_event_page(data={'motor': [1, 2], 'image':
datum_page['datum_id']},
timestamps={'motor': [0, 0],
'image': [0, 0]},
filled={'image': [False, False]},
seq_num=[1, 2])
assert 'descriptor' in event_doc
assert 'descriptor' in event_page
assert event_doc['seq_num'] == 1
data={"motor": 0.0, "counter": 1, "image": datum_doc["datum_id"]},
timestamps={"motor": 0, "counter": 0, "image": 0},
filled={"image": False},
)
datum_page = compose_datum_page(datum_kwargs={"slice": [10, 15]})
event_page = compose_event_page(
data={
"motor": [1.0, 2.0],
"image": datum_page["datum_id"],
"counter": [10, 11],
},
timestamps={"motor": [0, 0], "image": [0, 0], "counter": [0, 0]},
filled={"image": [False, False]},
seq_num=[1, 2],
)
assert "descriptor" in event_doc
assert "descriptor" in event_page
assert event_doc["seq_num"] == 1
stop_doc = compose_stop()
assert 'primary' in stop_doc['num_events']
assert stop_doc['num_events']['primary'] == 3
assert "primary" in stop_doc["num_events"]
assert stop_doc["num_events"]["primary"] == 3


def test_round_trip_pagination():
Expand Down

0 comments on commit 956bf30

Please sign in to comment.