| 212 | return result |
| 213 | |
| 214 | def __sub__(self, other): |
| 215 | if isinstance(other, Analysis): |
| 216 | if other.range != self.range: |
| 217 | raise ValueError("Can't subtract! Both Analysis have" + |
| 218 | " different band limits.") |
| 219 | if self.anType == 'L': |
| 220 | if other.anType == 'L': |
| 221 | data = [] |
| 222 | for idx, value in enumerate(self.data): |
| 223 | d = 10*np.log10(10**(value/10) - |
| 224 | 10**(other.data[idx]/10)) |
| 225 | data.append(d) |
| 226 | anType = 'L' |
| 227 | elif other.anType in ['mixed', 'C', 'D', 'RT']: |
| 228 | data = self.data - other.data |
| 229 | anType = 'mixed' |
| 230 | else: |
| 231 | raise NotImplementedError("Operation not implemented " + |
| 232 | "for Analysis types " + |
| 233 | anTypes[self.anType][1] + |
| 234 | " and " + |
| 235 | anTypes[other.anType][1] + |
| 236 | ".") |
| 237 | else: |
| 238 | data = self.data - other.data |
| 239 | anType = 'mixed' |
| 240 | elif isinstance(other, (int, float)): |
| 241 | if self.anType == 'L': |
| 242 | data = [10*np.log10(10**(dt/10) - 10**(other/10)) |
| 243 | for dt in self.data] |
| 244 | anType = 'L' |
| 245 | else: |
| 246 | data = self.data - other |
| 247 | anType = 'mixed' |
| 248 | else: |
| 249 | raise NotImplementedError("Operation not implemented between " + |
| 250 | "Analysis and {}".format(type(other)) + |
| 251 | "types.") |
| 252 | selfDataLabel = self.dataLabel if self.dataLabel is not None \ |
| 253 | else 'Analysis 1' |
| 254 | if hasattr(other,'dataLabel'): |
| 255 | if other.dataLabel is not None: |
| 256 | otherDataLabel = other.dataLabel |
| 257 | else: |
| 258 | otherDataLabel = 'Analysis 2' |
| 259 | else: |
| 260 | otherDataLabel = 'Analysis 2' |
| 261 | result = Analysis(anType=anType, nthOct=self.nthOct, |
| 262 | minBand=self.minBand, maxBand=self.maxBand, |
| 263 | data=data, dataLabel=selfDataLabel + |
| 264 | ' - ' + otherDataLabel, |
| 265 | error=None, errorLabel=None, |
| 266 | comment=None, |
| 267 | xLabel=self.xLabel, yLabel=self.yLabel, |
| 268 | title=None) |
| 269 | |
| 270 | return result |
| 271 | |