Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jul 1, 2022

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^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from astromancer July 1, 2022 17:01
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

n = 1. + delta * (rho / RHO0)
return n
return 1. + delta * (rho / RHO0)
Copy link
Author

Choose a reason for hiding this comment

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

Function refractive_index refactored with the following changes:

Comment on lines -52 to +51
def atmosphere(H_gp): # class StandardAtmosphere
def atmosphere(H_gp): # class StandardAtmosphere
Copy link
Author

Choose a reason for hiding this comment

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

Function atmosphere refactored with the following changes:

Comment on lines -365 to +367
dM = rho * np.sqrt(rh * rh + rhp * rhp - 2 * rh * rhp * cos_delphi)
return dM
return rho * np.sqrt(rh * rh + rhp * rhp - 2 * rh * rhp * cos_delphi)
Copy link
Author

Choose a reason for hiding this comment

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

Function Kivalov07.delM refactored with the following changes:

Comment on lines -156 to +160
else:
data = np.array(cosort(phase, *data))
data = np.array(cosort(phase, *data))

phase = data[0]
data = data[1:]
return phase, data
phase = data[0]
data = data[1:]
return phase, 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 rephase refactored with the following changes:

for i, line in enumerate(fp):
for line in fp:
Copy link
Author

Choose a reason for hiding this comment

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

Function iter_lines refactored with the following changes:

Comment on lines -648 to +640
if not self in ax.collections:
if self not in ax.collections:
Copy link
Author

Choose a reason for hiding this comment

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

Function ApertureCollection.add_to_axes refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -891 to +883
if radii.size:
return [list(zip((r, r), (0, 1))) for r in radii]
else:
return []
return [list(zip((r, r), (0, 1))) for r in radii] if radii.size 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 ApLineCollection.make_segments refactored with the following changes:

Comment on lines -1116 to +1105
if not self.size:
concatenate = lambda o, a: a
# HACK! if the Collection was initialized as empty, set the new properties as current
else:
concatenate = PropertyManager.concatenate

concatenate = PropertyManager.concatenate if self.size else (lambda o, a: a)
Copy link
Author

Choose a reason for hiding this comment

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

Function InteractionMixin.append refactored with the following changes:

This removes the following comments ( why? ):

# HACK! if the Collection was initialized as empty, set the new properties as current

Comment on lines -1151 to +1135
if not relative_motion is None:
if relative_motion is not 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 InteractionMixin.resize refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

if instance is None:
return self
return getattr(instance, self.name)
return self if instance is None else getattr(instance, self.name)
Copy link
Author

Choose a reason for hiding this comment

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

Function CalibrationImage.__get__ refactored with the following changes:

frame_kws.update(frame)
frame_kws |= frame
Copy link
Author

Choose a reason for hiding this comment

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

Function plot_transformed_image refactored with the following changes:

if not image.__class__.__name__ == 'SkyImage':
if image.__class__.__name__ != 'SkyImage':
Copy link
Author

Choose a reason for hiding this comment

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

Function MosaicPlotter.plot_image refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

_kws.update(self.label_props)
_kws |= self.label_props
Copy link
Author

Choose a reason for hiding this comment

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

Function MosaicPlotter.label_image refactored with the following changes:

if (p is None) or (p == ()):
# default parameter values for evaluation
return np.zeros(self.dof)
return p
return np.zeros(self.dof) if (p is None) or (p == ()) else p
Copy link
Author

Choose a reason for hiding this comment

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

Function MultivariateGaussians._check_params refactored with the following changes:

This removes the following comments ( why? ):

# default parameter values for evaluation

Comment on lines -376 to +374
else:
if (grid.ndim != 3) or (grid.shape[-1] != self.n_dims):
raise ValueError('Invalid grid')
elif (grid.ndim != 3) or (grid.shape[-1] != self.n_dims):
raise ValueError('Invalid grid')
Copy link
Author

Choose a reason for hiding this comment

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

Function MultivariateGaussians.plot refactored with the following changes:

Comment on lines -644 to +642
if seg is None: # called from class
return self

# bind this class to the seg instance from whence the lookup came.
# Essentially this binds the first argument `seg` in `__call__` below
return types.MethodType(self, seg)
return self if seg is None else types.MethodType(self, seg)
Copy link
Author

Choose a reason for hiding this comment

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

Function MaskedStatistic.__get__ refactored with the following changes:

This removes the following comments ( why? ):

# bind this class to the seg instance from whence the lookup came.
# Essentially this binds the first argument `seg` in `__call__` below
# called from class

Comment on lines -1075 to +1068
s.update(zip(self.labels, SegmentationImage.slices.fget(self)))
s |= zip(self.labels, SegmentationImage.slices.fget(self))
Copy link
Author

