From cdb001b1440cde508128ab2cdd0f3abd8bf32e7a Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Fri, 14 Aug 2020 17:28:17 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- RIXSPlot/__main__.py | 31 ++++++++++++------------------- RIXSPlot/normalize.py | 26 ++++++++------------------ 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/RIXSPlot/__main__.py b/RIXSPlot/__main__.py index 402f689..f6b9c12 100644 --- a/RIXSPlot/__main__.py +++ b/RIXSPlot/__main__.py @@ -170,29 +170,26 @@ def plot_contour(self): self.ax3.set_ylabel('Energy Transfer (eV)') # Setting up the RIXS-Map with optional contour-plot if self.cont_t: - if self.cont_n != 0: - self.cont = self.ax3.contour(self.x, self.y, self.amp, self.cont_n, cmap=plt.get_cmap(self.style)) - else: + if self.cont_n == 0: self.cont = self.ax3.contour(self.x, self.y, self.amp, cmap=plt.get_cmap(self.style)) + else: + self.cont = self.ax3.contour(self.x, self.y, self.amp, self.cont_n, cmap=plt.get_cmap(self.style)) self.cont.set_norm( norm.MyNormalize(vmin=self.amp.min(), vmax=self.amp.max(), stretch=self.stretch, clip=True)) else: extent = (min(self.x), max(self.x), min(self.y), max(self.y)) - if self.cont_n != 0: - self.cont = self.ax3.contour(self.x, self.y, self.amp, self.cont_n, colors='w', aspect='auto', - linewidths=0.75, origin='lower') + if self.cont_n == 0: self.im = self.ax3.imshow(self.amp, extent=extent, cmap=plt.get_cmap(self.style), aspect='auto', interpolation='bilinear', origin='lower') - self.cont.set_norm( - norm.MyNormalize(vmin=self.amp.min(), vmax=self.amp.max(), stretch=self.stretch, clip=True)) - self.im.set_norm( - norm.MyNormalize(vmin=self.amp.min(), vmax=self.amp.max(), stretch=self.stretch, clip=True)) else: + self.cont = self.ax3.contour(self.x, self.y, self.amp, self.cont_n, colors='w', aspect='auto', + linewidths=0.75, origin='lower') self.im = self.ax3.imshow(self.amp, extent=extent, cmap=plt.get_cmap(self.style), aspect='auto', interpolation='bilinear', origin='lower') - self.im.set_norm( + self.cont.set_norm( norm.MyNormalize(vmin=self.amp.min(), vmax=self.amp.max(), stretch=self.stretch, clip=True)) - + self.im.set_norm( + norm.MyNormalize(vmin=self.amp.min(), vmax=self.amp.max(), stretch=self.stretch, clip=True)) # catch error if dividing by zero for normalization # But not working try: @@ -292,7 +289,7 @@ def zoompick(self, event): np.savetxt(self.pathway + newpath + '/XAS_Cut_at_' + label + '.txt', CUT_XAS.T, delimiter='\t', newline='\n', header='En\tnorm.Int\tInt', fmt="%.4f") os.chdir('..') - elif event.inaxes == self.ax2 and event.button == 1: + elif event.button == 1: xpos = int(np.argmin(np.abs(event.xdata - self.x))) if self.aver_x == 0: int_xes = self.amp[:, xpos] @@ -327,7 +324,7 @@ def onpick(self, event): """ if event.inaxes != self.ax3: return - elif event.inaxes == self.ax3: + else: if event.button == 1: xpos = int(np.argmin(np.abs(event.xdata - self.x))) if self.aver_x == 0: @@ -391,11 +388,7 @@ def norm_XAS(data): """ Normalization of the XAS-Spectra according to the maxima of the all RIXS-intensities """ - if np.max(data) != 0: - norm = data / np.max(data) - else: - norm = data - return norm + return data / np.max(data) if np.max(data) != 0 else data def norm_XES(self, data, mode): """ diff --git a/RIXSPlot/normalize.py b/RIXSPlot/normalize.py index 16162f0..6c25828 100644 --- a/RIXSPlot/normalize.py +++ b/RIXSPlot/normalize.py @@ -47,29 +47,19 @@ def __init__(self, stretch='Linear', exponent=5, vmid=None, vmin=None, vmax=None if stretch == 'Power' and np.equal(self.exponent, None): raise Exception("For stretch=='Power', an exponent should be specified") - if np.equal(vmid, None): - if stretch == 'Log': - if vmin > 0: - self.midpoint = vmax / vmin - elif vmin <= 0: + if stretch == 'Log': + if np.equal(vmid, None): + if vmin <= 0: vmin = 0.00001 - self.midpoint = vmax / vmin - else: - raise Exception("When using a Log stretch, if vmin < 0, then vmid has to be specified") - elif stretch == 'Arcsinh' or stretch == 'Arccosh': - self.midpoint = -1. / 30. + self.midpoint = vmax / vmin else: - self.midpoint = None - else: - if stretch == 'Log': if vmin < vmid: raise Exception("When using a Log stretch, vmin should be larger than vmid") self.midpoint = (vmax - vmid) / (vmin - vmid) - elif stretch == 'Arcsinh' or stretch == 'Arccosh': - self.midpoint = (vmid - vmin) / (vmax - vmin) - - else: - self.midpoint = None + elif stretch in ['Arcsinh', 'Arccosh']: + self.midpoint = -1. / 30. + else: + self.midpoint = None def __call__(self, value, clip=None):