<commit_before>import sys
import wx
import wx.lib.newevent
import numpy
import copy
import math
from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion

from sans.guicomm.events import StatusEvent   
from sans.guiframe.utils import format_number

## event to post model to fit to fitting plugins
(ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()

## event to know the selected fit engine
(FitterTypeEvent, EVT_FITTER_TYPE)   = wx.lib.newevent.NewEvent()
_BOX_WIDTH = 80

import basepage
from basepage import BasicPage
from basepage import PageInfoEvent


class FitPage(BasicPage):
    """
        FitPanel class contains fields allowing to display results when
        fitting  a model and one data
        @note: For Fit to be performed the user should check at least one parameter
        on fit Panel window.
  
    """
    def __init__(self,parent, page_info):
        BasicPage.__init__(self, parent, page_info)
        """ 
            Initialization of the Panel
        """
        ## fit page does not content npts txtcrtl
        self.npts=None
        ## if no dispersity parameters is avaible 
        self.text_disp_1=None
        ## default fitengine type
        self.engine_type = None
        ## draw sizer
        self._fill_datainfo_sizer()
        self._fill_model_sizer( self.sizer1)
        self._fill_range_sizer() 
        self._on_select_model(event=None)
    
        ## to update the panel according to the fit engine type selected
        self.Bind(EVT_FITTER_TYPE,self._on_engine_change)
    
    
    def _on_engine_change(self, event):
        """
            get an event containing the current name of the fit engine type
            @param event: FitterTypeEvent containing  the name of the current engine
        """
        self.engine_type = event.type
         
        if len(self.parameters)==0:
            return
        for item in self.parameters:
            if event.type =="scipy":
                item[5].SetValue(format_number(""))
                item[5].Hide()
                item[6].SetValue(format_number(""))
                item[6].Hide()
                self.text2_min.Hide()
                self.text2_max.Hide()
            else:
                item[5].Show(True)
                item[6].Show(True)
                self.text2_min.Show(True)
                self.text2_max.Show(True)
                
        self.sizer3.Layout()
        self.SetScrollbars(20,20,200,100)
        
    
    def _fill_range_sizer(self):
        """
            Fill the sizer containing the plotting range
            add  access to npts
        """
        sizer_fit = wx.GridSizer(1, 1,0, 0)
    
        self.btFit = wx.Button(self,wx.NewId(),'Fit')
        self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId())
        self.btFit.SetToolTipString("Perform fit.")
      
        
        sizer_fit.Add((5,5),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5)        
        sizer_fit.Add(self.btFit,0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 
        
        sizer_smearer = wx.BoxSizer(wx.HORIZONTAL)
        #Filling the sizer containing instruments smearing info.
        self.disable_smearer = wx.RadioButton(self, -1, 'No', style=wx.RB_GROUP)
        self.enable_smearer = wx.RadioButton(self, -1, 'Yes')
        self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId())
        self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId())
        
        sizer_smearer.Add(wx.StaticText(self,-1,'Instrument Smearing? '))
        sizer_smearer.Add((10, 10))
        sizer_smearer.Add( self.enable_smearer )
        sizer_smearer.Add((10,10))
        sizer_smearer.Add( self.disable_smearer )
        
        self._set_range_sizer( title="Fitting",
                               object1=sizer_smearer, object= sizer_fit)
       
       
    def _fill_datainfo_sizer(self):
        """
            fill sizer 0 with data info
        """
        self.sizer0.Clear(True)
        ## no loaded data , don't fill the sizer
        if self.data== None:
            self.sizer0.Layout()
            return
        
        box_description= wx.StaticBox(self, -1, 'Data')
        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
        #----------------------------------------------------------
        sizer_data = wx.GridSizer(3, 3,5, 5)
        #Filling the sizer containing data related fields
        DataSource  =wx.StaticText(self, -1,str(self.data.name))

        sizer_data.Add(wx.StaticText(self, -1, 'Source Name : '))
        sizer_data.Add(DataSource )
        sizer_data.Add( (5,5) )
        
        #---------sizer 2 draw--------------------------------
        #set maximum range for x in linear scale
        if not hasattr(self.data,"data"): #Display only for 1D data fit
            # Minimum value of data   
            data_min = str(format_number(numpy.min(self.data.x)))
            # Maximum value of data  
            data_max = str(format_number(numpy.max(self.data.x)))
            text4_3 = wx.StaticText(self, -1, 'Total Q Range(1/A)',
                                     style=wx.ALIGN_LEFT)
            sizer_data.Add( text4_3 )
            sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%data_min))
            sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%data_max))
            
        else:
            radius_min= 0
            x= numpy.max(self.data.xmin, self.data.xmax)
            y= numpy.max(self.data.ymin, self.data.ymax)
            radius_max = math.sqrt(x*x + y*y)
            # Minimum value of data   
            data_min = str(format_number(radius_min))
            # Maximum value of data  
            data_max = str(format_number(radius_max))
            text4_3 = wx.StaticText(self, -1, 'Total Q Range',
                                     style=wx.ALIGN_LEFT)
            sizer_data.Add( text4_3 )
            sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%data_min))
            sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%data_max))
            
        boxsizer1.Add(sizer_data)
        #------------------------------------------------------------
        self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)
        self.sizer0.Layout()
        
        self.qmin_x= data_min
        self.qmax_x= data_max
        
        
    def _fill_model_sizer(self, sizer):
        """
            fill sizer containing model info
        """
       
        box_description= wx.StaticBox(self, -1,'Chi2/dof')
        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
        boxsizer1.SetMinSize((50,-1))
        self.tcChi    =  wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT)
        boxsizer1.Add( self.tcChi )
        
            
        ## class base method  to add view 2d button    
        self._set_model_sizer(sizer=sizer, title="Model",object= boxsizer1 )    
    
    
    def _set_sizer_gaussian(self):
        """
            draw sizer with gaussian dispersity parameters
        """
        self.fittable_param=[]
        self.fixed_param=[]
    
        self.sizer4_4.Clear(True)
       
        if self.model==None:
            ##no model is selected
            return
        if not self.enable_disp.GetValue():
            ## the user didn't select dispersity display
            return 
        
        self._reset_dispersity()<commit_msg>chi2 moved<commit_after>import sys
