2626# version of the openPMD standard
2727openPMD = "2.0.0"
2828
29- ext_list = ["ED-PIC" ]
29+ ext_list = ["ED-PIC" , "SpeciesType" ]
3030
3131def 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
6469def open_file (file_name ):
@@ -392,7 +397,7 @@ 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_ , "^[a-zA-Z0-9\ -;]+$" )
396401 # optional but required for data
397402 result_array += test_attr (f , v , "optional" , "meshesPath" , np .string_ )
398403 result_array += test_attr (f , v , "optional" , "particlesPath" , np .string_ )
@@ -677,6 +682,16 @@ def check_meshes(f, iteration, v, extensionStates):
677682 if (valid == True ) and (field_smoothing != b"none" ) :
678683 result_array += test_attr (field ,v , "required" ,
679684 "fieldSmoothingParameters" , np .string_ )
685+
686+ # Check the attributes in the SpeciesType extension
687+ if extensionStates ['SpeciesType' ] :
688+ # Check for the attributes of each record
689+ for field_name in list_meshes :
690+ field = f [full_meshes_path + field_name .encode ('ascii' )]
691+ result_array += test_attr (field , v , "optional" ,
692+ "speciesType" , np .string_ ,
693+ "^[a-zA-Z0-9\-;:]+$" )
694+
680695 return (result_array )
681696
682697
@@ -824,6 +839,11 @@ def check_particles(f, iteration, v, extensionStates) :
824839 result_array += test_attr (species , v , "required" ,
825840 "particleSmoothingParameters" , np .string_ )
826841
842+ # Check the attributes associated with the SpeciesType extension
843+ if extensionStates ['SpeciesType' ] :
844+ result_array += test_attr (species , v , "optional" , "speciesType" ,
845+ np .string_ , "^[a-zA-Z0-9\-;:]+$" )
846+
827847 # Check attributes of each record of the particle
828848 for record in list (species .keys ()) :
829849 # all records (but particlePatches) require units
@@ -851,7 +871,8 @@ def check_particles(f, iteration, v, extensionStates) :
851871 return (result_array )
852872
853873
854- def check_file (file_name , verbose = False , force_extension_pic = False ):
874+ def check_file (file_name , verbose = False , force_extension_pic = False ,
875+ force_extension_speciestype = False ):
855876 f = open_file (file_name )
856877
857878 # root attributes at "/"
@@ -862,6 +883,9 @@ def check_file(file_name, verbose=False, force_extension_pic=False):
862883 if force_extension_pic and not extensionStates ["ED-PIC" ] :
863884 print ("Error: Extension `ED-PIC` not found in file!" )
864885 result_array += np .array ([1 , 0 ])
886+ if force_extension_speciestype and not extensionStates ["SpeciesType" ] :
887+ print ("Error: Extension `SpeciesType` not found in file!" )
888+ result_array += np .array ([1 , 0 ])
865889
866890 # Go through all the iterations, checking both the particles
867891 # and the meshes
@@ -871,8 +895,10 @@ def check_file(file_name, verbose=False, force_extension_pic=False):
871895
872896
873897def main ():
874- file_name , verbose , force_extension_pic = parse_cmd (sys .argv [1 :])
875- result_array = check_file (file_name , verbose , force_extension_pic )
898+ file_name , verbose , \
899+ force_extension_pic , force_extension_speciestype = parse_cmd (sys .argv [1 :])
900+ result_array = check_file (file_name , verbose ,
901+ force_extension_pic , force_extension_speciestype )
876902
877903 # results
878904 print ("Result: %d Errors and %d Warnings."
0 commit comments