Skip to content

Commit bfe5fa9

Browse files
committed
write attributes for streamed channels
1 parent 5c330da commit bfe5fa9

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

nxsblisswriter/NXSFile.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"trans_type": "transformation_type",
7373
"trans_vector": "vector",
7474
"trans_offset": "offset",
75-
"source": "nexdatas_source",
75+
# "source": "nexdatas_source",
7676
"strategy": "nexdatas_strategy",
7777
}
7878

@@ -278,18 +278,44 @@ def prepareChannels(self):
278278
lnxpath = nxpath.split("/")
279279
h5path = "/".join([nd.split(":")[0] for nd in lnxpath])
280280
root = self.__mfile.root()
281+
dataset = None
281282
try:
282283
self.__nxfields[key] = root.get_dataset(h5path)
284+
dataset = self.__nxfields[key]
283285
except Exception as e:
284286
if str(e).startswith("No node ["):
285287
# print("S", key, shape, chunk, stream.dtype, ch)
286288
self.__nxfields[key] = self.create_groupfield(
287289
root, lnxpath, dtype, value=None,
288290
shape=shape, chunk=chunk)
291+
dataset = self.__nxfields[key]
289292
else:
290293
self._streams.error(
291294
"NXSFile::prepareChannels() - " % (str(e)))
292295
raise
296+
item = ch
297+
if dataset is not None:
298+
attrs = set(item.keys()) - NOATTRS
299+
am = dataset.attributes
300+
for anm in attrs:
301+
avl = item[anm]
302+
if isinstance(avl, list):
303+
av = avl[0]
304+
while isinstance(av, list) and len(av):
305+
av = av[0]
306+
dtp = str(type(av).__name__)
307+
elif hasattr(avl, "dtype"):
308+
dtp = str(dtype.__name__)
309+
else:
310+
dtp = str(type(avl).__name__)
311+
nanm = ATTRDESC.get(anm, anm)
312+
try:
313+
self.write_attr(am, nanm, dtp, avl, item)
314+
except Exception as e:
315+
self._streams.error(
316+
"NXSFile::prepareChannels() "
317+
"- %s %s %s %s %s %s"
318+
% (am, nanm, dtp, avl, item, str(e)))
293319

294320
def write_scan_points(self):
295321
""" write step data

0 commit comments

Comments
 (0)