# Path: photometry/plots.py
# def plots_interactive(backend=('Qt5Agg', 'MacOSX', 'Qt4Agg', 'Qt5Cairo', 'TkAgg')):
# def plots_noninteractive():
# def plot_image(image, ax=None, scale='log', cmap=None, origin='lower', xlabel=None,
# 	ylabel=None, cbar=None, clabel='Flux ($e^{-}s^{-1}$)', cbar_ticks=None,
# 	cbar_ticklabels=None, cbar_pad=None, cbar_size='5%', title=None,
# 	percentile=95.0, vmin=None, vmax=None, offset_axes=None, color_bad='k', **kwargs):
# def plot_image_fit_residuals(fig, image, fit, residuals=None, percentile=95.0):
# def plot_outline(img, ax=None, threshold=0.5, **kwargs):
# def save_figure(path, fig=None, fmt='png', **kwargs):


import pytest
import os.path
import numpy as np
import conftest # noqa: F401
from scipy.stats import multivariate_normal
from photometry.plots import plt, plot_image, plot_image_fit_residuals, plots_interactive
"""


kwargs = {
	'baseline_dir': os.path.join(os.path.abspath(os.path.dirname(__file__)), 'correct_plots'),
	'tolerance': 30
}

#--------------------------------------------------------------------------------------------------
@pytest.mark.mpl_image_compare(**kwargs)
def test_plot_image():

	mu = [3.5, 3]
	x, y = np.mgrid[0:15, 0:15]
	pos = np.dstack((x, y))
	var = multivariate_normal(mean=mu, cov=[[1,0],[0,1]])
	gauss = 5 * var.pdf(pos) - 0.05 # Make sure it has some negative values as well
	gauss[8,8] = np.NaN
	gauss[4,4] = -0.2

	scales = ['linear', 'sqrt', 'log', 'asinh', 'histeq', 'sinh', 'squared']

	fig, axes = plt.subplots(2, 4, figsize=(14, 8))
	axes = axes.flatten()
	for k, scale in enumerate(scales):
		ax = axes[k]
		plot_image(gauss, ax=ax, scale=scale, title=scale, cbar='right')
		ax.plot(mu[1], mu[0], 'r+')

	# In the final plot:

# Path: photometry/plots.py
# def plots_interactive(backend=('Qt5Agg', 'MacOSX', 'Qt4Agg', 'Qt5Cairo', 'TkAgg')):
# def plots_noninteractive():
# def plot_image(image, ax=None, scale='log', cmap=None, origin='lower', xlabel=None,
# 	ylabel=None, cbar=None, clabel='Flux ($e^{-}s^{-1}$)', cbar_ticks=None,
# 	cbar_ticklabels=None, cbar_pad=None, cbar_size='5%', title=None,
# 	percentile=95.0, vmin=None, vmax=None, offset_axes=None, color_bad='k', **kwargs):
# def plot_image_fit_residuals(fig, image, fit, residuals=None, percentile=95.0):
# def plot_outline(img, ax=None, threshold=0.5, **kwargs):
# def save_figure(path, fig=None, fmt='png', **kwargs):


# Path: tests/test_plots.py
import pytest
import os.path
import numpy as np
import conftest # noqa: F401
from scipy.stats import multivariate_normal
from photometry.plots import plt, plot_image, plot_image_fit_residuals, plots_interactive

"""


kwargs = {
	'baseline_dir': os.path.join(os.path.abspath(os.path.dirname(__file__)), 'correct_plots'),
	'tolerance': 30
}

#--------------------------------------------------------------------------------------------------
@pytest.mark.mpl_image_compare(**kwargs)
def test_plot_image():

	mu = [3.5, 3]
	x, y = np.mgrid[0:15, 0:15]
	pos = np.dstack((x, y))
	var = multivariate_normal(mean=mu, cov=[[1,0],[0,1]])
	gauss = 5 * var.pdf(pos) - 0.05 # Make sure it has some negative values as well
	gauss[8,8] = np.NaN
	gauss[4,4] = -0.2

	scales = ['linear', 'sqrt', 'log', 'asinh', 'histeq', 'sinh', 'squared']

	fig, axes = plt.subplots(2, 4, figsize=(14, 8))
	axes = axes.flatten()
	for k, scale in enumerate(scales):
		ax = axes[k]
		plot_image(gauss, ax=ax, scale=scale, title=scale, cbar='right')
		ax.plot(mu[1], mu[0], 'r+')

	# In the final plot:

	plot_image(gauss, ax=axes[-1], scale='log', title='log - Reds', cmap='Reds', cbar='right')