# Path: crowdastro/config.py
# SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
# def get(*args, **kwargs):


import logging
import astropy.io.fits
import astropy.wcs
import matplotlib
import matplotlib.pyplot as plt
import numpy
import sklearn.metrics
from matplotlib.pyplot import cm
from .config import config
"""




ARCMIN = 1 / 60  # deg
FITS_CONVENTION = 1
IMAGE_DIAMETER = config['surveys']['atlas']['fits_width']

wcs = None


def _init_wcs():
    """Initialise the ATLAS image WCS. Sets global variable wcs."""
    with astropy.io.fits.open(config['data_sources']['atlas_image'],
                              ignore_blank=True) as atlas_image:
        global wcs
        wcs = astropy.wcs.WCS(atlas_image[0].header).dropaxis(3).dropaxis(2)


def ra_dec_to_pixels(subject_coords, coords):
    if wcs is None:
        _init_wcs()

    offset, = wcs.all_world2pix([subject_coords], FITS_CONVENTION)
    # The coords are of the middle of the subject.
    coords = wcs.all_world2pix(coords, FITS_CONVENTION)
    coords -= offset
    
    coords[:, 0] /= config['surveys']['atlas']['mosaic_scale_x'] * 424 / 200

# Path: crowdastro/config.py
# SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
# def get(*args, **kwargs):


# Path: crowdastro/plot.py
import logging
import astropy.io.fits
import astropy.wcs
import matplotlib
import matplotlib.pyplot as plt
import numpy
import sklearn.metrics
from matplotlib.pyplot import cm
from .config import config

"""




ARCMIN = 1 / 60  # deg
FITS_CONVENTION = 1
IMAGE_DIAMETER = config['surveys']['atlas']['fits_width']

wcs = None


def _init_wcs():
    """Initialise the ATLAS image WCS. Sets global variable wcs."""
    with astropy.io.fits.open(config['data_sources']['atlas_image'],
                              ignore_blank=True) as atlas_image:
        global wcs
        wcs = astropy.wcs.WCS(atlas_image[0].header).dropaxis(3).dropaxis(2)


def ra_dec_to_pixels(subject_coords, coords):
    if wcs is None:
        _init_wcs()

    offset, = wcs.all_world2pix([subject_coords], FITS_CONVENTION)
    # The coords are of the middle of the subject.
    coords = wcs.all_world2pix(coords, FITS_CONVENTION)
    coords -= offset
    
    coords[:, 0] /= config['surveys']['atlas']['mosaic_scale_x'] * 424 / 200

    coords[:, 1] /= config['surveys']['atlas']['mosaic_scale_y'] * 424 / 200