Giter Site home page Giter Site logo

nexdatas / nxsdatawriter Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 7.1 MB

NXSDataWriter Tango server dedicated to store data in NeXuS/HDF5 files

License: GNU General Public License v3.0

Python 97.27% Shell 0.06% HTML 1.76% Dockerfile 0.89% PLpgSQL 0.02%
hdf5 nexusformat python tango

nxsdatawriter's Introduction

Welcome to NXSDataWriter's documentation!

Authors: Jan Kotanski, Eugen Wintersberger, Halil Pasic

Introduction

NXSDataWriter is a Tango server which allows to store NeXuS Data in H5 files.

The server provides storing data from other Tango devices, various databases as well as passed by a user client via JSON strings.

Tango Server API: https://nexdatas.github.io/nxsdatawriter/doc_html

Installation

Install the dependencies:

   pninexus or h5py, tango, numpy, nxstools, sphinx

From sources

Download the latest NexDaTaS version from

Extract sources and run

$ python setup.py install

Debian packages

Debian bookworm, bullseye, buster or Ubuntu lunar, jammy, focal packages can be found in the HDRI repository.

To install the debian packages, add the PGP repository key

$ sudo su
$ curl -s http://repos.pni-hdri.de/debian_repo.pub.gpg | gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/debian-hdri-repo.gpg --import
$ chmod 644 /etc/apt/trusted.gpg.d/debian-hdri-repo.gpg

and then download the corresponding source list

$ cd /etc/apt/sources.list.d
$ wget http://repos.pni-hdri.de/bookworm-pni-hdri.list

To install tango server

$ apt-get update
$ apt-get install nxswriter

or

$ apt-get update
$ apt-get install nxswriter3

for older python3 releases.

To install only the python3 package

$ apt-get update
$ apt-get install python3-nxswriter

and for python2

$ apt-get update
$ apt-get install python-nxswriter

if exists.

From pip

To install it from pip you can

$ python3 -m venv myvenv
$ . myvenv/bin/activate

$ pip install nxswriter

Moreover it is also good to install

$ pip install pytango
$ pip install pymysqldb
$ pip install psycopg2-binary
$ pip install cx-oracle

Setting NeXus Writer Server

To set up NeXus Writer Server run

$ nxsetup -x NXSDataWriter

The nxsetup command comes from the python-nxstools package.

Client code

In order to use Nexus Data Server one has to write a client code. Some simple client codes are in the nexdatas repository. In this section we add some comments related to the client code.

# To use the Tango Server we must import the tango module and
# create DeviceProxy for the server.

import tango

device = "p09/tdw/r228"
dpx = tango.DeviceProxy(device)
dpx.set_timeout_millis(10000)

dpx.Init()

# Here device corresponds to a name of our Nexus Data Server.
# The Init() method resets the state of the server.

dpx.FileName = "test.h5"
dpx.OpenFile()

# We set the name of the output HDF5 file and open it.

# Now we are ready to pass the XML settings describing a structure of
# the output file as well as defining a way of data storing.
# Examples of the XMLSettings can be found in the XMLExamples directory.

with open("test.xml", 'r') as fl:
    xml = fl.read()
dpx.XMLSettings = xml

dpx.JSONRecord = '{"data": {"parameterA":0.2},
          "decoders":{"DESY2D":"desydecoders.desy2Ddec.desy2d"},
          "datasources":{
                   "MCLIENT":"sources.DataSources.LocalClientSource"}
}'

dpx.OpenEntry()

# We read our XML settings settings from a file and pass them to the server via
# the XMLSettings attribute. Then we open an entry group related to the XML
# configuration. Optionally, we can also set JSONRecord, i.e. an attribute
# which contains a global JSON string with data needed to store during opening
# the entry and also other stages of recording. If external decoder for
# DevEncoded data is need one can registred it passing its packages and
# class names in JSONRecord,
# e.g. "desy2d" class of "DESY2D" label in "desydecoders.desy2Ddec" package.
# Similarly making use of "datasources" records of the JSON string one can
# registred additional datasources. The OpenEntry method stores data defined
# in the XML string with strategy=INIT.
# The JSONRecord attribute can be changed during recording our data.

