@@ -43,7 +43,7 @@ class EddingtonGUI(toga.App): # pylint: disable=too-many-instance-attributes
43
43
main_window : toga .Window
44
44
45
45
__a0 : np .ndarray = None
46
- __fit_result : FittingResult = None
46
+ __fitting_result : FittingResult = None
47
47
48
48
def startup (self ):
49
49
"""
@@ -57,29 +57,35 @@ def startup(self):
57
57
main_box .add (HeaderBox ())
58
58
59
59
self .input_file_box = InputFileBox (flex = 1 )
60
- self .input_file_box .add_handler (self .reset_fit_data )
60
+ self .input_file_box .add_handler (self .reset_fitting_data )
61
61
main_box .add (self .input_file_box )
62
62
63
63
self .fitting_function_box = FittingFunctionBox (flex = 1 )
64
- self .fitting_function_box .add_handler (lambda fit_func : self .reset_fit_result ())
64
+ self .fitting_function_box .add_handler (
65
+ lambda fit_func : self .reset_fitting_result ()
66
+ )
65
67
main_box .add (self .fitting_function_box )
66
68
67
69
self .initial_guess_box = InitialGuessBox ()
68
- self .initial_guess_box .add_handler (lambda a0 : self .reset_fit_result ())
70
+ self .initial_guess_box .add_handler (lambda a0 : self .reset_fitting_result ())
69
71
self .fitting_function_box .add_handler (self .set_parameters_number )
70
72
main_box .add (self .initial_guess_box )
71
73
72
74
self .data_columns_box = DataColumnsBox (flex = 5 )
73
- self .data_columns_box .add_handler (lambda fit_data : self .reset_fit_result ())
75
+ self .data_columns_box .add_handler (
76
+ lambda fitting_data : self .reset_fitting_result ()
77
+ )
74
78
self .input_file_box .on_csv_read = self .read_csv
75
79
self .input_file_box .on_excel_read = self .read_excel
76
80
self .input_file_box .on_select_file = self .select_default_sheet
77
81
78
82
self .plot_configuration_box = PlotConfigurationBox (flex = 5 )
79
83
self .fitting_function_box .add_handler (
80
- self .plot_configuration_box .on_fit_function_load
84
+ self .plot_configuration_box .on_fitting_function_load
85
+ )
86
+ self .data_columns_box .add_handler (
87
+ self .plot_configuration_box .on_fitting_data_load
81
88
)
82
- self .data_columns_box .add_handler (self .plot_configuration_box .on_fit_data_load )
83
89
84
90
main_box .add (
85
91
toga .Box (
@@ -160,16 +166,16 @@ def startup(self):
160
166
self .main_window .show ()
161
167
162
168
@property
163
- def fit_result (self ):
169
+ def fitting_result (self ):
164
170
"""Getter of the fit result."""
165
- if self .__fit_result is None :
166
- self .__calculate_fit_result ()
167
- return self .__fit_result
171
+ if self .__fitting_result is None :
172
+ self .__calculate_fitting_result ()
173
+ return self .__fitting_result
168
174
169
- @fit_result .setter
170
- def fit_result (self , fit_result ):
175
+ @fitting_result .setter
176
+ def fitting_result (self , fitting_result ):
171
177
"""Setter of the fit result."""
172
- self .__fit_result = fit_result
178
+ self .__fitting_result = fitting_result
173
179
174
180
def read_csv (self , filepath ):
175
181
"""
@@ -183,7 +189,7 @@ def read_csv(self, filepath):
183
189
self .data_columns_box .read_csv (filepath )
184
190
except FittingDataError as error :
185
191
self .main_window .error_dialog (title = "Input data error" , message = str (error ))
186
- self .data_columns_box .fit_data = None
192
+ self .data_columns_box .fitting_data = None
187
193
self .input_file_box .file_path = None
188
194
189
195
def read_excel (self , filepath , sheet ):
@@ -199,57 +205,59 @@ def read_excel(self, filepath, sheet):
199
205
self .data_columns_box .read_excel (filepath , sheet )
200
206
except FittingDataError as error :
201
207
self .main_window .error_dialog (title = "Input data error" , message = str (error ))
202
- self .data_columns_box .fit_data = None
208
+ self .data_columns_box .fitting_data = None
203
209
self .input_file_box .selected_sheet = None
204
210
205
211
def choose_records (self , widget ): # pylint: disable=unused-argument
206
212
"""Open the choose records window."""
207
- if self .data_columns_box .fit_data is None :
213
+ if self .data_columns_box .fitting_data is None :
208
214
self .main_window .info_dialog (
209
215
title = "Choose Records" , message = "No data been given yet"
210
216
)
211
217
return
212
- window = RecordsChoiceWindow (fit_data = self .data_columns_box .fit_data )
218
+ window = RecordsChoiceWindow (fitting_data = self .data_columns_box .fitting_data )
213
219
window .show ()
214
- self .reset_fit_result ()
220
+ self .reset_fitting_result ()
215
221
self .initial_guess_box .reset_initial_guess ()
216
222
217
223
def fit (self , widget ): # pylint: disable=unused-argument
218
224
"""Handler for the "fit" button."""
219
225
try :
220
- if self .fit_result is None :
226
+ if self .fitting_result is None :
221
227
self .main_window .info_dialog (
222
228
title = "Fit Result" , message = "Nothing to fit yet"
223
229
)
224
230
return
225
231
except EddingtonException :
226
232
return
227
- self .main_window .info_dialog (title = "Fit Result" , message = str (self .fit_result ))
233
+ self .main_window .info_dialog (
234
+ title = "Fit Result" , message = str (self .fitting_result )
235
+ )
228
236
229
237
def plot_data (self , widget ): # pylint: disable=unused-argument
230
238
"""Handler for the "plot data" button."""
231
- if self .data_columns_box .fit_data is None :
239
+ if self .data_columns_box .fitting_data is None :
232
240
self .show_nothing_to_plot ()
233
241
else :
234
242
self .show_figure_window (
235
243
self .plot_configuration_box .plot_data (
236
- data = self .data_columns_box .fit_data
244
+ data = self .data_columns_box .fitting_data
237
245
)
238
246
)
239
247
240
248
def plot_initial_guess (self , widget ): # pylint: disable=unused-argument
241
249
"""Handler for the "plot initial guess" button."""
242
250
try :
243
251
if (
244
- self .data_columns_box .fit_data is None
252
+ self .data_columns_box .fitting_data is None
245
253
or self .initial_guess_box .a0 is None # noqa: W503
246
254
):
247
255
self .show_nothing_to_plot ()
248
256
return
249
257
self .show_figure_window (
250
258
self .plot_configuration_box .plot_fitting (
251
- func = self .fitting_function_box .fit_function ,
252
- data = self .data_columns_box .fit_data ,
259
+ func = self .fitting_function_box .fitting_function ,
260
+ data = self .data_columns_box .fitting_data ,
253
261
a = self .initial_guess_box .a0 ,
254
262
)
255
263
)
@@ -261,14 +269,14 @@ def plot_initial_guess(self, widget): # pylint: disable=unused-argument
261
269
def plot (self , widget ): # pylint: disable=unused-argument
262
270
"""Handler for the "plot fitting" button."""
263
271
try :
264
- if self .fit_result is None :
272
+ if self .fitting_result is None :
265
273
self .show_nothing_to_plot ()
266
274
return
267
275
self .show_figure_window (
268
276
self .plot_configuration_box .plot_fitting (
269
- func = self .fitting_function_box .fit_function ,
270
- data = self .data_columns_box .fit_data ,
271
- a = self .fit_result .a ,
277
+ func = self .fitting_function_box .fitting_function ,
278
+ data = self .data_columns_box .fitting_data ,
279
+ a = self .fitting_result .a ,
272
280
)
273
281
)
274
282
except EddingtonException as error :
@@ -279,14 +287,14 @@ def plot(self, widget): # pylint: disable=unused-argument
279
287
def residuals (self , widget ): # pylint: disable=unused-argument
280
288
"""Handler for the "residuals" button."""
281
289
try :
282
- if self .fit_result is None :
290
+ if self .fitting_result is None :
283
291
self .show_nothing_to_plot ()
284
292
return
285
293
self .show_figure_window (
286
294
self .plot_configuration_box .plot_residuals (
287
- func = self .fitting_function_box .fit_function ,
288
- data = self .data_columns_box .fit_data ,
289
- a = self .fit_result .a ,
295
+ func = self .fitting_function_box .fitting_function ,
296
+ data = self .data_columns_box .fitting_data ,
297
+ a = self .fitting_result .a ,
290
298
)
291
299
)
292
300
except EddingtonException as error :
@@ -307,7 +315,7 @@ def choose_output_dir(self, widget): # pylint: disable=unused-argument
307
315
def save_to_output_dir (self , widget ): # pylint: disable=unused-argument
308
316
"""Handler for the "save to output directory" button."""
309
317
try :
310
- if self .fit_result is None :
318
+ if self .fitting_result is None :
311
319
self .show_nothing_to_plot ()
312
320
return
313
321
except EddingtonException :
@@ -321,17 +329,17 @@ def save_to_output_dir(self, widget): # pylint: disable=unused-argument
321
329
output_dir = Path (self .output_directory_input .value )
322
330
if not output_dir .exists ():
323
331
output_dir .mkdir ()
324
- func_name = self .fitting_function_box .fit_function .name
325
- self .fit_result .save_txt (output_dir / f"{ func_name } _result.txt" )
332
+ func_name = self .fitting_function_box .fitting_function .name
333
+ self .fitting_result .save_txt (output_dir / f"{ func_name } _result.txt" )
326
334
self .plot_configuration_box .plot_fitting (
327
- func = self .fitting_function_box .fit_function ,
328
- data = self .data_columns_box .fit_data ,
329
- a = self .fit_result .a ,
335
+ func = self .fitting_function_box .fitting_function ,
336
+ data = self .data_columns_box .fitting_data ,
337
+ a = self .fitting_result .a ,
330
338
).savefig (output_dir / f"{ func_name } _fitting.png" )
331
339
self .plot_configuration_box .plot_residuals (
332
- func = self .fitting_function_box .fit_function ,
333
- data = self .data_columns_box .fit_data ,
334
- a = self .fit_result .a ,
340
+ func = self .fitting_function_box .fitting_function ,
341
+ data = self .data_columns_box .fitting_data ,
342
+ a = self .fitting_result .a ,
335
343
).savefig (output_dir / f"{ func_name } _residuals.png" )
336
344
self .main_window .info_dialog (
337
345
title = "Save output" , message = "All plots have been saved successfully!"
@@ -347,13 +355,13 @@ def show_figure_window(fig):
347
355
figure_window = FigureWindow (fig )
348
356
figure_window .show ()
349
357
350
- def reset_fit_data (self ):
358
+ def reset_fitting_data (self ):
351
359
"""Set fit data to None."""
352
- self .data_columns_box .fit_data = None
360
+ self .data_columns_box .fitting_data = None
353
361
354
- def reset_fit_result (self ):
362
+ def reset_fitting_result (self ):
355
363
"""Set fit result to None."""
356
- self .fit_result = None
364
+ self .fitting_result = None
357
365
358
366
def set_parameters_number (self , func ):
359
367
"""Set number of parameters."""
@@ -362,21 +370,21 @@ def set_parameters_number(self, func):
362
370
else :
363
371
self .initial_guess_box .n = func .n
364
372
365
- def __calculate_fit_result (self ):
373
+ def __calculate_fitting_result (self ):
366
374
if (
367
- self .data_columns_box .fit_data is None
368
- or self .fitting_function_box .fit_function is None # noqa: W503
375
+ self .data_columns_box .fitting_data is None
376
+ or self .fitting_function_box .fitting_function is None # noqa: W503
369
377
):
370
- self .fit_result = None
378
+ self .fitting_result = None
371
379
return
372
380
try :
373
- self .fit_result = fit (
374
- data = self .data_columns_box .fit_data ,
375
- func = self .fitting_function_box .fit_function ,
381
+ self .fitting_result = fit (
382
+ data = self .data_columns_box .fitting_data ,
383
+ func = self .fitting_function_box .fitting_function ,
376
384
a0 = self .initial_guess_box .a0 ,
377
385
)
378
386
except EddingtonException as error :
379
- self .fit_result = None
387
+ self .fitting_result = None
380
388
self .main_window .error_dialog (title = "Fit result error" , message = str (error ))
381
389
raise error
382
390
@@ -389,15 +397,15 @@ def select_default_sheet(self):
389
397
for sheet in self .input_file_box .sheets_options :
390
398
if sheet != NO_VALUE :
391
399
try :
392
- self .data_columns_box .fit_data = FittingData .read_from_excel (
400
+ self .data_columns_box .fitting_data = FittingData .read_from_excel (
393
401
Path (self .input_file_box .file_path ), sheet
394
402
)
395
403
self .input_file_box .selected_sheet = sheet
396
404
return
397
405
except FittingDataError :
398
406
pass
399
407
400
- if self .data_columns_box .fit_data is None :
408
+ if self .data_columns_box .fitting_data is None :
401
409
self .main_window .error_dialog (
402
410
title = "Input data error" ,
403
411
message = (
0 commit comments