Skip to content

Commit b3e1011

Browse files
authored
Merge pull request #36 from ax3l/topic-removeExtensionID
`openPMDextension`: Replace ID with String
2 parents a6f5f61 + 934d5d8 commit b3e1011

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

openpmd_validator/check_h5.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# version of the openPMD standard
2727
openPMD = "2.0.0"
2828

29-
ext_list = {"ED-PIC": np.uint32(1)}
29+
ext_list = ["ED-PIC"]
3030

3131
def help():
3232
""" Print usage information for this file """
@@ -77,7 +77,7 @@ def get_attr(f, name):
7777
return(True, f.attrs[name])
7878
else:
7979
return(False, None)
80-
80+
8181
def get_extensions(f, v):
8282
"""
8383
Get a dictionary which maps each extension name to a bool whether it is
@@ -89,31 +89,26 @@ def get_extensions(f, v):
8989
The object in which to find claimed extensions
9090
v : bool
9191
Verbose option
92-
92+
9393
Returns
9494
-------
9595
A dictionary {string:bool} where the keys are the extension names and the
9696
bool states whether it is enabled or not
9797
"""
98-
valid, extensionIDs = get_attr(f, "openPMDextension")
99-
result = {ext: False for ext in ext_list.keys()}
98+
valid, extensions = get_attr(f, "openPMDextension")
99+
result = {ext: False for ext in ext_list}
100100
if valid:
101-
enabledExtMask = 0
102-
for extension, bitmask in ext_list.items():
103-
# This uses a bitmask to identify activated extensions
104-
if (bitmask & extensionIDs) == bitmask:
105-
result[extension] = True
106-
enabledExtMask |= bitmask
101+
file_list = extensions.decode().split(";")
102+
for e in file_list:
103+
if e in ext_list:
104+
result[e] = True
107105
if v:
108-
print("Info: Found extension '%s'." % extension)
109-
# Mask out the extension bits we have already detected so only
110-
# unknown ones are left
111-
excessIDs = extensionIDs & ~enabledExtMask
112-
if excessIDs:
113-
print("Warning: Unknown extension Mask left: %s" % excessIDs)
106+
print("Info: Found extension '%s'." % e)
107+
else:
108+
print("Warning: Unknown extension: %s" % e)
114109
return result
115-
116-
110+
111+
117112
def test_record(g, r):
118113
"""
119114
Checks if a record is valid
@@ -374,7 +369,7 @@ def check_root_attr(f, v):
374369
----------
375370
f : an h5py.File object
376371
The HDF5 file in which to find the attribute
377-
372+
378373
v : bool
379374
Verbose option
380375
@@ -388,15 +383,16 @@ def check_root_attr(f, v):
388383
# First element : number of errors
389384
# Second element : number of warnings
390385
result_array = np.array([0,0])
391-
386+
392387
# STANDARD.md
393388
# required
394389
result_array += test_attr(f, v, "required", "openPMD", np.string_, "^[0-9]+\.[0-9]+\.[0-9]+$")
395-
result_array += test_attr(f, v, "required", "openPMDextension", np.uint32)
396390
result_array += test_attr(f, v, "required", "basePath", np.string_, "^\/data\/\%T\/$")
397391
result_array += test_attr(f, v, "required", "iterationEncoding", np.string_, "^groupBased|fileBased$")
398392
result_array += test_attr(f, v, "required", "iterationFormat", np.string_)
399393

394+
# optional but required for extensions
395+
result_array += test_attr(f, v, "optional", "openPMDextension", np.string_, "^[a-zA-Z0-9-;]+$")
400396
# optional but required for data
401397
result_array += test_attr(f, v, "optional", "meshesPath", np.string_)
402398
result_array += test_attr(f, v, "optional", "particlesPath", np.string_)

openpmd_validator/createExamples_h5.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ def setup_root_attr(f):
8888
The file in which to write the data
8989
"""
9090

91-
# extensions list
92-
ext_list = [["ED-PIC", np.uint32(1)]]
91+
# extensions list: ED-PIC extension is used
92+
ext_list = ["ED-PIC"]
9393

9494
# Required attributes
9595
f.attrs["openPMD"] = np.string_("2.0.0")
96-
f.attrs["openPMDextension"] = ext_list[0][1] # ED-PIC extension is used
96+
f.attrs["openPMDextension"] = np.string_(";".join(ext_list))
9797
f.attrs["basePath"] = np.string_("/data/%T/")
9898
f.attrs["meshesPath"] = np.string_("meshes/")
9999
f.attrs["particlesPath"] = np.string_("particles/")

0 commit comments

Comments
 (0)