NXDL extensions for data sources ================================ The NeXus Data Writer (nxswriter) creates NeXus files from XML configurations. They use the tags of `the NXDL standard `__, i.e. ````, ````, ````, ````, ```` and ````, extended by tags which describe * where and when the data are taken from -- ```` and ```` with its nested tags, * how the data are stored -- ```` and ````, * virtual datasets -- ````, ````, ````, ````, ```` and ````. The ```` and ```` tags can be situated inside * ```` -- for its value * ```` -- for its value * ```` -- for its value (from nxswriter v1.7.0) * ```` -- for its target (from nxswriter v1.9.0) * ```` -- for the description of virtual dataset maps * ```` and ```` -- for their selections The other datasource tags are nested inside the ```` tag. Groups can be given without a ``name`` attribute. Their names are then given by their types without the ``NX`` prefix, e.g. ``entry`` for ``NXentry``. In the same way, link targets can contain groups given by their types, e.g. ``/NXentry/NXinstrument/detector/data``. The ```` tag ---------------------- The **strategy** tag defines when and in which way the data is stored. An example of usage: .. code-block:: xml The tag can have the following attributes: * **mode** specifies when the data is fetched, i.e. * *INIT* during opening a new entry * *STEP* when the *record()* command is performed * *FINAL* at the time of closing the entry * *POSTRUN* during post-processing stage * *CONFIG* before opening a new entry (used only for dimensions) * **trigger** stands for the name of the related trigger in asynchronous *STEP* mode (optional) * **grows** selects which dimension of a field grows in the *STEP* mode. The default growing dimension is the first one, i.e. ``grows="1"`` (optional) * **compression** specifies if and how data are compressed (optional) * an integer filter ID, e.g. *32008* for bitshuffle * *true* data are compressed with deflate * *false* data are stored without compression (default) * **compression_opts** compression options of the filter, i.e. a list of integers separated by commas (optional) * **rate** compression rate for deflate, from *0* to *9* (optional) * **shuffle** shuffle filter before the compression (optional) * *true* shuffle enabled (default) * *false* shuffle disabled * **canfail** specifies what happens if the data cannot be read (optional) * *false* an exception is raised (default) * *true* a warning is printed and the record is filled by the maximum value of the record type A *STEP* field with a datasource gets an additional growing dimension of length 0 at the position given by **grows**, e.g. a field with dimensions ``4`` and ``5`` is stored with the shape ``(0, 4, 5)``, which grows by one ``4x5`` image with every *record()* command. The **content** of the strategy tags is a label describing data merged into the H5 file by a post-processing program. An example of usage: .. code-block:: xml http://haso.desy.de:/data/energy.dat The ```` tag ~~~~~~~~~~~~~~~~~~~~ The **filter** tags inside the **strategy** tag define a chain of HDF5 filters applied to the field data, e.g. for compression. The tag has the following attributes: * **index** position of the filter in the chain, the filters are applied in increasing order (optional, default *0*) * **id** integer ID of the HDF5 filter, e.g. *32008* for bitshuffle or *32001* for blosc (optional) * **name** name of a built-in HDF5 filter, i.e. *shuffle*, *deflate*, *nbit*, *fletcher32*, *szip* or *scaleoffset* (optional) * **cd_values** filter options, i.e. a list of integers separated by commas, e.g. the compression level of *deflate* (optional) * **availability** what happens if the filter is not available (optional) * *mandatory* writing fails (default) * *optional* the filter is skipped Either **id** or **name** has to be given. An example of usage: .. code-block:: xml The ```` tag ------------------- The **chunk** tag defines the HDF5 chunk shape of a field. Like the **dimensions** tag it has a **rank** attribute and contains ```` tags with the **index** (starting from 1) and **value** attributes. For *STEP* fields the growing dimension can be omitted, it is then chunked by 1. Without the **chunk** tag, the chunk shape is the field shape with the growing dimension of length 1. .. code-block:: xml stores the ``(0, 1024, 1024)`` field in chunks of ``(1, 256, 256)``. Virtual datasets ---------------- Data written into other files, e.g. by detectors, can be accessed via HDF5 virtual datasets, which combine parts of source datasets into one dataset. The ```` tag ~~~~~~~~~~~~~~~~~ The **vds** tag creates a virtual dataset. Like the **field** tag it has the **name** and **type** attributes, other attributes, e.g. **units**, are stored as HDF5 attributes. Its ```` define the shape of the virtual dataset and its ```` tags the source datasets. A ```` tag defines when the virtual dataset is created, *FINAL* by default. .. code-block:: xml The ```` tag ~~~~~~~~~~~~~~~~~ The **map** tag describes one block of the virtual dataset and its source. It has the following attributes: * **target** the source dataset, i.e. ``file.h5://path``, ``file.h5::/path``, ``h5file:/...`` or ``/path`` in the same file (optional) * **filename** the source file (optional) * **fieldpath** the path of the source dataset, ``/data`` by default (optional) Its ```` define the shape of the block in the virtual dataset, a ```` its position. Maps without a selection are stacked along the first dimension. A ```` selects a part of the source dataset, otherwise the whole source dataset is used. The maps can also be provided by a datasource, e.g. by detector servers. Its value is a JSON list of maps given by targets or by dictionaries with the **target**, **filename**, **fieldpath**, **shape**, **key** (the selection in the virtual dataset), **sourceshape**, **sourcekey** (the selection of the source) and **dtype** keys. The strategy of such maps is *STEP* by default. .. code-block:: xml The ````, ```` and ```` tags ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The **selection** tag, with the **rank** attribute, selects a part of a dataset by one ```` or ```` tag per dimension. Dimensions without them are selected entirely. Both tags have the **index** attribute of the dimension, starting from 1. The **slab** tag defines an HDF5 hyperslab, i.e. the attributes * **offset** the first element (default *0*) * **block** the size of a block (default *1*) * **count** the number of blocks (default *1*) * **stride** the distance between the blocks (default *1*) The **slice** tag defines a python-like slice, i.e. the attributes * **start** the first element (optional) * **stop** the element after the last one (optional) * **step** the distance between the elements (optional) Their values can also be provided by datasources with JSON lists, i.e. ``[offset, block, count, stride]`` or ``[start, stop, step]``. .. code-block:: xml places the source into the rows ``5`` to ``9`` of the virtual dataset. The ```` tag ~~~~~~~~~~~~~~~~~~~~~~~~ The **sourceview** tag inside the **map** tag selects a part of the source dataset. It contains the ```` of the source dataset and a ````, e.g. .. code-block:: xml maps every second element of the source dataset into the virtual dataset. The ```` tag ------------------------ The **datasource** tag specifies a type of the used data sources. They can be one of built types, i.e. *CLIENT*, *TANGO*, *DB*, *PYEVAL* or external ones -- defined in external python package and registered via JSON data. The ```` tag acquires the following attributes: * **type** related to a type of data source with possible values: * *CLIENT* for communication with client via JSON strings * *TANGO* for taking data from Tango servers * *DB* for fetching data from databases * *PYEVAL* for evaluating data from other data sources by python script * *other type name* of data source which has been registered via JSON data. * **name** datasource name (optional) *CLIENT* datasource ------------------- The CLIENT datasource allows to read data from client JSON strings. It should contain a ```` tag. An example of usage: .. code-block:: xml ```` ~~~~~~~~~~~~ The **record** tag defines the fetched data by its name. It has an attribute * **name** which for the *CLIENT* data source type denotes a name of the data in the JSON string. An example of usage: .. code-block:: xml *TANGO* datasource ------------------ The TANGO datasource allows to read data from other TANGO devices. It should contain ```` and ```` tags. An example of usage: .. code-block:: xml ```` ~~~~~~~~~~~~ The **device** tag describes the Tango device which is used to get the data. It has the following attributes: * **name** corresponding to a name of the Tango device * **member** defining a type of the class member, i.e. * *attribute* an attribute to read * *command* a result of a command to take * *property* a property to read * **hostname** a name of the host with the Tango device server (optional) * **port** a port number related to the Tango device server (optional) * **encoding** a label defining a required decoder for ``DevEncoded`` data (optional) * **group** tango group name (optional) If **group** attribute is defined data of the same group is read simultaneously and only once during one experimental step. ```` ~~~~~~~~~~~~ The **record** tag defines the fetched data by its name. It has an attribute * **name** which for the *TANGO* data source type is a name of the tango class member. *DB* datasource --------------- The DB datasource allows to read data from accessible databases. It should contain ```` and ```` tags. An example of usage: .. code-block:: xml SELECT pid FROM device limit 10 ```` ~~~~~~~~~~~~~~ The **database** tag specifies parameters to connect to the required database. It acquires the attributes * **dbtype** describing a type of the database, i.e. * *ORACLE* an ORACLE database * *MYSQL* a MySQL database * *PGSQL* a PostgreSQL database * **dbname** denoting a name of the database (optional) * **hostname** being a name of the host with the database (optional) * **port** corresponding to a port number related to the database (optional) * **user** denoting a user name (optional) * **passwd** being a user password (optional) * **mycnf** defining a location of the my.cnf file with MySQL database access configuration (optional) * **mode** connection mode of the ORACLE database, passed to the Oracle client library (optional) The **content** of the database tag defines Oracle DSN string (optional) ```` ~~~~~~~~~~~ The **query** tag defines the database query which fetches the data. It has one attribute * **format** which specifies a dimension of the fetch data, i.e. * *SCALAR* corresponds to 0-dimensional data, e.g. a separate numerical value or string * *SPECTRUM* is related to 1-dimensional data, e.g. a list of numerical values or strings * *IMAGE* describes 2-dimensional data, i.e. a table of specific type values, e.g. a table of strings The **content** of the query tags is the SQL query Another example of usage: .. code-block:: xml SELECT * FROM weather limit 3 *PYEVAL* datasource ------------------- The PYEVAL datasource allows to read data from other datasources and evaluate it by a user python script. An example of usage: .. code-block:: xml ds.finalposition = ds.position + ds.shift ```` ~~~~~~~~~~~~~~~~ The PYEVAL datasource can contain other datasources. They have to have defined name attributes. Those names with additional prefix 'ds.' correspond to input variable names from the python script, i.e. ds.\ **name**. ```` ~~~~~~~~~~~~ The **result** contains python script which evaluates input data. It has the following attribute: * **name** corresponding to a result name, which is related to the python script variable ``ds.name``. The default value is ``result``. (optional)