Skip to content

Commit b364e61

Browse files
authored
spec: add Matrix datatype (#8)
1 parent 96c3777 commit b364e61

File tree

3 files changed

+86
-47
lines changed

3 files changed

+86
-47
lines changed

protocol/issues/076 Interface for Measurable hardware.rst

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,35 @@ Proposal
3434
It is proposed to add three new interface classes.
3535

3636

37-
``MeasurableController`` (no base interface)
38-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37+
``Controller`` (no base interface)
38+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3939

4040
Accessibles:
4141

4242
``status``
4343
Mandatory: Standard SECoP status.
4444
The module is in ``BUSY`` state while the measurable is acquiring.
45-
The module is in ``PREPARED`` state after ``prepare()`` is called or data
46-
acquisition is paused by ``hold()``.
45+
The module is in ``PREPARED`` state after ``prepare`` is called or data
46+
acquisition is paused by ``hold``.
4747

48-
``prepare()``
48+
command ``prepare``
4949
Optional command: prepares a data acquisition so that triggering with ``go``
5050
is immediate. No-op if already prepared. Cannot be called when busy.
5151

52-
``go()``
52+
command ``go``
5353
Mandatory command: starts a data acquisition. No-op if busy.
5454
Data acquisition runs until one of the channels' active presets is hit or
55-
``stop`` is called explicitly. Runs the ``prepare()`` sequence first if
55+
``stop`` is called explicitly. Runs the ``prepare`` sequence first if
5656
module is not already prepared.
5757

58-
``hold()``
58+
command ``hold``
5959
Optional command: pauses a data acquisition. No-op if not busy.
60-
Subsequent ``go()`` continues the acquisition without clearing currently
60+
Subsequent ``go`` continues the acquisition without clearing currently
6161
acquired data.
6262

63-
``stop()``
63+
command ``stop``
6464
Optional command: stops a data acquisition. No-op if not busy.
65-
Subsequent ``go()`` starts a new acquisition with clearing currently
65+
Subsequent ``go`` starts a new acquisition with clearing currently
6666
acquired data.
6767

6868

@@ -116,10 +116,10 @@ Accessibles:
116116
``roi``
117117
Optional: a list containing a ``(min, max)`` tuple per dimension, to specify
118118
a sub-slice of matrix data to consider in ``value`` and return in
119-
``get_data()``.
119+
``get_data``.
120120

121-
``get_data()``
122-
Optional: returns the channel's matrix data, see below for details.
121+
command ``get_data``
122+
Optional: returns the channel's data, with a ``matrix`` data type.
123123

124124
The ``value`` parameter only contains a useful "reduced" form of the data, for
125125
example, the sum of all events in the matrix, or the average of all intensity
@@ -135,38 +135,6 @@ data is considered for this reduction.
135135
useful (i.e. not just "pixel 1..N"). (Precise semantics to be specified.)
136136

137137

138-
The return value of ``get_data()``
139-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140-
141-
Since the returned data matrix can get pretty large, it is not efficient to
142-
encode it as nested ``Array``\s. Instead, the data is kept in Blob form
143-
(base64-encoded for JSON transmission).
144-
145-
The return value is a struct, where the following members are currently
146-
specified:
147-
148-
- ``data``: The data as a ``Blob``, whose datainfo must have these additional
149-
properties:
150-
151-
- ``elementtype``: The type (and size, and byte order) of each matrix element,
152-
a string in Numpy convention (e.g. ``"<u4"``).
153-
- ``names``: A list of names for each dimension
154-
- ``maxlengths``: A list of maximum lengths for each dimension
155-
156-
- ``dims``: An array containing the actual lengths of each dimension.
157-
158-
The order of the matrix elements is defined so that the dimension with the
159-
fastest running index comes first in ``dims``, ``names`` and ``maxlengths``.
160-
161-
Example: ``data`` is ``[1, 2, 3, 4, 5, 6]``, ``dims`` is ``[2, 3]`` and
162-
``names`` is ``["x", "y"]``. Then the matrix looks as follows::
163-
164-
. x=0 x=1
165-
y=0 1 2
166-
y=1 3 4
167-
y=2 5 6
168-
169-
170138
Remarks
171139
~~~~~~~
172140

protocol/specification/datainfo.rst

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ SECoP defines some basic data types for numeric quantities, like double_,
1313
scaled_ and int_. An enum_ is defined for convenience of not having to remember
1414
the meaning of values from a reduced set. A bool_ datatype is similar to a
1515
predefined Enum, but uses the JSON values true and false. For non-numeric
16-
types, a string_ and a blob_ are defined as well.
16+
types, a string_ and a blob_ are defined as well. Finally, matrix_ can
17+
transport larger multi-dimensional homogeneous arrays.
1718

1819
Furthermore, SECoP not only defines basic data types, but also structured
1920
datatypes. tuple_ allows aggregation of a fixed amount of values with different
@@ -468,6 +469,75 @@ Example: ``{"x": 0.5, "y": 1}``
468469
Related issue: :issue:`035 Partial Structs`
469470

470471

472+
.. _matrix:
473+
474+
Binary Matrix: ``matrix``
475+
-------------------------
476+
477+
Type for transferring a medium to large amount of homogeneous arrays with
478+
potentially multiple dimensions.
479+
480+
At the moment, the type intends direct transfer of the data within the JSON
481+
data. It could be extended later to allow referring to a side-channel for
482+
obtaining the data.
483+
484+
Mandatory Data Properties
485+
~~~~~~~~~~~~~~~~~~~~~~~~~
486+
487+
``"names"``
488+
A list of names for each dimension in the data.
489+
490+
``"maxlen"``
491+
A list of maximum lengths for each dimension. The actual lengths can vary
492+
but may not exceed these limits.
493+
494+
``"elementtype"``
495+
A string defining the type of each element, as a combination of three parts:
496+
497+
- ``<`` or ``>`` to indicate little or big endianness.
498+
- ``i``, ``u``, ``f`` to indicate signed or unsigned integers or floating
499+
point numbers.
500+
- a number to indicate the number of bytes per element (1, 2, 4 or 8).
501+
502+
Example: ``"<u4"`` is a little-endian encoded 32-bit unsigned integer.
503+
504+
``"compression"``
505+
A string defining if and how the data is each ``blob`` is compressed.
506+
Currently, no compression types are defined.
507+
508+
509+
Example
510+
~~~~~~~
511+
``{"type": "matrix", "elementtype": "<f4", "names": ["x", "y"], "maxlen": [100, 100]}``
512+
513+
514+
Transport
515+
~~~~~~~~~
516+
517+
As a JSON object containing the following items:
518+
519+
``"len"``
520+
List of the actual length of each dimension in the data.
521+
522+
``"blob"``
523+
The data, encoded as a single-line base64 (see :RFC:`4648`) encoded
524+
JSON-string.
525+
526+
Example: ``{"len": [2, 3], "blob": "AACAPwAAAEAAAEBAAACAQAAAoEAAAMBA"}``
527+
528+
The order of the matrix elements is defined so that the first dimension
529+
named in ``names`` (and listed in ``maxlen``/``len``) varies the fastest.
530+
531+
In this example, the result of decoding ``blob`` as a flat sequence of 4-byte
532+
floats is ``[1, 2, 3, 4, 5, 6]``. Then the matrix looks as follows::
533+
534+
. x=0 x=1
535+
y=0 1 2
536+
y=1 3 4
537+
y=2 5 6
538+
539+
540+
471541
.. _command:
472542

473543
Commands: ``command``

protocol/specification/overview.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ example:
130130
- :ref:`Enum <enum>`
131131
- :ref:`String <string>`
132132
- :ref:`Blob <blob>`
133+
- :ref:`Matrix <matrix>`
133134

134135
For more complicated values, there are three structured datatypes:
135136

0 commit comments

Comments
 (0)