Skip to content

Commit

Permalink
extract time step from hdf5 directly not from file name
Browse files Browse the repository at this point in the history
  • Loading branch information
PrometheusPi committed Feb 21, 2017
1 parent b7e84c0 commit e69310b
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions opmd_viewer/openpmd_timeseries/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
It defines a number of helper functions that are used in main.py
Copyright 2015-2016, openPMD-viewer contributors
Authors: Remi Lehe
Copyright 2015-2017, openPMD-viewer contributors
Authors: Remi Lehe, Richard Pausch
License: 3-Clause-BSD-LBNL
"""

import os
import re
import numpy as np
import h5py
from .data_reader.particle_reader import read_species_data


Expand Down Expand Up @@ -38,17 +39,15 @@ def list_h5_files(path_to_dir):
for filename in all_files:
# Use only the name that end with .h5 or .hdf5
if filename[-3:] == '.h5' or filename[-5:] == '.hdf5':
# Extract the iteration, using regular expressions (regex)
regex_match = re.search('(\d+).h[df]*5', filename)
if regex_match is None:
print('Ill-formated HDF5 file: %s\n File names should end with'
' the iteration number, followed by ".h5"' % filename)
else:
iteration = int(regex_match.groups()[-1])
full_name = os.path.join(
os.path.abspath(path_to_dir), filename)
# Create list of tuples (which can be sorted together)
iters_and_names.append((iteration, full_name))
full_name = os.path.join(
os.path.abspath(path_to_dir), filename)
# extract time step / iteration from first time
# entry in hdf5 file
f = h5py.File(full_name, 'r')
iteration = int(list(f['/data'].items())[0][0])
f.close()
# Create list of tuples (which can be sorted together)
iters_and_names.append((iteration, full_name))

# Sort the list of tuples according to the iteration
iters_and_names.sort()
Expand Down

0 comments on commit e69310b

Please sign in to comment.