Skip to content

Commit c85d574

Browse files
authored
Merge pull request #38 from ax3l/topic-speciesTypeExtension
New Attribute: speciesType
2 parents b3e1011 + 71f9705 commit c85d574

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

openpmd_validator/check_h5.py

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

29-
ext_list = ["ED-PIC"]
29+
ext_list = ["ED-PIC", "SpeciesType"]
3030

3131
def help():
3232
""" Print usage information for this file """
3333
print('This is the openPMD file check for HDF5 files.\n')
3434
print('Check for format version: %s\n' % openPMD)
35-
print('Usage:\n checkOpenPMD_h5.py -i <fileName> [-v] [--EDPIC]')
35+
print('Usage:\n checkOpenPMD_h5.py -i <fileName> [-v] [--EDPIC] '
36+
'[--SpeciesType]')
3637
sys.exit()
3738

3839

@@ -41,8 +42,10 @@ def parse_cmd(argv):
4142
file_name = ''
4243
verbose = False
4344
force_extension_pic = False
45+
force_extension_speciestype = False
4446
try:
45-
opts, args = getopt.getopt(argv,"hvi:e",["file=","EDPIC"])
47+
opts, args = getopt.getopt(argv,"hvi:e",
48+
["file=","EDPIC", "SpeciesType"])
4649
except getopt.GetoptError:
4750
print('checkOpenPMD_h5.py -i <fileName>')
4851
sys.exit(2)
@@ -53,12 +56,14 @@ def parse_cmd(argv):
5356
verbose = True
5457
elif opt in ("--EDPIC"):
5558
force_extension_pic = True
59+
elif opt in ("--SpeciesType"):
60+
force_extension_speciestype = True
5661
elif opt in ("-i", "--file"):
5762
file_name = arg
5863
if not os.path.isfile(file_name):
5964
print("File '%s' not found!" % file_name)
6065
help()
61-
return(file_name, verbose, force_extension_pic)
66+
return file_name, verbose, force_extension_pic, force_extension_speciestype
6267

6368

6469
def open_file(file_name):
@@ -392,7 +397,9 @@ def check_root_attr(f, v):
392397
result_array += test_attr(f, v, "required", "iterationFormat", np.string_)
393398

394399
# optional but required for extensions
395-
result_array += test_attr(f, v, "optional", "openPMDextension", np.string_, "^[a-zA-Z0-9-;]+$")
400+
result_array += test_attr(f, v, "optional", "openPMDextension", np.string_,
401+
# allowed are a-Z 0-9 - ; (but no spaces!)
402+
"^[a-zA-Z0-9\-;]+$")
396403
# optional but required for data
397404
result_array += test_attr(f, v, "optional", "meshesPath", np.string_)
398405
result_array += test_attr(f, v, "optional", "particlesPath", np.string_)
@@ -677,6 +684,17 @@ def check_meshes(f, iteration, v, extensionStates):
677684
if (valid == True) and (field_smoothing != b"none") :
678685
result_array += test_attr(field,v, "required",
679686
"fieldSmoothingParameters", np.string_)
687+
688+
# Check the attributes in the SpeciesType extension
689+
if extensionStates['SpeciesType'] :
690+
# Check for the attributes of each record
691+
for field_name in list_meshes :
692+
field = f[full_meshes_path + field_name.encode('ascii')]
693+
# allowed are a-Z 0-9 - ; : (but no spaces!)
694+
result_array += test_attr(field, v, "optional",
695+
"speciesType", np.string_,
696+
"^[a-zA-Z0-9\-;:]+$")
697+
680698
return(result_array)
681699

682700

@@ -824,6 +842,12 @@ def check_particles(f, iteration, v, extensionStates) :
824842
result_array += test_attr(species, v, "required",
825843
"particleSmoothingParameters", np.string_)
826844

845+
# Check the attributes associated with the SpeciesType extension
846+
if extensionStates['SpeciesType'] :
847+
# allowed are a-Z 0-9 - ; : (but no spaces!)
848+
result_array += test_attr(species, v, "optional", "speciesType",
849+
np.string_, "^[a-zA-Z0-9\-;:]+$")
850+
827851
# Check attributes of each record of the particle
828852
for record in list(species.keys()) :
829853
# all records (but particlePatches) require units
@@ -851,7 +875,8 @@ def check_particles(f, iteration, v, extensionStates) :
851875
return(result_array)
852876

853877

854-
def check_file(file_name, verbose=False, force_extension_pic=False):
878+
def check_file(file_name, verbose=False, force_extension_pic=False,
879+
force_extension_speciestype=False):
855880
f = open_file(file_name)
856881

857882
# root attributes at "/"
@@ -862,6 +887,9 @@ def check_file(file_name, verbose=False, force_extension_pic=False):
862887
if force_extension_pic and not extensionStates["ED-PIC"] :
863888
print("Error: Extension `ED-PIC` not found in file!")
864889
result_array += np.array([1, 0])
890+
if force_extension_speciestype and not extensionStates["SpeciesType"] :
891+
print("Error: Extension `SpeciesType` not found in file!")
892+
result_array += np.array([1, 0])
865893

866894
# Go through all the iterations, checking both the particles
867895
# and the meshes
@@ -871,8 +899,10 @@ def check_file(file_name, verbose=False, force_extension_pic=False):
871899

872900

873901
def main():
874-
file_name, verbose, force_extension_pic = parse_cmd(sys.argv[1:])
875-
result_array = check_file(file_name, verbose, force_extension_pic)
902+
file_name, verbose, \
903+
force_extension_pic, force_extension_speciestype = parse_cmd(sys.argv[1:])
904+
result_array = check_file(file_name, verbose,
905+
force_extension_pic, force_extension_speciestype)
876906

877907
# results
878908
print("Result: %d Errors and %d Warnings."

openpmd_validator/createExamples_h5.py

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

91-
# extensions list: ED-PIC extension is used
92-
ext_list = ["ED-PIC"]
91+
# extensions list: ED-PIC and SpeciesType extensions are used
92+
ext_list = ["ED-PIC", "SpeciesType"]
9393

9494
# Required attributes
9595
f.attrs["openPMD"] = np.string_("2.0.0")
@@ -139,6 +139,7 @@ def write_rho_cylindrical(meshes, mode0, mode1):
139139
rho = meshes[full_rho_path]
140140
rho.attrs["comment"] = np.string_(
141141
"Density of electrons in azimuthal decomposition")
142+
rho.attrs["speciesType"] = np.string_("electron")
142143

143144
# Create the dataset (cylindrical with azimuthal modes up to m=1)
144145
# The first axis has size 2m+1
@@ -323,6 +324,7 @@ def add_EDPIC_attr_particles(particle):
323324
The group of the particle that gets additional attributes.
324325
325326
"""
327+
particle.attrs["speciesType"] = np.string_("electron")
326328
particle.attrs["particleShape"] = 3.0
327329
particle.attrs["currentDeposition"] = np.string_("Esirkepov")
328330
# particle.attrs["currentDepositionParameters"] = np.string_("")

0 commit comments

Comments
 (0)