def transform_to_2d(data, max_axis):
    """
    Projects 3d data cube along one axis using maximum intensity with
    preservation of the signs. Adapted from nilearn.
    """
    import numpy as np
    new_shape = list(data.shape)
    del new_shape[max_axis]
    a1, a2 = np.indices(new_shape)
    inds = [a1, a2]
    inds.insert(max_axis, np.abs(data).argmax(axis=max_axis))
    maximum_intensity_data = data[inds]
    return np.rot90(maximum_intensity_data)
