def shape_extent_to_header(shape, extent, nan_value=-9999):
    """ Create a header dict with shape and extent of an array
    """
    ncols = shape[1]
    nrows = shape[0]
    xllcorner = extent[0]
    yllcorner = extent[2]
    cellsize_x = (extent[1] - extent[0]) / ncols
    cellsize_y = (extent[3] - extent[2]) / nrows
    if cellsize_x != cellsize_y:
        raise ValueError('extent produces different cellsize in x and y')
    cellsize = cellsize_x
    header = {'ncols': ncols, 'nrows': nrows, 'xllcorner': xllcorner,
        'yllcorner': yllcorner, 'cellsize': cellsize, 'NODATA_value': nan_value
        }
    return header
