-
Notifications
You must be signed in to change notification settings - Fork 18
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
Crop edges update simplified #177
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,47 +23,18 @@ | |
|
||
from numpy import isnan | ||
from warnings import warn | ||
from lumispy.utils.signals import crop_edges | ||
|
||
|
||
class CommonLumi: | ||
"""**General luminescence signal class (dimensionless)**""" | ||
|
||
def crop_edges(self, crop_px): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make our work for the 1.0 release easier, add a comment in the line before: |
||
"""Crop the amount of pixels from the four edges of the scanning | ||
region, from out the edges inwards. | ||
|
||
Parameters | ||
---------- | ||
crop_px : int | ||
Amount of pixels to be cropped on each side individually. | ||
|
||
Returns | ||
------- | ||
signal_cropped : CommonLuminescence | ||
A smaller cropped CL signal object. If inplace is True, the original | ||
object is modified and no LumiSpectrum is returned. | ||
""" | ||
|
||
width = self.axes_manager.shape[0] | ||
height = self.axes_manager.shape[1] | ||
|
||
if crop_px * 2 > width or crop_px * 2 > height: | ||
raise ValueError( | ||
"The pixels to be cropped cannot be larger than half the width or the length!" | ||
) | ||
else: | ||
signal_cropped = self.inav[ | ||
crop_px + 1 : width - crop_px + 1, crop_px + 1 : height - crop_px + 1 | ||
] | ||
|
||
# Store transformation in metadata (or update the value if already previously transformed) | ||
|
||
try: | ||
signal_cropped.metadata.Signal.cropped_edges += crop_px | ||
except AttributeError: | ||
signal_cropped.metadata.set_item("Signal.cropped_edges", crop_px) | ||
|
||
return signal_cropped | ||
warn( | ||
"This function is deprecated and will be deleted in v1.0. Please use ``sc = lum.utils.crop_edges(s)`` instead with the ``crop_range`` parameter instead.", | ||
DeprecationWarning, | ||
) | ||
return crop_edges(self, crop_px=crop_px) | ||
|
||
def remove_negative(self, basevalue=1, inplace=False): | ||
"""Sets all negative values to 'basevalue', e.g. for logarithmic scale | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,18 +23,12 @@ | |
|
||
|
||
class TestCommonLumi: | ||
def test_crop_edges(self): | ||
def test_crop_edges_deprecated(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add comment before |
||
s1 = LumiSpectrum(np.ones((10, 10, 10))) | ||
s2 = LumiTransientSpectrum(np.ones((10, 10, 10, 10))) | ||
s3 = LumiSpectrum(np.ones((3, 3, 10))) | ||
s1 = s1.crop_edges(crop_px=2) | ||
s2 = s2.crop_edges(crop_px=2) | ||
assert s1.axes_manager.navigation_shape[0] == 6 | ||
assert s1.axes_manager.navigation_shape[1] == 6 | ||
assert s2.axes_manager.navigation_shape[0] == 6 | ||
assert s2.axes_manager.navigation_shape[1] == 6 | ||
with pytest.raises(ValueError): | ||
s3.crop_edges(crop_px=2) | ||
with pytest.warns(DeprecationWarning, match="This function is deprecated"): | ||
s2 = s1.crop_edges(crop_px=1) | ||
assert s2.axes_manager.navigation_shape[0] == 8 | ||
assert s2.axes_manager.navigation_shape[1] == 8 | ||
|
||
def test_remove_negative(self): | ||
s1 = LumiSpectrum(np.random.random((10, 10, 10))) - 0.3 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add blank line before