Skip to content

Commit

Permalink
meshesPath & particlesPath: optional
Browse files Browse the repository at this point in the history
Implements that `meshesPath` and `particlesPath` are optional
in openPMD 1.1.0+.
But if they are set, the directories those attributes point to must
exist.
  • Loading branch information
ax3l committed Jan 30, 2018
1 parent 96ba17e commit 4d0c6cb
Showing 1 changed file with 62 additions and 32 deletions.
94 changes: 62 additions & 32 deletions openpmd_validator/check_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,13 @@ def check_root_attr(f, v):
result_array += test_attr(f, v, "required", "openPMD", np.string_, "^[0-9]+\.[0-9]+\.[0-9]+$")
result_array += test_attr(f, v, "required", "openPMDextension", np.uint32)
result_array += test_attr(f, v, "required", "basePath", np.string_, "^\/data\/\%T\/$")
result_array += test_attr(f, v, "required", "meshesPath", np.string_)
result_array += test_attr(f, v, "required", "particlesPath", np.string_)
result_array += test_attr(f, v, "required", "iterationEncoding", np.string_, "^groupBased|fileBased$")
result_array += test_attr(f, v, "required", "iterationFormat", np.string_)

# optional but required for data
result_array += test_attr(f, v, "optional", "meshesPath", np.string_)
result_array += test_attr(f, v, "optional", "particlesPath", np.string_)

# groupBased iteration encoding needs to match basePath
if result_array[0] == 0 :
if f.attrs["iterationEncoding"].decode() == "groupBased" :
Expand Down Expand Up @@ -548,35 +550,45 @@ def check_meshes(f, iteration, v, extensionStates):
# First element : number of errors
# Second element : number of warnings
result_array = np.array([ 0, 0])

# Find the path to the data
base_path = "/data/%s/" % iteration
valid, meshes_path = get_attr(f, "meshesPath")
if not valid :
print("Error: `meshesPath` is missing or malformed in '/'")
return( np.array([1, 0]) )
meshes_path = meshes_path.decode()

if os.path.join( base_path, meshes_path) != ( base_path + meshes_path ):
print("Error: `basePath`+`meshesPath` seems to be malformed "
"(is `basePath` absolute and ends on a `/` ?)")
return( np.array([1, 0]) )
if not valid and v:
print("`meshesPath` attribute is missing in '/' "
"(will not search for mesh records)")
meshes_path = None
else:
meshes_path = meshes_path.decode()

if meshes_path:
if os.path.join( base_path, meshes_path) != ( base_path + meshes_path ):
print("Error: `basePath`+`meshesPath` seems to be malformed "
"(is `basePath` absolute and ends on a `/` ?)")
return( np.array([1, 0]) )
else:
full_meshes_path = (base_path + meshes_path).encode('ascii')
# if set, a directory must exist with this name
if not full_meshes_path in f:
print("Error: `basePath`+`meshesPath` are set but path '{0}' "
"does not exist in file!".format(full_meshes_path))
return( np.array([1, 0]) )
# Find all the meshes
try:
list_meshes = list(f[full_meshes_path].keys())
except KeyError:
list_meshes = []
print( "Iteration %s : found %d meshes"
%( iteration, len(list_meshes) ) )
else:
full_meshes_path = (base_path + meshes_path).encode('ascii')
# Find all the meshes
try:
list_meshes = list(f[full_meshes_path].keys())
except KeyError:
list_meshes = []
print( "Iteration %s : found %d meshes"
%( iteration, len(list_meshes) ) )
list_meshes = []

# Check for the attributes of the STANDARD.md
for field_name in list_meshes :
field = f[full_meshes_path + field_name.encode('ascii')]

result_array += test_record(f[full_meshes_path], field_name)

# General attributes of the record
result_array += test_attr(field, v, "required",
"unitDimension", np.ndarray, np.float64)
Expand Down Expand Up @@ -704,18 +716,36 @@ def check_particles(f, iteration, v, extensionStates) :
# Find the path to the data
base_path = ("/data/%s/" % iteration).encode('ascii')
valid, particles_path = get_attr(f, "particlesPath")
if os.path.join( base_path, particles_path) != \
( base_path + particles_path ) :
print("Error: `basePath`+`particlesPath` seems to be malformed "
"(is `basePath` absolute and ends on a `/` ?)")
return( np.array([1, 0]) )

if not valid and v:
print("`particlesPath` attribute is missing in '/' "
"(will not search for particle records)")
particles_path = None
else:
full_particle_path = base_path + particles_path
# Find all the particle species
try:
list_species = list(f[full_particle_path].keys())
except KeyError:
list_species = []
particles_path = meshes_path.decode()

if particles_path:
if os.path.join( base_path, particles_path) != \
( base_path + particles_path ) :
print("Error: `basePath`+`particlesPath` seems to be malformed "
"(is `basePath` absolute and ends on a `/` ?)")
return(np.array([1, 0]))
else:
full_particle_path = base_path + particles_path
# if set, a directory must exist with this name
if not full_particle_path in f:
print("Error: `basePath`+`particlesPath` are set but path "
"'{0}' does not exist in file!".format(
full_particle_path))
return(np.array([1, 0]))
# Find all the particle species
try:
list_species = list(f[full_particle_path].keys())
except KeyError:
list_species = []
else:
list_species = []

print( "Iteration %s : found %d particle species"
%( iteration, len(list_species) ) )

Expand Down

0 comments on commit 4d0c6cb

Please sign in to comment.