Skip to content

Commit

Permalink
Issue 126: add support for NeXusAcquisitionModes (#127)
Browse files Browse the repository at this point in the history
* add acq_modes

* add NeXusAcquisitionModes variable

* fix typos

* fix next typo

* replace NeXusSkipAcquisitionModes by NeXusAcquisitionModes variable

* fix typo
  • Loading branch information
jkotan authored Jun 10, 2024
1 parent d216647 commit 8115f58
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-06-19 Jan Kotanski <[email protected]>
* replace NeXusSkipAcquisitionModes by NeXusAcquisitionModes variable (#127)
* tagged as 3.26.0

2024-06-07 Jan Kotanski <[email protected]>
* set NeXusMeshScanID variable (#124)
* tagged as 3.25.0
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ The NeXus file recorder uses the following sardana environment variables
* **MetadataScript** *(str)* - a python module file name containing ``main()`` which provides a dictionary with user metadata stored in the INIT mode, default: ``""``
* **ScicatMeasurements** *(dict)* - a dictionary of measurement names indexed by ``ScanDir`` and used by ``scingestor``, default: ``{}``
* **CreateMeasurementFile** *(bool)* - create a measurement file with its filename releated to ``ScicatMeasurements`` or ``ScanFile``, default: ``False``
* **NeXusSkipAcquisitionModes** *(list)* - a list of strategy modes for which acquisition is skip
* **NeXusWriterProperties** *(dict)* - a dictionary of TangoDataWriter (NXSDataWriter) properties (starting with a small letter)
* **NeXusMeshScanID** *(int)* - ScanID used for composed scans e.g. mesh scan combined from many linear scans
* **NeXusAcquisitionModes** *(list)* - a list of strategy modes e.g. ``INIT``, ``NOINIT``, ``NOSTEP``, ``NOFINAL``, ``VDS`` separated by commas

6 changes: 3 additions & 3 deletions man/sardananxsrecorder.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "SARDANANXSRECORDER" "1" "Jun 06, 2024" "3.25" "Sardana NeXus Recorder"
.TH "SARDANANXSRECORDER" "1" "Jun 10, 2024" "3.26" "Sardana NeXus Recorder"
.SH NAME
sardananxsrecorder \- sardananxsrecorder Documentation
.sp
Expand Down Expand Up @@ -354,11 +354,11 @@ The NeXus file recorder uses the following sardana environment variables
.IP \(bu 2
\fBCreateMeasurementFile\fP \fI(bool)\fP \- create a measurement file with its filename releated to \fBScicatMeasurements\fP or \fBScanFile\fP, default: \fBFalse\fP
.IP \(bu 2
\fBNeXusSkipAcquisitionModes\fP \fI(list)\fP \- a list of strategy modes for which acquisition is skip
.IP \(bu 2
\fBNeXusWriterProperties\fP \fI(dict)\fP \- a dictionary of TangoDataWriter (NXSDataWriter) properties (starting with a small letter)
.IP \(bu 2
\fBNeXusMeshScanID\fP \fI(int)\fP \- ScanID used for composed scans e.g. mesh scan combined from many linear scans
.IP \(bu 2
\fBNeXusAcquisitionModes\fP \fI(list)\fP \- a list of strategy modes e.g. \fBINIT\fP, \fBNOINIT\fP, \fBNOSTEP\fP, \fBNOFINAL\fP, \fBVDS\fP separated by commas
.UNINDENT
.sp
Contents:
Expand Down
2 changes: 1 addition & 1 deletion sardananxsrecorder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
""" Sardana Scan Recorders """

#: package version
__version__ = "3.25.0"
__version__ = "3.26.0"
41 changes: 22 additions & 19 deletions sardananxsrecorder/nxsrecorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ def __init__(self, filename=None, macro=None, **pars):
#: (:obj:`dict` <:obj:`str` , :obj:`str`>) NeXus configuration
self.__conf = {}

#: (:obj:`list` <:obj:`str`>) skip Acquisition Modes
self.skipAcquisitionModes = self.__skipAcquisitionModes()
#: (:obj:`list` <:obj:`str`>) acquisition Modes
self.acquisitionModes = self.__variableList(
"NeXusAcquisitionModes")

#: (:obj:`dict` <:obj:`str` , `any`>) User data
self.__udata = None
Expand All @@ -177,7 +178,7 @@ def __init__(self, filename=None, macro=None, **pars):

def _serial(self, scanID):
serial = None
if "INIT" in self.skipAcquisitionModes:
if "NOINIT" in self.acquisitionModes:
if self.__macro:
serial = self.__macro().getEnv('NeXusMeshScanID', None)
if serial is None:
Expand All @@ -188,8 +189,7 @@ def _serial(self, scanID):
serial = scanID
else:
serial = scanID + 1
if self.skipAcquisitionModes and \
"INIT" not in self.skipAcquisitionModes:
if "INIT" in self.acquisitionModes:
if self.__macro:
self.__macro().setEnv('NeXusMeshScanID', serial)
return serial
Expand Down Expand Up @@ -1012,6 +1012,8 @@ def _startRecordList(self, recordlist):
self.__vars["vars"]["serialno"] = ("_%05i" % self.__serial) \
if appendscanid else ""
self.__vars["vars"]["scan_id"] = envRec["serialno"]
self.__vars["vars"]["acq_modes"] = \
",".join(self.acquisitionModes or [])
self.__vars["vars"]["scan_title"] = envRec["title"]
if self.__macro:
if hasattr(self.__macro(), "integ_time"):
Expand Down Expand Up @@ -1054,8 +1056,9 @@ def _startRecordList(self, recordlist):
# self.debug('START_DATA: %s' % str(envRec))

self.__nexuswriter_device.jsonrecord = rec
self.skipAcquisitionModes = self.__skipAcquisitionModes()
if "INIT" in self.skipAcquisitionModes:
self.acquisitionModes = self.__variableList(
"NeXusAcquisitionModes")
if "NOINIT" in self.acquisitionModes:
self.__nexuswriter_device.skipAcquisition = True

self.__command(self.__nexuswriter_device, "openEntry")
Expand Down Expand Up @@ -1144,7 +1147,7 @@ def _writeRecord(self, record):
rec = json.dumps(
envrecord, cls=NXS_FileRecorder.numpyEncoder)
self.__nexuswriter_device.jsonrecord = rec
if "STEP" in self.skipAcquisitionModes:
if "NOSTEP" in self.acquisitionModes:
self.__nexuswriter_device.skipAcquisition = True

# self.debug('DATA: {"data":%s}' % json.dumps(
Expand Down Expand Up @@ -1214,7 +1217,7 @@ def _endRecordList(self, recordlist):
rec = json.dumps(
envrecord, cls=NXS_FileRecorder.numpyEncoder)
self.__nexuswriter_device.jsonrecord = rec
if "FINAL" in self.skipAcquisitionModes:
if "NOFINAL" in self.acquisitionModes:
self.__nexuswriter_device.skipAcquisition = True
self.__command(self.__nexuswriter_device, "closeEntry")
self.__command(self.__nexuswriter_device, "closeFile")
Expand Down Expand Up @@ -1262,18 +1265,18 @@ def beamtimeid(self):
beamtimeid = self.beamtime_id(bmtfpath, bmtfprefix, bmtfext)
return beamtimeid or "00000000"

def __skipAcquisitionModes(self):
""" find skip acquisition modes
def __variableList(self, variable='NeXusAcquisitionModes'):
""" read variable list
"""
try:
skip_acq = self.__macro().getEnv('NeXusSkipAcquisitionModes')
msvar = self.__macro().getEnv(variable)
except Exception:
skip_acq = []
if isinstance(skip_acq, str):
skip_acq = re.split(r"[-;,.\s]\s*", skip_acq)
if skip_acq:
self.debug('Skip Acquisition Modes: %s' % str(skip_acq))
return skip_acq
msvar = []
if isinstance(msvar, str):
msvar = re.split(r"[-;,.\s]\s*", msvar)
if msvar:
self.debug('%s: %s' % (variable, str(msvar)))
return msvar

def __rawfilename(self, serial):
""" find scan name
Expand Down Expand Up @@ -1364,7 +1367,7 @@ def __appendSciCatDataset(self, hostname=None):
sid = self.__serial
sname = "%s::/%s_%05i;%s_%05i" % (
scanname, entryname, sid, scanname, sid)
if "INIT" in self.skipAcquisitionModes:
if "NOINIT" in self.acquisitionModes:
sname = "%s:%s" % (sname, time.time())

# auto grouping
Expand Down

0 comments on commit 8115f58

Please sign in to comment.