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. <group>,
<field>, <attribute>, <link>, <dimensions> and <dim>,
extended by tags which describe
where and when the data are taken from –
<strategy>and<datasource>with its nested tags,how the data are stored –
<filter>and<chunk>,virtual datasets –
<vds>,<map>,<sourceview>,<selection>,<slab>and<slice>.
The <strategy /> and <datasource /> tags can be situated inside
<field />– for its value<attribute />– for its value<dim />– for its value (from nxswriter v1.7.0)<link />– for its target (from nxswriter v1.9.0)<map />– for the description of virtual dataset maps<slab />and<slice />– for their selections
The other datasource tags are nested inside the <datasource/> 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 <strategy> tag#
The strategy tag defines when and in which way the data is stored. An example of usage:
<field name="energy" type="NX_FLOAT" units="GeV" >
<strategy mode="STEP" trigger="trigger1" />
<datasource type="CLIENT">
<record name="counter_1"/>
</datasource>
</field>
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:
<field name="energy" type="NX_FLOAT" units="GeV" >
<strategy mode="POSTRUN" >
http://haso.desy.de:/data/energy.dat
</strategy>
</field>
The <filter> 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:
<field name="data" type="NX_UINT32">
<dimensions rank="2">
<dim index="1" value="1024"/>
<dim index="2" value="1024"/>
</dimensions>
<strategy mode="STEP">
<filter index="0" name="shuffle"/>
<filter index="1" id="32008" cd_values="0,2" availability="optional"/>
</strategy>
<datasource type="CLIENT">
<record name="detector"/>
</datasource>
</field>
The <chunk> tag#
The chunk tag defines the HDF5 chunk shape of a field. Like the
dimensions tag it has a rank attribute and contains <dim>
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.
<field name="data" type="NX_UINT32">
<dimensions rank="2">
<dim index="1" value="1024"/>
<dim index="2" value="1024"/>
</dimensions>
<chunk rank="2">
<dim index="1" value="256"/>
<dim index="2" value="256"/>
</chunk>
<strategy mode="STEP"/>
<datasource type="CLIENT">
<record name="detector"/>
</datasource>
</field>
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 <vds> 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 <dimensions> define the shape of the
virtual dataset and its <map> tags the source datasets. A <strategy>
tag defines when the virtual dataset is created, FINAL by default.
<vds name="data" type="NX_INT32" units="counts">
<dimensions rank="2">
<dim index="1" value="10"/>
<dim index="2" value="5"/>
</dimensions>
<map target="scan_00001.h5://entry/data">
<dimensions rank="2">
<dim index="1" value="5"/>
<dim index="2" value="5"/>
</dimensions>
</map>
<map filename="scan_00002.h5" fieldpath="/entry/data">
<dimensions rank="2">
<dim index="1" value="5"/>
<dim index="2" value="5"/>
</dimensions>
</map>
</vds>
The <map> 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/pathin the same file (optional)filename the source file (optional)
fieldpath the path of the source dataset,
/databy default (optional)
Its <dimensions> define the shape of the block in the virtual dataset,
a <selection> its position. Maps without a selection are stacked along
the first dimension. A <sourceview> 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.
<vds name="counter" type="NX_FLOAT32">
<dimensions rank="2"/>
<map>
<strategy mode="STEP"/>
<datasource type="TANGO" name="countermap">
<device member="attribute" name="p/pilc/1"/>
<record name="CounterMap"/>
</datasource>
</map>
</vds>
The <sourceview> tag#
The sourceview tag inside the map tag selects a part of the source
dataset. It contains the <dimensions> of the source dataset and a
<selection>, e.g.
<map target="raw.h5://entry/line" >
<dimensions rank="1">
<dim index="1" value="4"/>
</dimensions>
<sourceview>
<dimensions rank="1">
<dim index="1" value="8"/>
</dimensions>
<selection rank="1">
<slice index="1" start="0" stop="8" step="2"/>
</selection>
</sourceview>
</map>
maps every second element of the source dataset into the virtual dataset.
The <datasource> 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 <datasource> 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 <record /> tag. An example of usage:
<datasource type="CLIENT" name="exp_c01">
<record name="counter_1"/>
</datasource>
<record>#
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:
<record name="Position"/>
TANGO datasource#
The TANGO datasource allows to read data from other TANGO devices. It
should contain <device/> and <record/> tags. An example of
usage:
<datasource type="TANGO">
<device hostname="haso.desy.de" member="attribute" name="p09/motor/exp.01" port="10000" encoding="LIMA_VIDEO_IMAGE"/>
<record name="Position"/>
</datasource>
<device>#
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
DevEncodeddata (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.
<record>#
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 <database /> and <query> tags. An example of
usage:
<datasource type="DB">
<database dbname="tango" dbtype="MYSQL" hostname="haso.desy.de"/>
<query format="SPECTRUM">
SELECT pid FROM device limit 10
</query>
</datasource>
<database>#
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)
<query>#
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:
<datasource type="DB">
<database dbname="mydb" dbtype="PGSQL"/>
<query format="IMAGE">
SELECT * FROM weather limit 3
</query>
</datasource>
PYEVAL datasource#
The PYEVAL datasource allows to read data from other datasources and evaluate it by a user python script. An example of usage:
<datasource type="PYEVAL">
<datasource type="TANGO" name="position">
<device hostname="haso.desy.de" member="attribute" name="p09/motor/exp.01" port="10000"/>
<record name="Position"/>
</datasource>
<datasource type="CLIENT" name="shift">
<record name="exp_c01"/>
</datasource>
<result name="finalposition">
ds.finalposition = ds.position + ds.shift
</result>
</datasource>
<datasource>#
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.
<result>#
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 isresult. (optional)