Converts list of regions to FITS region table and write to a file.

    Parameters
    ----------
    filename: str
        Filename in which the table is to be written. Default is 'new.fits'
    regions: list
        List of `regions.Region` objects
    header: `~astropy.io.fits.header.Header` object
        The FITS header.

    Examples
    --------

    >>> from astropy.utils.data import get_pkg_data_filename
    >>> from astropy.io import fits
    >>> file_sample = get_pkg_data_filename('data/fits_region.fits', package='regions.io.fits.tests')
    >>> from regions import CirclePixelRegion, PixCoord, write_fits_region
    >>> reg_pixel = CirclePixelRegion(PixCoord(1, 2), 5)
    >>> hdul = fits.open(file_sample)
    >>> write_fits_region('region_output.fits', regions=[reg_pixel], header=hdul[1].header)

def write_fits_region(filename, regions, header=None):
    """
    Converts list of regions to FITS region table and write to a file.

    Parameters
    ----------
    filename: str
        Filename in which the table is to be written. Default is 'new.fits'
    regions: list
        List of `regions.Region` objects
    header: `~astropy.io.fits.header.Header` object
        The FITS header.

    Examples
    --------

    >>> from astropy.utils.data import get_pkg_data_filename
    >>> from astropy.io import fits
    >>> file_sample = get_pkg_data_filename('data/fits_region.fits', package='regions.io.fits.tests')
    >>> from regions import CirclePixelRegion, PixCoord, write_fits_region
    >>> reg_pixel = CirclePixelRegion(PixCoord(1, 2), 5)
    >>> hdul = fits.open(file_sample)
    >>> write_fits_region('region_output.fits', regions=[reg_pixel], header=hdul[1].header)

    """
    output = fits_region_objects_to_table(regions)

    bin_table = fits.BinTableHDU(data=output, header=header)
    bin_table.writeto(filename)