Repository navigation
Deprecate undefined data type management in radon function - #4131
Conversation
| if theta is None: | ||
| theta = np.arange(180) | ||
|
|
||
| image = convert_to_float(image, preserve_range) |
There was a problem hiding this comment.
I think I would feel better with a deprecation cycle. This kind of unit change is REALLY annoying pin down, and a warning can go a long way.
There was a problem hiding this comment.
This deprecation warning should only be raised when a non float array is provided, right? But this is strange since the doc says that only float array is supported.
There was a problem hiding this comment.
The challenges encountered here are why this deserves its own PR. I would identify the cases where the behavior is changed, and warn only on those.
Finally, update the documentation specifying the support for uint8 if you want. If you don't, keep it as is.
There was a problem hiding this comment.
Yes, I agree, the addition of a new parameter can't be harmless. I will write a test to assert the multiple data types support.
The use of convert_to_float allows to use any data type, so I think that it is enough to simply remove the restriction to float in the doc.
|
When |
|
|
||
|
|
||
| def radon(image, theta=None, circle=True): | ||
| def radon(image, theta=None, circle=True, preserve_range=False): |
There was a problem hiding this comment.
To keep the old behavior going, this should be set to None with a warning for users that it will change in a future version.
@jni, this function's documentation only included support for floating point types, but actually accepted integer types. Should we follow the general deprecation procedure?
There was a problem hiding this comment.
Actually, setting preserve_range to True keeps the actual behavior unchanged since the actual version of convert_to_float directly convert any array to double when preserve_range is True.
When preserve_range is False, img_as_float is called, and in this case, non float arrays are rescaled betweeen 0 and 1. The backward compatibility may be broken here.
Should we raise a deprecation warning when preserve_range is False and dtype is not floating?
There was a problem hiding this comment.
Right, so I was suggesting we go through a deprecation cycle.
- Set
preserve_range=Noneby default. - If not set, and we have integer types, raise a warning, and set it to True
- In 0.18, make it
Falseby default.
| theta = np.arange(180) | ||
|
|
||
| if preserve_range is None and np.issubdtype(image.dtype, np.integer): | ||
| warn('Image dtype is not float. To keep old behavior, ' |
There was a problem hiding this comment.
This needs to be fleshed out a little more.
Imge dtype is not float. By default radon will assume you want to preserve the range of your image (preserve_range=True). In scikit-image 0.18 this behavior will change to preserve_range=False. To avoid this warning, explictiely specify the preserve_range parameter.
|
|
||
|
|
||
| def radon(image, theta=None, circle=True): | ||
| def radon(image, theta=None, circle=True, preserve_range=None): |
There was a problem hiding this comment.
| def radon(image, theta=None, circle=True, preserve_range=None): | |
| def radon(image, theta=None, circle=True, *, preserve_range=None): |
These kind of "behavior" parameters should definitely be made keyword only (something that wasn't possible in python 2.7)
This way #4128 issue and its equivalent for |
| '(preserve_range=True). In scikit-image 0.18 this behavior will' | ||
| 'change to preserve_range=False. To avoid this warning,' | ||
| 'explictiely specify the preserve_range parameter.', | ||
| DeprecationWarning) |
There was a problem hiding this comment.
I don't like DeprecationWarning, it tends to get hidden if it isn't called directly by __main__, and users won't get the warning. Let it be a standard warning, or FutureWarning.
| DeprecationWarning) | |
| stacklevel=2) |
For us, Deperecations will actually break things for users in 2 versions (1 year).
| if preserve_range is None and np.issubdtype(image.dtype, np.integer): | ||
| warn('Image dtype is not float. By default radon will assume' | ||
| 'you want to preserve the range of your image' | ||
| '(preserve_range=True). In scikit-image 0.18 this behavior will' |
There was a problem hiding this comment.
you need spaces just before each closing quote.
| T = np.deg2rad(theta) | ||
| R = np.array([[np.cos(T), np.sin(T), 0], | ||
| [-np.sin(T), np.cos(T), 0], | ||
| c, s = np.cos(T), np.sin(T) |
There was a problem hiding this comment.
| c, s = np.cos(T), np.sin(T) | |
| cos_T, sin_T = np.cos(T), np.sin(T) |
| R = np.array([[np.cos(T), np.sin(T), 0], | ||
| [-np.sin(T), np.cos(T), 0], | ||
| c, s = np.cos(T), np.sin(T) | ||
| R = np.array([[c, s, 0], |
There was a problem hiding this comment.
| R = np.array([[c, s, 0], | |
| R = np.array([[ cos_T, sin_T, 0], |
| [-np.sin(T), np.cos(T), 0], | ||
| c, s = np.cos(T), np.sin(T) | ||
| R = np.array([[c, s, 0], | ||
| [-s, c, 0], |
There was a problem hiding this comment.
| [-s, c, 0], | |
| [-sin_T, cos_T, 0], |
|
|
||
|
|
||
| @testing.parametrize("shape, circle", | ||
| @testing.parametrize("shape, circle, dtype, preserve_range", |
There was a problem hiding this comment.
this is extremely confusing. You can just have multiple parametrize decorators which becomes much more readable. One decorator per parameter. itertools product is pretty obscur for science programming.
There was a problem hiding this comment.
I agree, just wanted to keep the same test structure as before. Can I also rename the parameter lists 😄 ?
| def test_radon_center_rectangular(shape): | ||
| check_radon_center(shape, False) | ||
| # @testing.parametrize("shape", rectangular_shapes) | ||
| @testing.parametrize("shape, dtype, preserve_range", |
There was a problem hiding this comment.
same thing for this use of itertools product.
|
|
||
| rectangular_shapes = [(32, 16), (33, 17)] | ||
| dtype_for_test_radon_center = [np.float64, np.float32, np.uint8, bool] | ||
| preserve_range_for_test_radon_center = [True, False] |
There was a problem hiding this comment.
once you stop using itertools product, these definitions are likely useless too.
hmaarrfk
left a comment
There was a problem hiding this comment.
A few nitpicks regarding the design of the tests. I know you were trying to follow the old style, but it is clear that that style isn't manageable. Whatever happens, I think it is ready for somebody else to take a look at.
…into Fix_radon_data_type_management
…into Fix_radon_data_type_management
…into Fix_radon_data_type_management
|
I resolved the conflicts with #4136, everything is fine now ;-) |
Description
Fixes #4130 and #3799.
Checklist
./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x