Skip to content

Commit

Permalink
Merge pull request #179 from dylanmcreynolds/projections
Browse files Browse the repository at this point in the history
Add projections schema to start doc
  • Loading branch information
danielballan authored Aug 11, 2020
2 parents cc4c340 + 2ca0aec commit 0c29664
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/source/data-model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ A typical example
Time is given in UNIX time (seconds since 1970). Software for looking at
the data would, of course, translate that into a more human-readable form.

Projections (Experimental):

The run_start metadata can include a projections field.
It is intended that a projection is an aid to interacting with external systems using standardized vocabularies.
Projections might be used in a variety of use cases such as providing run data to analysis tools or suitcases.
Each projection represents multiple ways to represent data from the run. Each field in the projection dictionary
is an unique and externally-identifiable string and each value is an instruction for accessing dat from the run.

The run start document formal schema:

.. literalinclude:: ../../event_model/schemas/run_start.json
Expand Down
40 changes: 40 additions & 0 deletions event_model/schemas/run_start.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@
"title" : "data_type",
"patternProperties": {"^([^./]+)$": {"$ref": "#/definitions/data_type"}},
"additionalProperties": false
},
"projection": {
"description": "Where to get the data from",
"type": "object",
"properties" : {
"type": {"type": "string", "enum": ["linked", "calculated", "static"], "description": "linked: a value linked from the data set, calculated: a value that requires calculation, static: a value defined here in the projection "},
"stream": {"type": "string"},
"location": {"enum" : ["event", "configuration"], "description": "event comes from event, configuration comes from fields inthe run_start document"},
"field": {"type": "string"},
"calculation": {
"title" : "calculation properties",
"properties": {
"callable": {"type": "string", "description": "callable function to perform calculation"},
"args": {"type": "array", "decription": "args for calculation callable"},
"kwargs": {"type": "object", "description": "kwargs for calcalation callable"}
},
"required": ["callable"]
}
},
"required" : ["type"],
"additionalProperties": false
},
"projections": {
"title" : "Describe how to interperet this run as the given projection",
"properties":{
"name": {"type": "string", "description": "The name of the projection"},
"version": {"type": "string", "description": "The version of the projection spec. Can specify the version of an external specification."},
"configuration" : {"type": "object", "description": "Static information about projection"},
"projection" : {
"type": "object",
"patternProperties": {".": {"$ref": "#/definitions/projection"}},
"additionalProperties": false
}
},
"additionalProperties": false,
"required" : ["projection", "version", "configuration"]
}
},
"properties": {
Expand Down Expand Up @@ -35,6 +71,10 @@
"type": "string",
"description": "Unix owner to associate this data with"
},
"projections": {
"type": "array",
"items": {"$ref": "#/definitions/projections"}
},
"hints": {
"type": "object",
"description": "Start-level hints",
Expand Down
62 changes: 62 additions & 0 deletions event_model/tests/test_projections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import event_model
import pytest
from jsonschema.exceptions import ValidationError


def test_projection_start_doc():
run_bundle = event_model.compose_run(uid="42", metadata={"projections": valid_projections})
start_doc = run_bundle.start_doc
assert start_doc['projections'] == valid_projections


def test_projection_schema():
start_doc['projections'] = valid_projections
event_model.schema_validators[event_model.DocumentNames.start].validate(start_doc)

with pytest.raises(ValidationError):
start_doc['projections'] = invalid_projections
event_model.schema_validators[event_model.DocumentNames.start].validate(start_doc)


valid_projections = [
{
"name": "test",
"version": "42.0.0",
"configuration": {},
"projection": {
'entry/instrument/detector/data': {
'type': 'linked',
'location': 'event',
'stream': 'primary',
'field': 'ccd',
},
'/entry/instrument/wavelength': {
'type': 'calculated',
'calculation': {
'callable': 'pizza.order:slice',
'kwargs': {'toppings': 'cheese'}
}
}
},
}
]

invalid_projections = [
{
"name": "test",
"version": "42.0.0",
"configuration": {},
"projection": {
'entry/instrument/detector/data': {
'location': 'THIS IS NOT VALID',
'stream': 'primary',
'field': 'ccd',
},
},
}
]

start_doc = {
"uid": "abc",
"time": 0,
}

0 comments on commit 0c29664

Please sign in to comment.