def write_fits(data, filename, shape=None, overwrite=True):
    """Write the data to a fits-file.

	If the data is a Field with SeparatedCoords, the shaped field will be written to the
	fits-file, to allow for easier viewing with external tools.

	Parameters
	----------
	data : ndarray or Field
		The ndarray or Field to write to the fits file.
	filename : string
		The filename of the newly created file. This can include a path.
	shape : ndarray or None
		The shape to which to reshape the data. If this is given, it will override a potential
		shape from the grid accompaning the field.
	overwrite : boolean
		Whether to overwrite the fits-file if it already exists.
	"""
    from astropy.io import fits
    hdu = None
    if shape is not None:
        hdu = fits.PrimaryHDU(data.reshape(shape))
    elif hasattr(data, 'grid'):
        if data.grid.is_separated:
            hdu = fits.PrimaryHDU(data.shaped)
    if hdu is None:
        hdu = fits.PrimaryHDU(data)
    hdu.writeto(filename, overwrite=True)
