Changeset 5c1c486 in sasview for src/sas/sasgui/perspectives/fitting/basepage.py
- Timestamp:
- Sep 13, 2017 8:27:29 AM (7 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- fca1f50
- Parents:
- b76e65a (diff), 7b3f154 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
r914c49d5 rb76e65a 2929 2929 return False 2930 2930 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 2931 2966 def get_copy_excel(self): 2932 2967 """ … … 2942 2977 Get the string copies of the param names and values in the tap 2943 2978 """ 2979 if not self.parameters: 2980 # Do nothing if parameters doesn't exist 2981 return False 2982 2944 2983 content = '' 2945 2946 2984 crlf = chr(13) + chr(10) 2947 2985 tab = chr(9) 2948 2986 2949 # Do it if params exist 2950 if self.parameters: 2951 2952 for param in self.parameters: 2953 content += param[1] # parameter name 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" 2954 2997 content += tab 2955 content += param[1] + "_err" 2956 content += tab 2957 2958 content += crlf 2959 2960 # row of values and errors... 2961 for param in self.parameters: 2962 content += param[2].GetValue() # value 2963 content += tab 2964 content += param[4].GetValue() # error 2965 content += tab 2966 2967 return content 2968 else: 2969 return False 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 2970 3018 2971 3019 def get_copy_latex(self): … … 2982 3030 Get the string copies of the param names and values in the tap 2983 3031 """ 3032 if not self.parameters: 3033 # Do nothing if self.parameters doesn't exist 3034 return False 3035 2984 3036 content = '\\begin{table}' 2985 3037 content += '\\begin{tabular}[h]' … … 2988 3040 tab = chr(9) 2989 3041 2990 # Do it if params exist 2991 if self.parameters: 2992 2993 content += '{|' 2994 for param in self.parameters: 2995 content += 'l|l|' 2996 content += '}\hline' 2997 content += crlf 2998 2999 for index, param in enumerate(self.parameters): 3000 content += param[1].replace('_', '\_') # parameter name 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 3001 3056 content += ' & ' 3002 content += param[1].replace('_', '\_') + "\_err" 3003 if index < len(self.parameters) - 1: 3004 content += ' & ' 3005 content += '\\\\ \\hline' 3006 content += crlf 3007 3008 # row of values and errors... 3009 for index, param in enumerate(self.parameters): 3010 content += param[2].GetValue() # parameter value 3057 content += name.replace('_', '\_') + "\_err" 3058 if index < len(all_params) - 1: 3011 3059 content += ' & ' 3012 content += param[4].GetValue() # parameter error 3013 if index < len(self.parameters) - 1: 3014 content += ' & ' 3015 content += '\\\\ \\hline' 3016 content += crlf 3017 3018 content += '\\end{tabular}' 3019 content += '\\end{table}' 3020 return content 3021 else: 3022 return False 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 3023 3087 3024 3088 def set_clipboard(self, content=None):
Note: See TracChangeset
for help on using the changeset viewer.