# Path: osrefl/loaders/ginput_rect.py
# def ginput_rect(ax=None,autoRemove = True):
#     """
#     Wait for user to select a region on the axes.
# 
#     Returns x1,x2,y1,y2
#     """
#     s = BlockingRectangleSelector(ax=ax)
#     s.select()
#     if autoRemove == True:
#         s.remove()
#     return s.x1,s.x2,s.y1,s.y2


from numpy import shape, searchsorted
from .wxrebin import *
from osrefl.model.sample_prep import *
from osrefl.viewers.view import *
from .ginput_rect import ginput_rect

class Data(object):
    '''
    **Overview:**

        This is a data loader for .cg1 files which is converted into a format
        that can be understood by the rest of software infrastructure.

    '''
    def __init__(self,preSpace = None,centerPixel=309.0):

        a = rebinned_data(plot_data = False)

        xindex = [None]*2
        zindex = [None]*2
        
        if preSpace == None:
            a.runConversion(plot_result = False)
            
            qz_for_search = a.qz[0,:]
            qx_for_search = a.qx[:,0]
    
            plot_for_select = view.intensity_plot(
                                          a.qxqz_2d_data.bin_data[:,:,3],
                                          [a.qx[0,0],a.qz[0,0]],
                                          [a.qx[-1,-1],a.qz[-1,-1]],
                                          'Please Select Data:', bar = False)
            
            data = a.qxqz_2d_data.bin_data[:,:,3]
            

# Path: osrefl/loaders/ginput_rect.py
# def ginput_rect(ax=None,autoRemove = True):
#     """
#     Wait for user to select a region on the axes.
# 
#     Returns x1,x2,y1,y2
#     """
#     s = BlockingRectangleSelector(ax=ax)
#     s.select()
#     if autoRemove == True:
#         s.remove()
#     return s.x1,s.x2,s.y1,s.y2


# Path: osrefl/loaders/andr_load.py
from numpy import shape, searchsorted
from .wxrebin import *
from osrefl.model.sample_prep import *
from osrefl.viewers.view import *
from .ginput_rect import ginput_rect


class Data(object):
    '''
    **Overview:**

        This is a data loader for .cg1 files which is converted into a format
        that can be understood by the rest of software infrastructure.

    '''
    def __init__(self,preSpace = None,centerPixel=309.0):

        a = rebinned_data(plot_data = False)

        xindex = [None]*2
        zindex = [None]*2
        
        if preSpace == None:
            a.runConversion(plot_result = False)
            
            qz_for_search = a.qz[0,:]
            qx_for_search = a.qx[:,0]
    
            plot_for_select = view.intensity_plot(
                                          a.qxqz_2d_data.bin_data[:,:,3],
                                          [a.qx[0,0],a.qz[0,0]],
                                          [a.qx[-1,-1],a.qz[-1,-1]],
                                          'Please Select Data:', bar = False)
            
            data = a.qxqz_2d_data.bin_data[:,:,3]
            

            x1,x2,z1,z2 = ginput_rect()