| 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 | import argparse  | 
            ||
| 118 | if pref_over_pl_chi2_list[idx] > 5:  | 
            ||
| 119 | sp_idx_lrt = idx  | 
            ||
| 120 |             log.info("Best preferred spectral model over PL is %s", spec_models_list[idx]) | 
            ||
| 121 | else:  | 
            ||
| 122 | sp_idx_lrt = PL_idx  | 
            ||
| 123 |             log.info("No other model preferred over PL") | 
            ||
| 124 | |||
| 125 | list_rel_p = check_model_preference_aic(stat_list, dof_list)  | 
            ||
| 126 | |||
| 127 | best_sp_idx_aic = np.nonzero(list_rel_p == np.nanmax(list_rel_p))[0]  | 
            ||
| 128 | |||
| 129 | for idx in best_sp_idx_aic:  | 
            ||
| 130 | if list_rel_p[idx] > 0.95:  | 
            ||
| 131 | sp_idx_aic = idx  | 
            ||
| 132 |             log.info("Best preferred spectral model is %s", spec_models_list[fit_success_list][idx]) | 
            ||
| 133 | else:  | 
            ||
| 134 | sp_idx_aic = PL_idx  | 
            ||
| 135 |             log.info("No other model preferred, hence PL is selected") | 
            ||
| 136 | |||
| 137 | stats_table = tabulate_best_fit_stats(spec_models_list, fit_success_list, main_analysis_list, list_rel_p)  | 
            ||
| 138 | |||
| 139 | stats_table.meta["Target source name"] = target_source_name  | 
            ||
| 140 | stats_table.meta["EBL model"] = args.ebl_model_name  | 
            ||
| 141 | stats_table.meta["EBL scale factor"] = args.ebl_scale_factor  | 
            ||
| 142 | |||
| 143 |     file_name = f"{config_path_file_name}_{args.ebl_model_name}_{args.ebl_scale_factor}_fit_stats.ecsv" | 
            ||
| 144 | stats_table.write(  | 
            ||
| 145 | main_config.general.outdir / file_name,  | 
            ||
| 146 | format="ascii.ecsv",  | 
            ||
| 147 | overwrite=True,  | 
            ||
| 148 | )  | 
            ||
| 149 | |||
| 150 | if args.write_config:  | 
            ||
| 151 |         log.info("Write the spectral model") | 
            ||
| 152 | |||
| 153 | for idx, name in zip([sp_idx_lrt, sp_idx_aic], ["lrt", "aic"], strict=False):  | 
            ||
| 154 | tag = spec_models_list[fit_success_list][idx]  | 
            ||
| 155 | |||
| 156 |             path = config_path.parent / f"{config_path_file_name}_model_most_pref_{name}.yaml" | 
            ||
| 157 | |||
| 158 | yaml_ = write_output_config_yaml(main_analysis_list[tag]["Analysis"].final_model[0])  | 
            ||
| 159 | path.write_text(yaml_)  | 
            ||
| 160 | |||
| 161 | |||
| 162 | if __name__ == "__main__":  | 
            ||
| 163 | main()  | 
            ||
| 164 |