EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Save MCA record data
From: Pete Jemian <[email protected]>
To: <[email protected]>
Date: Wed, 13 Dec 2017 07:16:03 -0600

Abdalla:

On 12/13/2017 2:04 AM, Abdalla  Ahmad wrote:
> How to save mca record waveform data into any of the following formats:
> MCA, HDF5, NXS?

Attached is an example using Python with the PyEpics package to read the MCA waveform, and h5py to write the HDF5 NeXus file. You'll need to change the PV in the code to one of yours, of course. The waveform is stored in the HDF5 file at this address:

/entry/instrument/detector/waveform

but it is also available, by using an HDF5 hard link, at

/entry/data/data

The data is stored using GZIP compression, support for which should be available with all HDF5 clients. There are other possibilities. The output format has been validated with the "punx" NeXus data file validation tool.

I believe this example satisfies two of your three output formats.

You can view the resulting file with hdfview, PyMCA, or NeXPy.

Hope this helps,
   Pete

hdfview: https://support.hdfgroup.org/products/java/hdfview/
PyMCA: http://pymca.sourceforge.net/
NeXPy: https://nexpy.github.io/nexpy/
punx: http://punx.readthedocs.io


On 12/13/2017 2:04 AM, Abdalla  Ahmad wrote:
Hi

How to save mca record waveform data into any of the following formats: MCA, HDF5, NXS?

Best Regards,

Abdalla Ahmad

Control Engineer

SESAME

Allan, Jordan.

Tel: (+962-5) 3511348 , ext. 265

Fax: (+962-5) 3511423

Mob: (+962-7)88183296

www.sesame.org.jo <http://www.sesame.org.jo/>


--
----------------------------------------------------------
Pete R. Jemian, Ph.D.                <[email protected]>
Beam line Controls and Data Acquisition, Group Leader
Advanced Photon Source,   Argonne National Laboratory
Argonne, IL  60439                   630 - 252 - 3189
-----------------------------------------------------------
   Education is the one thing for which people
      are willing to pay yet not receive.
-----------------------------------------------------------


import numpy as np
import h5py
import datetime

def write_nexus_file(fname, waveform, md={}):
	"""
	write the waveform to a NeXus HDF5 data file

	Parameters
	----------
	fname : str
		name of the file (relative or absolute) to be written
	waveform : numpy array
		the MCA waveform data
	md : dictionary
		key: value where value is something that can be written by h5py
			 (such as str, int, float, numpy array, ...)
	"""
	nexus = h5py.File(fname, "w")
	nexus.attrs["filename"] = fname
	nexus.attrs["file_time"] = str(datetime.datetime.now())
	nexus.attrs["creator"] = "write_nexus_file()"
	nexus.attrs["H5PY_VERSION"] = h5py.__version__

	# /entry
	nxentry = nexus.create_group("entry")
	nxentry.attrs["NX_class"] = "NXentry"
	nexus.attrs["default"] = nxentry.name

	# /entry/instrument
	nxinstrument = nxentry.create_group("instrument")
	nxinstrument.attrs["NX_class"] = "NXinstrument"

	# /entry/instrument/detector
	nxdetector = nxinstrument.create_group("detector")
	nxdetector.attrs["NX_class"] = "NXdetector"

	# /entry/instrument/detector/waveform
	ds = nxdetector.create_dataset("waveform", data=waveform, compression="gzip")
	ds.attrs["units"] = "counts"
	ds.attrs["target"] = "/entry/instrument/detector/waveform"

	# /entry/data
	nxdata = nxentry.create_group("data")
	nxdata.attrs["NX_class"] = "NXdata"
	nxentry.attrs["default"] = nxdata.name

	# /entry/data/data --> /entry/instrument/detector/waveform
	nxdata["data"] = nexus["/entry/instrument/detector/waveform"]
	nxdata.attrs["signal"] = "data"

	if len(md) > 0:
		# /entry/instrument/metadata (optional, for metadata)
		metadata = nxinstrument.create_group("metadata")
		metadata.attrs["NX_class"] = "NXcollection"
		for k, v in md.items():
			try:
				metadata.create_dataset(k, data=v)
			except Exception:
				metadata.create_dataset(k, data=str(v))

	nexus.close()

	
if __name__ == "__main__":
	"""
	demonstrate how to use this code

	Read MCA waveform from EPICS.
	"""
	import epics
	waveform = epics.caget("ioc:mca1")

	extra_information = dict(
		pv_name = epics.caget("ioc:mca1"),
		bitcoin_value="15000",		# just an example
	)
	write_nexus_file("example.h5", img, md=extra_information)

References:
Save MCA record data Abdalla Ahmad

Navigate by Date:
Prev: Save MCA record data Abdalla Ahmad
Next: Re: Save MCA record data Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Save MCA record data Abdalla Ahmad
Next: Re: Save MCA record data Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024 
ANJ, 21 Dec 2017 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·