@@ -394,11 +394,13 @@ def check_root_attr(f, v):
394394 result_array += test_attr (f , v , "required" , "openPMD" , np .string_ , "^[0-9]+\.[0-9]+\.[0-9]+$" )
395395 result_array += test_attr (f , v , "required" , "openPMDextension" , np .uint32 )
396396 result_array += test_attr (f , v , "required" , "basePath" , np .string_ , "^\/data\/\%T\/$" )
397- result_array += test_attr (f , v , "required" , "meshesPath" , np .string_ )
398- result_array += test_attr (f , v , "required" , "particlesPath" , np .string_ )
399397 result_array += test_attr (f , v , "required" , "iterationEncoding" , np .string_ , "^groupBased|fileBased$" )
400398 result_array += test_attr (f , v , "required" , "iterationFormat" , np .string_ )
401399
400+ # optional but required for data
401+ result_array += test_attr (f , v , "optional" , "meshesPath" , np .string_ )
402+ result_array += test_attr (f , v , "optional" , "particlesPath" , np .string_ )
403+
402404 # groupBased iteration encoding needs to match basePath
403405 if result_array [0 ] == 0 :
404406 if f .attrs ["iterationEncoding" ].decode () == "groupBased" :
@@ -550,35 +552,43 @@ def check_meshes(f, iteration, v, extensionStates):
550552 # First element : number of errors
551553 # Second element : number of warnings
552554 result_array = np .array ([ 0 , 0 ])
553-
555+
554556 # Find the path to the data
555557 base_path = "/data/%s/" % iteration
556558 valid , meshes_path = get_attr (f , "meshesPath" )
557- if not valid :
558- print ("Error: `meshesPath` is missing or malformed in '/'" )
559- return ( np .array ([1 , 0 ]) )
560- meshes_path = meshes_path .decode ()
561-
562- if os .path .join ( base_path , meshes_path ) != ( base_path + meshes_path ):
563- print ("Error: `basePath`+`meshesPath` seems to be malformed "
564- "(is `basePath` absolute and ends on a `/` ?)" )
565- return ( np .array ([1 , 0 ]) )
559+ if valid :
560+ meshes_path = meshes_path .decode ()
566561 else :
567- full_meshes_path = (base_path + meshes_path ).encode ('ascii' )
568- # Find all the meshes
569- try :
562+ meshes_path = None
563+ if v :
564+ print ("`meshesPath` attribute is missing in '/' "
565+ "(will not search for mesh records)" )
566+
567+ if meshes_path :
568+ if os .path .join ( base_path , meshes_path ) != ( base_path + meshes_path ):
569+ print ("Error: `basePath`+`meshesPath` seems to be malformed "
570+ "(is `basePath` absolute and ends on a `/` ?)" )
571+ return ( np .array ([1 , 0 ]) )
572+ else :
573+ full_meshes_path = (base_path + meshes_path ).encode ('ascii' )
574+ # if set, a directory must exist with this name
575+ if not full_meshes_path in f :
576+ print ("Error: `basePath`+`meshesPath` are set but path '{0}' "
577+ "does not exist in file!" .format (full_meshes_path ))
578+ return ( np .array ([1 , 0 ]) )
579+ # Find all the meshes
570580 list_meshes = list (f [full_meshes_path ].keys ())
571- except KeyError :
572- list_meshes = []
573- print ( "Iteration %s : found %d meshes"
574- % ( iteration , len ( list_meshes ) ) )
581+ print ( "Iteration %s : found %d meshes"
582+ % ( iteration , len ( list_meshes ) ) )
583+ else :
584+ list_meshes = []
575585
576586 # Check for the attributes of the STANDARD.md
577587 for field_name in list_meshes :
578588 field = f [full_meshes_path + field_name .encode ('ascii' )]
579589
580590 result_array += test_record (f [full_meshes_path ], field_name )
581-
591+
582592 # General attributes of the record
583593 result_array += test_attr (field , v , "required" ,
584594 "unitDimension" , np .ndarray , np .float64 )
@@ -704,27 +714,43 @@ def check_particles(f, iteration, v, extensionStates) :
704714 result_array = np .array ([ 0 , 0 ])
705715
706716 # Find the path to the data
707- base_path = ( "/data/%s/" % iteration ). encode ( 'ascii' )
717+ base_path = "/data/%s/" % iteration
708718 valid , particles_path = get_attr (f , "particlesPath" )
709- if os .path .join ( base_path , particles_path ) != \
710- ( base_path + particles_path ) :
711- print ("Error: `basePath`+`particlesPath` seems to be malformed "
712- "(is `basePath` absolute and ends on a `/` ?)" )
713- return ( np .array ([1 , 0 ]) )
719+
720+ if valid :
721+ particles_path = particles_path .decode ()
714722 else :
715- full_particle_path = base_path + particles_path
716- # Find all the particle species
717- try :
723+ particles_path = None
724+ if v :
725+ print ("`particlesPath` attribute is missing in '/' "
726+ "(will not search for particle records)" )
727+
728+ if particles_path :
729+ if os .path .join ( base_path , particles_path ) != \
730+ ( base_path + particles_path ) :
731+ print ("Error: `basePath`+`particlesPath` seems to be malformed "
732+ "(is `basePath` absolute and ends on a `/` ?)" )
733+ return (np .array ([1 , 0 ]))
734+ else :
735+ full_particle_path = (base_path + particles_path ).encode ('ascii' )
736+ # if set, a directory must exist with this name
737+ if not full_particle_path in f :
738+ print ("Error: `basePath`+`particlesPath` are set but path "
739+ "'{0}' does not exist in file!" .format (
740+ full_particle_path ))
741+ return (np .array ([1 , 0 ]))
742+ # Find all the particle species
718743 list_species = list (f [full_particle_path ].keys ())
719- except KeyError :
720- list_species = []
744+ else :
745+ list_species = []
746+
721747 print ( "Iteration %s : found %d particle species"
722748 % ( iteration , len (list_species ) ) )
723749
724750 # Go through all the particle species
725751 for species_name in list_species :
726752 species = f [full_particle_path + species_name .encode ('ascii' )]
727-
753+
728754 # Check all records for this species
729755 for species_record_name in species :
730756 result_array += test_record (species , species_record_name )
0 commit comments