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,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
873901def 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."
0 commit comments