Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/basepage.py

    rb76e65a r33dc18f  
    18411841            if models.name != "NoStructure": 
    18421842                mlist.append((models.name, models)) 
    1843  
    18441843        # Sort the models 
    18451844        mlist_sorted = sorted(mlist) 
     
    29292928            return False 
    29302929 
    2931  
    2932     def _get_copy_params_details(self): 
    2933         """ 
    2934         Combines polydisperse parameters with self.parameters so that they can 
    2935         be written to the clipboard (for Excel or LaTeX). Also returns a list of 
    2936         the names of parameters that have been fitted 
    2937  
    2938         :returns: all_params - A list of all parameters, in the format of  
    2939         self.parameters 
    2940         :returns: fitted_par_names - A list of the names of parameters that have 
    2941         been fitted 
    2942         """ 
    2943         # Names of params that are being fitted 
    2944         fitted_par_names = [param[1] for param in self.param_toFit] 
    2945         # Names of params with associated polydispersity 
    2946         disp_params = [param[1].split('.')[0] for param in self.fittable_param] 
    2947  
    2948         # Create array of all parameters 
    2949         all_params = copy.copy(self.parameters) 
    2950         for param in self.parameters: 
    2951             if param[1] in disp_params: 
    2952                 # Polydisperse params aren't in self.parameters, so need adding 
    2953                 # to all_params 
    2954                 name = param[1] + ".width" 
    2955                 index = all_params.index(param) + 1 
    2956                 to_insert = [] 
    2957                 if name in fitted_par_names: 
    2958                     # Param is fitted, so already has a param list in self.param_toFit 
    2959                     to_insert = self.param_toFit[fitted_par_names.index(name)] 
    2960                 else: 
    2961                     # Param isn't fitted, so mockup a param list 
    2962                     to_insert = [None, name, self.model.getParam(name), None, None] 
    2963                 all_params.insert(index, to_insert) 
    2964         return all_params, fitted_par_names 
    2965  
    29662930    def get_copy_excel(self): 
    29672931        """ 
     
    29772941        Get the string copies of the param names and values in the tap 
    29782942        """ 
    2979         if not self.parameters: 
    2980             # Do nothing if parameters doesn't exist 
    2981             return False 
    2982  
    29832943        content = '' 
     2944 
    29842945        crlf = chr(13) + chr(10) 
    29852946        tab = chr(9) 
    29862947 
    2987         all_params, fitted_param_names = self._get_copy_params_details() 
    2988  
    2989         # Construct row of parameter names 
    2990         for param in all_params: 
    2991             name = param[1] # Parameter name 
    2992             content += name 
    2993             content += tab 
    2994             if name in fitted_param_names: 
    2995                 # Only print errors for fitted parameters 
    2996                 content += name + "_err" 
     2948        # Do it if params exist 
     2949        if self.parameters: 
     2950 
     2951            for param in self.parameters: 
     2952                content += param[1]  # parameter name 
    29972953                content += tab 
    2998  
    2999         content += crlf 
    3000  
    3001         # Construct row of parameter values and errors 
    3002         for param in all_params: 
    3003             value = param[2] 
    3004             if hasattr(value, 'GetValue'): 
    3005                 # param[2] is a text box 
    3006                 value = value.GetValue() 
    3007             else: 
    3008                 # param[2] is a float (from our self._get_copy_params_details) 
    3009                 value = str(value) 
    3010             content += value 
    3011             content += tab 
    3012             if param[1] in fitted_param_names: 
    3013                 # Only print errors for fitted parameters 
    3014                 content += param[4].GetValue() 
    3015                 content += tab  
    3016  
    3017         return content 
     2954                content += param[1] + "_err" 
     2955                content += tab 
     2956 
     2957            content += crlf 
     2958 
     2959            # row of values and errors... 
     2960            for param in self.parameters: 
     2961                content += param[2].GetValue()  # value 
     2962                content += tab 
     2963                content += param[4].GetValue()  # error 
     2964                content += tab 
     2965 
     2966            return content 
     2967        else: 
     2968            return False 
    30182969 
    30192970    def get_copy_latex(self): 
     
    30302981        Get the string copies of the param names and values in the tap 
    30312982        """ 
    3032         if not self.parameters: 
    3033             # Do nothing if self.parameters doesn't exist 
    3034             return False 
    3035          
    30362983        content = '\\begin{table}' 
    30372984        content += '\\begin{tabular}[h]' 
     
    30402987        tab = chr(9) 
    30412988 
    3042         all_params, fitted_param_names = self._get_copy_params_details() 
    3043  
    3044         content += '{|' 
    3045         for param in all_params: 
    3046             content += 'l|l|' 
    3047         content += '}\hline' 
    3048         content += crlf 
    3049  
    3050         # Construct row of parameter names 
    3051         for index, param in enumerate(all_params): 
    3052             name = param[1] # Parameter name 
    3053             content += name.replace('_', '\_')  # Escape underscores 
    3054             if name in fitted_param_names: 
    3055                 # Only print errors for fitted parameters 
     2989        # Do it if params exist 
     2990        if self.parameters: 
     2991 
     2992            content += '{|' 
     2993            for param in self.parameters: 
     2994                content += 'l|l|' 
     2995            content += '}\hline' 
     2996            content += crlf 
     2997 
     2998            for index, param in enumerate(self.parameters): 
     2999                content += param[1].replace('_', '\_')  # parameter name 
    30563000                content += ' & ' 
    3057                 content += name.replace('_', '\_') + "\_err" 
    3058             if index < len(all_params) - 1: 
     3001                content += param[1].replace('_', '\_') + "\_err" 
     3002                if index < len(self.parameters) - 1: 
     3003                    content += ' & ' 
     3004            content += '\\\\ \\hline' 
     3005            content += crlf 
     3006 
     3007            # row of values and errors... 
     3008            for index, param in enumerate(self.parameters): 
     3009                content += param[2].GetValue()  # parameter value 
    30593010                content += ' & ' 
    3060  
    3061         content += '\\\\ \\hline' 
    3062         content += crlf 
    3063  
    3064         # Construct row of values and errors 
    3065         for index, param in enumerate(all_params): 
    3066             value = param[2] 
    3067             if hasattr(value, "GetValue"): 
    3068                 # value is a text box 
    3069                 value = value.GetValue() 
    3070             else: 
    3071                 # value is a float (from self._get_copy_params_details) 
    3072                 value = str(value) 
    3073             content += value 
    3074             if param[1] in fitted_param_names: 
    3075                 # Only print errors for fitted params 
    3076                 content += ' & ' 
    3077                 content += param[4].GetValue() 
    3078             if index < len(all_params) - 1: 
    3079                 content += ' & ' 
    3080          
    3081         content += '\\\\ \\hline' 
    3082         content += crlf 
    3083         content += '\\end{tabular}' 
    3084         content += '\\end{table}' 
    3085  
    3086         return content 
     3011                content += param[4].GetValue()  # parameter error 
     3012                if index < len(self.parameters) - 1: 
     3013                    content += ' & ' 
     3014            content += '\\\\ \\hline' 
     3015            content += crlf 
     3016 
     3017            content += '\\end{tabular}' 
     3018            content += '\\end{table}' 
     3019            return content 
     3020        else: 
     3021            return False 
    30873022 
    30883023    def set_clipboard(self, content=None): 
Note: See TracChangeset for help on using the changeset viewer.