| Conditions | 12 | 
| Total Lines | 60 | 
| Code Lines | 38 | 
| 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 | """ | ||
| 141 | def run(self, steps=None, overwrite=None, **kwargs): | ||
| 142 | """ | ||
| 143 | Main function to run the AnalaysisSteps provided. | ||
| 144 | """ | ||
| 145 | if steps is None: | ||
| 146 | steps = self.config.general.steps | ||
| 147 | overwrite = self.config.general.overwrite | ||
| 148 | else: | ||
| 149 | if overwrite is None: | ||
| 150 | overwrite = True | ||
| 151 | |||
| 152 | dl3_dl4_steps = [step for step in steps if "datasets" in step] | ||
| 153 | dl4_dl5_steps = [step for step in steps if "datasets" not in step] | ||
| 154 | |||
| 155 | if len(dl3_dl4_steps) > 0: | ||
| 156 |             self.log.info("Perform DL3 to DL4 process!") | ||
| 157 | |||
| 158 | for step in dl3_dl4_steps: | ||
| 159 | analysis_step = AnalysisStep.create(step, self.config, **kwargs) | ||
| 160 | |||
| 161 | datasets_list, models_list, instrument_spectral_info = analysis_step.run() | ||
| 162 | |||
| 163 | self.update_models_list(models_list) | ||
| 164 | |||
| 165 | # To get all datasets_names from the datasets and update the final datasets list | ||
| 166 | for data in datasets_list: | ||
| 167 | if data.name not in self.dataset_name_list: | ||
| 168 | self.dataset_name_list.append(data.name) | ||
| 169 | self.datasets.append(data) | ||
| 170 | |||
| 171 | self.add_to_instrument_info(instrument_spectral_info) | ||
| 172 | |||
| 173 | self.datasets, self.final_model = set_models( | ||
| 174 | self.config.target, | ||
| 175 | self.datasets, | ||
| 176 | self.dataset_name_list, | ||
| 177 | models=self.final_model, | ||
| 178 | ) | ||
| 179 |             self.log.info("Models have been associated with the Datasets") | ||
| 180 | |||
| 181 | self.update_dof_value() | ||
| 182 | |||
| 183 | if len(dl4_dl5_steps) > 0: | ||
| 184 |             self.log.info("Perform DL4 to DL5 processes!") | ||
| 185 | |||
| 186 | for step in dl4_dl5_steps: | ||
| 187 | analysis_step = AnalysisStep.create(step, self.config, **kwargs) | ||
| 188 | |||
| 189 | analysis_step.run(datasets=self.datasets, instrument_spectral_info=self.instrument_spectral_info) | ||
| 190 | |||
| 191 | # Update the final data product objects | ||
| 192 | for data_product in self.final_data_products: | ||
| 193 | if hasattr(analysis_step, data_product): | ||
| 194 | setattr(self, data_product, getattr(analysis_step, data_product)) | ||
| 195 | |||
| 196 | if self.fit_result: | ||
| 197 | self.instrument_spectral_info, message = get_goodness_of_fit_stats( | ||
| 198 | self.datasets, self.instrument_spectral_info | ||
| 199 | ) | ||
| 200 | self.log.info(message) | ||
| 201 | |||
| 222 |