# After finalization of the configuration process we can start recording
# the main experiment data in a STEP mode.

dpx.Record('{"data": {"p09/counter/exp.01":0.1, "p09/counter/exp.02":1.1}}')

# Every time we call the Record method all nexus fields defined with
# strategy=STEP are extended by one record unit and the assigned to them data
# is stored. As the method argument we pass a local JSON string with the client
# data. To record the client data one can also use the global JSONRecord string.
# Contrary to the global JSON string the local one is only
# valid during one record step.

dpx.Record('{"data": {"emittance_x": 0.1},  "triggers":["trigger1", "trigger2"]  }')

# If you denote in your XML configuration string some fields by additional
# trigger attributes you may ask the server to store your data only in specific
# record steps. This can be helpful if you want to store your data in
# asynchronous mode. To this end you define in the local JSON string a list of
# triggers which are used in the current record step.

dpx.JSONRecord = '{"data": {"parameterB":0.3}}'
dpx.CloseEntry()

# After scanning experiment data in 'STEP' mode we close the entry.
# To this end we call the CloseEntry method which also stores data defined
# with strategy=FINAL. Since our HDF5 file can contain many entries we can again
# open the entry and repeat our record procedure. If we define more than one entry
# in one XML setting string the defined entries are recorded parallel
# with the same steps.

# Finally, we can close our output file by

dpx.CloseFile()

Additionally, one can use asynchronous versions of OpenEntry, Record, CloseEntry, i.e. OpenEntryAsynch, RecordAsynch, CloseEntryAsynch. In this case data is stored in a background thread and during this writing Tango Data Server has a state RUNNING.

In order to build the XML configurations in the easy way the authors of the server provide for this purpose a specialized GUI tool, Component Designer. The attached to the server XML examples was created by XMLFile class defined in XMLCreator/simpleXML.py.

nxsdatawriter's People

Contributors

jkotan avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nxsdatawriter's Issues

problems in parsing inner xml with spaces

If one uses pyeval datasouces it happens that inner xml is cut with spaces. It causes

654875792 [139905237759744] INFO nxs/nxsdatawriter/dellek EField::markFailed() - value marked as failed
1654875792 [139905237759744] WARN nxs/nxsdatawriter/dellek ThreadPool::checkErrors() - ('Data for /scan:NXentry/sample:NXsample/sim_uniaxialpressuredevice:NXenvironment/transducer:NXsensor/parameters:NXcollection/_slope:NXlog/value not found. DATASOURCE: PYEVAL \nfrom nxstools.pyeval import secop\nds.result = secop.secop_group_cmd(\n    "read transducer:_slope",\n    "",\n    "5000",\n    "0.001",\n    "sim_uniaxialpressuredevice_transducer__slope",\n    [0', 'unexpected EOF while parsing (<string>, line 8)\n   File "/home/jkotan/ndts/writer/nxswriter/EField.py", line 542, in run\n    dt = self.source.getData()\n   File "/home/jkotan/ndts/writer/nxswriter/PyEvalSource.py", line 232, in getData\n    exec(self.__script.strip(), {}, {"ds": ds})\n')

e.g. when one add spaces between parameters of groupsecop datasource on deb11.

The issue needs to be investigated.

external filters does not work with h5py module on ubuntu focal

