# Path: astwro/coord/coord_tools.py
# def fix_scamp_wcs(hdu):
#     """Make FITS image scamp WCS headers WCSLib compatible
# 
#     Warning
#     -------
#     Current implementation just removes distortion parameters,
#     astrometry is not accurate anymore!
#     """
#     for i in range(11):
#         for pv in ['PV1_{:d}', 'PV2_{:d}']:
#             hdu.header.remove(pv.format(i), ignore_missing=True, remove_all=True)


import astropy.io.fits as fits
import astropy.visualization as vis
import matplotlib.pyplot as plt
import astwro.sampledata
from astropy.wcs import WCS
from .coord_tools import fix_scamp_wcs
# coding=utf-8
from __future__ import absolute_import, division, print_function

__metaclass__ = type

def plot_coords(fig=None, ax=None, fits_file=astwro.sampledata.fits_image(), gal=True, img_alpha=1.0, cmap=None,
                grid_c='gray', grid_alpha=0.5, grid_ls='solid', keep_scale=True, img=True,
                ):
    if ax is None or  isinstance(ax, int):
        if fig is None:
            fig = plt.figure(figsize=(6, 6))
            fig.tight_layout()
        if ax is None: ax = 111
        hdu = fits.open(fits_file)[0]
        fix_scamp_wcs(hdu)
        wcs = WCS(hdu.header)

# Path: astwro/coord/coord_tools.py
# def fix_scamp_wcs(hdu):
#     """Make FITS image scamp WCS headers WCSLib compatible
# 
#     Warning
#     -------
#     Current implementation just removes distortion parameters,
#     astrometry is not accurate anymore!
#     """
#     for i in range(11):
#         for pv in ['PV1_{:d}', 'PV2_{:d}']:
#             hdu.header.remove(pv.format(i), ignore_missing=True, remove_all=True)


# Path: astwro/coord/plots.py
import astropy.io.fits as fits
import astropy.visualization as vis
import matplotlib.pyplot as plt
import astwro.sampledata
from astropy.wcs import WCS
from .coord_tools import fix_scamp_wcs

# coding=utf-8
from __future__ import absolute_import, division, print_function

__metaclass__ = type

def plot_coords(fig=None, ax=None, fits_file=astwro.sampledata.fits_image(), gal=True, img_alpha=1.0, cmap=None,
                grid_c='gray', grid_alpha=0.5, grid_ls='solid', keep_scale=True, img=True,
                ):
    if ax is None or  isinstance(ax, int):
        if fig is None:
            fig = plt.figure(figsize=(6, 6))
            fig.tight_layout()
        if ax is None: ax = 111
        hdu = fits.open(fits_file)[0]
        fix_scamp_wcs(hdu)
        wcs = WCS(hdu.header)

        ax = fig.add_subplot(ax, projection=wcs)