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