| Conditions | 3 |
| Total Lines | 53 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | """ |
||
| 84 | def fetch_all_analysis_fit_info(main_analysis_list, spec_models_list): |
||
| 85 | """ |
||
| 86 | For a list of spectral models, with the AsgardpyAnalysis run till the fit |
||
| 87 | step, get the relevant information for testing the model preference. |
||
| 88 | """ |
||
| 89 | fit_success_list = [] |
||
| 90 | pref_over_pl_chi2_list = [] |
||
| 91 | stat_list = [] |
||
| 92 | dof_list = [] |
||
| 93 | |||
| 94 | for tag in spec_models_list: |
||
| 95 | dict_tag = main_analysis_list[tag]["Analysis"].instrument_spectral_info |
||
| 96 | dict_pl = main_analysis_list["pl"]["Analysis"].instrument_spectral_info |
||
| 97 | |||
| 98 | # Collect parameters for AIC check |
||
| 99 | stat = dict_tag["best_fit_stat"] |
||
| 100 | dof = dict_tag["DoF"] |
||
| 101 | |||
| 102 | fit_success = main_analysis_list[tag]["Analysis"].fit_result.success |
||
| 103 | |||
| 104 | fit_success_list.append(fit_success) |
||
| 105 | stat_list.append(stat) |
||
| 106 | dof_list.append(dof) |
||
| 107 | |||
| 108 | # Checking the preference of a "nested" spectral model (observed), |
||
| 109 | # over Power Law. |
||
| 110 | if tag == "pl": |
||
| 111 | main_analysis_list[tag]["Pref_over_pl_chi2"] = 0 |
||
| 112 | main_analysis_list[tag]["Pref_over_pl_pval"] = 0 |
||
| 113 | main_analysis_list[tag]["DoF_over_pl"] = 0 |
||
| 114 | pref_over_pl_chi2_list.append(0) |
||
| 115 | continue |
||
| 116 | |||
| 117 | p_pl_x, g_pl_x, ndof_pl_x = check_model_preference_lrt( |
||
| 118 | dict_pl["best_fit_stat"], |
||
| 119 | dict_tag["best_fit_stat"], |
||
| 120 | dict_pl["DoF"], |
||
| 121 | dict_tag["DoF"], |
||
| 122 | ) |
||
| 123 | |||
| 124 | main_analysis_list[tag]["Pref_over_pl_chi2"] = g_pl_x |
||
| 125 | pref_over_pl_chi2_list.append(g_pl_x) |
||
| 126 | main_analysis_list[tag]["Pref_over_pl_pval"] = p_pl_x |
||
| 127 | main_analysis_list[tag]["DoF_over_pl"] = ndof_pl_x |
||
| 128 | |||
| 129 | fit_success_list = np.array(fit_success_list) |
||
| 130 | |||
| 131 | # Only select fit results that were successful for comparisons |
||
| 132 | stat_list = np.array(stat_list)[fit_success_list] |
||
| 133 | dof_list = np.array(dof_list)[fit_success_list] |
||
| 134 | pref_over_pl_chi2_list = np.array(pref_over_pl_chi2_list)[fit_success_list] |
||
| 135 | |||
| 136 | return fit_success_list, stat_list, dof_list, pref_over_pl_chi2_list |
||
| 137 | |||
| 167 |