# Buggy code
def _set_paths(self, handle, path):
    """Parses relevant hdf5-paths out of ``handle``.

    Parameters
    ----------
    handle : h5py.File
    path : str
        (absolute) filepath for current hdf5 container
    """
    iterations = []
    encoding = handle.attrs["iterationEncoding"].decode()
    if "groupBased" in encoding:
        iterations = list(handle["/data"].keys())
        mylog.info("open_pmd - found {} iterations in file".format(len(iterations)))
    elif "fileBased" in encoding:
        itformat = handle.attrs["iterationFormat"].decode().split("/")[-1]
        regex = "^" + itformat.replace("%T", "[0-9]+") + "$"
        if path is "":
            mylog.warning(
                "open_pmd - For file based iterations, please use absolute file paths!"
            )
            pass
        for filename in listdir(path):
            if match(regex, filename):
                iterations.append(filename)
        mylog.info(
            "open_pmd - found {} iterations in directory".format(len(iterations))
        )

    if len(iterations) == 0:
        mylog.warning("open_pmd - no iterations found!")
    if "groupBased" in encoding and len(iterations) > 1:
        mylog.warning(
            "open_pmd - only choose to load one iteration ({})".format(
                list(handle["/data"].keys())[0]
            )
        )

    self.base_path = "/data/{}/".format(list(handle["/data"].keys())[0])
    self.meshes_path = self._handle["/"].attrs["meshesPath"].decode()
    self.particles_path = self._handle["/"].attrs["particlesPath"].decode()


# Traceback (KeyError)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-6-606762cc9ee1> in <module>()
----> 1 yt.load('./example-ptcl/hdf5/data00000400.h5')

~/miniconda3/lib/python3.6/site-packages/yt/convenience.py in load(*args, **kwargs)
84     candidates = find_lowest_subclasses(candidates)
85     if len(candidates) == 1:
---> 86         return candidates[0](*args, **kwargs)
87     if len(candidates) == 0:
88         if ytcfg.get("yt", "enzo_db") != '' \

~/miniconda3/lib/python3.6/site-packages/yt/frontends/open_pmd/data_structures.py in __init__(self, filename, dataset_type, storage_filename, units_override, unit_system, **kwargs)
385         self.storage_filename = storage_filename
386         self.fluid_types += ("openPMD",)
--> 387         particles = tuple(str(c) for c in self._handle[self.base_path + self.particles_path].keys())
388         if len(particles) > 1:
389             # Only use on-disk particle names if there is more than one species

~/miniconda3/lib/python3.6/site-packages/yt/utilities/file_handler.py in __getitem__(self, key)
43
44     def __getitem__(self, key):
---> 45         return self.handle[key]
46
47     def __contains__(self, item):

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/_objects.c:2846)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/_objects.c:2804)()

~/miniconda3/lib/python3.6/site-packages/h5py/_hl/group.py in __getitem__(self, name)
167                 raise ValueError("Invalid HDF5 object reference")
168         else:
--> 169             oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
170
171         otype = h5i.get_type(oid)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/_objects.c:2846)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/_objects.c:2804)()

h5py/h5o.pyx in h5py.h5o.open (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/h5o.c:3740)()

KeyError: "Unable to open object (Object 'particles' doesn't exist)"

# Fixed code
def _set_paths(self, handle, path, iteration):
    """Parses relevant hdf5-paths out of ``handle``.

    Parameters
    ----------
    handle : h5py.File
    path : str
        (absolute) filepath for current hdf5 container
    """
    iterations = []
    if iteration is None:
        iteration = list(handle["/data"].keys())[0]
    encoding = handle.attrs["iterationEncoding"].decode()
    if "groupBased" in encoding:
        iterations = list(handle["/data"].keys())
        mylog.info("Found {} iterations in file".format(len(iterations)))
    elif "fileBased" in encoding:
        itformat = handle.attrs["iterationFormat"].decode().split("/")[-1]
        regex = "^" + itformat.replace("%T", "[0-9]+") + "$"
        if path is "":
            mylog.warning("For file based iterations, please use absolute file paths!")
            pass
        for filename in listdir(path):
            if match(regex, filename):
                iterations.append(filename)
        mylog.info("Found {} iterations in directory".format(len(iterations)))

    if len(iterations) == 0:
        mylog.warning("No iterations found!")
    if "groupBased" in encoding and len(iterations) > 1:
        mylog.warning("Only chose to load one iteration ({})".format(iteration))

    self.base_path = "/data/{}/".format(iteration)
    self.meshes_path = self._handle["/"].attrs["meshesPath"].decode()
    try:
        handle[self.base_path + self.meshes_path]
    except KeyError:
        if self.standard_version <= StrictVersion("1.1.0"):
            mylog.info(
                "meshesPath not present in file."
                " Assuming file contains no meshes and has a domain extent of 1m^3!"
            )
        else:
            raise
    self.particles_path = self._handle["/"].attrs["particlesPath"].decode()
    try:
        handle[self.base_path + self.particles_path]
    except KeyError:
        if self.standard_version <= StrictVersion("1.1.0"):
            mylog.info(
                "particlesPath not present in file."
                " Assuming file contains no particles!"
            )
        else:
            raise