Skip to content

Commit fb122b3

Browse files
authored
Merge pull request #94 from dihm/shot_utils
Moving `get_shot_globals` function from runmanager to labscript_utils.
2 parents 87de9cd + 1568793 commit fb122b3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

labscript_utils/shot_utils.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#####################################################################
2+
# #
3+
# __init__.py #
4+
# #
5+
# Copyright 2013, Monash University #
6+
# #
7+
# This file is part of the labscript suite (see #
8+
# http://labscriptsuite.org) and is licensed under the Simplified #
9+
# BSD License. See the license.txt file in the root of the project #
10+
# for the full license. #
11+
# #
12+
#####################################################################
13+
14+
import h5py
15+
import numpy as np
16+
17+
def get_shot_globals(filepath):
18+
"""Returns the evaluated globals for a shot, for use by labscript or lyse.
19+
Simple dictionary access as in dict(h5py.File(filepath).attrs) would be fine
20+
except we want to apply some hacks, so it's best to do that in one place."""
21+
params = {}
22+
with h5py.File(filepath, 'r') as f:
23+
for name, value in f['globals'].attrs.items():
24+
# Convert numpy bools to normal bools:
25+
if isinstance(value, np.bool_):
26+
value = bool(value)
27+
# Convert null HDF references to None:
28+
if isinstance(value, h5py.Reference) and not value:
29+
value = None
30+
# Convert numpy strings to Python ones.
31+
# DEPRECATED, for backward compat with old files.
32+
if isinstance(value, np.str_):
33+
value = str(value)
34+
if isinstance(value, bytes):
35+
value = value.decode()
36+
params[name] = value
37+
return params

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy