# Buggy code
def _parse_image(self, xml_node, overview=False):
    """parse image from bruker xml image node."""
    if overview:
        rect_node = xml_node.find(
            "./ChildClassInstances"
            "/ClassInstance["
            # "@Type='TRTRectangleOverlayElement' and "
            "@Name='Map']/TRTSolidOverlayElement/"
            "TRTBasicLineOverlayElement/TRTOverlayElement"
        )
        if rect_node is not None:
            over_rect = dictionarize(rect_node)["TRTOverlayElement"]["Rect"]
            rect = {
                "y1": over_rect["Top"] * self.y_res,
                "x1": over_rect["Left"] * self.x_res,
                "y2": over_rect["Bottom"] * self.y_res,
                "x2": over_rect["Right"] * self.x_res,
            }
            over_dict = {
                "marker_type": "Rectangle",
                "plot_on_signal": True,
                "data": rect,
                "marker_properties": {"color": "yellow", "linewidth": 2},
            }
    image = Container()
    image.width = int(xml_node.find("./Width").text)  # in pixels
    image.height = int(xml_node.find("./Height").text)  # in pixels
    image.plane_count = int(xml_node.find("./PlaneCount").text)
    image.images = []
    for i in range(image.plane_count):
        img = xml_node.find("./Plane" + str(i))
        raw = codecs.decode((img.find("./Data").text).encode("ascii"), "base64")
        array1 = np.frombuffer(raw, dtype=np.uint16)
        if any(array1):
            item = self.gen_hspy_item_dict_basic()
            data = array1.reshape((image.height, image.width))
            detector_name = str(img.find("./Description").text)
            item["data"] = data
            item["axes"][0]["size"] = image.height
            item["axes"][1]["size"] = image.width
            item["metadata"]["General"] = {"title": detector_name}
            item["metadata"]["Signal"] = {
                "signal_type": detector_name,
                "record_by": "image",
            }
            if overview and (rect_node is not None):
                item["metadata"]["Markers"] = {"overview": over_dict}
            image.images.append(item)
    return image


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-e233613e1d5d> in <module>()
----> 1 bk=hs.load('eds.bcf')

~/Documents/hyperspy/hyperspy/io.py in load(filenames, signal_type, stack, stack_axis, new_axis_name, lazy, **kwds)
    241             objects = [load_single_file(filename, lazy=lazy,
    242                                         **kwds)
--> 243                        for filename in filenames]
    244 
    245         if len(objects) == 1:

~/Documents/hyperspy/hyperspy/io.py in <listcomp>(.0)
    241             objects = [load_single_file(filename, lazy=lazy,
    242                                         **kwds)
--> 243                        for filename in filenames]
    244 
    245         if len(objects) == 1:

~/Documents/hyperspy/hyperspy/io.py in load_single_file(filename, signal_type, **kwds)
    284                                 reader=reader,
    285                                 signal_type=signal_type,
--> 286                                 **kwds)
    287 
    288 

~/Documents/hyperspy/hyperspy/io.py in load_with_reader(filename, reader, signal_type, **kwds)
    293     lazy = kwds.get('lazy', False)
    294     file_data_list = reader.file_reader(filename,
--> 295                                         **kwds)
    296     objects = []
    297 

~/Documents/hyperspy/hyperspy/io_plugins/bcf.py in file_reader(filename, select_type, index, downsample, cutoff_at_kV, instrument, lazy)
   1213 
   1214     # objectified bcf file:
-> 1215     obj_bcf = BCF_reader(filename, instrument=instrument)
   1216     if select_type == 'image':
   1217         return bcf_imagery(obj_bcf)

~/Documents/hyperspy/hyperspy/io_plugins/bcf.py in __init__(self, filename, instrument)
    880         header_byte_str = header_file.get_as_BytesIO_string().getvalue()
    881         hd_bt_str = fix_dec_patterns.sub(b'\\1.\\2', header_byte_str)
--> 882         self.header = HyperHeader(header_byte_str, self.available_indexes, instrument=instrument)
    883         self.hypermap = {}
    884 

~/Documents/hyperspy/hyperspy/io_plugins/bcf.py in __init__(self, xml_str, indexes, instrument)
    569         self._set_microscope(root)
    570         self._get_mode(instrument)
--> 571         self._set_images(root)
    572         self.elements = {}
    573         self._set_elements(root)

~/Documents/hyperspy/hyperspy/io_plugins/bcf.py in _set_images(self, root)
    692             if not(n.get('Name')):
    693                 image_node = n
--> 694         self.image = self._parse_image(image_node)
    695         if self.version == 2:
    696             overview_node = root.findall(

~/Documents/hyperspy/hyperspy/io_plugins/bcf.py in _parse_image(self, xml_node, overview)
    671             if any(array1):
    672                 item = self.gen_hspy_item_dict_basic()
--> 673                 data = array1.reshape((image.height, image.width))
    674                 detector_name = str(img.find('./Description').text)
    675                 item['data'] = data

ValueError: cannot reshape array of size 114688 into shape (448,512)


# Fixed code
def _parse_image(self, xml_node, overview=False):
    """parse image from bruker xml image node."""
    if overview:
        rect_node = xml_node.find(
            "./ChildClassInstances"
            "/ClassInstance["
            # "@Type='TRTRectangleOverlayElement' and "
            "@Name='Map']/TRTSolidOverlayElement/"
            "TRTBasicLineOverlayElement/TRTOverlayElement"
        )
        if rect_node is not None:
            over_rect = dictionarize(rect_node)["TRTOverlayElement"]["Rect"]
            rect = {
                "y1": over_rect["Top"] * self.y_res,
                "x1": over_rect["Left"] * self.x_res,
                "y2": over_rect["Bottom"] * self.y_res,
                "x2": over_rect["Right"] * self.x_res,
            }
            over_dict = {
                "marker_type": "Rectangle",
                "plot_on_signal": True,
                "data": rect,
                "marker_properties": {"color": "yellow", "linewidth": 2},
            }
    image = Container()
    image.width = int(xml_node.find("./Width").text)  # in pixels
    image.height = int(xml_node.find("./Height").text)  # in pixels
    image.dtype = "u" + xml_node.find("./ItemSize").text  # in bytes ('u1','u2','u4')
    image.plane_count = int(xml_node.find("./PlaneCount").text)
    image.images = []
    for i in range(image.plane_count):
        img = xml_node.find("./Plane" + str(i))
        raw = codecs.decode((img.find("./Data").text).encode("ascii"), "base64")
        array1 = np.frombuffer(raw, dtype=image.dtype)
        if any(array1):
            item = self.gen_hspy_item_dict_basic()
            data = array1.reshape((image.height, image.width))
            desc = img.find("./Description")
            item["data"] = data
            item["axes"][0]["size"] = image.height
            item["axes"][1]["size"] = image.width
            item["metadata"]["Signal"] = {"record_by": "image"}
            item["metadata"]["General"] = {}
            if desc is not None:
                item["metadata"]["General"]["title"] = str(desc.text)
            if overview and (rect_node is not None):
                item["metadata"]["Markers"] = {"overview": over_dict}
            image.images.append(item)
    return image