import wx
import wx.lib.newevent
import numpy
import copy
import math
from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion

from sans.guicomm.events import StatusEvent   
from sans.guiframe.utils import format_number

## event to post model to fit to fitting plugins
(ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()

## event to know the selected fit engine
(FitterTypeEvent, EVT_FITTER_TYPE)   = wx.lib.newevent.NewEvent()
_BOX_WIDTH = 80

import basepage
from basepage import BasicPage
from basepage import PageInfoEvent


class FitPage(BasicPage):
    """
        FitPanel class contains fields allowing to display results when
        fitting  a model and one data
        @note: For Fit to be performed the user should check at least one parameter
        on fit Panel window.
  
    """
    def __init__(self,parent, page_info):
        BasicPage.__init__(self, parent, page_info)
        """ 
            Initialization of the Panel
        """
        ## fit page does not content npts txtcrtl
        self.npts=None
        ## if no dispersity parameters is avaible 
        self.text_disp_1=None
        ## default fitengine type
        self.engine_type = None
        ## draw sizer
        self._fill_datainfo_sizer()
        self._fill_model_sizer( self.sizer1)
        self._fill_range_sizer() 
        self._on_select_model(event=None)
    
        ## to update the panel according to the fit engine type selected
        self.Bind(EVT_FITTER_TYPE,self._on_engine_change)
    
    
    def _on_engine_change(self, event):
        """
            get an event containing the current name of the fit engine type
            @param event: FitterTypeEvent containing  the name of the current engine
        """
        self.engine_type = event.type
         
        if len(self.parameters)==0:
            return
        for item in self.parameters:
            if event.type =="scipy":
                item[5].SetValue(format_number(""))
                item[5].Hide()
                item[6].SetValue(format_number(""))
                item[6].Hide()
                self.text2_min.Hide()
                self.text2_max.Hide()
            else:
                item[5].Show(True)
                item[6].Show(True)
                self.text2_min.Show(True)
                self.text2_max.Show(True)
                
        self.sizer3.Layout()
        self.SetScrollbars(20,20,200,100)
        
    
    def _fill_range_sizer(self):
        """
            Fill the sizer containing the plotting range
            add  access to npts
        """
        sizer_fit = wx.GridSizer(1, 1,0, 0)
    
        self.btFit = wx.Button(self,wx.NewId(),'Fit')
        self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId())
        self.btFit.SetToolTipString("Perform fit.")
      
        
        sizer_fit.Add((5,5),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5)        
        sizer_fit.Add(self.btFit,0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 
        
        sizer_smearer = wx.BoxSizer(wx.HORIZONTAL)
        #Filling the sizer containing instruments smearing info.
        self.disable_smearer = wx.RadioButton(self, -1, 'No', style=wx.RB_GROUP)
        self.enable_smearer = wx.RadioButton(self, -1, 'Yes')
        self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId())
        self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId())
        
        sizer_smearer.Add(wx.StaticText(self,-1,'Instrument Smearing? '))
        sizer_smearer.Add((10, 10))
        sizer_smearer.Add( self.enable_smearer )
        sizer_smearer.Add((10,10))
        sizer_smearer.Add( self.disable_smearer )
        
        #Display Chi^2/dof
        sizer_smearer.Add((70,10))
        box_description= wx.StaticBox(self, -1,'Chi2/dof')
        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
        boxsizer1.SetMinSize((55,-1))
        self.tcChi    =  wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT)        
        boxsizer1.Add( self.tcChi )   
        sizer_smearer.Add( boxsizer1 )
               
        #Set sizer for Fitting section
        self._set_range_sizer( title="Fitting",
                               object1=sizer_smearer, object= sizer_fit)
  
       
    def _fill_datainfo_sizer(self):
        """
            fill sizer 0 with data info
        """
        self.sizer0.Clear(True)
        ## no loaded data , don't fill the sizer
        if self.data== None:
            self.sizer0.Layout()
            return
        
        box_description= wx.StaticBox(self, -1, 'Data')
        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
        #----------------------------------------------------------
        sizer_data = wx.GridSizer(3, 3,5, 5)
        #Filling the sizer containing data related fields
        DataSource  =wx.StaticText(self, -1,str(self.data.name))

        sizer_data.Add(wx.StaticText(self, -1, 'Source Name : '))
        sizer_data.Add(DataSource )
        sizer_data.Add( (5,5) )
        
        #---------sizer 2 draw--------------------------------
        #set maximum range for x in linear scale
        if not hasattr(self.data,"data"): #Display only for 1D data fit
            # Minimum value of data   
            data_min = str(format_number(numpy.min(self.data.x)))
            # Maximum value of data  
            data_max = str(format_number(numpy.max(self.data.x)))
            text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)',
                                     style=wx.ALIGN_LEFT)
            sizer_data.Add( text4_3 )
            sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%data_min))
            sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%data_max))
            
        else:
            radius_min= 0
            x= numpy.max(self.data.xmin, self.data.xmax)
            y= numpy.max(self.data.ymin, self.data.ymax)
            radius_max = math.sqrt(x*x + y*y)
            # Minimum value of data   
            data_min = str(format_number(radius_min))
            # Maximum value of data  
            data_max = str(format_number(radius_max))
            text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)',
                                     style=wx.ALIGN_LEFT)
            sizer_data.Add( text4_3 )
            sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%data_min))
            sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%data_max))
            
        boxsizer1.Add(sizer_data)
        #------------------------------------------------------------
        self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)
        self.sizer0.Layout()
        
        self.qmin_x= data_min
        self.qmax_x= data_max
        
       
    def _fill_model_sizer(self, sizer):
        """
            fill sizer containing model info
        """
       
        ## class base method  to add view 2d button    
        self._set_model_sizer(sizer=sizer, title="Model",object=None )    
        
    
    def _set_sizer_gaussian(self):
        """
            draw sizer with gaussian dispersity parameters
        """
        self.fittable_param=[]
        self.fixed_param=[]
    
        self.sizer4_4.Clear(True)
       
        if self.model==None:
            ##no model is selected
            return
        if not self.enable_disp.GetValue():
            ## the user didn't select dispersity display
            return 
        
        self._reset_dispersity()
{'fraction_non_alphanumeric': 0.11987381703470032, 'fraction_numerical': 0.013759312705550707, 'mean_word_length': 1.79183061645119, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '118865', 'n_tokens_mistral': 4756, 'n_tokens_neox': 4630, 'n_words': 953}