Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions RIXSPlot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Comment on lines -173 to +192

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RIXS.plot_contour refactored with the following changes:

  • Hoist repeated code outside conditional statement (hoist-statement-from-if)

# catch error if dividing by zero for normalization
# But not working
try:
Expand Down Expand Up @@ -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:
Comment on lines -295 to +292

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RIXS.zoompick refactored with the following changes:

  • Remove redundant conditional (remove-redundant-if)

xpos = int(np.argmin(np.abs(event.xdata - self.x)))
if self.aver_x == 0:
int_xes = self.amp[:, xpos]
Expand Down Expand Up @@ -327,7 +324,7 @@ def onpick(self, event):
"""
if event.inaxes != self.ax3:
return
elif event.inaxes == self.ax3:
else:
Comment on lines -330 to +327

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RIXS.onpick refactored with the following changes:

  • Remove redundant conditional (remove-redundant-if)

if event.button == 1:
xpos = int(np.argmin(np.abs(event.xdata - self.x)))
if self.aver_x == 0:
Expand Down Expand Up @@ -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
Comment on lines -394 to +391

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RIXS.norm_XAS refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)


def norm_XES(self, data, mode):
"""
Expand Down
26 changes: 8 additions & 18 deletions RIXSPlot/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines -50 to +62

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MyNormalize.__init__ refactored with the following changes:

  • Remove redundant conditional (remove-redundant-if)
  • Hoist repeated code outside conditional statement (hoist-statement-from-if)
  • Hoist repeated code outside conditional statement (hoist-statement-from-if)
  • Swap if/else to remove empty if body (remove-pass-body)
  • Replace multiple comparisons of same variable with in operator (merge-comparisons)


def __call__(self, value, clip=None):

Expand Down