Conditions | 21 |
Total Lines | 52 |
Code Lines | 26 |
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 mutis.flares.bayblocks.BayesianBlocks.plot() 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 | """ Flare analysis """ |
||
60 | def plot(self, style='color.strict', ax=None, **kwargs): |
||
61 | """ Plot the bayesian block representation |
||
62 | |||
63 | E.g: |
||
64 | >>> signal = mutis.Signal(data['jyear'], data['Flux'], data['Flux_err']) |
||
65 | >>> BayesianBlocks(signal).plot(color='k') |
||
66 | |||
67 | """ |
||
68 | |||
69 | ax = plt.gca() if ax is None else ax |
||
70 | |||
71 | #self.signal.plot() |
||
72 | |||
73 | x = self.edges |
||
74 | y = self.values[np.r_[0:len(self.values),-1]] |
||
75 | |||
76 | |||
77 | if self.inflare is None or style == 'none': |
||
78 | |||
79 | ax.step(x, y, 'k', where='post', **kwargs) |
||
80 | |||
81 | else: |
||
82 | |||
83 | if style == 'area': |
||
84 | |||
85 | ax.step(x, y, 'k', where='post') |
||
86 | for i in range(len(self.inflare)): |
||
87 | if self.inflare[i]: |
||
88 | ax.axvspan(x[i], x[i+1], facecolor='r', edgecolor=None, alpha=0.2, **kwargs) |
||
89 | |||
90 | elif style == 'color.simple': |
||
91 | |||
92 | for i in range(len(self.edges)-2): |
||
93 | ax.step(self.edges[[i,i+1]], self.values[[i,i+1]], 'r' if self.inflare[i] else 'k', where='post', **kwargs) |
||
94 | ax.step(self.edges[[-2,-1]], self.values[[-1,-1]], 'r' if self.inflare[-1] else 'k', where='post', **kwargs) |
||
95 | |||
96 | elif style == 'color.loose': |
||
97 | |||
98 | for i in range(len(self.edges)-2): |
||
99 | ax.step(self.edges[[i,i+1]], self.values[[i,i]], 'r' if self.inflare[i] else 'k', where='post', **kwargs) |
||
100 | ax.step(self.edges[[i+1,i+1]], self.values[[i,i+1]], 'r' if self.inflare[i] or self.inflare[i+1] else 'k', where='post', **kwargs) |
||
101 | ax.step(self.edges[[-2,-1]], self.values[[-1,-1]], 'r' if self.inflare[-1] else 'k', where='post', **kwargs) |
||
102 | |||
103 | elif style == 'color.strict': |
||
104 | |||
105 | for i in range(len(self.edges)-2): |
||
106 | ax.step(self.edges[[i,i+1]], self.values[[i,i]], 'r' if self.inflare[i] else 'k', where='post', **kwargs) |
||
107 | ax.step(self.edges[[i+1,i+1]], self.values[[i,i+1]], 'r' if self.inflare[i] and self.inflare[i+1] else 'k', where='post', **kwargs) |
||
108 | ax.step(self.edges[[-2,-1]], self.values[[-1,-1]], 'r' if self.inflare[-1] else 'k', where='post', **kwargs) |
||
109 | |||
110 | else: |
||
111 | raise Exception("Unknown style. Available styles are 'none', 'area', 'color.simple', 'color.strict', 'color.loose'.") |
||
112 | |||
232 | return flareL |
||