| 154 | f'comment={self.comment!r})') |
| 155 | |
| 156 | def __add__(self, other): |
| 157 | if isinstance(other, Analysis): |
| 158 | if other.range != self.range: |
| 159 | raise ValueError("Can't subtract! Both Analysis have" + |
| 160 | " different band limits.") |
| 161 | if self.anType == 'L': |
| 162 | if other.anType == 'L': |
| 163 | data = [] |
| 164 | for idx, value in enumerate(self.data): |
| 165 | d = 10*np.log10(10**(value/10) + |
| 166 | 10**(other.data[idx]/10)) |
| 167 | data.append(d) |
| 168 | anType = 'L' |
| 169 | elif other.anType in ['mixed', 'C', 'D', 'RT']: |
| 170 | data = self.data + other.data |
| 171 | anType = 'mixed' |
| 172 | else: |
| 173 | raise NotImplementedError("Operation not implemented " + |
| 174 | "for Analysis types " + |
| 175 | anTypes[self.anType][1] + |
| 176 | " and " + |
| 177 | anTypes[other.anType][1] + |
| 178 | ".") |
| 179 | else: |
| 180 | data = self.data + other.data |
| 181 | anType = 'mixed' |
| 182 | elif isinstance(other, (int, float)): |
| 183 | if self.anType == 'L': |
| 184 | data = [10*np.log10(10**(dt/10) + 10**(other/10)) |
| 185 | for dt in self.data] |
| 186 | anType = 'L' |
| 187 | else: |
| 188 | data = self.data + other |
| 189 | anType = 'mixed' |
| 190 | else: |
| 191 | raise NotImplementedError("Operation not implemented between " + |
| 192 | "Analysis and {}".format(type(other)) + |
| 193 | "types.") |
| 194 | selfDataLabel = self.dataLabel if self.dataLabel is not None \ |
| 195 | else 'Analysis 1' |
| 196 | if hasattr(other,'dataLabel'): |
| 197 | if other.dataLabel is not None: |
| 198 | otherDataLabel = other.dataLabel |
| 199 | else: |
| 200 | otherDataLabel = 'Analysis 2' |
| 201 | else: |
| 202 | otherDataLabel = 'Analysis 2' |
| 203 | result = Analysis(anType=anType, nthOct=self.nthOct, |
| 204 | minBand=self.minBand, maxBand=self.maxBand, |
| 205 | data=data, dataLabel=selfDataLabel + |
| 206 | ' + ' + otherDataLabel, |
| 207 | error=None, errorLabel=None, |
| 208 | comment=None, |
| 209 | xLabel=self.xLabel, yLabel=self.yLabel, |
| 210 | title=None) |
| 211 | |
| 212 | return result |
| 213 | |