Skip to content

Commit

Permalink
Merge pull request #100 from RemiLehe/fix_check_all_files
Browse files Browse the repository at this point in the history
Close #98 : `check_all_files=False` breaks slider and time access of data
  • Loading branch information
soerenjalas committed May 4, 2016
2 parents a796a79 + da8a21f commit 135809c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
24 changes: 17 additions & 7 deletions opmd_viewer/openpmd_timeseries/data_reader/params_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .utilities import is_scalar_record, get_shape, get_bpath


def read_openPMD_params(filename):
def read_openPMD_params(filename, extract_parameters=True):
"""
Extract the time and some openPMD parameters from a file
Expand All @@ -23,14 +23,17 @@ def read_openPMD_params(filename):
filename: string
The path to the file from which parameters should be extracted
extract_parameters: bool, optional
Whether to extract all parameters or only the time
(Function execution is faster when extract_parameters is False)
Returns
-------
A tuple with:
- A float corresponding to the time of this iteration in SI units
- A dictionary containing several parameters, such as the geometry, etc.
When extract_parameters is False, the second argument returned is None.
"""
params = {}

# Open the file, and do a version check
f = h5py.File(filename, 'r')
version = f.attrs['openPMD'].decode()
Expand All @@ -39,6 +42,17 @@ def read_openPMD_params(filename):
"File %s is not supported: Invalid openPMD version: "
"%s)" % (filename, version))

# Find the base path object, and extract the time
bpath = f[get_bpath(f)]
t = bpath.attrs["time"] * bpath.attrs["timeUnitSI"]

# If the user did not request more parameters, exit now.
if not extract_parameters:
return(t, None)

# Otherwise, extract the rest of the parameters
params = {}

# Find out supported openPMD extensions claimed by this file
# note: a file might implement multiple extensions
known_extensions = {'ED-PIC': np.uint32(1)}
Expand All @@ -53,10 +67,6 @@ def read_openPMD_params(filename):
if bitmask_all_extensions & bitmask == bitmask:
params['extensions'].append(extension)

# Find the base path object, and extract the time
bpath = f[get_bpath(f)]
t = bpath.attrs["time"] * bpath.attrs["timeUnitSI"]

# Find out whether fields are present and extract their geometry
meshes_path = f.attrs['meshesPath'].decode().strip('/')
if meshes_path in bpath.keys():
Expand Down
24 changes: 10 additions & 14 deletions opmd_viewer/openpmd_timeseries/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@
'The opmd_viewer API is nonetheless working.')
parent_class = object

# Define a custom Exception


# Define a custom Exception
class OpenPMDException(Exception):

"Exception raised for invalid use of the openPMD-viewer API"
pass


# Define the OpenPMDTimeSeries class and have it inherit
# from the parent class defined above


class OpenPMDTimeSeries(parent_class):

"""
Main class for the exploration of an openPMD timeseries
Expand Down Expand Up @@ -100,19 +96,19 @@ def __init__(self, path_to_dir, check_all_files=True):
self.avail_species = params0['avail_species']
self.avail_record_components = \
params0['avail_record_components']
# deprecated
self.avail_ptcl_quantities = params0['avail_ptcl_quantities']

# - Check that the other files have the same parameters
if check_all_files:
for k in range(1, N_files):
t, params = read_openPMD_params(self.h5_files[k])
self.t[k] = t

# - Extract the time for each file and, if requested, check
# that the other files have the same parameters
for k in range(1, N_files):
t, params = read_openPMD_params(self.h5_files[k], check_all_files)
self.t[k] = t
if check_all_files:
for key in params0.keys():
if params != params0:
print("Warning: File %s has different openPMD "
"parameters than the rest of the time series."
% self.h5_files[k])
break

# - Set the current iteration and time
self.current_i = 0
Expand Down

0 comments on commit 135809c

Please sign in to comment.