on ubuntu focal tests we get


  File "/usr/local/lib/python3.8/dist-packages/nxswriter-2.26.0-py3.8.egg/nxswriter/EField.py", line 183, in __createObject

    f = self._lastObject().create_field(

  File "/usr/lib/python3/dist-packages/nxstools/h5pywriter.py", line 412, in create_field

    self._h5object.create_dataset(

  File "/usr/lib/python3/dist-packages/h5py/_hl/group.py", line 136, in create_dataset

    dsid = dataset.make_new_dset(self, shape, dtype, data, **kwds)

  File "/usr/lib/python3/dist-packages/h5py/_hl/dataset.py", line 167, in make_new_dset

    dset_id = h5d.create(parent.id, None, tid, sid, dcpl=dcpl)

  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper

  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper

  File "h5py/h5d.pyx", line 80, in h5py.h5d.create

ValueError: Unable to create dataset (error during user callback)

'take datasources' and multiple list entries

If 'take datasources' is called multiple times on a component already imported 
sources are added again to the list. Thus one ends up with several list entries 
for the same component. Although the program is keeping only one file for each 
component this behavior is confusing and will most probably lead to many error 
reports from users once it is realease.


Original issue reported on code.google.com by [email protected] on 15 Jan 2013 at 10:22

Release 3.3.0

In the v3.3.0 release

  • the metadataOutput property added (#91)

It requires nxstools 3.16.2

Release v3.0.0

In the v3.0.0 release

  • store strings by default as scalar
  • the old pni writer dropped
  • nxstools 3.0.1 required

Close button on component window not working

The close button on the component window is not working (the one on the bottom 
left of the window). It does not close the window. However, the button in the 
window's title bar works as expected. Most probably some signal is not 
connected.


Original issue reported on code.google.com by [email protected] on 15 Jan 2013 at 10:23

Release 3.4.2

In the v3.4.2 release

  • Metadata parameters updated (#112)
  • tests to nxstools 3.25.0 adopted (#110)

Release 3.4.0

In the v3.4.0 release

  • add a workaround for etree.tostring utf8 problem added (#102)
  • add a step counter to the PYEVAL common block added (#98, #99, #100)
  • remove default mysql localhost removed (#94)
  • add tests for ubuntu jammy added (#94)

Release v3.0.1

It the v3.0.1 release

  • fix for storing strings by default as scalar
  • set default strategy as init

update tests

It would be good to run tests with pytest modules

store strings by default as scalar

Since NIAC 2018 changed Nexus format (breaking backward compatibility) we need to update a way of storing strings.
From NIAC 2018 the string type is special and by default it should be stored in the scalar dataspace.

Segmentation fault when loading a datasource

When using the 'Load datasource' option from the pull down menu of a field the 
program produces a segmentation fault after the selection of the XML file has 
been confirmed by the OK button of the file selection dialog. 

Original issue reported on code.google.com by [email protected] on 21 Jan 2013 at 10:32

Release v3.0.2

In the v3.0.2 release:

  • test for nxstools v3.1.0 updated

Link target attributes are not set

Using v3.1.2 of nxswriter and the h5py writer, the target attribute of links is not written. Tested using the following code

import lxml.etree
import tango

px = tango.DeviceProxy("sys/acquisition/nxswriter")
px.Init()
px.FileName = r"C:\Users\tvips\PycharmProjects\nexus-definitions\test.h5"

xml = lxml.etree.parse("test.xml")
px.XMLSettings = lxml.etree.tostring(xml, pretty_print=True, xml_declaration=True, encoding="UTF-8").decode()

px.OpenFile()
px.OpenEntry()
px.CloseEntry()
px.CloseFile()

and the XML file

<?xml version='1.0' encoding='UTF-8'?>
<definition>
    <group name="entry" type="NXentry">
        <field name="values" type="NX_CHAR">
            test
        </field>
        <link name="values_link" target="/entry/values"/>
    </group>
</definition>

Cheers,
Pascal Dreher

Release v3.1.2

In the v3.1.2 release

  • currenttime() from the nxstools package used

Delete button on keyboard does not work as expected

As a user I would expect that the 'delete'-button on the keyboard removes a 
component or whatever from the tree or list. This is, at least for datasources, 
not the case.
To avoid confusion of users the behavior of the GUI should be fixed in a way 
that this works.  



Original issue reported on code.google.com by [email protected] on 15 Jan 2013 at 10:19

create JSON with metadata

It would be good to consider possibility of creation JSON dictionary with metadata which can be send e.g to SciCat

add support for VDS

IT would be good to add possibility of creating Virtual dataset fields from nexus configuration

Release v3.1.0

In the v3.1.0 release

  • DATA_ARRAY decoder for LimaCCDs images added (#74)

Release 3.2

In the v3.2.0 Release

  • add stdoutflag and stderrflag to switch on/off std streams

Release v2.29.0

In the v2.29.0 release

  • support for pni writer module removed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.