def read_mantid_MDHisto(filename):
    """Read the saved MDHisto from from Mantid and returns an xarray.DataArray object"""
    import h5py
    import numpy as np
    import xarray as xr
    from javelin.unitcell import UnitCell
    with h5py.File(filename, 'r') as f:
        if 'SaveMDVersion' not in f['MDHistoWorkspace'].attrs or f[
            'MDHistoWorkspace'].attrs['SaveMDVersion'] < 2:
            raise RuntimeError('Cannot open ' + filename +
                ', must be saved by SaveMD Version 2')
        path = 'MDHistoWorkspace/data/'
        if path + 'signal' not in f:
            raise RuntimeError('Cannot open ' + path + 'signal in ' + filename)
        signal = f[path + 'signal']
        data = np.array(signal)
        if 'axes' not in signal.attrs:
            print("Can't find axes")
            return xr.DataArray(data)
        axes = signal.attrs['axes'].decode().split(':')
        dims_list = []
        coords_list = []
        for a in axes:
            dims_list.append(a)
            axis = np.array(f[path + a])
            axis = (axis + np.roll(axis, -1))[:-1] / 2
            coords_list.append(np.array(axis))
        data_set = xr.DataArray(data, dims=dims_list, coords=coords_list)
        oriented_lattice = (
            'MDHistoWorkspace/experiment0/sample/oriented_lattice')
        if oriented_lattice in f:
            lattice = f[oriented_lattice]
            data_set.attrs['unit_cell'] = UnitCell(lattice['unit_cell_a'][0
                ], lattice['unit_cell_b'][0], lattice['unit_cell_c'][0],
                lattice['unit_cell_alpha'][0], lattice['unit_cell_beta'][0],
                lattice['unit_cell_gamma'][0])
        W_MATRIX = 'MDHistoWorkspace/experiment0/logs/W_MATRIX/value'
        if W_MATRIX in f:
            data_set.attrs['projection_matrix'] = np.array(f[W_MATRIX]
                ).reshape(3, 3)
    return data_set
