# Buggy code
def parse_hypermap(self, index=0, downsample=1, cutoff_at_kV=None, lazy=False):
    """Unpack the Delphi/Bruker binary spectral map and return
    numpy array in memory efficient way.

    Pure python/numpy implimentation -- slow, or
    cython/memoryview/numpy implimentation if compilied and present
    (fast) is used.

    Arguments:
    index -- the index of hypermap in bcf if there is more than one
        hyper map in file.
    downsample -- downsampling factor (integer). Diferently than
        block_reduce from skimage.measure, the parser populates
        reduced array by suming results of pixels, thus having lower
        memory requiriments. (default 1)
    cutoff_at_kV -- value in keV to truncate the array at. Helps reducing
      size of array. (default None)
    lazy -- return dask.array (True) or numpy.array (False) (default False)

    Returns:
    numpy or dask array of bruker hypermap, with (y,x,E) shape.
    """

    if type(cutoff_at_kV) in (int, float):
        eds = self.header.get_spectra_metadata()
        cutoff_chan = eds.energy_to_channel(cutoff_at_kV)
    else:
        cutoff_chan = None

    if fast_unbcf:
        fh = dd(self.get_file)("EDSDatabase/SpectrumData" + str(index))  # noqa
        value = dd(unbcf_fast.parse_to_numpy)(
            fh,  # noqa
            downsample=downsample,
            cutoff=cutoff_chan,
            description=False,
        )
        if lazy:
            shape, dtype = unbcf_fast.parse_to_numpy(
                fh.compute(),
                downsample=downsample,
                cutoff=cutoff_chan,
                description=True,
            )
            res = da.from_delayed(value, shape=shape, dtype=dtype)
        else:
            res = value.compute()
        return res
    else:
        value = dd(self.py_parse_hypermap)(
            index=0,
            downsample=downsample,
            cutoff_at_channel=cutoff_chan,
            description=False,
        )
        if lazy:
            shape, dtype = self.py_parse_hypermap(
                index=0,
                downsample=downsample,
                cutoff_at_channel=cutoff_chan,
                description=True,
            )
            res = da.from_delayed(value, shape=shape, dtype=dtype)
        else:
            res = value.compute()
        return res


# Traceback (IndexError)
hs.load(filename)
Traceback (most recent call last):

File "<ipython-input-3-ada763a7934e>", line 1, in <module>
hs.load(filename)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io.py", line 243, in load
for filename in filenames]

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io.py", line 243, in <listcomp>
for filename in filenames]

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io.py", line 286, in load_single_file
**kwds)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io.py", line 295, in load_with_reader
**kwds)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io_plugins\bcf.py", line 1189, in file_reader
obj_bcf = BCF_reader(filename, instrument=instrument)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io_plugins\bcf.py", line 876, in __init__
self.header = HyperHeader(header_byte_str, instrument=instrument)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io_plugins\bcf.py", line 585, in __init__
self._set_sum_edx(root)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io_plugins\bcf.py", line 735, in _set_sum_edx
str(i))[0].ClassInstance)

IndexError: list index out of range

# Fixed code
def parse_hypermap(self, index=None, downsample=1, cutoff_at_kV=None, lazy=False):
    """Unpack the Delphi/Bruker binary spectral map and return
    numpy array in memory efficient way.

    Pure python/numpy implementation -- slow, or
    cython/memoryview/numpy implimentation if compilied and present
    (fast) is used.

    Arguments:
    index -- the index of hypermap in bcf if there is more than one
        hyper map in file.
    downsample -- downsampling factor (integer). Diferently than
        block_reduce from skimage.measure, the parser populates
        reduced array by suming results of pixels, thus having lower
        memory requiriments. (default 1)
    cutoff_at_kV -- value in keV to truncate the array at. Helps reducing
      size of array. (default None)
    lazy -- return dask.array (True) or numpy.array (False) (default False)

    Returns:
    numpy or dask array of bruker hypermap, with (y,x,E) shape.
    """
    if index is None:
        index = self.def_index
    if type(cutoff_at_kV) in (int, float):
        eds = self.header.get_spectra_metadata(index)
        cutoff_chan = eds.energy_to_channel(cutoff_at_kV)
    else:
        cutoff_chan = None

    if fast_unbcf:
        fh = dd(self.get_file)("EDSDatabase/SpectrumData" + str(index))  # noqa
        value = dd(unbcf_fast.parse_to_numpy)(
            fh,  # noqa
            downsample=downsample,
            cutoff=cutoff_chan,
            description=False,
            index=index,
        )
        if lazy:
            shape, dtype = unbcf_fast.parse_to_numpy(
                fh.compute(),
                downsample=downsample,
                cutoff=cutoff_chan,
                description=True,
                index=index,
            )
            res = da.from_delayed(value, shape=shape, dtype=dtype)
        else:
            res = value.compute()
        return res
    else:
        value = dd(self.py_parse_hypermap)(
            index=index,
            downsample=downsample,
            cutoff_at_channel=cutoff_chan,
            description=False,
        )
        if lazy:
            shape, dtype = self.py_parse_hypermap(
                index=index,
                downsample=downsample,
                cutoff_at_channel=cutoff_chan,
                description=True,
            )
            res = da.from_delayed(value, shape=shape, dtype=dtype)
        else:
            res = value.compute()
        return res