Choose a reason for hiding this comment

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

Function slices refactored with the following changes:

Comment on lines -1116 to +1109
if len(self.labels):
return super().max_label
else:
# otherwise `np.max` borks with empty sequence
return 0
return super().max_label if len(self.labels) else 0
Copy link
Author

Choose a reason for hiding this comment

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

Function max_label refactored with the following changes:

This removes the following comments ( why? ):

# otherwise `np.max` borks with empty sequence

Comment on lines -1212 to +1201
raise ValueError('Invalid label(s): %s' % str(tuple(invalid)))
raise ValueError(f'Invalid label(s): {tuple(invalid)}')
Copy link
Author

Choose a reason for hiding this comment

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

Function has_labels refactored with the following changes:

Comment on lines -1558 to +1553
if np.ma.is_masked(image):
# ignore masked pixels
seg_data = self.data.copy()
seg_data[image.mask] = masked_pixels_label
# this label will not be used for statistic computation
return seg_data
else:
if not np.ma.is_masked(image):
return self.data
# ignore masked pixels
seg_data = self.data.copy()
seg_data[image.mask] = masked_pixels_label
# this label will not be used for statistic computation
return seg_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 _relabel_masked refactored with the following changes:

Comment on lines -1861 to +1849
d = {4: 1, 8: 2}.get(connectivity)
if d:
if d := {4: 1, 8: 2}.get(connectivity):
Copy link
Author

Choose a reason for hiding this comment

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

Function dilate refactored with the following changes:

