Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Aug 14, 2020

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -173 to +192
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))
Copy link
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)

Comment on lines -295 to +292
elif event.inaxes == self.ax2 and event.button == 1:
elif event.button == 1:
Copy link
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)

Comment on lines -330 to +327
elif event.inaxes == self.ax3:
else:
Copy link
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)

Comment on lines -394 to +391
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
Copy link
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)

Comment on lines -50 to +62
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
Copy link
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)

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Aug 14, 2020

Sourcery Code Quality Report (beta)

✅  Merging this PR will increase code quality in the affected files by 0.06 out of 10.

Quality metrics Before After Change
Complexity 5.79 5.45 -0.34 🔵
Method Length 127.44 124.61 -2.83 🔵
Quality 7.42 7.48 0.06 🔵
Other metrics Before After Change
Lines 682 665 -17
Changed files Quality Before Quality After Quality Change
RIXSPlot/main.py 7.66 7.67 0.01 🔵
RIXSPlot/normalize.py 5.95 6.29 0.34 🔵

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Overall Recommendation
RIXSPlot/main.py RIXS.onpick 27 496.64 2.60 Split out functionality
RIXSPlot/main.py MainWindow.getfiles 28 363.60 2.72 Split out functionality
RIXSPlot/main.py RIXS.zoompick 21 506.64 3.08 Split out functionality
RIXSPlot/normalize.py MyNormalize.__call__ 18 266.77 3.92 Split out functionality
RIXSPlot/main.py RIXS.plot_contour 11 430.62 4.05 Split out functionality

Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant