-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from kif/ID02
Id02
- Loading branch information
Showing
5 changed files
with
153 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "MIT" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "26/08/2021" | ||
__date__ = "18/03/2022" | ||
__status__ = "development" | ||
__version__ = "0.9.2" | ||
|
||
|
@@ -16,9 +16,12 @@ | |
import json | ||
import numpy | ||
from dahu.plugin import Plugin | ||
from dahu import version as dahu_version | ||
from dahu.utils import get_isotime, fully_qualified_name | ||
import PyTango | ||
try: | ||
import PyTango | ||
except ImportError: | ||
PyTango = None | ||
|
||
import logging | ||
logger = logging.getLogger("id02.metadata") | ||
from .common import StringTypes, Nexus, ensure_str | ||
|
@@ -237,7 +240,10 @@ def read_c216(self): | |
""" | ||
Manage the metadata coming from C216 Time Frame Generator | ||
""" | ||
if PyTango is None: | ||
self.log_error("PyTango is needed to connect to C216", do_raise=True) | ||
c216ds = PyTango.DeviceProxy(str(self.c216)) | ||
c216ds.set_timeout_millis(5000) | ||
if c216ds.CompStatus("Tango::RUNNING") == "Tango::ON": | ||
msg = "C216 is running while reading counters ... possible issue" | ||
self._logging.append(msg) | ||
|
@@ -280,7 +286,10 @@ def read_c216(self): | |
self.tfg_grp[key].attrs["interpretation"] = "scalar" | ||
|
||
# raw scalers: | ||
raw_scalers = c216ds.ReadScalersForNLiveFrames([0, frames - 1]) | ||
blocksize = 512 | ||
raw_scalers = numpy.concatenate([c216ds.ReadScalersForNLiveFrames([start, min(start + blocksize, frames) - 1]) | ||
for start in range(0, frames, blocksize)]) | ||
|
||
raw_scalers.shape = frames, -1 | ||
counters = raw_scalers.shape[1] | ||
self.mcs_grp["HS32C"] = raw_scalers | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
"""Module for writing HDF5 in the Nexus style""" | ||
|
||
__author__ = "Jerome Kieffer" | ||
__author__ = "Jérôme Kieffer" | ||
__contact__ = "[email protected]" | ||
__license__ = "MIT" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "20/02/2020" | ||
__date__ = "29/01/2024" | ||
__status__ = "production" | ||
__docformat__ = 'restructuredtext' | ||
|
||
|
@@ -85,13 +85,14 @@ class Nexus(object): | |
TODO: make it thread-safe !!! | ||
""" | ||
|
||
def __init__(self, filename, mode=None, creator=None): | ||
def __init__(self, filename, mode=None, creator=None, start_time=None): | ||
""" | ||
Constructor | ||
:param filename: name of the hdf5 file containing the nexus | ||
:param mode: can be 'r', 'a', 'w', '+' .... | ||
:param creator: set as attr of the NXroot | ||
:param start_time: set as attr of the NXroot | ||
""" | ||
self.filename = os.path.abspath(filename) | ||
self.mode = mode | ||
|
@@ -105,12 +106,18 @@ def __init__(self, filename, mode=None, creator=None): | |
self.mode = "r" | ||
else: | ||
self.mode = "a" | ||
self.h5 = h5py.File(self.filename, mode=self.mode) | ||
|
||
if self.mode == "r" and h5py.version.version_tuple >= (2, 9): | ||
self.file_handle = open(self.filename, mode=self.mode + "b") | ||
self.h5 = h5py.File(self.file_handle, mode=self.mode) | ||
else: | ||
self.file_handle = None | ||
self.h5 = h5py.File(self.filename, mode=self.mode) | ||
self.to_close = [] | ||
|
||
if not pre_existing: | ||
if not pre_existing or "w" in mode: | ||
self.h5.attrs["NX_class"] = "NXroot" | ||
self.h5.attrs["file_time"] = get_isotime() | ||
self.h5.attrs["file_time"] = get_isotime(start_time) | ||
self.h5.attrs["file_name"] = self.filename | ||
self.h5.attrs["HDF5_Version"] = h5py.version.hdf5_version | ||
self.h5.attrs["creator"] = creator or self.__class__.__name__ | ||
|
@@ -125,6 +132,8 @@ def close(self, end_time=None): | |
entry["end_time"] = end_time | ||
self.h5.attrs["file_update_time"] = get_isotime() | ||
self.h5.close() | ||
if self.file_handle: | ||
self.file_handle.close() | ||
|
||
# Context manager for "with" statement compatibility | ||
def __enter__(self, *arg, **kwarg): | ||
|
@@ -133,6 +142,10 @@ def __enter__(self, *arg, **kwarg): | |
def __exit__(self, *arg, **kwarg): | ||
self.close() | ||
|
||
def flush(self): | ||
if self.h5: | ||
self.h5.flush() | ||
|
||
def get_entry(self, name): | ||
""" | ||
Retrieves an entry from its name | ||
|
Oops, something went wrong.