Comment on lines -2271 to +2257
assert origin in (0, 1)
assert origin in {0, 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 format_term refactored with the following changes:

raise ValueError('Invalid edge_cutoffs %s' % edge_cutoffs)
raise ValueError(f'Invalid edge_cutoffs {edge_cutoffs}')
Copy link
Author

Choose a reason for hiding this comment

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

Function make_border_mask refactored with the following changes:

if deblend and not no_sources:
if deblend:
Copy link
Author

Choose a reason for hiding this comment

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

Function detect refactored with the following changes:

# check if we are done. Jacob's stopping criterion
done = (current == start).all() and (mv == (0, -1)).all()
if done:
if done := (current == start).all() and (mv == (0, -1)).all():
Copy link
Author

Choose a reason for hiding this comment

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

Function trace_boundary refactored with the following changes:

This removes the following comments ( why? ):

# check if we are done. Jacob's stopping criterion

Comment on lines -965 to +958
dtype = []
for key in keys:
dtype.append(
self._adapt_dtype(self.models[key], ())
)
return dtype
return [self._adapt_dtype(self.models[key], ()) for key in keys]
Copy link
Author

Choose a reason for hiding this comment

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

Function CompoundModel.get_dtype refactored with the following changes:

Comment on lines -979 to +975
if out_shape == 1:
out_shape = ()
else:
out_shape = int2tup(out_shape)

out_shape = () if out_shape == 1 else int2tup(out_shape)
dt = model.get_dtype()
if len(dt) == 1: # simple model
name, base, dof = dt[0]
dof = int2tup(dof)
# extend shape of dtype
return model.name, base, out_shape + dof
else: # compound model
if len(dt) != 1:
# structured dtype - nest!
return model.name, dt, out_shape
name, base, dof = dt[0]
dof = int2tup(dof)
# extend shape of dtype
return model.name, base, out_shape + dof
Copy link
Author

Choose a reason for hiding this comment

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

Function CompoundModel._adapt_dtype refactored with the following changes:

This removes the following comments ( why? ):

# compound model
# simple model

self.logger.debug('Guessed: (%s)' % ', '.join(map(decimal_repr, p0)))
self.logger.debug(f"Guessed: ({', '.join(map(decimal_repr, p0))})")
Copy link
Author

Choose a reason for hiding this comment

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

Function lmMixin.fit refactored with the following changes:

This removes the following comments ( why? ):

# model "converged" to the initial values

Comment on lines -156 to +161
def __new__(meta, name, bases, namespace):
def __new__(cls, name, bases, namespace):
for base in bases:
for mn, method in inspect.getmembers(base, inspect.isfunction):
if (mn in method_names):
# decorate the method
namespace[mn] = convert_params(method)
return type.__new__(meta, name, bases, namespace)
return type.__new__(cls, name, bases, namespace)
Copy link
Author

Choose a reason for hiding this comment

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

Function lmModelFactory.lmConvertMeta.__new__ refactored with the following changes:

if isinstance(data, Parameters):
return data.npar
else:
return np.shape(data)
return data.npar if isinstance(data, Parameters) else np.shape(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 get_shape refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jul 1, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.05%.

Quality metrics Before After Change
Complexity 4.25 ⭐ 4.12 ⭐ -0.13 👍
Method Length 52.97 ⭐ 52.79 ⭐ -0.18 👍
Working memory 9.93 😞 9.95 😞 0.02 👎
Quality 67.72% 🙂 67.77% 🙂 0.05% 👍
Other metrics Before After Change
Lines 16978 16735 -243
Changed files Quality Before Quality After Quality Change
src/obstools/airmass.py 75.31% ⭐ 75.76% ⭐ 0.45% 👍
src/obstools/ephemeris.py 84.26% ⭐ 84.81% ⭐ 0.55% 👍
src/obstools/rkcat.py 74.97% 🙂 75.14% ⭐ 0.17% 👍
src/obstools/utils.py 77.44% ⭐ 77.23% ⭐ -0.21% 👎
src/obstools/aps/ApertureCollections.py 81.54% ⭐ 81.46% ⭐ -0.08% 👎
src/obstools/image/calibration.py 92.82% ⭐ 92.36% ⭐ -0.46% 👎
src/obstools/image/mosaic.py 66.83% 🙂 66.88% 🙂 0.05% 👍
src/obstools/image/registration.py 66.32% 🙂 66.45% 🙂 0.13% 👍
src/obstools/image/transforms.py 84.86% ⭐ 84.95% ⭐ 0.09% 👍
src/obstools/image/utils.py 55.47% 🙂 55.49% 🙂 0.02% 👍
src/obstools/image/segmentation/core.py 67.57% 🙂 67.56% 🙂 -0.01% 👎
src/obstools/image/segmentation/detect.py 37.30% 😞 37.51% 😞 0.21% 👍
src/obstools/image/segmentation/trace.py 37.91% 😞 38.20% 😞 0.29% 👍
src/obstools/lc/ascii.py 70.01% 🙂 69.71% 🙂 -0.30% 👎
src/obstools/modelling/core.py 76.30% ⭐ 76.61% ⭐ 0.31% 👍
src/obstools/modelling/lm_compat.py 75.36% ⭐ 75.59% ⭐ 0.23% 👍
src/obstools/modelling/parameters.py 83.86% ⭐ 84.63% ⭐ 0.77% 👍
src/obstools/modelling/utils.py 94.67% ⭐ 89.65% ⭐ -5.02% 👎
src/obstools/modelling/image/core.py 78.65% ⭐ 78.68% ⭐ 0.03% 👍
src/obstools/modelling/image/diagnostics.py 39.91% 😞 39.95% 😞 0.04% 👍
src/obstools/modelling/psf/models.py 79.21% ⭐ 79.42% ⭐ 0.21% 👍
src/obstools/phot/init.py 92.22% ⭐ 94.68% ⭐ 2.46% 👍
src/obstools/phot/campaign.py 72.48% 🙂 72.32% 🙂 -0.16% 👎
src/obstools/phot/diagnostics.py 51.09% 🙂 51.07% 🙂 -0.02% 👎
src/obstools/phot/gui.py 66.34% 🙂 66.50% 🙂 0.16% 👍
src/obstools/phot/proc.py 59.31% 🙂 60.28% 🙂 0.97% 👍
src/obstools/phot/utils.py 94.16% ⭐ 94.15% ⭐ -0.01% 👎
src/obstools/phot/tracking/core.py 59.74% 🙂 59.67% 🙂 -0.07% 👎
src/obstools/plan/limits.py 67.23% 🙂 68.50% 🙂 1.27% 👍
src/obstools/plan/skytracks.py 68.30% 🙂 68.11% 🙂 -0.19% 👎
src/obstools/transients/master.py 67.82% 🙂 66.78% 🙂 -1.04% 👎
tests/image/test_registration.py 92.16% ⭐ 92.29% ⭐ 0.13% 👍
tests/image/test_segmentation.py 80.34% ⭐ 80.76% ⭐ 0.42% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
src/obstools/phot/diagnostics.py plot_position_measures 46 ⛔ 682 ⛔ 27 ⛔ 5.45% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/obstools/image/segmentation/detect.py detect_loop 36 ⛔ 466 ⛔ 25 ⛔ 9.50% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/obstools/phot/proc.py FrameProcessor.optimal_aperture_photometry 22 😞 330 ⛔ 26 ⛔ 18.31% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/obstools/image/segmentation/core.py format_term 22 😞 404 ⛔ 19 ⛔ 20.11% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/obstools/phot/tracking/core.py StarTracker.from_images 11 🙂 550 ⛔ 26 ⛔ 24.66% ⛔ Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


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!

Help us improve this quality report!

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.

0 participants