| Conditions | 11 | 
| Total Lines | 60 | 
| Code Lines | 36 | 
| 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:
Complex classes like asgardpy.analysis.analysis.AsgardpyAnalysis.run() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | """  | 
            ||
| 146 | def run(self, steps=None, **kwargs):  | 
            ||
| 147 | """  | 
            ||
| 148 | Main function to run the AnalaysisSteps provided.  | 
            ||
| 149 | |||
| 150 | Currently overwrite option is used from the value in AsgardpyConfig,  | 
            ||
| 151 | and is True by default.  | 
            ||
| 152 | """  | 
            ||
| 153 | if steps is None:  | 
            ||
| 154 | steps = self.config.general.steps  | 
            ||
| 155 | self.overwrite = self.config.general.overwrite  | 
            ||
| 156 | |||
| 157 | dl3_dl4_steps = [step for step in steps if "datasets" in step]  | 
            ||
| 158 | dl4_dl5_steps = [step for step in steps if "datasets" not in step]  | 
            ||
| 159 | |||
| 160 | if len(dl3_dl4_steps) > 0:  | 
            ||
| 161 |             self.log.info("Perform DL3 to DL4 process!") | 
            ||
| 162 | |||
| 163 | for step in dl3_dl4_steps:  | 
            ||
| 164 | analysis_step = AnalysisStep.create(step, self.config, **kwargs)  | 
            ||
| 165 | |||
| 166 | datasets_list, models_list, instrument_spectral_info = analysis_step.run()  | 
            ||
| 167 | |||
| 168 | self.update_models_list(models_list)  | 
            ||
| 169 | |||
| 170 | # To get all datasets_names from the datasets and update the final datasets list  | 
            ||
| 171 | for data in datasets_list:  | 
            ||
| 172 | if data.name not in self.dataset_name_list:  | 
            ||
| 173 | self.dataset_name_list.append(data.name)  | 
            ||
| 174 | self.datasets.append(data)  | 
            ||
| 175 | |||
| 176 | self.add_to_instrument_info(instrument_spectral_info)  | 
            ||
| 177 | |||
| 178 | self.datasets, self.final_model = set_models(  | 
            ||
| 179 | self.config.target,  | 
            ||
| 180 | self.datasets,  | 
            ||
| 181 | self.dataset_name_list,  | 
            ||
| 182 | models=self.final_model,  | 
            ||
| 183 | )  | 
            ||
| 184 |             self.log.info("Models have been associated with the Datasets") | 
            ||
| 185 | |||
| 186 | self.update_dof_value()  | 
            ||
| 187 | |||
| 188 | if len(dl4_dl5_steps) > 0:  | 
            ||
| 189 |             self.log.info("Perform DL4 to DL5 processes!") | 
            ||
| 190 | |||
| 191 | for step in dl4_dl5_steps:  | 
            ||
| 192 | analysis_step = AnalysisStep.create(step, self.config, **kwargs)  | 
            ||
| 193 | |||
| 194 | analysis_step.run(datasets=self.datasets, instrument_spectral_info=self.instrument_spectral_info)  | 
            ||
| 195 | |||
| 196 | # Update the final data product objects  | 
            ||
| 197 | for data_product in self.final_data_products:  | 
            ||
| 198 | if hasattr(analysis_step, data_product):  | 
            ||
| 199 | setattr(self, data_product, getattr(analysis_step, data_product))  | 
            ||
| 200 | |||
| 201 | if self.fit_result:  | 
            ||
| 202 | self.instrument_spectral_info, message = get_goodness_of_fit_stats(  | 
            ||
| 203 | self.datasets, self.instrument_spectral_info  | 
            ||
| 204 | )  | 
            ||
| 205 | self.log.info(message)  | 
            ||
| 206 | |||
| 227 |