# Buggy code
def __init__(self, ds, field_list):
    f = ds._handle
    bp = ds.base_path
    mp = ds.meshes_path
    pp = ds.particles_path
    fields = f[bp + mp]

    for fname in fields.keys():
        field = fields[fname]
        if type(field) is h5.Dataset or is_const_component(field):
            # Don't consider axes. This appears to be a vector field of single dimensionality
            ytname = str("_".join([fname.replace("_", "-")]))
            parsed = parse_unit_dimension(
                np.asarray(field.attrs["unitDimension"], dtype=np.int)
            )
            unit = str(YTQuantity(1, parsed).units)
            aliases = []
            # Save a list of magnetic fields for aliasing later on
            # We can not reasonably infer field type/unit by name in openPMD
            if unit == "T" or unit == "kg/(A*s**2)":
                self._mag_fields.append(ytname)
            self.known_other_fields += ((ytname, (unit, aliases, None)),)
        else:
            for axis in field.keys():
                ytname = str("_".join([fname.replace("_", "-"), axis]))
                parsed = parse_unit_dimension(
                    np.asarray(field.attrs["unitDimension"], dtype=np.int)
                )
                unit = str(YTQuantity(1, parsed).units)
                aliases = []
                # Save a list of magnetic fields for aliasing later on
                # We can not reasonably infer field type by name in openPMD
                if unit == "T" or unit == "kg/(A*s**2)":
                    self._mag_fields.append(ytname)
                self.known_other_fields += ((ytname, (unit, aliases, None)),)
    for i in self.known_other_fields:
        mylog.debug("open_pmd - known_other_fields - {}".format(i))
    particles = f[bp + pp]
    for species in particles.keys():
        for record in particles[species].keys():
            try:
                pds = particles[species + "/" + record]
                parsed = parse_unit_dimension(pds.attrs["unitDimension"])
                unit = str(YTQuantity(1, parsed).units)
                ytattrib = str(record).replace("_", "-")
                if ytattrib == "position":
                    # Symbolically rename position to preserve yt's interpretation of the pfield
                    # particle_position is later derived in setup_absolute_positions in the way yt expects it
                    ytattrib = "positionCoarse"
                if type(pds) is h5.Dataset or is_const_component(pds):
                    name = ["particle", ytattrib]
                    self.known_particle_fields += (
                        (str("_".join(name)), (unit, [], None)),
                    )
                else:
                    for axis in pds.keys():
                        aliases = []
                        name = ["particle", ytattrib, axis]
                        ytname = str("_".join(name))
                        self.known_particle_fields += ((ytname, (unit, aliases, None)),)
            except KeyError:
                mylog.info(
                    "open_pmd - {}_{} does not seem to have unitDimension".format(
                        species, record
                    )
                )
    for i in self.known_particle_fields:
        mylog.debug("open_pmd - known_particle_fields - {}".format(i))
    super(OpenPMDFieldInfo, self).__init__(ds, field_list)


# 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 __init__(self, ds, field_list):
    f = ds._handle
    bp = ds.base_path
    mp = ds.meshes_path
    pp = ds.particles_path

    try:
        fields = f[bp + mp]
        for fname in fields.keys():
            field = fields[fname]
            if type(field) is h5.Dataset or is_const_component(field):
                # Don't consider axes. This appears to be a vector field of single dimensionality
                ytname = str("_".join([fname.replace("_", "-")]))
                parsed = parse_unit_dimension(
                    np.asarray(field.attrs["unitDimension"], dtype=np.int)
                )
                unit = str(YTQuantity(1, parsed).units)
                aliases = []
                # Save a list of magnetic fields for aliasing later on
                # We can not reasonably infer field type/unit by name in openPMD
                if unit == "T" or unit == "kg/(A*s**2)":
                    self._mag_fields.append(ytname)
                self.known_other_fields += ((ytname, (unit, aliases, None)),)
            else:
                for axis in field.keys():
                    ytname = str("_".join([fname.replace("_", "-"), axis]))
                    parsed = parse_unit_dimension(
                        np.asarray(field.attrs["unitDimension"], dtype=np.int)
                    )
                    unit = str(YTQuantity(1, parsed).units)
                    aliases = []
                    # Save a list of magnetic fields for aliasing later on
                    # We can not reasonably infer field type by name in openPMD
                    if unit == "T" or unit == "kg/(A*s**2)":
                        self._mag_fields.append(ytname)
                    self.known_other_fields += ((ytname, (unit, aliases, None)),)
        for i in self.known_other_fields:
            mylog.debug("open_pmd - known_other_fields - {}".format(i))
    except KeyError:
        pass

    try:
        particles = f[bp + pp]
        for pname in particles.keys():
            species = particles[pname]
            for recname in species.keys():
                try:
                    record = species[recname]
                    parsed = parse_unit_dimension(record.attrs["unitDimension"])
                    unit = str(YTQuantity(1, parsed).units)
                    ytattrib = str(recname).replace("_", "-")
                    if ytattrib == "position":
                        # Symbolically rename position to preserve yt's interpretation of the pfield
                        # particle_position is later derived in setup_absolute_positions in the way yt expects it
                        ytattrib = "positionCoarse"
                    if type(record) is h5.Dataset or is_const_component(record):
                        name = ["particle", ytattrib]
                        self.known_particle_fields += (
                            (str("_".join(name)), (unit, [], None)),
                        )
                    else:
                        for axis in record.keys():
                            aliases = []
                            name = ["particle", ytattrib, axis]
                            ytname = str("_".join(name))
                            self.known_particle_fields += (
                                (ytname, (unit, aliases, None)),
                            )
                except KeyError:
                    if recname != "particlePatches":
                        mylog.info(
                            "open_pmd - {}_{} does not seem to have unitDimension".format(
                                pname, recname
                            )
                        )
        for i in self.known_particle_fields:
            mylog.debug("open_pmd - known_particle_fields - {}".format(i))
    except KeyError:
        pass

    super(OpenPMDFieldInfo, self).__init__(ds, field_list)