# Path: pyqstem/detection.py
# def detect(img,sampling,dose=None,MTF_param=None,MTF_func=None,blur=None,resample=None):
# 
#     if resample is not None:
#         if not isinstance(resample, (list, tuple)):
#             resample=(resample,)*2
#         zoom=(sampling[0]/resample[0],sampling[1]/resample[1])
#         sampling=resample
#         warnings.filterwarnings('ignore')
#         img = scipy.ndimage.interpolation.zoom(img, zoom)
#         warnings.filterwarnings('always')
#         
#     
#     if blur is not None:
#         img=gaussian(img,blur)
#     
#     if dose is not None:
#         img = img/np.sum(img)*dose*np.product(sampling)*np.product(img.shape)
#         
#         img[img<0]=0
#         #vals = len(np.unique(img))
#         #vals = 2**np.ceil(np.log2(vals))
#         #img = np.random.poisson(img * vals) / float(vals)
# 
#         img = np.random.poisson(img).astype(np.int64)
#     
#     if MTF_param is not None:
#         if MTF_func is None:
#             MTF_func=MTF_a
#     
#         kx,ky,k2=spatial_frequencies(img.shape,sampling)
#         k=np.sqrt(k2)
#         mtf=MTF_func(k,*MTF_param)
#         img=np.fft.ifft2(np.fft.fft2(img)*np.sqrt(mtf))
#         img=(img.real+img.imag)/2
#     
#     return img


import matplotlib.pyplot as plt
import scipy
import scipy.ndimage
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.widgets import Slider
from .detection import detect
    imshow = ax.imshow(img[ind,:,:].T,extent=sig_extent,cmap=cmap,**kwargs)
    plt.grid(False)

    if create_cbar:
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="5%", pad=0.05)
        plt.colorbar(imshow, cax=cax)

    if slider == True:
        plt.subplots_adjust(bottom=0.25)
        axframe = plt.axes([0.2, 0.08, 0.6, 0.04])

        slider=Slider(axframe, nav_label, np.min(nav_extent), np.max(nav_extent), valinit=0.)

        sampling=(np.max(nav_extent)-np.min(nav_extent))/(img.shape[0]-1)

        def update(val):
            frame = np.min((img.shape[0]-1,np.around(slider.val/sampling)))
            imshow.set_data(img[int(frame),:,:].T)

        slider.on_changed(update)

    ax.set_xlabel('{0} [{1}]'.format(sig_labels[0],units))
    ax.set_ylabel('{0} [{1}]'.format(sig_labels[1],units))

    return [slider]

class BaseArray(object):
    def __init__(self, array, sampling=None):


# Path: pyqstem/detection.py
# def detect(img,sampling,dose=None,MTF_param=None,MTF_func=None,blur=None,resample=None):
# 
#     if resample is not None:
#         if not isinstance(resample, (list, tuple)):
#             resample=(resample,)*2
#         zoom=(sampling[0]/resample[0],sampling[1]/resample[1])
#         sampling=resample
#         warnings.filterwarnings('ignore')
#         img = scipy.ndimage.interpolation.zoom(img, zoom)
#         warnings.filterwarnings('always')
#         
#     
#     if blur is not None:
#         img=gaussian(img,blur)
#     
#     if dose is not None:
#         img = img/np.sum(img)*dose*np.product(sampling)*np.product(img.shape)
#         
#         img[img<0]=0
#         #vals = len(np.unique(img))
#         #vals = 2**np.ceil(np.log2(vals))
#         #img = np.random.poisson(img * vals) / float(vals)
# 
#         img = np.random.poisson(img).astype(np.int64)
#     
#     if MTF_param is not None:
#         if MTF_func is None:
#             MTF_func=MTF_a
#     
#         kx,ky,k2=spatial_frequencies(img.shape,sampling)
#         k=np.sqrt(k2)
#         mtf=MTF_func(k,*MTF_param)
#         img=np.fft.ifft2(np.fft.fft2(img)*np.sqrt(mtf))
#         img=(img.real+img.imag)/2
#     
#     return img


# Path: pyqstem/wave.py
import matplotlib.pyplot as plt
import scipy
import scipy.ndimage
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.widgets import Slider
from .detection import detect

    imshow = ax.imshow(img[ind,:,:].T,extent=sig_extent,cmap=cmap,**kwargs)
    plt.grid(False)

    if create_cbar:
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="5%", pad=0.05)
        plt.colorbar(imshow, cax=cax)

    if slider == True:
        plt.subplots_adjust(bottom=0.25)
        axframe = plt.axes([0.2, 0.08, 0.6, 0.04])

        slider=Slider(axframe, nav_label, np.min(nav_extent), np.max(nav_extent), valinit=0.)

        sampling=(np.max(nav_extent)-np.min(nav_extent))/(img.shape[0]-1)

        def update(val):
            frame = np.min((img.shape[0]-1,np.around(slider.val/sampling)))
            imshow.set_data(img[int(frame),:,:].T)

        slider.on_changed(update)

    ax.set_xlabel('{0} [{1}]'.format(sig_labels[0],units))
    ax.set_ylabel('{0} [{1}]'.format(sig_labels[1],units))

    return [slider]

class BaseArray(object):
    def __init__(self, array, sampling=None):


        self.array=np.array(array,dtype=complex)