Merged in unitattfix (pull request #57)

Fixing a bug w/ dbpic

Approved-by: Eric Winter
Approved-by: Michael Wiltberger
This commit is contained in:
ksorathia
2025-02-04 14:27:09 +00:00
committed by Michael Wiltberger
2 changed files with 12 additions and 5 deletions

View File

@@ -221,7 +221,7 @@ class GameraPipe(object):
None
"""
uID = kh5.PullAtt(f0, "UnitsID")
uID = kh5.PullAtt(f0, "UnitsID",a0="CODE") #Setting default
#with h5py.File(f0, 'r') as hf:
# uID = hf.attrs.get("UnitsID", "CODE")
if not isinstance(uID, str):

View File

@@ -585,7 +585,7 @@ def PullVar(fname, vID, s0=None, slice=()):
return V
#Get attribute data from Step#s0 or root (s0=None)
def PullAtt(fname, vID, s0=None):
def PullAtt(fname, vID, s0=None, a0=None):
'''
Retrieve an attribute from an HDF5 file.
@@ -593,7 +593,7 @@ def PullAtt(fname, vID, s0=None):
fname (str): The path to the HDF5 file.
vID (str): The name of the attribute to retrieve.
s0 (int, optional): The step number. If provided, the attribute will be retrieved from the group corresponding to the step number.
a0 (whatevs, optional): The default for the attribute if it's not in the file
Returns:
The value of the attribute.
@@ -604,9 +604,16 @@ def PullAtt(fname, vID, s0=None):
CheckOrDie(fname)
with h5py.File(fname, 'r') as hf:
if s0 is None:
Q = hf.attrs[vID]
hfA = hf.attrs
else:
gID = "/Step#%d" % (s0)
Q = hf[gID].attrs[vID]
hfA = hf[gID].attrs
if (vID not in hfA.keys()):
#Use default
Q = a0
else:
Q = hfA[vID]
return Q